123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555 |
- <?php
- abstract class sfAction extends sfComponent
- {
- protected
- $security = array();
-
- public function initialize($context, $moduleName, $actionName)
- {
- parent::initialize($context, $moduleName, $actionName);
-
- if ($file = $context->getConfigCache()->checkConfig('modules/'.$this->getModuleName().'/config/security.yml', true))
- {
- require($file);
- }
- }
-
- public function preExecute()
- {
- }
-
- public function postExecute()
- {
- }
-
- public function forward404($message = null)
- {
- throw new sfError404Exception($this->get404Message($message));
- }
-
- public function forward404Unless($condition, $message = null)
- {
- if (!$condition)
- {
- throw new sfError404Exception($this->get404Message($message));
- }
- }
-
- public function forward404If($condition, $message = null)
- {
- if ($condition)
- {
- throw new sfError404Exception($this->get404Message($message));
- }
- }
-
- public function redirect404()
- {
- return $this->redirect('/'.sfConfig::get('sf_error_404_module').'/'.sfConfig::get('sf_error_404_action'));
- }
-
- public function forward($module, $action)
- {
- if (sfConfig::get('sf_logging_enabled'))
- {
- $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Forward to action "%s/%s"', $module, $action))));
- }
- $this->getController()->forward($module, $action);
- throw new sfStopException();
- }
-
- public function forwardIf($condition, $module, $action)
- {
- if ($condition)
- {
- $this->forward($module, $action);
- }
- }
-
- public function forwardUnless($condition, $module, $action)
- {
- if (!$condition)
- {
- $this->forward($module, $action);
- }
- }
-
- public function redirect($url, $statusCode = 302)
- {
- $this->getController()->redirect($url, 0, $statusCode);
- throw new sfStopException();
- }
-
- public function redirectIf($condition, $url, $statusCode = 302)
- {
- if ($condition)
- {
- $this->redirect($url, $statusCode);
- }
- }
-
- public function redirectUnless($condition, $url, $statusCode = 302)
- {
- if (!$condition)
- {
- $this->redirect($url, $statusCode);
- }
- }
-
- public function renderText($text)
- {
- $this->getResponse()->setContent($this->getResponse()->getContent().$text);
- return sfView::NONE;
- }
-
- public function getPartial($templateName, $vars = null)
- {
- $this->getContext()->getConfiguration()->loadHelpers('Partial');
- $vars = !is_null($vars) ? $vars : $this->varHolder->getAll();
- return get_partial($templateName, $vars);
- }
-
- public function renderPartial($templateName, $vars = null)
- {
- return $this->renderText($this->getPartial($templateName, $vars));
- }
-
- public function getComponent($moduleName, $componentName, $vars = null)
- {
- $this->getContext()->getConfiguration()->loadHelpers('Partial');
- $vars = !is_null($vars) ? $vars : $this->varHolder->getAll();
- return get_component($moduleName, $componentName, $vars);
- }
-
- public function renderComponent($moduleName, $componentName, $vars = null)
- {
- return $this->renderText($this->getComponent($moduleName, $componentName, $vars));
- }
-
- public function getDefaultView()
- {
- if (!sfConfig::get('sf_compat_10'))
- {
- throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');
- }
- return sfView::INPUT;
- }
-
- public function handleError()
- {
- if (!sfConfig::get('sf_compat_10'))
- {
- throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');
- }
- return sfView::ERROR;
- }
-
- public function validate()
- {
- if (!sfConfig::get('sf_compat_10'))
- {
- throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');
- }
- return true;
- }
-
- public function getSecurityConfiguration()
- {
- return $this->security;
- }
-
- public function setSecurityConfiguration($security)
- {
- $this->security = $security;
- }
-
- public function isSecure()
- {
- $actionName = strtolower($this->getActionName());
- if (isset($this->security[$actionName]['is_secure']))
- {
- return $this->security[$actionName]['is_secure'];
- }
- if (isset($this->security['all']['is_secure']))
- {
- return $this->security['all']['is_secure'];
- }
- return false;
- }
-
- public function getCredential()
- {
- $actionName = strtolower($this->getActionName());
- if (isset($this->security[$actionName]['credentials']))
- {
- $credentials = $this->security[$actionName]['credentials'];
- }
- else if (isset($this->security['all']['credentials']))
- {
- $credentials = $this->security['all']['credentials'];
- }
- else
- {
- $credentials = null;
- }
- return $credentials;
- }
-
- public function setTemplate($name, $module = null)
- {
- if (sfConfig::get('sf_logging_enabled'))
- {
- $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Change template to "%s/%s"', is_null($module) ? 'CURRENT' : $module, $name))));
- }
- if (!is_null($module))
- {
- $name = sfConfig::get('sf_app_dir').'/modules/'.$module.'/templates/'.$name;
- }
- sfConfig::set('symfony.view.'.$this->getModuleName().'_'.$this->getActionName().'_template', $name);
- }
-
- public function getTemplate()
- {
- return sfConfig::get('symfony.view.'.$this->getModuleName().'_'.$this->getActionName().'_template');
- }
-
- public function setLayout($name)
- {
- if (sfConfig::get('sf_logging_enabled'))
- {
- $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Change layout to "%s"', $name))));
- }
- sfConfig::set('symfony.view.'.$this->getModuleName().'_'.$this->getActionName().'_layout', $name);
- }
-
- public function getLayout()
- {
- return sfConfig::get('symfony.view.'.$this->getModuleName().'_'.$this->getActionName().'_layout');
- }
-
- public function setViewClass($class)
- {
- sfConfig::set('mod_'.strtolower($this->getModuleName()).'_view_class', $class);
- }
- public function getRoute()
- {
- return $this->getRequest()->getAttribute('sf_route');
- }
-
- protected function get404Message($message = null)
- {
- return is_null($message) ? sprintf('This request has been forwarded to a 404 error page by the action "%s/%s".', $this->getModuleName(), $this->getActionName()) : $message;
- }
- }
|