class Route
{
/**
- * URL of this Route
- * @var string
- */
+ * URL of this Route
+ * @var string
+ */
private $url;
/**
- * Accepted HTTP methods for this route
- * @var array
- */
+ * Accepted HTTP methods for this route.
+ *
+ * @var string[]
+ */
private $methods = array('GET', 'POST', 'PUT', 'DELETE');
/**
- * Target for this route, can be anything.
- * @var mixed
- */
+ * Target for this route, can be anything.
+ * @var mixed
+ */
private $target;
/**
- * The name of this route, used for reversed routing
- * @var string
- */
+ * The name of this route, used for reversed routing
+ * @var string
+ */
private $name;
/**
- * Custom parameter filters for this route
- * @var array
- */
+ * Custom parameter filters for this route
+ * @var array
+ */
private $filters = array();
/**
- * Array containing parameters passed through request URL
- * @var array
- */
+ * Array containing parameters passed through request URL
+ * @var array
+ */
private $parameters = array();
/**
- * @param $resource
+ * @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']) ? $config['methods'] : array();
- $this->target = isset($config['target']) ? $config['target'] : null;
+ $this->url = $resource;
+ $this->config = $config;
+ $this->methods = $config['methods'] ?: array();
+ $this->target = $config['target'] ?: null;
}
public function getUrl()
public function setUrl($url)
{
- $url = (string) $url;
+ $url = (string)$url;
// make sure that the URL is suffixed with a forward slash
if (substr($url, -1) !== '/') {
public function setName($name)
{
- $this->name = (string) $name;
+ $this->name = (string)$name;
}
public function setFilters(array $filters)
public function dispatch()
{
- $action = explode('::', $this->_config['_controller']);
+ $action = explode('::', $this->config['_controller']);
$instance = new $action[0];
call_user_func_array(array($instance, $action[1]), $this->_parameters);
}