Example #1
0
 /**
  * RouteLink constructor.
  *
  * @param $params
  * @param \HBM\DatagridBundle\Model\Route $route
  */
 public function __construct($params, Route $route)
 {
     parent::__construct();
     $this->params = $params;
     if ($route !== NULL) {
         $this->name = $route->getName();
         $this->defaults = $route->getDefaults();
     }
 }
Example #2
0
 /**
  * Checking if identified route is valid.
  *
  * @static
  * @access   private
  * @param    Route $oRoute
  * @return   boolean
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 private static function checkRoute(Route $oRoute)
 {
     $aRouteDefaults = $oRoute->getDefaults();
     // relocation
     if (Helper\Arrays::path($aRouteDefaults, 'relocate', FALSE) !== FALSE) {
         static::relocate($aRouteDefaults['relocate']);
     }
     // check controller
     static::checkControllerExistance($oRoute->getController(), Helper\Arrays::path($aRouteDefaults, 'package', NULL));
     // check action
     static::checkActionExistance($oRoute->getAction());
     return TRUE;
 }
Example #3
0
 /**
  * @param Context $context
  * @param Route $route
  * @return array
  */
 public function extract(Context $context, Route $route) : array
 {
     $names = $this->getCompiler()->getNames($route->getPattern());
     $regex = $this->getRouteCollection()->getRegex($route->getID());
     $values = $this->getCompiler()->getValues($regex, (string) $context);
     return array_intersect_key($values, array_flip($names)) + $route->getDefaults();
 }
 /**
  * @param Route $route Route object matching rules
  */
 protected function setGetData($route)
 {
     $routePath = str_replace(array('(', ')'), array('', ''), $route->getPath());
     $trim = explode('<', $routePath);
     $parsed_url = str_replace(array($this->basePath), array(''), $this->url);
     $parsed_url = preg_replace("#{$trim['0']}#", '', $parsed_url, 1);
     // sets the parameters passed in the URL
     foreach ($route->getParams() as $key => $param) {
         preg_match("#{$param}#", $parsed_url, $results);
         if (isset($results[0])) {
             $_GET[$key] = $results[0];
             $parsed_url = str_replace($results[0], '', $parsed_url);
         }
     }
     // if no parameter in the URL, it sets the default values from the table
     foreach ($route->getDefaults() as $key => $default) {
         if (!isset($_GET[$key])) {
             $_GET[$key] = $default;
         }
     }
 }
Example #5
0
 public function testSetDefaults()
 {
     $route = new Route("/");
     $route->setDefaults(array("controller" => "main"));
     $this->assertEquals(array("controller" => "main"), $route->getDefaults());
     $route->setDefaults(array("controller" => "main", "action" => "index"));
     $this->assertEquals(array("controller" => "main", "action" => "index"), $route->getDefaults());
     // add a default
     $route->setDefault("param", "one");
     $this->assertEquals(array("controller" => "main", "action" => "index", "param" => "one"), $route->getDefaults());
 }