public function dispatch($action, Sonata_TemplateView $templateView) { $this->preDispatch(); if (in_array($action, get_class_methods($this))) { $res = $this->{$action}(); if (substr($action, -6) == 'Action') { if (is_null($res) || empty($res)) { $res = self::ACTION_SUCCESS; } $templateViewName = null; $resource = $this->request->getParameter('resource'); switch ($res) { case self::ACTION_SUCCESS: $templateViewName = substr($action, 0, strlen($action) - 6); break; case self::ACTION_FAILURE: $templateViewName = 'Error'; $resource = null; break; default: $templateViewName = $res; break; } // Assign template vars $templateView->assign($this->varHolder->getAll()); // Render template and save raw data $rawData = $templateView->render($templateViewName, $resource, $this->request->getParameter('format')); // Append raw data to response body $this->response->appendToBody($rawData); } } else { $this->__call($action, array()); } $this->postDispatch(); }
if (is_null($foo)) { $foo = 'Here be dragons'; } $this->foo = $foo; } public function set($foo) { $this->foo = $foo; } public function get() { return $this->foo; } } // @Before $paramHolder = new Sonata_ParameterHolder(); $paramHolder->add($params = array('foo' => 42, 'bar' => 4711, 'baz' => new Foo())); // @After unset($paramHolder); unset($params); // @Test: ->add() $t->is($paramHolder->getAll(), $params, 'All parameters were added correctly'); $paramHolder->add(null); $t->isnt($paramHolder->getAll(), null, 'Nothing is added if NULL was given'); $paramHolder->add(array()); $t->isntSame($paramHolder->getAll(), array(), 'Nothing is added if an empty array was given'); $paramHolder->add('this fails'); $t->isnt($paramHolder->getAll(), 'this fails', 'Nothing is added if parameter isn\'t an array'); // @Test: ->get() $foo = $paramHolder->get('foo'); $t->is($foo, 42, 'The value is retrieved correctly');