Commit 637a83a8 authored by Andrzej Prusinowski's avatar Andrzej Prusinowski

shortening

parent cb0f94d8
Pipeline #3724599 (#) passed with stage
in 4 seconds
#!/usr/bin/env php
<?php
for($i=0;$i<4;$i++)if(file_exists($l=($d=__DIR__.str_repeat('/..',$i)).'/vendor/autoload.php')){require$l;break;}
while(@$i<4)if(file_exists($l=($d=__DIR__.str_repeat('/..',@$i++)).'/vendor/autoload.php')){require$l;break;}
define('D',"$d/");define('AB',"$d/web");define('E',true);
$c=new Picco\Container;$c->dispatcher=new Picco\Dispatcher;
$a=$argv;array_shift($a);App\Services::get($c);
if(!is_callable($d=[new App\Tasks,$m=array_shift($a)?:'help']))throw new Exception("Undefined task $m");
call_user_func_array($d,array_merge([$c],$a));
\ No newline at end of file
$c=new Picco\Container;$c->dispatcher=new Picco\Dispatcher;App\Services::get($c);$a=$argv;$s='array_shift';$s($a);
if(!is_callable($d=[new App\Tasks,$m=$s($a)?:'help']))throw new Exception("Undefined task $m");call_user_func_array($d,array_merge([$c],$a));
\ No newline at end of file
<?php
namespace Picco;class App{
function __construct($e){session_start();$s=$_SERVER;define('D',dirname($s['SCRIPT_FILENAME']).'/../');$l=strlen($r=@$s['PATH_INFO']);$u=explode('?',$s['REQUEST_URI'],2)[0];define('F',$l?substr($u,0,-$l):$u);define('R',rtrim($r,'/')?:'/');define('B',preg_replace('#/[^/]+\.php$#','',F).'/');define('E',$e);}
function run(){$c=new Container();$c->router=new Router(\App\Routing::get());$c->view=new View;$q=$c->controllers=new \App\Controllers;$d=$c->dispatcher=new Dispatcher;\App\Services::get($c);
function run(){$c=new Container();$c->router=new Router(\App\Routing::get());$c->view=new View;$q=$c->controllers=new\App\Controllers;$d=$c->dispatcher=new Dispatcher;\App\Services::get($c);
$t=function($f,$m)use($c,$q,$d){$r=(array)call_user_func_array([$q,$f],$m);return$d->trigger('response',[$c,&$r])?:$c->view->render($f,$r+['r'=>$c->router]);};
$d->set('error',function($c, $e)use($t){if(E)throw$e;return$t('error',[$c,$e]);});
set_error_handler(function($t,$m,$f,$l)use($c,$d){if(!error_reporting())return;echo$d->trigger('error',[$c,new\ErrorException("$m in $f line $l",500)]);die;},E_ALL);
$d->set('error',function($c,$e)use($t){if(E)throw$e;return$t('error',[$c,$e]);});
set_error_handler(function($t,$m,$f,$l)use($c,$d){if(error_reporting()){echo$d->trigger('error',[$c,new\ErrorException("$m in $f line $l",500)]);die;}},E_ALL);
try{list($f,$m)=$c->router->match(R);return$d->trigger('request',[$c,$f,$m])?:$t($f,[0=>$c]+$m);}catch(\Exception$e){return$d->trigger('error',[$c,$e]);}}}
\ No newline at end of file
<?php
namespace Picco;class Container{
protected $s=[],$r=[];
namespace Picco;class Container{protected$s,$r;
function __set($n,$v){$this->s[$n]=$v;}
function __get($n){return isset($this->r[$n])?$this->r[$n]:$this->r[$n]=$this->b($this->s[$n]);}
protected function b($s){return is_callable($s)?$s($this):$s;}}
\ No newline at end of file
function __get($n){return isset($this->r[$n])?$this->r[$n]:$this->r[$n]=is_callable($s=$this->s[$n])?$s($this):$s;}}
\ No newline at end of file
<?php
namespace Picco;class Dispatcher{
protected $e;
namespace Picco;class Dispatcher{protected$e;
function set($n,$c){$this->e[$n][]=$c;}
function trigger($n,$a){foreach((array)@$this->e[$n]as$e)if(null!==$r=call_user_func_array($e,$a))return$r;}}
\ No newline at end of file
<?php
namespace Picco;class Router{
protected $r;
namespace Picco;class Router{protected$r;
function __construct($r){$this->r=$r;}
function match($u){foreach($this->r as$n=>$p)if(preg_match("#^$p$#",$u,$m))return[$n,$m];throw new\Exception("Route for $u not found",404);}
function get($c, $o=[]){return F.(rtrim(strtr(preg_replace_callback('#\([^(]*\)#',function()use($o){static$count=0;return@$o[$count++];},$this->r[$c]),['?'=>'']),'/')?:'/');}}
\ No newline at end of file
function get($c,$o=[]){return F.(rtrim(strtr(preg_replace_callback('#\([^(]*\)#',function()use($o){static$count=0;return@$o[$count++];},$this->r[$c]),['?'=>'']),'/')?:'/');}}
\ No newline at end of file
<?php
namespace Picco;class View{function render($v, $p=[]){unset($p['v']);extract($p);ob_start();require D."views/$v.phtml";return ob_get_clean();}}
\ No newline at end of file
namespace Picco;class View{function render($v,$p=[]){unset($p['v']);extract($p);ob_start();require D."views/$v.phtml";return ob_get_clean();}}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment