[ ["link_id"] => "12312" ] ] * @var bool */ private $parametersByName; /** * @var string */ private $action; /** * @var array */ private $config; /** * @param $resource * @param array $config */ public function __construct($resource, array $config) { $this->url = $resource; $this->config = $config; $this->methods = isset($config['methods']) ? (array)$config['methods'] : array(); $this->target = isset($config['target']) ? $config['target'] : null; $this->name = isset($config['name']) ? $config['name'] : null; $this->parameters = isset($config['parameters']) ? $config['parameters'] : array(); $action = explode('::', $this->config['_controller']); $this->action = isset($action[1]) ? $action[1] : null; } public function getUrl() { return $this->url; } public function setUrl($url) { $url = (string)$url; // make sure that the URL is suffixed with a forward slash if (substr($url, -1) !== '/') { $url .= '/'; } $this->url = $url; } public function getTarget() { return $this->target; } public function setTarget($target) { $this->target = $target; } public function getMethods() { return $this->methods; } public function setMethods(array $methods) { $this->methods = $methods; } public function getName() { return $this->name; } public function setName($name) { $this->name = (string)$name; } public function setFilters(array $filters, $parametersByName = false) { $this->filters = $filters; $this->parametersByName = $parametersByName; } public function getRegex() { return preg_replace_callback('/(:\w+)/', array(&$this, 'substituteFilter'), $this->url); } private function substituteFilter($matches) { if (isset($matches[1], $this->filters[$matches[1]])) { return $this->filters[$matches[1]]; } return '([\w-%]+)'; } public function getParameters() { return $this->parameters; } public function setParameters(array $parameters) { $this->parameters = $parameters; } public function getValidRouteAction() { $action = explode('::', $this->config['_controller']); $class = @$action[0]; $method = @$action[1]; if ( !class_exists($class)) { return null; } $instance = new $class(); if (empty($action[1]) || trim($action[1]) === '') { $method = "__invoke"; } if ( !method_exists($instance, $method)) { return null; } return $this->config['_controller']; } public function dispatch() { $action = explode('::', $this->config['_controller']); $instance = new $action[0]; if ($this->parametersByName) { $this->parameters = array($this->parameters); } ob_start(); if (empty($action[1]) || trim($action[1]) === '') { // __invoke on a class call_user_func_array($instance, $this->parameters); } else { call_user_func_array(array($instance, $action[1]), $this->parameters); } $result = ob_get_clean(); return $result; } public function getAction() { return $this->action; } }