1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace Juju\App;
- require_once('dypath.class.php');
- $dir = dirname(__DIR__).'/Http/';
- require_once(realpath("{$dir}/request.class.php"));
- require_once(realpath("{$dir}/response.class.php"));
- require_once('arguments.class.php');
- use \Juju\Http\{Request, Response};
- class Path implements \JsonSerializable{
- private $handles = [];
- public $path;
- public function __construct(string $path){
- $this->path = new DyPath($path);
- }
- public function __invoke(Request $req, Response $res, Arguments $args){
- $err = null;
- $ret = true;
- foreach($this->handles as $k => $fn){
- try{
- $ret = $fn($req, $res, $args, $err) !== false;
- }catch(\Exception $e){
- $err = $e;
- }
- }
- return $ret;
- }
- public function __clone(){
-
- }
- public function __destruct(){
-
- }
- public function jsonSerialize(){
- return [
- 'dypath'=>$this->path
- ];
- }
- public function __toString(){
- return "[Path {$this->path}]";
- }
- public function handle(callable $fn){
- array_push($this->handles, $fn);
- return $this;
- }
- public function matches(string $path){
- return $this->path->matches($path);
- }
- public function args(string $path){
- return $this->path->args($path);
- }
- }
- ?>
|