Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. class Route
  2. {
  3.   protected $action;
  4.   protected $module;
  5.   protected $url;
  6.   protected $varsNames;
  7.   protected $vars = [];
  8.  
  9.   public function __construct($url, $module, $action, array $varsNames)
  10.   {
  11.     $this->setUrl($url);
  12.     $this->setModule($module);
  13.     $this->setAction($action);
  14.     $this->setVarsNames($varsNames);
  15.   }
  16.  
  17.   public function hasVars()
  18.   {
  19.     return !empty($this->varsNames);
  20.   }
  21.  
  22.   public function match($url)
  23.   {
  24.     if (preg_match('`^'.$this->url.'$`', $url, $matches))
  25.     {
  26.       return $matches;
  27.     }
  28.     else
  29.     {
  30.       return false;
  31.     }
  32.   }
  33.  
  34.   public function setAction($action)
  35.   {
  36.     if (is_string($action))
  37.     {
  38.       $this->action = $action;
  39.     }
  40.   }
  41.  
  42.   public function setModule($module)
  43.   {
  44.     if (is_string($module))
  45.     {
  46.       $this->module = $module;
  47.     }
  48.   }
  49.  
  50.   public function setUrl($url)
  51.   {
  52.     if (is_string($url))
  53.     {
  54.       $this->url = $url;
  55.     }
  56.   }
  57.  
  58.   public function setVarsNames(array $varsNames) { $this->varsNames = $varsNames; }
  59.   public function setVars(array $vars) { $this->vars = $vars; }
  60.   public function action() { return $this->action; }
  61.   public function module() { return $this->module; }
  62.   public function vars(){ return $this->vars; }
  63.   public function varsNames() { return $this->varsNames; }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement