Esempio n. 1
0
 public function testGetParam()
 {
     $expectedValue = array('name' => 'test', 'param' => array('test' => array('name' => 'test', 'value' => 'val', 'test2' => array('value' => 'val2', 'test3' => array('value' => 'yo'))), 'test2' => array('name' => 'test', 'value' => 'val', 'test2' => array('value' => 'val2', 'test3' => array('value' => 'yo')))));
     $object = new Block($expectedValue);
     $this->assertEquals('val', $object->getParam('test'));
     $this->assertEquals('val2', $object->getParam('test/test2'));
     $object->removeParam('test/test2');
     $this->assertEquals(null, $object->getParam('test/test2'));
     $this->assertEquals('val', $object->getParam('test2'));
     $object->removeParam('test2');
     $this->assertEquals(null, $object->getParam('test2'));
     $object->removeParam(null);
     $this->assertEquals(null, $object->getParam('test'));
 }
Esempio n. 2
0
 /**
  * @param mixed $block
  * @throws \App\Exception\InvalidArgumentException
  * @return $this
  */
 public function addBlock($block)
 {
     if (is_array($block)) {
         $block = new Block($block);
     } elseif (!$block instanceof Block) {
         throw new InvalidArgumentException('Block must be instance of Block or an array');
     }
     $this[$block->getName()] = $block;
     $this->isDirtyIndex = true;
     return $this;
 }
Esempio n. 3
0
 /**
  * Диспетчеризация для Controller Action блока
  *
  * @param Block $block
  * @return Response|bool
  */
 public function dispatchControllerAction($block)
 {
     try {
         $controllerParam = $block->getController();
         $actionParam = $block->getAction();
         $request = $this->getServiceManager()->get('request');
         $controllerClass = 'Application\\Controller\\Block\\' . implode('', array_map('ucfirst', explode('-', $controllerParam))) . 'Controller';
         $actionMethod = implode('', array_map('ucfirst', explode('-', $actionParam))) . 'Action';
         $actionMethod = strtolower(substr($actionMethod, 0, 1)) . substr($actionMethod, 1);
         $response = $this->getResponse();
         /** @var $controller AbstractAction */
         $controller = new $controllerClass($request, $response, $block);
         $classMethods = get_class_methods($controller);
         if (in_array('preDispatch', $classMethods)) {
             $controller->preDispatch();
         }
         $forward = $controller->getForward();
         if (!$controller->getBreakRun() && empty($forward)) {
             $actionResponse = $controller->{$actionMethod}();
             if (in_array('postDispatch', $classMethods)) {
                 $controller->postDispatch();
             }
         }
         /*
                     if (!empty($forward)) {
                         $request->setParams($forward);
                         $controller->removeForward();
                         return $this->dispatch($request, $response);
                     }*/
         return $response;
     } catch (Exception $e) {
         $response = $this->getResponse();
         $response->setException($e);
     }
     return false;
 }