/** * @param RouteParameter $Route * * @throws \Exception */ public static function registerRoute(RouteParameter $Route) { if (Access::useService()->hasAuthorization($Route->getPath())) { if (in_array($Route->getPath(), self::$Router->getRouteList())) { throw new \Exception(__CLASS__ . ' > Route already available! (' . $Route->getPath() . ')'); } else { self::$Router->addRoute($Route); } } }
/** * @param RouteParameter $Route * * @throws \Exception */ public static function registerRoute(RouteParameter $Route) { try { if (Access::useService()->hasAuthorization($Route->getPath())) { if (in_array($Route->getPath(), self::$Router->getRouteList())) { throw new \Exception(__CLASS__ . ' > Route already available! (' . $Route->getPath() . ')'); } else { self::$Router->addRoute($Route); } } if (!Access::useService()->getRightByName('/' . $Route->getPath())) { if (!in_array($Route->getPath(), self::$PublicRoutes)) { array_push(self::$PublicRoutes, '/' . $Route->getPath()); } } } catch (\Exception $Exception) { Main::runSelfHeal($Exception); } }
public function testRouteParameter() { $Route = new RouteParameter('/', 'NoClass::NoMethod'); $this->assertInternalType('string', $Route->getController()); $Route->setParameterDefault('Name', 'Value'); $this->assertInternalType('array', $Route->getParameterDefault()); $this->assertInternalType('string', $Route->getParameterDefault('Name')); $Route->setParameterPattern('Name', 'Pattern'); $this->assertInternalType('array', $Route->getParameterPattern()); $this->assertInternalType('string', $Route->getPath()); try { new RouteParameter('/', 'WrongFormat:WithController'); } catch (\Exception $E) { $this->assertInstanceOf('MOC\\V\\Component\\Router\\Component\\Exception\\ComponentException', $E); } }
/** * @param callable $Controller * @param RouteParameter $Route * * @throws MissingParameterException * @return array */ private function handleArguments($Controller, RouteParameter $Route) { $Reflection = new \ReflectionMethod($Controller[0], $Controller[1]); $MethodParameters = $Reflection->getParameters(); $RequestParameters = HttpKernel::getRequest()->getParameterArray(); $MethodArguments = array(); /** @var \ReflectionParameter $MethodParameter */ foreach ((array) $MethodParameters as $MethodParameter) { // @codeCoverageIgnoreStart if (array_key_exists($MethodParameter->name, $RequestParameters)) { $MethodArguments[] = $RequestParameters[$MethodParameter->name]; } elseif (array_key_exists($MethodParameter->name, $Route->getParameterDefault())) { $MethodArguments[] = $Route->getParameterDefault($MethodParameter->name); } elseif ($MethodParameter->isDefaultValueAvailable()) { $MethodArguments[] = $MethodParameter->getDefaultValue(); } else { throw new MissingParameterException($MethodParameter->name); } // @codeCoverageIgnoreEnd } return $MethodArguments; }
/** * @param RouteParameter $RouteOption * * @return IBridgeInterface */ public function addRoute(RouteParameter $RouteOption) { $this->SymfonyRouteCollection->add($RouteOption->getPath(), new Route($RouteOption->getPath(), array_merge(array('_controller' => $RouteOption->getController()), $RouteOption->getParameterDefault()), $RouteOption->getParameterPattern())); return $this; }