コード例 #1
0
ファイル: EventsTest.php プロジェクト: splot/framework
 /**
  * @covers \Splot\Framework\Events\ControllerWillRespond::__construct
  * @covers \Splot\Framework\Events\ControllerWillRespond::getControllerName
  * @covers \Splot\Framework\Events\ControllerWillRespond::getController
  * @covers \Splot\Framework\Events\ControllerWillRespond::getMethod
  * @covers \Splot\Framework\Events\ControllerWillRespond::getArguments
  * @covers \Splot\Framework\Events\ControllerWillRespond::setArguments
  * @covers \Splot\Framework\Events\ControllerWillRespond::setMethod
  */
 public function testControllerWillRespond()
 {
     $controller = new TestController(new Container());
     $arguments = array('id' => 123);
     $event = new Events\ControllerWillRespond('SplotTestModule:TestController', $controller, 'index', $arguments);
     $this->assertEquals('SplotTestModule:TestController', $event->getControllerName());
     $this->assertSame($controller, $event->getController());
     $this->assertEquals('index', $event->getMethod());
     $this->assertEquals($arguments, $event->getArguments());
     $event->setMethod('customMethod');
     $this->assertEquals('customMethod', $event->getMethod());
     $newArguments = array('id' => 15);
     $event->setArguments($newArguments);
     $this->assertEquals($newArguments, $event->getArguments());
 }
コード例 #2
0
 /**
  * When the found controller method wants to have the request injected,
  * this method will do it.
  * 
  * @param  ControllerWillRespond $event Event triggered before execution of controller.
  */
 public function injectRequest(ControllerWillRespond $event)
 {
     $route = $this->router->getRoute($event->getControllerName());
     // find the method's meta data
     $methods = $route->getMethods();
     $i = ArrayUtils::search($methods, 'method', $event->getMethod());
     if ($i === false) {
         return;
     }
     $method = $methods[$i];
     $arguments = $event->getArguments();
     foreach ($method['params'] as $i => $param) {
         if ($param['class'] && Debugger::isExtending($param['class'], Request::class, true) && !$arguments[$i] instanceof Request) {
             $arguments[$i] = $this->request;
         }
     }
     $event->setArguments($arguments);
 }