path.class.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. require_once('dypath.class.php');
  3. class Path implements JsonSerializable{
  4. private $handles = array();
  5. public $path;
  6. public function __construct($path){
  7. $this->path = new DyPath($path);
  8. }
  9. public function __invoke($res,$args){
  10. $err = null;
  11. foreach($this->handles as $k => $fn){
  12. try{
  13. $fn($res,$args,$err);
  14. }catch(Exception $e){
  15. $err = $e;
  16. }
  17. }
  18. }
  19. public function __clone(){
  20. // No cloning for now
  21. }
  22. public function __destruct(){
  23. // Nothing to do here
  24. }
  25. public function jsonSerialize(){
  26. return array(
  27. 'dypath'=>$this->path
  28. );
  29. }
  30. public function __toString(){
  31. return "[Path {$this->path}]";
  32. }
  33. public function __get($name){
  34. switch($name){
  35. }
  36. }
  37. public function __set($name,$value){
  38. switch($name){
  39. }
  40. }
  41. public function handle(Callable $fn){
  42. array_push($this->handles,$fn);
  43. return $this;
  44. }
  45. public function matches($path){
  46. return $this->path->matches($path);
  47. }
  48. public function args($path){
  49. return $this->path->args($path);
  50. }
  51. }
  52. ?>