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;
 }
Ejemplo n.º 3
0
 /**
  * @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;
 }