thd/cache/frontend/prod/config/config_core_compile.yml.php
changeset 35 94a1dc255022
equal deleted inserted replaced
34:56befcb22751 35:94a1dc255022
       
     1 <?php
       
     2 // auto-generated by sfCompileConfigHandler
       
     3 // date: 2009/09/16 12:26:20
       
     4 
       
     5 
       
     6 class sfAutoload
       
     7 {
       
     8   static protected
       
     9     $freshCache = false,
       
    10     $instance   = null;
       
    11   protected
       
    12     $overriden = array(),
       
    13     $classes   = array();
       
    14   protected function __construct()
       
    15   {
       
    16   }
       
    17   static public function getInstance()
       
    18   {
       
    19     if (!isset(self::$instance))
       
    20     {
       
    21       self::$instance = new sfAutoload();
       
    22     }
       
    23     return self::$instance;
       
    24   }
       
    25   static public function register()
       
    26   {
       
    27     ini_set('unserialize_callback_func', 'spl_autoload_call');
       
    28     if (false === spl_autoload_register(array(self::getInstance(), 'autoload')))
       
    29     {
       
    30       throw new sfException(sprintf('Unable to register %s::autoload as an autoloading method.', get_class(self::getInstance())));
       
    31     }
       
    32   }
       
    33   static public function unregister()
       
    34   {
       
    35     spl_autoload_unregister(array(self::getInstance(), 'autoload'));
       
    36   }
       
    37   public function setClassPath($class, $path)
       
    38   {
       
    39     $this->overriden[$class] = $path;
       
    40     $this->classes[$class] = $path;
       
    41   }
       
    42   public function getClassPath($class)
       
    43   {
       
    44     return isset($this->classes[$class]) ? $this->classes[$class] : null;
       
    45   }
       
    46   public function reloadClasses($force = false)
       
    47   {
       
    48         if (self::$freshCache)
       
    49     {
       
    50       return;
       
    51     }
       
    52     $configuration = sfProjectConfiguration::getActive();
       
    53     if (!$configuration || !$configuration instanceof sfApplicationConfiguration)
       
    54     {
       
    55       return;
       
    56     }
       
    57     self::$freshCache = true;
       
    58     if (file_exists($configuration->getConfigCache()->getCacheName('config/autoload.yml')))
       
    59     {
       
    60       self::$freshCache = false;
       
    61       if ($force)
       
    62       {
       
    63         unlink($configuration->getConfigCache()->getCacheName('config/autoload.yml'));
       
    64       }
       
    65     }
       
    66     $file = $configuration->getConfigCache()->checkConfig('config/autoload.yml');
       
    67     $this->classes = include($file);
       
    68     foreach ($this->overriden as $class => $path)
       
    69     {
       
    70       $this->classes[$class] = $path;
       
    71     }
       
    72   }
       
    73   public function autoload($class)
       
    74   {
       
    75         if (!$this->classes)
       
    76     {
       
    77       self::reloadClasses();
       
    78     }
       
    79     return self::loadClass($class);
       
    80   }
       
    81   public function autoloadAgain($class)
       
    82   {
       
    83     self::reloadClasses(true);
       
    84     return self::loadClass($class);
       
    85   }
       
    86   public function loadClass($class)
       
    87   {
       
    88         if (class_exists($class, false) || interface_exists($class, false))
       
    89     {
       
    90       return true;
       
    91     }
       
    92         if (isset($this->classes[$class]))
       
    93     {
       
    94       require($this->classes[$class]);
       
    95       return true;
       
    96     }
       
    97             if (sfContext::hasInstance() && ($module = sfContext::getInstance()->getModuleName()) && isset($this->classes[$module.'/'.$class]))
       
    98     {
       
    99       require($this->classes[$module.'/'.$class]);
       
   100       return true;
       
   101     }
       
   102     return false;
       
   103   }
       
   104 }
       
   105 
       
   106 
       
   107 abstract class sfComponent
       
   108 {
       
   109   protected
       
   110     $moduleName             = '',
       
   111     $actionName             = '',
       
   112     $context                = null,
       
   113     $dispatcher             = null,
       
   114     $request                = null,
       
   115     $response               = null,
       
   116     $varHolder              = null,
       
   117     $requestParameterHolder = null;
       
   118   public function __construct($context, $moduleName, $actionName)
       
   119   {
       
   120     $this->initialize($context, $moduleName, $actionName);
       
   121   }
       
   122   public function initialize($context, $moduleName, $actionName)
       
   123   {
       
   124     $this->moduleName             = $moduleName;
       
   125     $this->actionName             = $actionName;
       
   126     $this->context                = $context;
       
   127     $this->dispatcher             = $context->getEventDispatcher();
       
   128     $this->varHolder              = new sfParameterHolder();
       
   129     $this->request                = $context->getRequest();
       
   130     $this->response               = $context->getResponse();
       
   131     $this->requestParameterHolder = $this->request->getParameterHolder();
       
   132   }
       
   133   abstract function execute($request);
       
   134   public function getModuleName()
       
   135   {
       
   136     return $this->moduleName;
       
   137   }
       
   138   public function getActionName()
       
   139   {
       
   140     return $this->actionName;
       
   141   }
       
   142   public final function getContext()
       
   143   {
       
   144     return $this->context;
       
   145   }
       
   146   public final function getLogger()
       
   147   {
       
   148     return $this->context->getLogger();
       
   149   }
       
   150   public function logMessage($message, $priority = 'info')
       
   151   {
       
   152     if (sfConfig::get('sf_logging_enabled'))
       
   153     {
       
   154       $this->dispatcher->notify(new sfEvent($this, 'application.log', array($message, 'priority' => constant('sfLogger::'.strtoupper($priority)))));
       
   155     }
       
   156   }
       
   157   public function debugMessage($message)
       
   158   {
       
   159     if (sfConfig::get('sf_web_debug') && sfConfig::get('sf_logging_enabled'))
       
   160     {
       
   161       $this->dispatcher->notify(new sfEvent(null, 'application.log', array('This feature is deprecated in favor of the log_message helper.', 'priority' => sfLogger::ERR)));
       
   162     }
       
   163   }
       
   164   public function getRequestParameter($name, $default = null)
       
   165   {
       
   166     return $this->requestParameterHolder->get($name, $default);
       
   167   }
       
   168   public function hasRequestParameter($name)
       
   169   {
       
   170     return $this->requestParameterHolder->has($name);
       
   171   }
       
   172   public function getRequest()
       
   173   {
       
   174     return $this->request;
       
   175   }
       
   176   public function getResponse()
       
   177   {
       
   178     return $this->response;
       
   179   }
       
   180   public function getController()
       
   181   {
       
   182     return $this->context->getController();
       
   183   }
       
   184   public function generateUrl($route, $params = array(), $absolute = false)
       
   185   {
       
   186     return $this->context->getRouting()->generate($route, $params, $absolute);
       
   187   }
       
   188   public function getUser()
       
   189   {
       
   190     return $this->context->getUser();
       
   191   }
       
   192   public function setVar($name, $value, $safe = false)
       
   193   {
       
   194     $this->varHolder->set($name, $safe ? new sfOutputEscaperSafe($value) : $value);
       
   195   }
       
   196   public function getVar($name)
       
   197   {
       
   198     return $this->varHolder->get($name);
       
   199   }
       
   200   public function getVarHolder()
       
   201   {
       
   202     return $this->varHolder;
       
   203   }
       
   204   public function __set($key, $value)
       
   205   {
       
   206     return $this->varHolder->setByRef($key, $value);
       
   207   }
       
   208   public function & __get($key)
       
   209   {
       
   210     return $this->varHolder->get($key);
       
   211   }
       
   212   public function __isset($name)
       
   213   {
       
   214     return $this->varHolder->has($name);
       
   215   }
       
   216   public function __unset($name)
       
   217   {
       
   218     $this->varHolder->remove($name);
       
   219   }
       
   220   public function __call($method, $arguments)
       
   221   {
       
   222     $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'component.method_not_found', array('method' => $method, 'arguments' => $arguments)));
       
   223     if (!$event->isProcessed())
       
   224     {
       
   225       throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
       
   226     }
       
   227     return $event->getReturnValue();
       
   228   }
       
   229 }
       
   230 
       
   231 
       
   232 abstract class sfAction extends sfComponent
       
   233 {
       
   234   protected
       
   235     $security = array();
       
   236   public function initialize($context, $moduleName, $actionName)
       
   237   {
       
   238     parent::initialize($context, $moduleName, $actionName);
       
   239         if ($file = $context->getConfigCache()->checkConfig('modules/'.$this->getModuleName().'/config/security.yml', true))
       
   240     {
       
   241       require($file);
       
   242     }
       
   243   }
       
   244   public function preExecute()
       
   245   {
       
   246   }
       
   247   public function postExecute()
       
   248   {
       
   249   }
       
   250   public function forward404($message = null)
       
   251   {
       
   252     throw new sfError404Exception($this->get404Message($message));
       
   253   }
       
   254   public function forward404Unless($condition, $message = null)
       
   255   {
       
   256     if (!$condition)
       
   257     {
       
   258       throw new sfError404Exception($this->get404Message($message));
       
   259     }
       
   260   }
       
   261   public function forward404If($condition, $message = null)
       
   262   {
       
   263     if ($condition)
       
   264     {
       
   265       throw new sfError404Exception($this->get404Message($message));
       
   266     }
       
   267   }
       
   268   public function redirect404()
       
   269   {
       
   270     return $this->redirect('/'.sfConfig::get('sf_error_404_module').'/'.sfConfig::get('sf_error_404_action'));
       
   271   }
       
   272   public function forward($module, $action)
       
   273   {
       
   274     if (sfConfig::get('sf_logging_enabled'))
       
   275     {
       
   276       $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Forward to action "%s/%s"', $module, $action))));
       
   277     }
       
   278     $this->getController()->forward($module, $action);
       
   279     throw new sfStopException();
       
   280   }
       
   281   public function forwardIf($condition, $module, $action)
       
   282   {
       
   283     if ($condition)
       
   284     {
       
   285       $this->forward($module, $action);
       
   286     }
       
   287   }
       
   288   public function forwardUnless($condition, $module, $action)
       
   289   {
       
   290     if (!$condition)
       
   291     {
       
   292       $this->forward($module, $action);
       
   293     }
       
   294   }
       
   295   public function redirect($url, $statusCode = 302)
       
   296   {
       
   297     $this->getController()->redirect($url, 0, $statusCode);
       
   298     throw new sfStopException();
       
   299   }
       
   300   public function redirectIf($condition, $url, $statusCode = 302)
       
   301   {
       
   302     if ($condition)
       
   303     {
       
   304       $this->redirect($url, $statusCode);
       
   305     }
       
   306   }
       
   307   public function redirectUnless($condition, $url, $statusCode = 302)
       
   308   {
       
   309     if (!$condition)
       
   310     {
       
   311       $this->redirect($url, $statusCode);
       
   312     }
       
   313   }
       
   314   public function renderText($text)
       
   315   {
       
   316     $this->getResponse()->setContent($this->getResponse()->getContent().$text);
       
   317     return sfView::NONE;
       
   318   }
       
   319   public function getPartial($templateName, $vars = null)
       
   320   {
       
   321     $this->getContext()->getConfiguration()->loadHelpers('Partial');
       
   322     $vars = !is_null($vars) ? $vars : $this->varHolder->getAll();
       
   323     return get_partial($templateName, $vars);
       
   324   }
       
   325   public function renderPartial($templateName, $vars = null)
       
   326   {
       
   327     return $this->renderText($this->getPartial($templateName, $vars));
       
   328   }
       
   329   public function getComponent($moduleName, $componentName, $vars = null)
       
   330   {
       
   331     $this->getContext()->getConfiguration()->loadHelpers('Partial');
       
   332     $vars = !is_null($vars) ? $vars : $this->varHolder->getAll();
       
   333     return get_component($moduleName, $componentName, $vars);
       
   334   }
       
   335   public function renderComponent($moduleName, $componentName, $vars = null)
       
   336   {
       
   337     return $this->renderText($this->getComponent($moduleName, $componentName, $vars));
       
   338   }
       
   339   public function getDefaultView()
       
   340   {
       
   341     if (!sfConfig::get('sf_compat_10'))
       
   342     {
       
   343       throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');
       
   344     }
       
   345     return sfView::INPUT;
       
   346   }
       
   347   public function handleError()
       
   348   {
       
   349     if (!sfConfig::get('sf_compat_10'))
       
   350     {
       
   351       throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');
       
   352     }
       
   353     return sfView::ERROR;
       
   354   }
       
   355   public function validate()
       
   356   {
       
   357     if (!sfConfig::get('sf_compat_10'))
       
   358     {
       
   359       throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');
       
   360     }
       
   361     return true;
       
   362   }
       
   363   public function getSecurityConfiguration()
       
   364   {
       
   365     return $this->security;
       
   366   }
       
   367   public function setSecurityConfiguration($security)
       
   368   {
       
   369     $this->security = $security;
       
   370   }
       
   371   public function isSecure()
       
   372   {
       
   373     $actionName = strtolower($this->getActionName());
       
   374     if (isset($this->security[$actionName]['is_secure']))
       
   375     {
       
   376       return $this->security[$actionName]['is_secure'];
       
   377     }
       
   378     if (isset($this->security['all']['is_secure']))
       
   379     {
       
   380       return $this->security['all']['is_secure'];
       
   381     }
       
   382     return false;
       
   383   }
       
   384   public function getCredential()
       
   385   {
       
   386     $actionName = strtolower($this->getActionName());
       
   387     if (isset($this->security[$actionName]['credentials']))
       
   388     {
       
   389       $credentials = $this->security[$actionName]['credentials'];
       
   390     }
       
   391     else if (isset($this->security['all']['credentials']))
       
   392     {
       
   393       $credentials = $this->security['all']['credentials'];
       
   394     }
       
   395     else
       
   396     {
       
   397       $credentials = null;
       
   398     }
       
   399     return $credentials;
       
   400   }
       
   401   public function setTemplate($name, $module = null)
       
   402   {
       
   403     if (sfConfig::get('sf_logging_enabled'))
       
   404     {
       
   405       $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Change template to "%s/%s"', is_null($module) ? 'CURRENT' : $module, $name))));
       
   406     }
       
   407     if (!is_null($module))
       
   408     {
       
   409       $name = sfConfig::get('sf_app_dir').'/modules/'.$module.'/templates/'.$name;
       
   410     }
       
   411     sfConfig::set('symfony.view.'.$this->getModuleName().'_'.$this->getActionName().'_template', $name);
       
   412   }
       
   413   public function getTemplate()
       
   414   {
       
   415     return sfConfig::get('symfony.view.'.$this->getModuleName().'_'.$this->getActionName().'_template');
       
   416   }
       
   417   public function setLayout($name)
       
   418   {
       
   419     if (sfConfig::get('sf_logging_enabled'))
       
   420     {
       
   421       $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Change layout to "%s"', $name))));
       
   422     }
       
   423     sfConfig::set('symfony.view.'.$this->getModuleName().'_'.$this->getActionName().'_layout', $name);
       
   424   }
       
   425   public function getLayout()
       
   426   {
       
   427     return sfConfig::get('symfony.view.'.$this->getModuleName().'_'.$this->getActionName().'_layout');
       
   428   }
       
   429   public function setViewClass($class)
       
   430   {
       
   431     sfConfig::set('mod_'.strtolower($this->getModuleName()).'_view_class', $class);
       
   432   }
       
   433   public function getRoute()
       
   434   {
       
   435     return $this->getRequest()->getAttribute('sf_route');
       
   436   }
       
   437   protected function get404Message($message = null)
       
   438   {
       
   439     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;
       
   440   }
       
   441 }
       
   442 
       
   443 
       
   444 abstract class sfActions extends sfAction
       
   445 {
       
   446   public function execute($request)
       
   447   {
       
   448         $actionToRun = 'execute'.ucfirst($this->getActionName());
       
   449     if ($actionToRun === 'execute')
       
   450     {
       
   451             throw new sfInitializationException(sprintf('sfAction initialization failed for module "%s". There was no action given.', $this->getModuleName()));
       
   452     }
       
   453     if (!is_callable(array($this, $actionToRun)))
       
   454     {
       
   455             throw new sfInitializationException(sprintf('sfAction initialization failed for module "%s", action "%s". You must create a "%s" method.', $this->getModuleName(), $this->getActionName(), $actionToRun));
       
   456     }
       
   457     if (sfConfig::get('sf_logging_enabled'))
       
   458     {
       
   459       $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Call "%s->%s()"', get_class($this), $actionToRun))));
       
   460     }
       
   461         return $this->$actionToRun($request);
       
   462   }
       
   463 }
       
   464 
       
   465 
       
   466 class sfActionStack
       
   467 {
       
   468   protected
       
   469     $stack = array();
       
   470   public function addEntry($moduleName, $actionName, $actionInstance)
       
   471   {
       
   472         $actionEntry = new sfActionStackEntry($moduleName, $actionName, $actionInstance);
       
   473     $this->stack[] = $actionEntry;
       
   474     return $actionEntry;
       
   475   }
       
   476   public function getEntry($index)
       
   477   {
       
   478     $retval = null;
       
   479     if ($index > -1 && $index < count($this->stack))
       
   480     {
       
   481       $retval = $this->stack[$index];
       
   482     }
       
   483     return $retval;
       
   484   }
       
   485   public function popEntry()
       
   486   {
       
   487     return array_pop($this->stack);
       
   488   }
       
   489   public function getFirstEntry()
       
   490   {
       
   491     $retval = null;
       
   492     if (isset($this->stack[0]))
       
   493     {
       
   494       $retval = $this->stack[0];
       
   495     }
       
   496     return $retval;
       
   497   }
       
   498   public function getLastEntry()
       
   499   {
       
   500     $count  = count($this->stack);
       
   501     $retval = null;
       
   502     if (isset($this->stack[0]))
       
   503     {
       
   504       $retval = $this->stack[$count - 1];
       
   505     }
       
   506     return $retval;
       
   507   }
       
   508   public function getSize()
       
   509   {
       
   510     return count($this->stack);
       
   511   }
       
   512 }
       
   513 
       
   514 
       
   515 class sfActionStackEntry
       
   516 {
       
   517   protected
       
   518     $actionInstance = null,
       
   519     $actionName     = null,
       
   520     $moduleName     = null,
       
   521     $presentation   = null;
       
   522   public function __construct($moduleName, $actionName, $actionInstance)
       
   523   {
       
   524     $this->actionName     = $actionName;
       
   525     $this->actionInstance = $actionInstance;
       
   526     $this->moduleName     = $moduleName;
       
   527   }
       
   528   public function getActionName()
       
   529   {
       
   530     return $this->actionName;
       
   531   }
       
   532   public function getActionInstance()
       
   533   {
       
   534     return $this->actionInstance;
       
   535   }
       
   536   public function getModuleName()
       
   537   {
       
   538     return $this->moduleName;
       
   539   }
       
   540   public function & getPresentation()
       
   541   {
       
   542     return $this->presentation;
       
   543   }
       
   544   public function setPresentation(&$presentation)
       
   545   {
       
   546     $this->presentation =& $presentation;
       
   547   }
       
   548 }
       
   549 
       
   550 
       
   551 class sfLoader
       
   552 {
       
   553   static public function getHelperDirs($moduleName = '')
       
   554   {
       
   555     $configuration = sfProjectConfiguration::getActive();
       
   556     $configuration->getEventDispatcher()->notify(new sfEvent(null, 'application.log', array('The sfLoader::getHelperDirs() method is deprecated. Please use the same method from sfApplicationConfiguration.', 'priority' => sfLogger::ERR)));
       
   557     return $configuration->getHelperDirs($moduleName);
       
   558   }
       
   559   static public function loadHelpers($helpers, $moduleName = '')
       
   560   {
       
   561     $configuration = sfProjectConfiguration::getActive();
       
   562     $configuration->getEventDispatcher()->notify(new sfEvent(null, 'application.log', array('The sfLoader::loadHelpers() method is deprecated. Please use the same method from sfApplicationConfiguration.', 'priority' => sfLogger::ERR)));
       
   563     return $configuration->loadHelpers($helpers, $moduleName);
       
   564   }
       
   565 }
       
   566 
       
   567 
       
   568 abstract class sfController
       
   569 {
       
   570   protected
       
   571     $context           = null,
       
   572     $dispatcher        = null,
       
   573     $controllerClasses = array(),
       
   574     $maxForwards       = 5,
       
   575     $renderMode        = sfView::RENDER_CLIENT;
       
   576   public function __construct($context)
       
   577   {
       
   578     $this->initialize($context);
       
   579   }
       
   580   public function initialize($context)
       
   581   {
       
   582     $this->context    = $context;
       
   583     $this->dispatcher = $context->getEventDispatcher();
       
   584         $this->maxForwards = sfConfig::get('sf_max_forwards', $this->maxForwards);
       
   585   }
       
   586   public function componentExists($moduleName, $componentName)
       
   587   {
       
   588     return $this->controllerExists($moduleName, $componentName, 'component', false);
       
   589   }
       
   590   public function actionExists($moduleName, $actionName)
       
   591   {
       
   592     return $this->controllerExists($moduleName, $actionName, 'action', false);
       
   593   }
       
   594   protected function controllerExists($moduleName, $controllerName, $extension, $throwExceptions)
       
   595   {
       
   596     $dirs = $this->context->getConfiguration()->getControllerDirs($moduleName);
       
   597     foreach ($dirs as $dir => $checkEnabled)
       
   598     {
       
   599             if ($checkEnabled && !in_array($moduleName, sfConfig::get('sf_enabled_modules')) && is_readable($dir))
       
   600       {
       
   601         throw new sfConfigurationException(sprintf('The module "%s" is not enabled.', $moduleName));
       
   602       }
       
   603             $classFile   = strtolower($extension);
       
   604       $classSuffix = ucfirst(strtolower($extension));
       
   605       $file        = $dir.'/'.$controllerName.$classSuffix.'.class.php';
       
   606       if (is_readable($file))
       
   607       {
       
   608                 require_once($file);
       
   609         $this->controllerClasses[$moduleName.'_'.$controllerName.'_'.$classSuffix] = $controllerName.$classSuffix;
       
   610         return true;
       
   611       }
       
   612       $module_file = $dir.'/'.$classFile.'s.class.php';
       
   613       if (is_readable($module_file))
       
   614       {
       
   615                 require_once($module_file);
       
   616         if (!class_exists($moduleName.$classSuffix.'s', false))
       
   617         {
       
   618           if ($throwExceptions)
       
   619           {
       
   620             throw new sfControllerException(sprintf('There is no "%s" class in your action file "%s".', $moduleName.$classSuffix.'s', $module_file));
       
   621           }
       
   622           return false;
       
   623         }
       
   624                 if (!in_array('execute'.ucfirst($controllerName), get_class_methods($moduleName.$classSuffix.'s')))
       
   625         {
       
   626           if ($throwExceptions)
       
   627           {
       
   628             throw new sfControllerException(sprintf('There is no "%s" method in your action class "%s".', 'execute'.ucfirst($controllerName), $moduleName.$classSuffix.'s'));
       
   629           }
       
   630           return false;
       
   631         }
       
   632         $this->controllerClasses[$moduleName.'_'.$controllerName.'_'.$classSuffix] = $moduleName.$classSuffix.'s';
       
   633         return true;
       
   634       }
       
   635     }
       
   636         if ($throwExceptions && sfConfig::get('sf_debug'))
       
   637     {
       
   638       $dirs = array_keys($dirs);
       
   639             foreach ($dirs as &$dir)
       
   640       {
       
   641         $dir = str_replace(sfConfig::get('sf_root_dir'), '%SF_ROOT_DIR%', $dir);
       
   642       }
       
   643       throw new sfControllerException(sprintf('Controller "%s/%s" does not exist in: %s.', $moduleName, $controllerName, implode(', ', $dirs)));
       
   644     }
       
   645     return false;
       
   646   }
       
   647   public function forward($moduleName, $actionName)
       
   648   {
       
   649         $moduleName = preg_replace('/[^a-z0-9_]+/i', '', $moduleName);
       
   650     $actionName = preg_replace('/[^a-z0-9_]+/i', '', $actionName);
       
   651     if ($this->getActionStack()->getSize() >= $this->maxForwards)
       
   652     {
       
   653             throw new sfForwardException(sprintf('Too many forwards have been detected for this request (> %d).', $this->maxForwards));
       
   654     }
       
   655         $this->context->getConfigCache()->import('modules/'.$moduleName.'/config/generator.yml', false, true);
       
   656     if (!$this->actionExists($moduleName, $actionName))
       
   657     {
       
   658             if (sfConfig::get('sf_logging_enabled'))
       
   659       {
       
   660         $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Action "%s/%s" does not exist', $moduleName, $actionName))));
       
   661       }
       
   662       throw new sfError404Exception(sprintf('Action "%s/%s" does not exist.', $moduleName, $actionName));
       
   663     }
       
   664         $actionInstance = $this->getAction($moduleName, $actionName);
       
   665         $this->getActionStack()->addEntry($moduleName, $actionName, $actionInstance);
       
   666         require($this->context->getConfigCache()->checkConfig('modules/'.$moduleName.'/config/module.yml'));
       
   667         if ($this->getActionStack()->getSize() == 1 && sfConfig::get('mod_'.strtolower($moduleName).'_is_internal') && !sfConfig::get('sf_test'))
       
   668     {
       
   669       throw new sfConfigurationException(sprintf('Action "%s" from module "%s" cannot be called directly.', $actionName, $moduleName));
       
   670     }
       
   671         if (sfConfig::get('mod_'.strtolower($moduleName).'_enabled'))
       
   672     {
       
   673             $moduleConfig = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/config/config.php';
       
   674       if (is_readable($moduleConfig))
       
   675       {
       
   676         require_once($moduleConfig);
       
   677       }
       
   678             $filterChain = new sfFilterChain();
       
   679       $filterChain->loadConfiguration($actionInstance);
       
   680       $this->context->getEventDispatcher()->notify(new sfEvent($this, 'controller.change_action', array('module' => $moduleName, 'action' => $actionName)));
       
   681       if ($moduleName == sfConfig::get('sf_error_404_module') && $actionName == sfConfig::get('sf_error_404_action'))
       
   682       {
       
   683         $this->context->getResponse()->setStatusCode(404);
       
   684         $this->context->getResponse()->setHttpHeader('Status', '404 Not Found');
       
   685         $this->dispatcher->notify(new sfEvent($this, 'controller.page_not_found', array('module' => $moduleName, 'action' => $actionName)));
       
   686       }
       
   687             $filterChain->execute();
       
   688     }
       
   689     else
       
   690     {
       
   691       $moduleName = sfConfig::get('sf_module_disabled_module');
       
   692       $actionName = sfConfig::get('sf_module_disabled_action');
       
   693       if (!$this->actionExists($moduleName, $actionName))
       
   694       {
       
   695                 throw new sfConfigurationException(sprintf('Invalid configuration settings: [sf_module_disabled_module] "%s", [sf_module_disabled_action] "%s".', $moduleName, $actionName));
       
   696       }
       
   697       $this->forward($moduleName, $actionName);
       
   698     }
       
   699   }
       
   700   public function getAction($moduleName, $actionName)
       
   701   {
       
   702     return $this->getController($moduleName, $actionName, 'action');
       
   703   }
       
   704   public function getComponent($moduleName, $componentName)
       
   705   {
       
   706     return $this->getController($moduleName, $componentName, 'component');
       
   707   }
       
   708   protected function getController($moduleName, $controllerName, $extension)
       
   709   {
       
   710     $classSuffix = ucfirst(strtolower($extension));
       
   711     if (!isset($this->controllerClasses[$moduleName.'_'.$controllerName.'_'.$classSuffix]))
       
   712     {
       
   713       $this->controllerExists($moduleName, $controllerName, $extension, true);
       
   714     }
       
   715     $class = $this->controllerClasses[$moduleName.'_'.$controllerName.'_'.$classSuffix];
       
   716         $moduleClass = $moduleName.'_'.$class;
       
   717     if (class_exists($moduleClass, false))
       
   718     {
       
   719       $class = $moduleClass;
       
   720     }
       
   721     return new $class($this->context, $moduleName, $controllerName);
       
   722   }
       
   723   public function getActionStack()
       
   724   {
       
   725     return $this->context->getActionStack();
       
   726   }
       
   727   public function getRenderMode()
       
   728   {
       
   729     return $this->renderMode;
       
   730   }
       
   731   public function getView($moduleName, $actionName, $viewName)
       
   732   {
       
   733         $file = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/view/'.$actionName.$viewName.'View.class.php';
       
   734     if (is_readable($file))
       
   735     {
       
   736       require_once($file);
       
   737       $class = $actionName.$viewName.'View';
       
   738             $moduleClass = $moduleName.'_'.$class;
       
   739       if (class_exists($moduleClass, false))
       
   740       {
       
   741         $class = $moduleClass;
       
   742       }
       
   743     }
       
   744     else
       
   745     {
       
   746             $class = sfConfig::get('mod_'.strtolower($moduleName).'_view_class', 'sfPHP').'View';
       
   747     }
       
   748     return new $class($this->context, $moduleName, $actionName, $viewName);
       
   749   }
       
   750   public function sendEmail($module, $action)
       
   751   {
       
   752     if (sfConfig::get('sf_logging_enabled'))
       
   753     {
       
   754       $this->dispatcher->notify(new sfEvent($this, 'application.log', array('sendEmail method is deprecated', 'priority' => sfLogger::ERR)));
       
   755     }
       
   756     return $this->getPresentationFor($module, $action, 'sfMail');
       
   757   }
       
   758   public function getPresentationFor($module, $action, $viewName = null)
       
   759   {
       
   760     if (sfConfig::get('sf_logging_enabled'))
       
   761     {
       
   762       $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Get presentation for action "%s/%s" (view class: "%s")', $module, $action, $viewName))));
       
   763     }
       
   764         $renderMode = $this->getRenderMode();
       
   765         $this->setRenderMode(sfView::RENDER_VAR);
       
   766         $actionStack = $this->getActionStack();
       
   767         $index = $actionStack->getSize();
       
   768         if ($viewName)
       
   769     {
       
   770       $currentViewName = sfConfig::get('mod_'.strtolower($module).'_view_class');
       
   771       sfConfig::set('mod_'.strtolower($module).'_view_class', $viewName);
       
   772     }
       
   773     try
       
   774     {
       
   775             $this->forward($module, $action);
       
   776     }
       
   777     catch (Exception $e)
       
   778     {
       
   779             $this->setRenderMode($renderMode);
       
   780             if ($viewName)
       
   781       {
       
   782         sfConfig::set('mod_'.strtolower($module).'_view_class', $currentViewName);
       
   783       }
       
   784       throw $e;
       
   785     }
       
   786         $actionEntry = $actionStack->getEntry($index);
       
   787         $presentation =& $actionEntry->getPresentation();
       
   788         $this->setRenderMode($renderMode);
       
   789         $nb = $actionStack->getSize() - $index;
       
   790     while ($nb-- > 0)
       
   791     {
       
   792       $actionEntry = $actionStack->popEntry();
       
   793       if ($actionEntry->getModuleName() == sfConfig::get('sf_login_module') && $actionEntry->getActionName() == sfConfig::get('sf_login_action'))
       
   794       {
       
   795         throw new sfException('Your action is secured, but the user is not authenticated.');
       
   796       }
       
   797       else if ($actionEntry->getModuleName() == sfConfig::get('sf_secure_module') && $actionEntry->getActionName() == sfConfig::get('sf_secure_action'))
       
   798       {
       
   799         throw new sfException('Your action is secured, but the user does not have access.');
       
   800       }
       
   801     }
       
   802         if ($viewName)
       
   803     {
       
   804       sfConfig::set('mod_'.strtolower($module).'_view_class', $currentViewName);
       
   805     }
       
   806     return $presentation;
       
   807   }
       
   808   public function setRenderMode($mode)
       
   809   {
       
   810     if ($mode == sfView::RENDER_CLIENT || $mode == sfView::RENDER_VAR || $mode == sfView::RENDER_NONE)
       
   811     {
       
   812       $this->renderMode = $mode;
       
   813       return;
       
   814     }
       
   815         throw new sfRenderException(sprintf('Invalid rendering mode: %s.', $mode));
       
   816   }
       
   817   public function inCLI()
       
   818   {
       
   819     return 0 == strncasecmp(PHP_SAPI, 'cli', 3);
       
   820   }
       
   821   public function __call($method, $arguments)
       
   822   {
       
   823     $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'controller.method_not_found', array('method' => $method, 'arguments' => $arguments)));
       
   824     if (!$event->isProcessed())
       
   825     {
       
   826       throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
       
   827     }
       
   828     return $event->getReturnValue();
       
   829   }
       
   830 }
       
   831 
       
   832 
       
   833 class sfDatabaseManager
       
   834 {
       
   835   protected
       
   836     $configuration = null,
       
   837     $databases     = array();
       
   838   public function __construct(sfProjectConfiguration $configuration, $options = array())
       
   839   {
       
   840     $this->initialize($configuration);
       
   841     if (!isset($options['auto_shutdown']) || $options['auto_shutdown'])
       
   842     {
       
   843       register_shutdown_function(array($this, 'shutdown'));
       
   844     }
       
   845   }
       
   846   public function initialize(sfProjectConfiguration $configuration)
       
   847   {
       
   848     $this->configuration = $configuration;
       
   849     $this->loadConfiguration();
       
   850   }
       
   851   public function loadConfiguration()
       
   852   {
       
   853     if ($this->configuration instanceof sfApplicationConfiguration)
       
   854     {
       
   855       $databases = include($this->configuration->getConfigCache()->checkConfig('config/databases.yml'));
       
   856     }
       
   857     else
       
   858     {
       
   859       $configHandler = new sfDatabaseConfigHandler();
       
   860       $databases = $configHandler->evaluate(array($this->configuration->getRootDir().'/config/databases.yml'));
       
   861     }
       
   862     foreach ($databases as $name => $database)
       
   863     {
       
   864       $this->setDatabase($name, $database);
       
   865     }
       
   866   }
       
   867   public function setDatabase($name, sfDatabase $database)
       
   868   {
       
   869     $this->databases[$name] = $database;
       
   870   }
       
   871   public function getDatabase($name = 'default')
       
   872   {
       
   873     if (isset($this->databases[$name]))
       
   874     {
       
   875       return $this->databases[$name];
       
   876     }
       
   877         throw new sfDatabaseException(sprintf('Database "%s" does not exist.', $name));
       
   878   }
       
   879   public function getNames()
       
   880   {
       
   881     return array_keys($this->databases);
       
   882   }
       
   883   public function shutdown()
       
   884   {
       
   885         foreach ($this->databases as $database)
       
   886     {
       
   887       $database->shutdown();
       
   888     }
       
   889   }
       
   890 }
       
   891 
       
   892 
       
   893 class sfEvent implements ArrayAccess
       
   894 {
       
   895   protected
       
   896     $value      = null,
       
   897     $processed  = false,
       
   898     $subject    = null,
       
   899     $name       = '',
       
   900     $parameters = null;
       
   901   public function __construct($subject, $name, $parameters = array())
       
   902   {
       
   903     $this->subject = $subject;
       
   904     $this->name = $name;
       
   905     $this->parameters = $parameters;
       
   906   }
       
   907   public function getSubject()
       
   908   {
       
   909     return $this->subject;
       
   910   }
       
   911   public function getName()
       
   912   {
       
   913     return $this->name;
       
   914   }
       
   915   public function setReturnValue($value)
       
   916   {
       
   917     $this->value = $value;
       
   918   }
       
   919   public function getReturnValue()
       
   920   {
       
   921     return $this->value;
       
   922   }
       
   923   public function setProcessed($processed)
       
   924   {
       
   925     $this->processed = (boolean) $processed;
       
   926   }
       
   927   public function isProcessed()
       
   928   {
       
   929     return $this->processed;
       
   930   }
       
   931   public function getParameters()
       
   932   {
       
   933     return $this->parameters;
       
   934   }
       
   935   public function offsetExists($name)
       
   936   {
       
   937     return array_key_exists($name, $this->parameters);
       
   938   }
       
   939   public function offsetGet($name)
       
   940   {
       
   941     if (!array_key_exists($name, $this->parameters))
       
   942     {
       
   943       throw new InvalidArgumentException(sprintf('The event "%s" has no "%s" parameter.', $this->name, $name));
       
   944     }
       
   945     return $this->parameters[$name];
       
   946   }
       
   947   public function offsetSet($name, $value)
       
   948   {
       
   949     $this->parameters[$name] = $value;
       
   950   }
       
   951   public function offsetUnset($name)
       
   952   {
       
   953     unset($this->parameters[$name]);
       
   954   }
       
   955 }
       
   956 
       
   957 
       
   958 abstract class sfFilter
       
   959 {
       
   960   protected
       
   961     $parameterHolder = null,
       
   962     $context         = null;
       
   963   public static
       
   964     $filterCalled    = array();
       
   965   public function __construct($context, $parameters = array())
       
   966   {
       
   967     $this->initialize($context, $parameters);
       
   968   }
       
   969   public function initialize($context, $parameters = array())
       
   970   {
       
   971     $this->context = $context;
       
   972     $this->parameterHolder = new sfParameterHolder();
       
   973     $this->parameterHolder->add($parameters);
       
   974     return true;
       
   975   }
       
   976   protected function isFirstCall()
       
   977   {
       
   978     $class = get_class($this);
       
   979     if (isset(self::$filterCalled[$class]))
       
   980     {
       
   981       return false;
       
   982     }
       
   983     else
       
   984     {
       
   985       self::$filterCalled[$class] = true;
       
   986       return true;
       
   987     }
       
   988   }
       
   989   public final function getContext()
       
   990   {
       
   991     return $this->context;
       
   992   }
       
   993   public function getParameterHolder()
       
   994   {
       
   995     return $this->parameterHolder;
       
   996   }
       
   997   public function getParameter($name, $default = null)
       
   998   {
       
   999     return $this->parameterHolder->get($name, $default);
       
  1000   }
       
  1001   public function hasParameter($name)
       
  1002   {
       
  1003     return $this->parameterHolder->has($name);
       
  1004   }
       
  1005   public function setParameter($name, $value)
       
  1006   {
       
  1007     return $this->parameterHolder->set($name, $value);
       
  1008   }
       
  1009 }
       
  1010 
       
  1011 
       
  1012 class sfCommonFilter extends sfFilter
       
  1013 {
       
  1014   public function execute($filterChain)
       
  1015   {
       
  1016         $filterChain->execute();
       
  1017         $response = $this->context->getResponse();
       
  1018         $content = $response->getContent();
       
  1019     if (false !== ($pos = strpos($content, '</head>')))
       
  1020     {
       
  1021       $this->context->getConfiguration()->loadHelpers(array('Tag', 'Asset'));
       
  1022       $html = '';
       
  1023       if (!sfConfig::get('symfony.asset.javascripts_included', false))
       
  1024       {
       
  1025         $html .= get_javascripts($response);
       
  1026       }
       
  1027       if (!sfConfig::get('symfony.asset.stylesheets_included', false))
       
  1028       {
       
  1029         $html .= get_stylesheets($response);
       
  1030       }
       
  1031       if ($html)
       
  1032       {
       
  1033         $response->setContent(substr($content, 0, $pos).$html.substr($content, $pos));
       
  1034       }
       
  1035     }
       
  1036     sfConfig::set('symfony.asset.javascripts_included', false);
       
  1037     sfConfig::set('symfony.asset.stylesheets_included', false);
       
  1038   }
       
  1039 }
       
  1040 
       
  1041 
       
  1042 class sfExecutionFilter extends sfFilter
       
  1043 {
       
  1044   public function execute($filterChain)
       
  1045   {
       
  1046         $actionInstance = $this->context->getController()->getActionStack()->getLastEntry()->getActionInstance();
       
  1047         if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled'))
       
  1048     {
       
  1049       $timer = sfTimerManager::getTimer(sprintf('Action "%s/%s"', $actionInstance->getModuleName(), $actionInstance->getActionName()));
       
  1050       $viewName = $this->handleAction($filterChain, $actionInstance);
       
  1051       $timer->addTime();
       
  1052       $timer = sfTimerManager::getTimer(sprintf('View "%s" for "%s/%s"', $viewName, $actionInstance->getModuleName(), $actionInstance->getActionName()));
       
  1053       $this->handleView($filterChain, $actionInstance, $viewName);
       
  1054       $timer->addTime();
       
  1055     }
       
  1056     else
       
  1057     {
       
  1058       $viewName = $this->handleAction($filterChain, $actionInstance);
       
  1059       $this->handleView($filterChain, $actionInstance, $viewName);
       
  1060     }
       
  1061   }
       
  1062   protected function handleAction($filterChain, $actionInstance)
       
  1063   {
       
  1064     $uri = $this->context->getRouting()->getCurrentInternalUri();
       
  1065     if (sfConfig::get('sf_cache') && !is_null($uri) && $this->context->getViewCacheManager()->hasActionCache($uri))
       
  1066     {
       
  1067             return sfView::SUCCESS;
       
  1068     }
       
  1069     return $this->executeAction($actionInstance);
       
  1070   }
       
  1071   protected function executeAction($actionInstance)
       
  1072   {
       
  1073         $actionInstance->preExecute();
       
  1074     $viewName = $actionInstance->execute($this->context->getRequest());
       
  1075     $actionInstance->postExecute();
       
  1076     return is_null($viewName) ? sfView::SUCCESS : $viewName;
       
  1077   }
       
  1078   protected function handleView($filterChain, $actionInstance, $viewName)
       
  1079   {
       
  1080     switch ($viewName)
       
  1081     {
       
  1082       case sfView::HEADER_ONLY:
       
  1083         $this->context->getResponse()->setHeaderOnly(true);
       
  1084         return;
       
  1085       case sfView::NONE:
       
  1086         return;
       
  1087     }
       
  1088     $this->executeView($actionInstance->getModuleName(), $actionInstance->getActionName(), $viewName, $actionInstance->getVarHolder()->getAll());
       
  1089   }
       
  1090   protected function executeView($moduleName, $actionName, $viewName, $viewAttributes)
       
  1091   {
       
  1092     $controller = $this->context->getController();
       
  1093         $view = $controller->getView($moduleName, $actionName, $viewName);
       
  1094         $view->execute();
       
  1095         $view->getAttributeHolder()->add($viewAttributes);
       
  1096         switch ($controller->getRenderMode())
       
  1097     {
       
  1098       case sfView::RENDER_NONE:
       
  1099         break;
       
  1100       case sfView::RENDER_CLIENT:
       
  1101         $viewData = $view->render();
       
  1102         $this->context->getResponse()->setContent($viewData);
       
  1103         break;
       
  1104       case sfView::RENDER_VAR:
       
  1105         $viewData = $view->render();
       
  1106         $controller->getActionStack()->getLastEntry()->setPresentation($viewData);
       
  1107         break;
       
  1108     }
       
  1109   }
       
  1110 }
       
  1111 
       
  1112 
       
  1113 class sfRenderingFilter extends sfFilter
       
  1114 {
       
  1115   public function execute($filterChain)
       
  1116   {
       
  1117         $filterChain->execute();
       
  1118         $response = $this->context->getResponse();
       
  1119         if (sfForm::hasToStringException())
       
  1120     {
       
  1121       throw sfForm::getToStringException();
       
  1122     }
       
  1123     else if (sfFormField::hasToStringException())
       
  1124     {
       
  1125       throw sfFormField::getToStringException();
       
  1126     }
       
  1127         $response->send();
       
  1128   }
       
  1129 }
       
  1130 
       
  1131 
       
  1132 class sfFilterChain
       
  1133 {
       
  1134   protected
       
  1135     $chain = array(),
       
  1136     $index = -1;
       
  1137   public function loadConfiguration($actionInstance)
       
  1138   {
       
  1139     require(sfContext::getInstance()->getConfigCache()->checkConfig('modules/'.$actionInstance->getModuleName().'/config/filters.yml'));
       
  1140   }
       
  1141   public function execute()
       
  1142   {
       
  1143         ++$this->index;
       
  1144     if ($this->index < count($this->chain))
       
  1145     {
       
  1146       if (sfConfig::get('sf_logging_enabled'))
       
  1147       {
       
  1148         sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array(sprintf('Executing filter "%s"', get_class($this->chain[$this->index])))));
       
  1149       }
       
  1150             $this->chain[$this->index]->execute($this);
       
  1151     }
       
  1152   }
       
  1153   public function hasFilter($class)
       
  1154   {
       
  1155     foreach ($this->chain as $filter)
       
  1156     {
       
  1157       if ($filter instanceof $class)
       
  1158       {
       
  1159         return true;
       
  1160       }
       
  1161     }
       
  1162     return false;
       
  1163   }
       
  1164   public function register($filter)
       
  1165   {
       
  1166     $this->chain[] = $filter;
       
  1167   }
       
  1168 }
       
  1169 
       
  1170 
       
  1171 abstract class sfLogger
       
  1172 {
       
  1173   const EMERG   = 0;   const ALERT   = 1;   const CRIT    = 2;   const ERR     = 3;   const WARNING = 4;   const NOTICE  = 5;   const INFO    = 6;   const DEBUG   = 7;
       
  1174   protected
       
  1175     $level = self::INFO;
       
  1176   public function __construct(sfEventDispatcher $dispatcher, $options = array())
       
  1177   {
       
  1178     $this->initialize($dispatcher, $options);
       
  1179     if (!isset($options['auto_shutdown']) || $options['auto_shutdown'])
       
  1180     {
       
  1181       register_shutdown_function(array($this, 'shutdown'));
       
  1182     }
       
  1183   }
       
  1184   public function initialize(sfEventDispatcher $dispatcher, $options = array())
       
  1185   {
       
  1186     if (isset($options['level']))
       
  1187     {
       
  1188       $this->setLogLevel($options['level']);
       
  1189     }
       
  1190     $dispatcher->connect('application.log', array($this, 'listenToLogEvent'));
       
  1191   }
       
  1192   public function getLogLevel()
       
  1193   {
       
  1194     return $this->level;
       
  1195   }
       
  1196   public function setLogLevel($level)
       
  1197   {
       
  1198     if (!is_int($level))
       
  1199     {
       
  1200       $level = constant('sfLogger::'.strtoupper($level));
       
  1201     }
       
  1202     $this->level = $level;
       
  1203   }
       
  1204   public function log($message, $priority = self::INFO)
       
  1205   {
       
  1206     if ($this->getLogLevel() < $priority)
       
  1207     {
       
  1208       return false;
       
  1209     }
       
  1210     return $this->doLog($message, $priority);
       
  1211   }
       
  1212   abstract protected function doLog($message, $priority);
       
  1213   public function emerg($message)
       
  1214   {
       
  1215     $this->log($message, self::EMERG);
       
  1216   }
       
  1217   public function alert($message)
       
  1218   {
       
  1219     $this->log($message, self::ALERT);
       
  1220   }
       
  1221   public function crit($message)
       
  1222   {
       
  1223     $this->log($message, self::CRIT);
       
  1224   }
       
  1225   public function err($message)
       
  1226   {
       
  1227     $this->log($message, self::ERR);
       
  1228   }
       
  1229   public function warning($message)
       
  1230   {
       
  1231     $this->log($message, self::WARNING);
       
  1232   }
       
  1233   public function notice($message)
       
  1234   {
       
  1235     $this->log($message, self::NOTICE);
       
  1236   }
       
  1237   public function info($message)
       
  1238   {
       
  1239     $this->log($message, self::INFO);
       
  1240   }
       
  1241   public function debug($message)
       
  1242   {
       
  1243     $this->log($message, self::DEBUG);
       
  1244   }
       
  1245   public function listenToLogEvent(sfEvent $event)
       
  1246   {
       
  1247     $priority = isset($event['priority']) ? $event['priority'] : self::INFO;
       
  1248     $subject  = $event->getSubject();
       
  1249     $subject  = is_object($subject) ? get_class($subject) : (is_string($subject) ? $subject : 'main');
       
  1250     foreach ($event->getParameters() as $key => $message)
       
  1251     {
       
  1252       if ('priority' === $key)
       
  1253       {
       
  1254         continue;
       
  1255       }
       
  1256       $this->log(sprintf('{%s} %s', $subject, $message), $priority);
       
  1257     }
       
  1258   }
       
  1259   public function shutdown()
       
  1260   {
       
  1261   }
       
  1262   static public function getPriorityName($priority)
       
  1263   {
       
  1264     static $levels  = array(
       
  1265       self::EMERG   => 'emerg',
       
  1266       self::ALERT   => 'alert',
       
  1267       self::CRIT    => 'crit',
       
  1268       self::ERR     => 'err',
       
  1269       self::WARNING => 'warning',
       
  1270       self::NOTICE  => 'notice',
       
  1271       self::INFO    => 'info',
       
  1272       self::DEBUG   => 'debug',
       
  1273     );
       
  1274     if (!isset($levels[$priority]))
       
  1275     {
       
  1276       throw new sfException(sprintf('The priority level "%s" does not exist.', $priority));
       
  1277     }
       
  1278     return $levels[$priority];
       
  1279   }
       
  1280 }
       
  1281 
       
  1282 
       
  1283 class sfNoLogger extends sfLogger
       
  1284 {
       
  1285   public function initialize(sfEventDispatcher $dispatcher, $options = array())
       
  1286   {
       
  1287   }
       
  1288   protected function doLog($message, $priority)
       
  1289   {
       
  1290   }
       
  1291 }
       
  1292 
       
  1293 
       
  1294 abstract class sfRequest
       
  1295 {
       
  1296   const GET    = 'GET';
       
  1297   const POST   = 'POST';
       
  1298   const PUT    = 'PUT';
       
  1299   const DELETE = 'DELETE';
       
  1300   const HEAD   = 'HEAD';
       
  1301   protected
       
  1302     $dispatcher      = null,
       
  1303     $method          = null,
       
  1304     $options         = array(),
       
  1305     $parameterHolder = null,
       
  1306     $attributeHolder = null;
       
  1307   public function __construct(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array(), $options = array())
       
  1308   {
       
  1309     $this->initialize($dispatcher, $parameters, $attributes, $options);
       
  1310   }
       
  1311   public function initialize(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array(), $options = array())
       
  1312   {
       
  1313     $this->dispatcher = $dispatcher;
       
  1314     $this->options = $options;
       
  1315     if (!isset($this->options['logging']))
       
  1316     {
       
  1317       $this->options['logging'] = false;
       
  1318     }
       
  1319         $this->parameterHolder = new sfParameterHolder();
       
  1320     $this->attributeHolder = new sfParameterHolder();
       
  1321     $this->parameterHolder->add($parameters);
       
  1322     $this->attributeHolder->add($attributes);
       
  1323   }
       
  1324   public function extractParameters($names)
       
  1325   {
       
  1326     $array = array();
       
  1327     $parameters = $this->parameterHolder->getAll();
       
  1328     foreach ($parameters as $key => $value)
       
  1329     {
       
  1330       if (in_array($key, $names))
       
  1331       {
       
  1332         $array[$key] = $value;
       
  1333       }
       
  1334     }
       
  1335     return $array;
       
  1336   }
       
  1337   public function getMethod()
       
  1338   {
       
  1339     return $this->method;
       
  1340   }
       
  1341   public function setMethod($method)
       
  1342   {
       
  1343     if (!in_array(strtoupper($method), array(self::GET, self::POST, self::PUT, self::DELETE, self::HEAD)))
       
  1344     {
       
  1345       throw new sfException(sprintf('Invalid request method: %s.', $method));
       
  1346     }
       
  1347     $this->method = strtoupper($method);
       
  1348   }
       
  1349   public function getParameterHolder()
       
  1350   {
       
  1351     return $this->parameterHolder;
       
  1352   }
       
  1353   public function getAttributeHolder()
       
  1354   {
       
  1355     return $this->attributeHolder;
       
  1356   }
       
  1357   public function getAttribute($name, $default = null)
       
  1358   {
       
  1359     return $this->attributeHolder->get($name, $default);
       
  1360   }
       
  1361   public function hasAttribute($name)
       
  1362   {
       
  1363     return $this->attributeHolder->has($name);
       
  1364   }
       
  1365   public function setAttribute($name, $value)
       
  1366   {
       
  1367     $this->attributeHolder->set($name, $value);
       
  1368   }
       
  1369   public function getParameter($name, $default = null)
       
  1370   {
       
  1371     return $this->parameterHolder->get($name, $default);
       
  1372   }
       
  1373   public function hasParameter($name)
       
  1374   {
       
  1375     return $this->parameterHolder->has($name);
       
  1376   }
       
  1377   public function setParameter($name, $value)
       
  1378   {
       
  1379     $this->parameterHolder->set($name, $value);
       
  1380   }
       
  1381   public function __call($method, $arguments)
       
  1382   {
       
  1383     $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'request.method_not_found', array('method' => $method, 'arguments' => $arguments)));
       
  1384     if (!$event->isProcessed())
       
  1385     {
       
  1386       throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
       
  1387     }
       
  1388     return $event->getReturnValue();
       
  1389   }
       
  1390   public function __clone()
       
  1391   {
       
  1392     $this->parameterHolder = clone $this->parameterHolder;
       
  1393     $this->attributeHolder = clone $this->attributeHolder;
       
  1394   }
       
  1395 }
       
  1396 
       
  1397 
       
  1398 abstract class sfResponse implements Serializable
       
  1399 {
       
  1400   protected
       
  1401     $options    = array(),
       
  1402     $dispatcher = null,
       
  1403     $content    = '';
       
  1404   public function __construct(sfEventDispatcher $dispatcher, $options = array())
       
  1405   {
       
  1406     $this->initialize($dispatcher, $options);
       
  1407   }
       
  1408   public function initialize(sfEventDispatcher $dispatcher, $options = array())
       
  1409   {
       
  1410     $this->dispatcher = $dispatcher;
       
  1411     $this->options = $options;
       
  1412     if (!isset($this->options['logging']))
       
  1413     {
       
  1414       $this->options['logging'] = false;
       
  1415     }
       
  1416   }
       
  1417   public function setEventDispatcher(sfEventDispatcher $dispatcher)
       
  1418   {
       
  1419     $this->dispatcher = $dispatcher;
       
  1420   }
       
  1421   public function setContent($content)
       
  1422   {
       
  1423     $this->content = $content;
       
  1424   }
       
  1425   public function getContent()
       
  1426   {
       
  1427     return $this->content;
       
  1428   }
       
  1429   public function sendContent()
       
  1430   {
       
  1431     $event = $this->dispatcher->filter(new sfEvent($this, 'response.filter_content'), $this->getContent());
       
  1432     $content = $event->getReturnValue();
       
  1433     if ($this->options['logging'])
       
  1434     {
       
  1435       $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Send content (%s o)', strlen($content)))));
       
  1436     }
       
  1437     echo $content;
       
  1438   }
       
  1439   public function send()
       
  1440   {
       
  1441     $this->sendContent();
       
  1442   }
       
  1443   public function getOptions()
       
  1444   {
       
  1445     return $this->options;
       
  1446   }
       
  1447   public function __call($method, $arguments)
       
  1448   {
       
  1449     $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'response.method_not_found', array('method' => $method, 'arguments' => $arguments)));
       
  1450     if (!$event->isProcessed())
       
  1451     {
       
  1452       throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
       
  1453     }
       
  1454     return $event->getReturnValue();
       
  1455   }
       
  1456   public function serialize()
       
  1457   {
       
  1458     return serialize($this->content);
       
  1459   }
       
  1460   public function unserialize($serialized)
       
  1461   {
       
  1462     $this->content = unserialize($serialized);
       
  1463   }
       
  1464 }
       
  1465 
       
  1466 
       
  1467 abstract class sfRouting
       
  1468 {
       
  1469   protected
       
  1470     $dispatcher        = null,
       
  1471     $cache             = null,
       
  1472     $defaultParameters = array(),
       
  1473     $options           = array();
       
  1474   public function __construct(sfEventDispatcher $dispatcher, sfCache $cache = null, $options = array())
       
  1475   {
       
  1476     $this->initialize($dispatcher, $cache, $options);
       
  1477     if (!isset($this->options['auto_shutdown']) || $this->options['auto_shutdown'])
       
  1478     {
       
  1479       register_shutdown_function(array($this, 'shutdown'));
       
  1480     }
       
  1481   }
       
  1482   public function getCache()
       
  1483   {
       
  1484     return $this->cache;
       
  1485   }
       
  1486   public function initialize(sfEventDispatcher $dispatcher, sfCache $cache = null, $options = array())
       
  1487   {
       
  1488     $this->dispatcher = $dispatcher;
       
  1489     $options['debug'] = isset($options['debug']) ? (boolean) $options['debug'] : false;
       
  1490         $this->cache = $options['debug'] ? null : $cache;
       
  1491     $this->setDefaultParameter('module', isset($options['default_module']) ? $options['default_module'] : 'default');
       
  1492     $this->setDefaultParameter('action', isset($options['default_action']) ? $options['default_action'] : 'index');
       
  1493     if (!isset($options['logging']))
       
  1494     {
       
  1495       $options['logging'] = false;
       
  1496     }
       
  1497     if (!isset($options['context']))
       
  1498     {
       
  1499       $options['context'] = array();
       
  1500     }
       
  1501     $this->options = $options;
       
  1502     $this->dispatcher->connect('user.change_culture', array($this, 'listenToChangeCultureEvent'));
       
  1503     $this->dispatcher->connect('request.filter_parameters', array($this, 'filterParametersEvent'));
       
  1504     $this->loadConfiguration();
       
  1505   }
       
  1506   public function getOptions()
       
  1507   {
       
  1508     return $this->options;
       
  1509   }
       
  1510   public function loadConfiguration()
       
  1511   {
       
  1512     $this->dispatcher->notify(new sfEvent($this, 'routing.load_configuration'));
       
  1513   }
       
  1514   abstract public function getCurrentInternalUri($with_route_name = false);
       
  1515   abstract public function getRoutes();
       
  1516   abstract public function setRoutes($routes);
       
  1517   abstract public function hasRoutes();
       
  1518   abstract public function clearRoutes();
       
  1519   abstract public function generate($name, $params = array(), $absolute = false);
       
  1520   abstract public function parse($url);
       
  1521   public function getDefaultParameters()
       
  1522   {
       
  1523     return $this->defaultParameters;
       
  1524   }
       
  1525   public function getDefaultParameter($key)
       
  1526   {
       
  1527     return isset($this->defaultParameters[$key]) ? $this->defaultParameters[$key] : null;
       
  1528   }
       
  1529   public function setDefaultParameter($key, $value)
       
  1530   {
       
  1531     $this->defaultParameters[$key] = $value;
       
  1532   }
       
  1533   public function setDefaultParameters($parameters)
       
  1534   {
       
  1535     $this->defaultParameters = $parameters;
       
  1536   }
       
  1537   protected function mergeArrays($arr1, $arr2)
       
  1538   {
       
  1539     foreach ($arr2 as $key => $value)
       
  1540     {
       
  1541       $arr1[$key] = $value;
       
  1542     }
       
  1543     return $arr1;
       
  1544   }
       
  1545   public function listenToChangeCultureEvent(sfEvent $event)
       
  1546   {
       
  1547         $this->setDefaultParameter('sf_culture', $event['culture']);
       
  1548   }
       
  1549   public function filterParametersEvent(sfEvent $event, $parameters)
       
  1550   {
       
  1551     $context = $event->getParameters();
       
  1552     $this->options['context'] = $context;
       
  1553     if (false === $params = $this->parse($event['path_info']))
       
  1554     {
       
  1555       return $parameters;
       
  1556     }
       
  1557     return array_merge($parameters, $params);
       
  1558   }
       
  1559   protected function fixGeneratedUrl($url, $absolute = false)
       
  1560   {
       
  1561     if (isset($this->options['context']['prefix']))
       
  1562     {
       
  1563       if (0 === strpos($url, 'http'))
       
  1564       {
       
  1565         $url = preg_replace('#https?\://[^/]+#', '$0'.$this->options['context']['prefix'], $url);
       
  1566       }
       
  1567       else
       
  1568       {
       
  1569         $url = $this->options['context']['prefix'].$url;
       
  1570       }
       
  1571     }
       
  1572     if ($absolute && isset($this->options['context']['host']) && 0 !== strpos($url, 'http'))
       
  1573     {
       
  1574       $url = 'http'.(isset($this->options['context']['is_secure']) && $this->options['context']['is_secure'] ? 's' : '').'://'.$this->options['context']['host'].$url;
       
  1575     }
       
  1576     return $url;
       
  1577   }
       
  1578   public function shutdown()
       
  1579   {
       
  1580   }
       
  1581 }
       
  1582 
       
  1583 
       
  1584 abstract class sfStorage
       
  1585 {
       
  1586   protected
       
  1587     $options = array();
       
  1588   public function __construct($options = array())
       
  1589   {
       
  1590     $this->initialize($options);
       
  1591     if ($this->options['auto_shutdown'])
       
  1592     {
       
  1593       register_shutdown_function(array($this, 'shutdown'));
       
  1594     }
       
  1595   }
       
  1596   public function initialize($options = array())
       
  1597   {
       
  1598     $this->options = array_merge(array(
       
  1599       'auto_shutdown' => true,
       
  1600     ), $options);
       
  1601   }
       
  1602   public function getOptions()
       
  1603   {
       
  1604     return $this->options;
       
  1605   }
       
  1606   abstract public function read($key);
       
  1607   abstract public function regenerate($destroy = false);
       
  1608   abstract public function remove($key);
       
  1609   abstract public function shutdown();
       
  1610   abstract public function write($key, $data);
       
  1611 }
       
  1612 
       
  1613 
       
  1614 class sfUser
       
  1615 {
       
  1616   const ATTRIBUTE_NAMESPACE = 'symfony/user/sfUser/attributes';
       
  1617   const CULTURE_NAMESPACE = 'symfony/user/sfUser/culture';
       
  1618   protected
       
  1619     $options         = array(),
       
  1620     $attributeHolder = null,
       
  1621     $culture         = null,
       
  1622     $storage         = null,
       
  1623     $dispatcher      = null;
       
  1624   public function __construct(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array())
       
  1625   {
       
  1626     $this->initialize($dispatcher, $storage, $options);
       
  1627     if ($this->options['auto_shutdown'])
       
  1628     {
       
  1629       register_shutdown_function(array($this, 'shutdown'));
       
  1630     }
       
  1631   }
       
  1632   public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array())
       
  1633   {
       
  1634     $this->dispatcher = $dispatcher;
       
  1635     $this->storage    = $storage;
       
  1636     $this->options = array_merge(array(
       
  1637       'auto_shutdown'   => true,
       
  1638       'culture'         => null,
       
  1639       'default_culture' => 'en',
       
  1640       'use_flash'       => false,
       
  1641       'logging'         => false,
       
  1642     ), $options);
       
  1643     $this->attributeHolder = new sfNamespacedParameterHolder(self::ATTRIBUTE_NAMESPACE);
       
  1644         $attributes = $storage->read(self::ATTRIBUTE_NAMESPACE);
       
  1645     if (is_array($attributes))
       
  1646     {
       
  1647       foreach ($attributes as $namespace => $values)
       
  1648       {
       
  1649         $this->attributeHolder->add($values, $namespace);
       
  1650       }
       
  1651     }
       
  1652                     $currentCulture = $storage->read(self::CULTURE_NAMESPACE);
       
  1653     $this->setCulture(!is_null($this->options['culture']) ? $this->options['culture'] : (!is_null($currentCulture) ? $currentCulture : $this->options['default_culture']));
       
  1654         if ($this->options['use_flash'] && $names = $this->attributeHolder->getNames('symfony/user/sfUser/flash'))
       
  1655     {
       
  1656       if ($this->options['logging'])
       
  1657       {
       
  1658         $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Flag old flash messages ("%s")', implode('", "', $names)))));
       
  1659       }
       
  1660       foreach ($names as $name)
       
  1661       {
       
  1662         $this->attributeHolder->set($name, true, 'symfony/user/sfUser/flash/remove');
       
  1663       }
       
  1664     }
       
  1665   }
       
  1666   public function getOptions()
       
  1667   {
       
  1668     return $this->options;
       
  1669   }
       
  1670   public function setCulture($culture)
       
  1671   {
       
  1672     if ($this->culture != $culture)
       
  1673     {
       
  1674       $this->culture = $culture;
       
  1675       $this->dispatcher->notify(new sfEvent($this, 'user.change_culture', array('culture' => $culture)));
       
  1676     }
       
  1677   }
       
  1678   public function setFlash($name, $value, $persist = true)
       
  1679   {
       
  1680     if (!$this->options['use_flash'])
       
  1681     {
       
  1682       return;
       
  1683     }
       
  1684     $this->setAttribute($name, $value, 'symfony/user/sfUser/flash');
       
  1685     if ($persist)
       
  1686     {
       
  1687             $this->attributeHolder->remove($name, null, 'symfony/user/sfUser/flash/remove');
       
  1688     }
       
  1689     else
       
  1690     {
       
  1691       $this->setAttribute($name, true, 'symfony/user/sfUser/flash/remove');
       
  1692     }
       
  1693   }
       
  1694   public function getFlash($name, $default = null)
       
  1695   {
       
  1696     if (!$this->options['use_flash'])
       
  1697     {
       
  1698       return $default;
       
  1699     }
       
  1700     return $this->getAttribute($name, $default, 'symfony/user/sfUser/flash');
       
  1701   }
       
  1702   public function hasFlash($name)
       
  1703   {
       
  1704     if (!$this->options['use_flash'])
       
  1705     {
       
  1706       return false;
       
  1707     }
       
  1708     return $this->hasAttribute($name, 'symfony/user/sfUser/flash');
       
  1709   }
       
  1710   public function getCulture()
       
  1711   {
       
  1712     return $this->culture;
       
  1713   }
       
  1714   public function getAttributeHolder()
       
  1715   {
       
  1716     return $this->attributeHolder;
       
  1717   }
       
  1718   public function getAttribute($name, $default = null, $ns = null)
       
  1719   {
       
  1720     return $this->attributeHolder->get($name, $default, $ns);
       
  1721   }
       
  1722   public function hasAttribute($name, $ns = null)
       
  1723   {
       
  1724     return $this->attributeHolder->has($name, $ns);
       
  1725   }
       
  1726   public function setAttribute($name, $value, $ns = null)
       
  1727   {
       
  1728     return $this->attributeHolder->set($name, $value, $ns);
       
  1729   }
       
  1730   public function shutdown()
       
  1731   {
       
  1732         if ($this->options['use_flash'] && $names = $this->attributeHolder->getNames('symfony/user/sfUser/flash/remove'))
       
  1733     {
       
  1734       if ($this->options['logging'])
       
  1735       {
       
  1736         $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Remove old flash messages ("%s")', implode('", "', $names)))));
       
  1737       }
       
  1738       foreach ($names as $name)
       
  1739       {
       
  1740         $this->attributeHolder->remove($name, null, 'symfony/user/sfUser/flash');
       
  1741         $this->attributeHolder->remove($name, null, 'symfony/user/sfUser/flash/remove');
       
  1742       }
       
  1743     }
       
  1744     $attributes = array();
       
  1745     foreach ($this->attributeHolder->getNamespaces() as $namespace)
       
  1746     {
       
  1747       $attributes[$namespace] = $this->attributeHolder->getAll($namespace);
       
  1748     }
       
  1749         $this->storage->write(self::ATTRIBUTE_NAMESPACE, $attributes);
       
  1750         $this->storage->write(self::CULTURE_NAMESPACE, $this->culture);
       
  1751   }
       
  1752   public function __call($method, $arguments)
       
  1753   {
       
  1754     $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'user.method_not_found', array('method' => $method, 'arguments' => $arguments)));
       
  1755     if (!$event->isProcessed())
       
  1756     {
       
  1757       throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
       
  1758     }
       
  1759     return $event->getReturnValue();
       
  1760   }
       
  1761 }
       
  1762 
       
  1763 
       
  1764 class sfNamespacedParameterHolder extends sfParameterHolder
       
  1765 {
       
  1766   protected $default_namespace = null;
       
  1767   protected $parameters = array();
       
  1768   public function __construct($namespace = 'symfony/default')
       
  1769   {
       
  1770     $this->default_namespace = $namespace;
       
  1771   }
       
  1772   public function setDefaultNamespace($namespace, $move = true)
       
  1773   {
       
  1774     if ($move)
       
  1775     {
       
  1776       $values = $this->removeNamespace();
       
  1777       $this->addByRef($values, $namespace);
       
  1778     }
       
  1779     $this->default_namespace = $namespace;
       
  1780   }
       
  1781   public function getDefaultNamespace()
       
  1782   {
       
  1783     return $this->default_namespace;
       
  1784   }
       
  1785   public function clear()
       
  1786   {
       
  1787     $this->parameters = null;
       
  1788     $this->parameters = array();
       
  1789   }
       
  1790   public function & get($name, $default = null, $ns = null)
       
  1791   {
       
  1792     if (!$ns)
       
  1793     {
       
  1794       $ns = $this->default_namespace;
       
  1795     }
       
  1796     if (isset($this->parameters[$ns][$name]))
       
  1797     {
       
  1798       $value = & $this->parameters[$ns][$name];
       
  1799     }
       
  1800     else if (isset($this->parameters[$ns]))
       
  1801     {
       
  1802       $value = sfToolkit::getArrayValueForPath($this->parameters[$ns], $name, $default);
       
  1803     }
       
  1804     else
       
  1805     {
       
  1806       $value = $default;
       
  1807     }
       
  1808     return $value;
       
  1809   }
       
  1810   public function getNames($ns = null)
       
  1811   {
       
  1812     if (!$ns)
       
  1813     {
       
  1814       $ns = $this->default_namespace;
       
  1815     }
       
  1816     if (isset($this->parameters[$ns]))
       
  1817     {
       
  1818       return array_keys($this->parameters[$ns]);
       
  1819     }
       
  1820     return array();
       
  1821   }
       
  1822   public function getNamespaces()
       
  1823   {
       
  1824     return array_keys($this->parameters);
       
  1825   }
       
  1826   public function & getAll($ns = null)
       
  1827   {
       
  1828     if (!$ns)
       
  1829     {
       
  1830       $ns = $this->default_namespace;
       
  1831     }
       
  1832     $parameters = array();
       
  1833     if (isset($this->parameters[$ns]))
       
  1834     {
       
  1835       $parameters = $this->parameters[$ns];
       
  1836     }
       
  1837     return $parameters;
       
  1838   }
       
  1839   public function has($name, $ns = null)
       
  1840   {
       
  1841     if (!$ns)
       
  1842     {
       
  1843       $ns = $this->default_namespace;
       
  1844     }
       
  1845     if (isset($this->parameters[$ns][$name]))
       
  1846     {
       
  1847       return true;
       
  1848     }
       
  1849     else if (isset($this->parameters[$ns]))
       
  1850     {
       
  1851       return sfToolkit::hasArrayValueForPath($this->parameters[$ns], $name);
       
  1852     }
       
  1853     return false;
       
  1854   }
       
  1855   public function hasNamespace($ns)
       
  1856   {
       
  1857     return isset($this->parameters[$ns]);
       
  1858   }
       
  1859   public function remove($name, $default = null, $ns = null)
       
  1860   {
       
  1861     if (!$ns)
       
  1862     {
       
  1863       $ns = $this->default_namespace;
       
  1864     }
       
  1865     $retval = $default;
       
  1866     if (isset($this->parameters[$ns]) && array_key_exists($name, $this->parameters[$ns]))
       
  1867     {
       
  1868       $retval = $this->parameters[$ns][$name];
       
  1869       unset($this->parameters[$ns][$name]);
       
  1870     }
       
  1871     else
       
  1872     {
       
  1873       $retval = sfToolkit::removeArrayValueForPath($this->parameters[$ns], $name, $default);
       
  1874     }
       
  1875     return $retval;
       
  1876   }
       
  1877   public function & removeNamespace($ns = null)
       
  1878   {
       
  1879     if (!$ns)
       
  1880     {
       
  1881       $ns = $this->default_namespace;
       
  1882     }
       
  1883     $retval = null;
       
  1884     if (isset($this->parameters[$ns]))
       
  1885     {
       
  1886       $retval =& $this->parameters[$ns];
       
  1887       unset($this->parameters[$ns]);
       
  1888     }
       
  1889     return $retval;
       
  1890   }
       
  1891   public function set($name, $value, $ns = null)
       
  1892   {
       
  1893     if (!$ns)
       
  1894     {
       
  1895       $ns = $this->default_namespace;
       
  1896     }
       
  1897     if (!isset($this->parameters[$ns]))
       
  1898     {
       
  1899       $this->parameters[$ns] = array();
       
  1900     }
       
  1901     $this->parameters[$ns][$name] = $value;
       
  1902   }
       
  1903   public function setByRef($name, & $value, $ns = null)
       
  1904   {
       
  1905     if (!$ns)
       
  1906     {
       
  1907       $ns = $this->default_namespace;
       
  1908     }
       
  1909     if (!isset($this->parameters[$ns]))
       
  1910     {
       
  1911       $this->parameters[$ns] = array();
       
  1912     }
       
  1913     $this->parameters[$ns][$name] =& $value;
       
  1914   }
       
  1915   public function add($parameters, $ns = null)
       
  1916   {
       
  1917     if ($parameters === null) return;
       
  1918     if (!$ns)
       
  1919     {
       
  1920       $ns = $this->default_namespace;
       
  1921     }
       
  1922     if (!isset($this->parameters[$ns]))
       
  1923     {
       
  1924       $this->parameters[$ns] = array();
       
  1925     }
       
  1926     foreach ($parameters as $key => $value)
       
  1927     {
       
  1928       $this->parameters[$ns][$key] = $value;
       
  1929     }
       
  1930   }
       
  1931   public function addByRef(& $parameters, $ns = null)
       
  1932   {
       
  1933     if (!$ns)
       
  1934     {
       
  1935       $ns = $this->default_namespace;
       
  1936     }
       
  1937     if (!isset($this->parameters[$ns]))
       
  1938     {
       
  1939       $this->parameters[$ns] = array();
       
  1940     }
       
  1941     foreach ($parameters as $key => &$value)
       
  1942     {
       
  1943       $this->parameters[$ns][$key] =& $value;
       
  1944     }
       
  1945   }
       
  1946   public function serialize()
       
  1947   {
       
  1948     return serialize(array($this->default_namespace, $this->parameters));
       
  1949   }
       
  1950   public function unserialize($serialized)
       
  1951   {
       
  1952     $data = unserialize($serialized);
       
  1953     $this->default_namespace = $data[0];
       
  1954     $this->parameters = $data[1];
       
  1955   }
       
  1956 }
       
  1957 
       
  1958 
       
  1959 abstract class sfView
       
  1960 {
       
  1961   const ALERT = 'Alert';
       
  1962   const ERROR = 'Error';
       
  1963   const INPUT = 'Input';
       
  1964   const NONE = 'None';
       
  1965   const SUCCESS = 'Success';
       
  1966   const RENDER_NONE = 1;
       
  1967   const RENDER_CLIENT = 2;
       
  1968   const RENDER_VAR = 4;
       
  1969   const HEADER_ONLY = 8;
       
  1970   protected
       
  1971     $context            = null,
       
  1972     $dispatcher         = null,
       
  1973     $decorator          = false,
       
  1974     $decoratorDirectory = null,
       
  1975     $decoratorTemplate  = null,
       
  1976     $directory          = null,
       
  1977     $componentSlots     = array(),
       
  1978     $template           = null,
       
  1979     $attributeHolder    = null,
       
  1980     $parameterHolder    = null,
       
  1981     $moduleName         = '',
       
  1982     $actionName         = '',
       
  1983     $viewName           = '',
       
  1984     $extension          = '.php';
       
  1985   public function __construct($context, $moduleName, $actionName, $viewName)
       
  1986   {
       
  1987     $this->initialize($context, $moduleName, $actionName, $viewName);
       
  1988   }
       
  1989   public function initialize($context, $moduleName, $actionName, $viewName)
       
  1990   {
       
  1991     $this->moduleName = $moduleName;
       
  1992     $this->actionName = $actionName;
       
  1993     $this->viewName   = $viewName;
       
  1994     $this->context    = $context;
       
  1995     $this->dispatcher = $context->getEventDispatcher();
       
  1996     sfOutputEscaper::markClassesAsSafe(array('sfForm', 'sfModelGeneratorHelper'));
       
  1997     $this->attributeHolder = $this->initializeAttributeHolder();
       
  1998     $this->parameterHolder = new sfParameterHolder();
       
  1999     $this->parameterHolder->add(sfConfig::get('mod_'.strtolower($moduleName).'_view_param', array()));
       
  2000     $request = $context->getRequest();
       
  2001     if (!is_null($format = $request->getRequestFormat()))
       
  2002     {
       
  2003       if ('html' != $format)
       
  2004       {
       
  2005         $this->setExtension('.'.$format.$this->getExtension());
       
  2006       }
       
  2007       if ($mimeType = $request->getMimeType($format))
       
  2008       {
       
  2009         $this->context->getResponse()->setContentType($mimeType);
       
  2010         if ('html' != $format)
       
  2011         {
       
  2012           $this->setDecorator(false);
       
  2013         }
       
  2014       }
       
  2015       $this->dispatcher->notify(new sfEvent($this, 'view.configure_format', array('format' => $format, 'response' => $context->getResponse(), 'request' => $context->getRequest())));
       
  2016     }
       
  2017         $this->configure();
       
  2018     return true;
       
  2019   }
       
  2020   protected function initializeAttributeHolder($attributes = array())
       
  2021   {
       
  2022     if ('both' === sfConfig::get('sf_escaping_strategy'))
       
  2023     {
       
  2024       $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Escaping strategy "both" is deprecated, please use "on".', 'priority' => sfLogger::ERR)));
       
  2025       sfConfig::set('sf_escaping_strategy', 'on');
       
  2026     }
       
  2027     else if ('bc' === sfConfig::get('sf_escaping_strategy'))
       
  2028     {
       
  2029       $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Escaping strategy "bc" is deprecated, please use "off".', 'priority' => sfLogger::ERR)));
       
  2030       sfConfig::set('sf_escaping_strategy', 'off');
       
  2031     }
       
  2032     $attributeHolder = new sfViewParameterHolder($this->dispatcher, $attributes, array(
       
  2033       'escaping_method'   => sfConfig::get('sf_escaping_method'),
       
  2034       'escaping_strategy' => sfConfig::get('sf_escaping_strategy'),
       
  2035     ));
       
  2036     return $attributeHolder;
       
  2037   }
       
  2038   abstract function execute();
       
  2039   abstract function configure();
       
  2040   public function getDecoratorDirectory()
       
  2041   {
       
  2042     return $this->decoratorDirectory;
       
  2043   }
       
  2044   public function getDecoratorTemplate()
       
  2045   {
       
  2046     return $this->decoratorTemplate;
       
  2047   }
       
  2048   public function getDirectory()
       
  2049   {
       
  2050     return $this->directory;
       
  2051   }
       
  2052   abstract function getEngine();
       
  2053   public function getTemplate()
       
  2054   {
       
  2055     return $this->template;
       
  2056   }
       
  2057   public function getAttributeHolder()
       
  2058   {
       
  2059     return $this->attributeHolder;
       
  2060   }
       
  2061   public function getAttribute($name, $default = null)
       
  2062   {
       
  2063     return $this->attributeHolder->get($name, $default);
       
  2064   }
       
  2065   public function hasAttribute($name)
       
  2066   {
       
  2067     return $this->attributeHolder->has($name);
       
  2068   }
       
  2069   public function setAttribute($name, $value)
       
  2070   {
       
  2071     $this->attributeHolder->set($name, $value);
       
  2072   }
       
  2073   public function getParameterHolder()
       
  2074   {
       
  2075     return $this->parameterHolder;
       
  2076   }
       
  2077   public function getParameter($name, $default = null)
       
  2078   {
       
  2079     return $this->parameterHolder->get($name, $default);
       
  2080   }
       
  2081   public function hasParameter($name)
       
  2082   {
       
  2083     return $this->parameterHolder->has($name);
       
  2084   }
       
  2085   public function setParameter($name, $value)
       
  2086   {
       
  2087     $this->parameterHolder->set($name, $value);
       
  2088   }
       
  2089   public function isDecorator()
       
  2090   {
       
  2091     return $this->decorator;
       
  2092   }
       
  2093   public function setDecorator($boolean)
       
  2094   {
       
  2095     $this->decorator = (boolean) $boolean;
       
  2096     if (false === $boolean)
       
  2097     {
       
  2098       $this->decoratorTemplate = false;
       
  2099     }
       
  2100   }
       
  2101   protected function preRenderCheck()
       
  2102   {
       
  2103     if (is_null($this->template))
       
  2104     {
       
  2105             throw new sfRenderException('A template has not been set.');
       
  2106     }
       
  2107     if (!is_readable($this->directory.'/'.$this->template))
       
  2108     {
       
  2109             if ('404' == $this->context->getResponse()->getStatusCode())
       
  2110       {
       
  2111                 $this->template = sfException::getTemplatePathForError($this->context->getRequest()->getRequestFormat(), false);
       
  2112         $this->directory = dirname($this->template);
       
  2113         $this->template = basename($this->template);
       
  2114         $this->setAttribute('code', '404');
       
  2115         $this->setAttribute('text', 'Not Found');
       
  2116       }
       
  2117       else
       
  2118       {
       
  2119         throw new sfRenderException(sprintf('The template "%s" does not exist or is unreadable in "%s".', $this->template, $this->directory));
       
  2120       }
       
  2121     }
       
  2122         if ($this->decorator && !is_readable($this->decoratorDirectory.'/'.$this->decoratorTemplate))
       
  2123     {
       
  2124       throw new sfRenderException(sprintf('The decorator template "%s" does not exist or is unreadable in "%s".', $this->decoratorTemplate, $this->decoratorDirectory));
       
  2125     }
       
  2126   }
       
  2127   abstract function render();
       
  2128   public function setDecoratorDirectory($directory)
       
  2129   {
       
  2130     $this->decoratorDirectory = $directory;
       
  2131   }
       
  2132   public function setDecoratorTemplate($template)
       
  2133   {
       
  2134     if (false === $template)
       
  2135     {
       
  2136       $this->setDecorator(false);
       
  2137       return;
       
  2138     }
       
  2139     else if (is_null($template))
       
  2140     {
       
  2141       return;
       
  2142     }
       
  2143     if (!strpos($template, '.'))
       
  2144     {
       
  2145       $template .= $this->getExtension();
       
  2146     }
       
  2147     if (sfToolkit::isPathAbsolute($template))
       
  2148     {
       
  2149       $this->decoratorDirectory = dirname($template);
       
  2150       $this->decoratorTemplate  = basename($template);
       
  2151     }
       
  2152     else
       
  2153     {
       
  2154       $this->decoratorDirectory = $this->context->getConfiguration()->getDecoratorDir($template);
       
  2155       $this->decoratorTemplate = $template;
       
  2156     }
       
  2157         $this->decorator = true;
       
  2158   }
       
  2159   public function setDirectory($directory)
       
  2160   {
       
  2161     $this->directory = $directory;
       
  2162   }
       
  2163   public function setComponentSlot($attributeName, $moduleName, $componentName)
       
  2164   {
       
  2165     $this->componentSlots[$attributeName]                   = array();
       
  2166     $this->componentSlots[$attributeName]['module_name']    = $moduleName;
       
  2167     $this->componentSlots[$attributeName]['component_name'] = $componentName;
       
  2168   }
       
  2169   public function hasComponentSlot($name)
       
  2170   {
       
  2171     return isset($this->componentSlots[$name]);
       
  2172   }
       
  2173   public function getComponentSlot($name)
       
  2174   {
       
  2175     if (isset($this->componentSlots[$name]) && $this->componentSlots[$name]['module_name'] && $this->componentSlots[$name]['component_name'])
       
  2176     {
       
  2177       return array($this->componentSlots[$name]['module_name'], $this->componentSlots[$name]['component_name']);
       
  2178     }
       
  2179     return null;
       
  2180   }
       
  2181   public function setTemplate($template)
       
  2182   {
       
  2183     if (sfToolkit::isPathAbsolute($template))
       
  2184     {
       
  2185       $this->directory = dirname($template);
       
  2186       $this->template  = basename($template);
       
  2187     }
       
  2188     else
       
  2189     {
       
  2190       $this->directory = $this->context->getConfiguration()->getTemplateDir($this->moduleName, $template);
       
  2191       $this->template = $template;
       
  2192     }
       
  2193   }
       
  2194   public function getExtension()
       
  2195   {
       
  2196     return $this->extension;
       
  2197   }
       
  2198   public function setExtension($extension)
       
  2199   {
       
  2200     $this->extension = $extension;
       
  2201   }
       
  2202   public function getModuleName()
       
  2203   {
       
  2204     return $this->moduleName;
       
  2205   }
       
  2206   public function getActionName()
       
  2207   {
       
  2208     return $this->actionName;
       
  2209   }
       
  2210   public function getViewName()
       
  2211   {
       
  2212     return $this->viewName;
       
  2213   }
       
  2214   public function __call($method, $arguments)
       
  2215   {
       
  2216     $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'view.method_not_found', array('method' => $method, 'arguments' => $arguments)));
       
  2217     if (!$event->isProcessed())
       
  2218     {
       
  2219       throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
       
  2220     }
       
  2221     return $event->getReturnValue();
       
  2222   }
       
  2223 }
       
  2224 
       
  2225 
       
  2226 class sfViewParameterHolder extends sfParameterHolder
       
  2227 {
       
  2228   protected
       
  2229     $dispatcher     = null,
       
  2230     $escaping       = null,
       
  2231     $escapingMethod = null;
       
  2232   public function __construct(sfEventDispatcher $dispatcher, $parameters = array(), $options = array())
       
  2233   {
       
  2234     $this->initialize($dispatcher, $parameters, $options);
       
  2235   }
       
  2236   public function initialize(sfEventDispatcher $dispatcher, $parameters = array(), $options = array())
       
  2237   {
       
  2238     $this->dispatcher = $dispatcher;
       
  2239     $this->add($parameters);
       
  2240     $this->setEscaping(isset($options['escaping_strategy']) ? $options['escaping_strategy'] : false);
       
  2241     $this->setEscapingMethod(isset($options['escaping_method']) ? $options['escaping_method'] : 'ESC_SPECIALCHARS');
       
  2242   }
       
  2243   public function isEscaped()
       
  2244   {
       
  2245     return in_array($this->getEscaping(), array('on', true), true);
       
  2246   }
       
  2247   public function toArray()
       
  2248   {
       
  2249     $event = $this->dispatcher->filter(new sfEvent($this, 'template.filter_parameters'), $this->getAll());
       
  2250     $parameters = $event->getReturnValue();
       
  2251     $attributes = array();
       
  2252     if ($this->isEscaped())
       
  2253     {
       
  2254       $attributes['sf_data'] = sfOutputEscaper::escape($this->getEscapingMethod(), $parameters);
       
  2255       foreach ($attributes['sf_data'] as $key => $value)
       
  2256       {
       
  2257         $attributes[$key] = $value;
       
  2258       }
       
  2259     }
       
  2260     else if (in_array($this->getEscaping(), array('off', false), true))
       
  2261     {
       
  2262       $attributes = $parameters;
       
  2263       $attributes['sf_data'] = sfOutputEscaper::escape(ESC_RAW, $parameters);
       
  2264     }
       
  2265     else
       
  2266     {
       
  2267       throw new InvalidArgumentException(sprintf('Unknown strategy "%s".', $this->getEscaping()));
       
  2268     }
       
  2269     return $attributes;
       
  2270   }
       
  2271   public function getEscaping()
       
  2272   {
       
  2273     return $this->escaping;
       
  2274   }
       
  2275   public function setEscaping($escaping)
       
  2276   {
       
  2277     $this->escaping = $escaping;
       
  2278   }
       
  2279   public function getEscapingMethod()
       
  2280   {
       
  2281     if (empty($this->escapingMethod))
       
  2282     {
       
  2283       return $this->escapingMethod;
       
  2284     }
       
  2285     if (!defined($this->escapingMethod))
       
  2286     {
       
  2287       throw new InvalidArgumentException(sprintf('The escaping method "%s" is not available.', $this->escapingMethod));
       
  2288     }
       
  2289     return constant($this->escapingMethod);
       
  2290   }
       
  2291   public function setEscapingMethod($method)
       
  2292   {
       
  2293     $this->escapingMethod = $method;
       
  2294   }
       
  2295   public function serialize()
       
  2296   {
       
  2297     return serialize(array($this->getAll(), $this->escapingMethod, $this->escaping));
       
  2298   }
       
  2299   public function unserialize($serialized)
       
  2300   {
       
  2301     list($this->parameters, $escapingMethod, $escaping) = unserialize($serialized);
       
  2302     $this->initialize(sfContext::hasInstance() ? sfContext::getInstance()->getEventDispatcher() : new sfEventDispatcher());
       
  2303     $this->setEscapingMethod($escapingMethod);
       
  2304     $this->setEscaping($escaping);
       
  2305   }
       
  2306 }
       
  2307 
       
  2308 
       
  2309 abstract class sfWebController extends sfController
       
  2310 {
       
  2311   public function genUrl($parameters = array(), $absolute = false)
       
  2312   {
       
  2313         if (is_string($parameters) && preg_match('#^[a-z][a-z0-9\+.\-]*\://#i', $parameters))
       
  2314     {
       
  2315       return $parameters;
       
  2316     }
       
  2317         if (is_string($parameters) && 0 === strpos($parameters, '/'))
       
  2318     {
       
  2319       return $parameters;
       
  2320     }
       
  2321     if (is_string($parameters) && $parameters == '#')
       
  2322     {
       
  2323       return $parameters;
       
  2324     }
       
  2325     $route = '';
       
  2326     $fragment = '';
       
  2327     if (is_string($parameters))
       
  2328     {
       
  2329             if (false !== ($pos = strpos($parameters, '#')))
       
  2330       {
       
  2331         $fragment = substr($parameters, $pos + 1);
       
  2332         $parameters = substr($parameters, 0, $pos);
       
  2333       }
       
  2334       list($route, $parameters) = $this->convertUrlStringToParameters($parameters);
       
  2335     }
       
  2336     else if (is_array($parameters))
       
  2337     {
       
  2338       if (isset($parameters['sf_route']))
       
  2339       {
       
  2340         $route = $parameters['sf_route'];
       
  2341         unset($parameters['sf_route']);
       
  2342       }
       
  2343     }
       
  2344         $url = $this->context->getRouting()->generate($route, $parameters, $absolute);
       
  2345     if ($fragment)
       
  2346     {
       
  2347       $url .= '#'.$fragment;
       
  2348     }
       
  2349     return $url;
       
  2350   }
       
  2351   public function convertUrlStringToParameters($url)
       
  2352   {
       
  2353     $givenUrl = $url;
       
  2354     $params = array();
       
  2355     $queryString = '';
       
  2356     $route = '';
       
  2357         if (!$url)
       
  2358     {
       
  2359       $url = '/';
       
  2360     }
       
  2361         if ($pos = strpos($url, '?'))
       
  2362     {
       
  2363       $queryString = substr($url, $pos + 1);
       
  2364       $url = substr($url, 0, $pos);
       
  2365     }
       
  2366         if ($url[0] == '/')
       
  2367     {
       
  2368       $url = substr($url, 1);
       
  2369     }
       
  2370         if ($url[0] == '@')
       
  2371     {
       
  2372       $route = substr($url, 1);
       
  2373     }
       
  2374     else if (false !== strpos($url, '/'))
       
  2375     {
       
  2376       list($params['module'], $params['action']) = explode('/', $url);
       
  2377     }
       
  2378     else if (!$queryString)
       
  2379     {
       
  2380       $route = $givenUrl;
       
  2381     }
       
  2382     else
       
  2383     {
       
  2384       throw new InvalidArgumentException(sprintf('An internal URI must contain a module and an action (module/action) ("%s" given).', $givenUrl));
       
  2385     }
       
  2386         if ($queryString)
       
  2387     {
       
  2388       $matched = preg_match_all('/
       
  2389         ([^&=]+)            # key
       
  2390         =                   # =
       
  2391         (.*?)               # value
       
  2392         (?:
       
  2393           (?=&[^&=]+=) | $  # followed by another key= or the end of the string
       
  2394         )
       
  2395       /x', $queryString, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
       
  2396       foreach ($matches as $match)
       
  2397       {
       
  2398         $params[urldecode($match[1][0])] = urldecode($match[2][0]);
       
  2399       }
       
  2400             if (!$matched)
       
  2401       {
       
  2402         throw new sfParseException(sprintf('Unable to parse query string "%s".', $queryString));
       
  2403       }
       
  2404     }
       
  2405     return array($route, $params);
       
  2406   }
       
  2407   public function redirect($url, $delay = 0, $statusCode = 302)
       
  2408   {
       
  2409     $url = $this->genUrl($url, true);
       
  2410     if (sfConfig::get('sf_logging_enabled'))
       
  2411     {
       
  2412       $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Redirect to "%s"', $url))));
       
  2413     }
       
  2414         $response = $this->context->getResponse();
       
  2415     $response->clearHttpHeaders();
       
  2416     $response->setStatusCode($statusCode);
       
  2417     $response->setHttpHeader('Location', $url);
       
  2418     $response->setContent(sprintf('<html><head><meta http-equiv="refresh" content="%d;url=%s"/></head></html>', $delay, htmlspecialchars($url, ENT_QUOTES, sfConfig::get('sf_charset'))));
       
  2419     $response->send();
       
  2420   }
       
  2421 }
       
  2422 
       
  2423 
       
  2424 class sfFrontWebController extends sfWebController
       
  2425 {
       
  2426   public function dispatch()
       
  2427   {
       
  2428     try
       
  2429     {
       
  2430             sfFilter::$filterCalled = array();
       
  2431             $request    = $this->context->getRequest();
       
  2432       $moduleName = $request->getParameter('module');
       
  2433       $actionName = $request->getParameter('action');
       
  2434       if (empty($moduleName) || empty($actionName))
       
  2435       {
       
  2436         throw new sfError404Exception(sprintf('Empty module and/or action after parsing the URL "%s" (%s/%s).', $request->getPathInfo(), $moduleName, $actionName));
       
  2437       }
       
  2438             $this->forward($moduleName, $actionName);
       
  2439     }
       
  2440     catch (sfException $e)
       
  2441     {
       
  2442       $e->printStackTrace();
       
  2443     }
       
  2444     catch (Exception $e)
       
  2445     {
       
  2446       sfException::createFromException($e)->printStackTrace();
       
  2447     }
       
  2448   }
       
  2449 }
       
  2450 
       
  2451 
       
  2452 class sfWebRequest extends sfRequest
       
  2453 {
       
  2454   protected
       
  2455     $languages              = null,
       
  2456     $charsets               = null,
       
  2457     $acceptableContentTypes = null,
       
  2458     $pathInfoArray          = null,
       
  2459     $relativeUrlRoot        = null,
       
  2460     $getParameters          = null,
       
  2461     $postParameters         = null,
       
  2462     $requestParameters      = null,
       
  2463     $formats                = array(),
       
  2464     $format                 = null,
       
  2465     $fixedFileArray         = false;
       
  2466   public function initialize(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array(), $options = array())
       
  2467   {
       
  2468     parent::initialize($dispatcher, $parameters, $attributes, $options);
       
  2469         $this->getParameters = get_magic_quotes_gpc() ? sfToolkit::stripslashesDeep($_GET) : $_GET;
       
  2470     $this->parameterHolder->add($this->getParameters);
       
  2471         $this->postParameters = get_magic_quotes_gpc() ? sfToolkit::stripslashesDeep($_POST) : $_POST;
       
  2472     $this->parameterHolder->add($this->postParameters);
       
  2473     if (isset($_SERVER['REQUEST_METHOD']))
       
  2474     {
       
  2475       switch ($_SERVER['REQUEST_METHOD'])
       
  2476       {
       
  2477         case 'GET':
       
  2478           $this->setMethod(self::GET);
       
  2479           break;
       
  2480         case 'POST':
       
  2481           $this->setMethod(strtoupper($this->getParameter('sf_method', 'POST')));
       
  2482           $this->parameterHolder->remove('sf_method');
       
  2483           break;
       
  2484         case 'PUT':
       
  2485           $this->setMethod(self::PUT);
       
  2486           break;
       
  2487         case 'DELETE':
       
  2488           $this->setMethod(self::DELETE);
       
  2489           break;
       
  2490         case 'HEAD':
       
  2491           $this->setMethod(self::HEAD);
       
  2492           break;
       
  2493         default:
       
  2494           $this->setMethod(self::GET);
       
  2495       }
       
  2496     }
       
  2497     else
       
  2498     {
       
  2499             $this->setMethod(self::GET);
       
  2500     }
       
  2501     if (isset($this->options['formats']))
       
  2502     {
       
  2503       foreach ($this->options['formats'] as $format => $mimeTypes)
       
  2504       {
       
  2505         $this->setFormat($format, $mimeTypes);
       
  2506       }
       
  2507     }
       
  2508     if (!isset($this->options['path_info_key']))
       
  2509     {
       
  2510       $this->options['path_info_key'] = 'PATH_INFO';
       
  2511     }
       
  2512     if (!isset($this->options['path_info_array']))
       
  2513     {
       
  2514       $this->options['path_info_array'] = 'SERVER';
       
  2515     }
       
  2516         $this->requestParameters = $this->parseRequestParameters();
       
  2517     $this->parameterHolder->add($this->requestParameters);
       
  2518     $this->fixParameters();
       
  2519   }
       
  2520   public function getUri()
       
  2521   {
       
  2522     $pathArray = $this->getPathInfoArray();
       
  2523         if ('HTTP_X_REWRITE_URL' == $this->options['path_info_key'])
       
  2524     {
       
  2525       $uri = isset($pathArray['HTTP_X_REWRITE_URL']) ? $pathArray['HTTP_X_REWRITE_URL'] : '';
       
  2526     }
       
  2527     else
       
  2528     {
       
  2529       $uri = isset($pathArray['REQUEST_URI']) ? $pathArray['REQUEST_URI'] : '';
       
  2530     }
       
  2531     return $this->isAbsUri() ? $uri : $this->getUriPrefix().$uri;
       
  2532   }
       
  2533   public function isAbsUri()
       
  2534   {
       
  2535     $pathArray = $this->getPathInfoArray();
       
  2536     return isset($pathArray['REQUEST_URI']) ? preg_match('/^http/', $pathArray['REQUEST_URI']) : false;
       
  2537   }
       
  2538   public function getUriPrefix()
       
  2539   {
       
  2540     $pathArray = $this->getPathInfoArray();
       
  2541     if ($this->isSecure())
       
  2542     {
       
  2543       $standardPort = '443';
       
  2544       $protocol = 'https';
       
  2545     }
       
  2546     else
       
  2547     {
       
  2548       $standardPort = '80';
       
  2549       $protocol = 'http';
       
  2550     }
       
  2551     $host = explode(":", $this->getHost());
       
  2552     if (count($host) == 1)
       
  2553     {
       
  2554       $host[] = isset($pathArray['SERVER_PORT']) ? $pathArray['SERVER_PORT'] : '';
       
  2555     }
       
  2556     if ($host[1] == $standardPort || empty($host[1]))
       
  2557     {
       
  2558       unset($host[1]);
       
  2559     }
       
  2560     return $protocol.'://'.implode(':', $host);;
       
  2561   }
       
  2562   public function getPathInfo()
       
  2563   {
       
  2564     $pathInfo = '';
       
  2565     $pathArray = $this->getPathInfoArray();
       
  2566         $sf_path_info_key = $this->options['path_info_key'];
       
  2567     if (!isset($pathArray[$sf_path_info_key]) || !$pathArray[$sf_path_info_key])
       
  2568     {
       
  2569       if (isset($pathArray['REQUEST_URI']))
       
  2570       {
       
  2571         $script_name = $this->getScriptName();
       
  2572         $uri_prefix = $this->isAbsUri() ? $this->getUriPrefix() : '';
       
  2573         $pathInfo = preg_replace('/^'.preg_quote($uri_prefix, '/').'/','',$pathArray['REQUEST_URI']);
       
  2574         $pathInfo = preg_replace('/^'.preg_quote($script_name, '/').'/', '', $pathInfo);
       
  2575         $prefix_name = preg_replace('#/[^/]+$#', '', $script_name);
       
  2576         $pathInfo = preg_replace('/^'.preg_quote($prefix_name, '/').'/', '', $pathInfo);
       
  2577         $pathInfo = preg_replace('/\??'.preg_quote($pathArray['QUERY_STRING'], '/').'$/', '', $pathInfo);
       
  2578       }
       
  2579     }
       
  2580     else
       
  2581     {
       
  2582       $pathInfo = $pathArray[$sf_path_info_key];
       
  2583       if ($relativeUrlRoot = $this->getRelativeUrlRoot())
       
  2584       {
       
  2585         $pathInfo = preg_replace('/^'.str_replace('/', '\\/', $relativeUrlRoot).'\//', '', $pathInfo);
       
  2586       }
       
  2587     }
       
  2588         if (isset($_SERVER['SERVER_SOFTWARE']) && false !== stripos($_SERVER['SERVER_SOFTWARE'], 'iis') && $pos = stripos($pathInfo, '.php'))
       
  2589     {
       
  2590       $pathInfo = substr($pathInfo, $pos + 4);
       
  2591     }
       
  2592     if (!$pathInfo)
       
  2593     {
       
  2594       $pathInfo = '/';
       
  2595     }
       
  2596     return $pathInfo;
       
  2597   }
       
  2598   public function getPathInfoPrefix()
       
  2599   {
       
  2600     $prefix = $this->getRelativeUrlRoot();
       
  2601     if (!isset($this->options['no_script_name']) || !$this->options['no_script_name'])
       
  2602     {
       
  2603       $scriptName = $this->getScriptName();
       
  2604       $prefix = is_null($prefix) ? $scriptName : $prefix.'/'.basename($scriptName);
       
  2605     }
       
  2606     return $prefix;
       
  2607   }
       
  2608   public function getGetParameters()
       
  2609   {
       
  2610     return $this->getParameters;
       
  2611   }
       
  2612   public function getPostParameters()
       
  2613   {
       
  2614     return $this->postParameters;
       
  2615   }
       
  2616   public function getRequestParameters()
       
  2617   {
       
  2618     return $this->requestParameters;
       
  2619   }
       
  2620   public function addRequestParameters($parameters)
       
  2621   {
       
  2622     $this->requestParameters = array_merge($this->requestParameters, $parameters);
       
  2623     $this->getParameterHolder()->add($parameters);
       
  2624     $this->fixParameters();
       
  2625   }
       
  2626   public function getReferer()
       
  2627   {
       
  2628     $pathArray = $this->getPathInfoArray();
       
  2629     return isset($pathArray['HTTP_REFERER']) ? $pathArray['HTTP_REFERER'] : '';
       
  2630   }
       
  2631   public function getHost()
       
  2632   {
       
  2633     $pathArray = $this->getPathInfoArray();
       
  2634     return isset($pathArray['HTTP_X_FORWARDED_HOST']) ? $pathArray['HTTP_X_FORWARDED_HOST'] : (isset($pathArray['HTTP_HOST']) ? $pathArray['HTTP_HOST'] : '');
       
  2635   }
       
  2636   public function getScriptName()
       
  2637   {
       
  2638     $pathArray = $this->getPathInfoArray();
       
  2639     return isset($pathArray['SCRIPT_NAME']) ? $pathArray['SCRIPT_NAME'] : (isset($pathArray['ORIG_SCRIPT_NAME']) ? $pathArray['ORIG_SCRIPT_NAME'] : '');
       
  2640   }
       
  2641   public function isMethod($method)
       
  2642   {
       
  2643     return strtoupper($method) == $this->getMethod();
       
  2644   }
       
  2645   public function getMethodName()
       
  2646   {
       
  2647     if ($this->options['logging'])
       
  2648     {
       
  2649       $this->dispatcher->notify(new sfEvent($this, 'application.log', array('The "sfWebRequest::getMethodName()" method is deprecated, please use "getMethod()" instead.', 'priority' => sfLogger::WARNING)));
       
  2650     }
       
  2651     return $this->getMethod();
       
  2652   }
       
  2653   public function getPreferredCulture(array $cultures = null)
       
  2654   {
       
  2655     $preferredCultures = $this->getLanguages();
       
  2656     if (is_null($cultures))
       
  2657     {
       
  2658       return isset($preferredCultures[0]) ? $preferredCultures[0] : null;
       
  2659     }
       
  2660     if (!$preferredCultures)
       
  2661     {
       
  2662       return $cultures[0];
       
  2663     }
       
  2664     $preferredCultures = array_values(array_intersect($preferredCultures, $cultures));
       
  2665     return isset($preferredCultures[0]) ? $preferredCultures[0] : $cultures[0];
       
  2666   }
       
  2667   public function getLanguages()
       
  2668   {
       
  2669     if ($this->languages)
       
  2670     {
       
  2671       return $this->languages;
       
  2672     }
       
  2673     if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
       
  2674     {
       
  2675       return array();
       
  2676     }
       
  2677     $languages = $this->splitHttpAcceptHeader($_SERVER['HTTP_ACCEPT_LANGUAGE']);
       
  2678     foreach ($languages as $lang)
       
  2679     {
       
  2680       if (strstr($lang, '-'))
       
  2681       {
       
  2682         $codes = explode('-', $lang);
       
  2683         if ($codes[0] == 'i')
       
  2684         {
       
  2685                                         if (count($codes) > 1)
       
  2686           {
       
  2687             $lang = $codes[1];
       
  2688           }
       
  2689         }
       
  2690         else
       
  2691         {
       
  2692           for ($i = 0, $max = count($codes); $i < $max; $i++)
       
  2693           {
       
  2694             if ($i == 0)
       
  2695             {
       
  2696               $lang = strtolower($codes[0]);
       
  2697             }
       
  2698             else
       
  2699             {
       
  2700               $lang .= '_'.strtoupper($codes[$i]);
       
  2701             }
       
  2702           }
       
  2703         }
       
  2704       }
       
  2705       $this->languages[] = $lang;
       
  2706     }
       
  2707     return $this->languages;
       
  2708   }
       
  2709   public function getCharsets()
       
  2710   {
       
  2711     if ($this->charsets)
       
  2712     {
       
  2713       return $this->charsets;
       
  2714     }
       
  2715     if (!isset($_SERVER['HTTP_ACCEPT_CHARSET']))
       
  2716     {
       
  2717       return array();
       
  2718     }
       
  2719     $this->charsets = $this->splitHttpAcceptHeader($_SERVER['HTTP_ACCEPT_CHARSET']);
       
  2720     return $this->charsets;
       
  2721   }
       
  2722   public function getAcceptableContentTypes()
       
  2723   {
       
  2724     if ($this->acceptableContentTypes)
       
  2725     {
       
  2726       return $this->acceptableContentTypes;
       
  2727     }
       
  2728     if (!isset($_SERVER['HTTP_ACCEPT']))
       
  2729     {
       
  2730       return array();
       
  2731     }
       
  2732     $this->acceptableContentTypes = $this->splitHttpAcceptHeader($_SERVER['HTTP_ACCEPT']);
       
  2733     return $this->acceptableContentTypes;
       
  2734   }
       
  2735   public function isXmlHttpRequest()
       
  2736   {
       
  2737     return ($this->getHttpHeader('X_REQUESTED_WITH') == 'XMLHttpRequest');
       
  2738   }
       
  2739   public function getHttpHeader($name, $prefix = 'http')
       
  2740   {
       
  2741     if ($prefix)
       
  2742     {
       
  2743       $prefix = strtoupper($prefix).'_';
       
  2744     }
       
  2745     $name = $prefix.strtoupper(strtr($name, '-', '_'));
       
  2746     $pathArray = $this->getPathInfoArray();
       
  2747     return isset($pathArray[$name]) ? sfToolkit::stripslashesDeep($pathArray[$name]) : null;
       
  2748   }
       
  2749   public function getCookie($name, $defaultValue = null)
       
  2750   {
       
  2751     $retval = $defaultValue;
       
  2752     if (isset($_COOKIE[$name]))
       
  2753     {
       
  2754       $retval = get_magic_quotes_gpc() ? sfToolkit::stripslashesDeep($_COOKIE[$name]) : $_COOKIE[$name];
       
  2755     }
       
  2756     return $retval;
       
  2757   }
       
  2758   public function isSecure()
       
  2759   {
       
  2760     $pathArray = $this->getPathInfoArray();
       
  2761     return (
       
  2762       (isset($pathArray['HTTPS']) && (strtolower($pathArray['HTTPS']) == 'on' || $pathArray['HTTPS'] == 1))
       
  2763       ||
       
  2764       (isset($pathArray['HTTP_SSL_HTTPS']) && (strtolower($pathArray['HTTP_SSL_HTTPS']) == 'on' || $pathArray['HTTP_SSL_HTTPS'] == 1))
       
  2765       ||
       
  2766       (isset($pathArray['HTTP_X_FORWARDED_PROTO']) && strtolower($pathArray['HTTP_X_FORWARDED_PROTO']) == 'https')
       
  2767     );
       
  2768   }
       
  2769   public function getRelativeUrlRoot()
       
  2770   {
       
  2771     if (is_null($this->relativeUrlRoot))
       
  2772     {
       
  2773       if (!isset($this->options['relative_url_root']))
       
  2774       {
       
  2775         $this->relativeUrlRoot = preg_replace('#/[^/]+\.php5?$#', '', $this->getScriptName());
       
  2776       }
       
  2777       else
       
  2778       {
       
  2779         $this->relativeUrlRoot = $this->options['relative_url_root'];
       
  2780       }
       
  2781     }
       
  2782     return $this->relativeUrlRoot;
       
  2783   }
       
  2784   public function setRelativeUrlRoot($value)
       
  2785   {
       
  2786     $this->relativeUrlRoot = $value;
       
  2787   }
       
  2788   public function splitHttpAcceptHeader($header)
       
  2789   {
       
  2790     $values = array();
       
  2791     foreach (array_filter(explode(',', $header)) as $value)
       
  2792     {
       
  2793             if ($pos = strpos($value, ';'))
       
  2794       {
       
  2795         $q     = (float) trim(substr($value, $pos + 3));
       
  2796         $value = trim(substr($value, 0, $pos));
       
  2797       }
       
  2798       else
       
  2799       {
       
  2800         $q = 1;
       
  2801       }
       
  2802       $values[$value] = $q;
       
  2803     }
       
  2804     arsort($values);
       
  2805     return array_keys($values);
       
  2806   }
       
  2807   public function getPathInfoArray()
       
  2808   {
       
  2809     if (!$this->pathInfoArray)
       
  2810     {
       
  2811             switch ($this->options['path_info_array'])
       
  2812       {
       
  2813         case 'SERVER':
       
  2814           $this->pathInfoArray =& $_SERVER;
       
  2815           break;
       
  2816         case 'ENV':
       
  2817         default:
       
  2818           $this->pathInfoArray =& $_ENV;
       
  2819       }
       
  2820     }
       
  2821     return $this->pathInfoArray;
       
  2822   }
       
  2823   public function getMimeType($format)
       
  2824   {
       
  2825     return isset($this->formats[$format]) ? $this->formats[$format][0] : null;
       
  2826   }
       
  2827   public function getFormat($mimeType)
       
  2828   {
       
  2829     foreach ($this->formats as $format => $mimeTypes)
       
  2830     {
       
  2831       if (in_array($mimeType, $mimeTypes))
       
  2832       {
       
  2833         return $format;
       
  2834       }
       
  2835     }
       
  2836     return null;
       
  2837   }
       
  2838   public function setFormat($format, $mimeTypes)
       
  2839   {
       
  2840     $this->formats[$format] = is_array($mimeTypes) ? $mimeTypes : array($mimeTypes);
       
  2841   }
       
  2842   public function setRequestFormat($format)
       
  2843   {
       
  2844     $this->format = $format;
       
  2845   }
       
  2846   public function getRequestFormat()
       
  2847   {
       
  2848     if (is_null($this->format))
       
  2849     {
       
  2850       $this->setRequestFormat($this->getParameter('sf_format'));
       
  2851     }
       
  2852     return $this->format;
       
  2853   }
       
  2854   public function getFiles($key = null)
       
  2855   {
       
  2856     if (false === $this->fixedFileArray)
       
  2857     {
       
  2858       $this->fixedFileArray = self::convertFileInformation($_FILES);
       
  2859     }
       
  2860     return is_null($key) ? $this->fixedFileArray : (isset($this->fixedFileArray[$key]) ? $this->fixedFileArray[$key] : array());
       
  2861   }
       
  2862   static public function convertFileInformation(array $taintedFiles)
       
  2863   {
       
  2864     $files = array();
       
  2865     foreach ($taintedFiles as $key => $data)
       
  2866     {
       
  2867       $files[$key] = self::fixPhpFilesArray($data);
       
  2868     }
       
  2869     return $files;
       
  2870   }
       
  2871   static protected function fixPhpFilesArray($data)
       
  2872   {
       
  2873     $fileKeys = array('error', 'name', 'size', 'tmp_name', 'type');
       
  2874     $keys = array_keys($data);
       
  2875     sort($keys);
       
  2876     if ($fileKeys != $keys || !isset($data['name']) || !is_array($data['name']))
       
  2877     {
       
  2878       return $data;
       
  2879     }
       
  2880     $files = $data;
       
  2881     foreach ($fileKeys as $k)
       
  2882     {
       
  2883       unset($files[$k]);
       
  2884     }
       
  2885     foreach (array_keys($data['name']) as $key)
       
  2886     {
       
  2887       $files[$key] = self::fixPhpFilesArray(array(
       
  2888         'error'    => $data['error'][$key],
       
  2889         'name'     => $data['name'][$key],
       
  2890         'type'     => $data['type'][$key],
       
  2891         'tmp_name' => $data['tmp_name'][$key],
       
  2892         'size'     => $data['size'][$key],
       
  2893       ));
       
  2894     }
       
  2895     return $files;
       
  2896   }
       
  2897   public function getGetParameter($name, $default = null)
       
  2898   {
       
  2899     if (isset($this->getParameters[$name]))
       
  2900     {
       
  2901       return $this->getParameters[$name];
       
  2902     }
       
  2903     else
       
  2904     {
       
  2905       return sfToolkit::getArrayValueForPath($this->getParameters, $name, $default);
       
  2906     }
       
  2907   }
       
  2908   public function getPostParameter($name, $default = null)
       
  2909   {
       
  2910     if (isset($this->postParameters[$name]))
       
  2911     {
       
  2912       return $this->postParameters[$name];
       
  2913     }
       
  2914     else
       
  2915     {
       
  2916       return sfToolkit::getArrayValueForPath($this->postParameters, $name, $default);
       
  2917     }
       
  2918   }
       
  2919   public function getUrlParameter($name, $default = null)
       
  2920   {
       
  2921     if (isset($this->requestParameters[$name]))
       
  2922     {
       
  2923       return $this->requestParameters[$name];
       
  2924     }
       
  2925     else
       
  2926     {
       
  2927       return sfToolkit::getArrayValueForPath($this->requestParameters, $name, $default);
       
  2928     }
       
  2929   }
       
  2930   public function getRemoteAddress()
       
  2931   {
       
  2932     $pathInfo = $this->getPathInfoArray();
       
  2933     return $pathInfo['REMOTE_ADDR'];
       
  2934   }
       
  2935   public function getForwardedFor()
       
  2936   {
       
  2937     $pathInfo = $this->getPathInfoArray();
       
  2938     if (empty($pathInfo['HTTP_X_FORWARDED_FOR']))
       
  2939     {
       
  2940       return null;
       
  2941     }
       
  2942     return explode(', ', $pathInfo['HTTP_X_FORWARDED_FOR']);
       
  2943   }
       
  2944   public function checkCSRFProtection()
       
  2945   {
       
  2946     $form = new sfForm();
       
  2947     $form->bind($form->isCSRFProtected() ? array($form->getCSRFFieldName() => $this->getParameter($form->getCSRFFieldName())) : array());
       
  2948     if (!$form->isValid())
       
  2949     {
       
  2950       throw $form->getErrorSchema();
       
  2951     }
       
  2952   }
       
  2953   protected function parseRequestParameters()
       
  2954   {
       
  2955     return $this->dispatcher->filter(new sfEvent($this, 'request.filter_parameters', $this->getRequestContext()), array())->getReturnValue();
       
  2956   }
       
  2957   public function getRequestContext()
       
  2958   {
       
  2959     return array(
       
  2960       'path_info'   => $this->getPathInfo(),
       
  2961       'prefix'      => $this->getPathInfoPrefix(),
       
  2962       'method'      => $this->getMethod(),
       
  2963       'format'      => $this->getRequestFormat(),
       
  2964       'host'        => $this->getHost(),
       
  2965       'is_secure'   => $this->isSecure(),
       
  2966       'request_uri' => $this->getUri(),
       
  2967     );
       
  2968   }
       
  2969   protected function fixParameters()
       
  2970   {
       
  2971         foreach ($this->parameterHolder->getAll() as $key => $value)
       
  2972     {
       
  2973       if (0 === stripos($key, '_sf_'))
       
  2974       {
       
  2975         $this->parameterHolder->remove($key);
       
  2976         $this->setAttribute(substr($key, 1), $value);
       
  2977       }
       
  2978     }
       
  2979   }
       
  2980 }
       
  2981 
       
  2982 
       
  2983 class sfPatternRouting extends sfRouting
       
  2984 {
       
  2985   protected
       
  2986     $currentRouteName   = null,
       
  2987     $currentInternalUri = array(),
       
  2988     $routes             = array(),
       
  2989     $cacheData          = array(),
       
  2990     $cacheChanged       = false,
       
  2991     $routesFullyLoaded  = true;
       
  2992   public function initialize(sfEventDispatcher $dispatcher, sfCache $cache = null, $options = array())
       
  2993   {
       
  2994     $options = array_merge(array(
       
  2995       'variable_prefixes'                => array(':'),
       
  2996       'segment_separators'               => array('/', '.'),
       
  2997       'variable_regex'                   => '[\w\d_]+',
       
  2998       'load_configuration'               => false,
       
  2999       'suffix'                           => '',
       
  3000       'generate_shortest_url'            => true,
       
  3001       'extra_parameters_as_query_string' => true,
       
  3002       'lazy_routes_deserialize'          => false,
       
  3003       'lookup_cache_dedicated_keys'      => false,
       
  3004     ), $options);
       
  3005         if ('.' == $options['suffix'])
       
  3006     {
       
  3007       $options['suffix'] = '';
       
  3008     }
       
  3009     parent::initialize($dispatcher, $cache, $options);
       
  3010     if (!is_null($this->cache) && !$options['lookup_cache_dedicated_keys'] && $cacheData = $this->cache->get('symfony.routing.data'))
       
  3011     {
       
  3012       $this->cacheData = unserialize($cacheData);
       
  3013     }
       
  3014   }
       
  3015   public function loadConfiguration()
       
  3016   {
       
  3017     if (!is_null($this->cache) && $routes = $this->cache->get('symfony.routing.configuration'))
       
  3018     {
       
  3019       $this->routes = unserialize($routes);
       
  3020       $this->routesFullyLoaded = false;
       
  3021     }
       
  3022     else
       
  3023     {
       
  3024       if ($this->options['load_configuration'] && $config = sfContext::getInstance()->getConfigCache()->checkConfig('config/routing.yml', true))
       
  3025       {
       
  3026         $this->setRoutes(include($config));
       
  3027       }
       
  3028       parent::loadConfiguration();
       
  3029       if (!is_null($this->cache))
       
  3030       {
       
  3031         if (!$this->options['lazy_routes_deserialize'])
       
  3032         {
       
  3033           $this->cache->set('symfony.routing.configuration', serialize($this->routes));
       
  3034         }
       
  3035         else
       
  3036         {
       
  3037           $lazyMap = array();
       
  3038           foreach ($this->routes as $name => $route)
       
  3039           {
       
  3040             if (is_string($route))
       
  3041             {
       
  3042               $route = $this->loadRoute($name);
       
  3043             }
       
  3044             $lazyMap[$name] = serialize($route);
       
  3045           }
       
  3046           $this->cache->set('symfony.routing.configuration', serialize($lazyMap));
       
  3047         }
       
  3048       }
       
  3049     }
       
  3050   }
       
  3051   protected function loadRoute($name)
       
  3052   {
       
  3053     if (is_string($route = $this->routes[$name]))
       
  3054     {
       
  3055       $this->routes[$name] = unserialize($route);
       
  3056       $this->routes[$name]->setDefaultParameters($this->defaultParameters);
       
  3057       return $this->routes[$name];
       
  3058     }
       
  3059     else
       
  3060     {
       
  3061       return $route;
       
  3062     }
       
  3063   }
       
  3064   protected function loadRoutes()
       
  3065   {
       
  3066     if ($this->routesFullyLoaded)
       
  3067     {
       
  3068       return;
       
  3069     }
       
  3070     foreach ($this->routes as $name => $route)
       
  3071     {
       
  3072       if (is_string($route))
       
  3073       {
       
  3074         $this->loadRoute($name);
       
  3075       }
       
  3076     }
       
  3077     $this->routesFullyLoaded = true;
       
  3078   }
       
  3079   public function getCurrentInternalUri($withRouteName = false)
       
  3080   {
       
  3081     return is_null($this->currentRouteName) ? null : $this->currentInternalUri[$withRouteName ? 0 : 1];
       
  3082   }
       
  3083   public function getCurrentRouteName()
       
  3084   {
       
  3085     return $this->currentRouteName;
       
  3086   }
       
  3087   public function getRoutes()
       
  3088   {
       
  3089     if (!$this->routesFullyLoaded)
       
  3090     {
       
  3091       $this->loadRoutes();
       
  3092     }
       
  3093     return $this->routes;
       
  3094   }
       
  3095   public function setRoutes($routes)
       
  3096   {
       
  3097     foreach ($routes as $name => $route)
       
  3098     {
       
  3099       $this->connect($name, $route);
       
  3100     }
       
  3101     if (!$this->routesFullyLoaded)
       
  3102     {
       
  3103       $this->loadRoutes();
       
  3104     }
       
  3105     return $this->routes;
       
  3106   }
       
  3107   public function hasRoutes()
       
  3108   {
       
  3109     return count($this->routes) ? true : false;
       
  3110   }
       
  3111   public function clearRoutes()
       
  3112   {
       
  3113     if ($this->options['logging'])
       
  3114     {
       
  3115       $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Clear all current routes')));
       
  3116     }
       
  3117     $this->routes = array();
       
  3118   }
       
  3119   public function hasRouteName($name)
       
  3120   {
       
  3121     return isset($this->routes[$name]) ? true : false;
       
  3122   }
       
  3123   public function prependRoute($name, $route)
       
  3124   {
       
  3125     $routes = $this->routes;
       
  3126     $this->routes = array();
       
  3127     $newroutes = $this->connect($name, $route);
       
  3128     $this->routes = array_merge($newroutes, $routes);
       
  3129     if (!$this->routesFullyLoaded)
       
  3130     {
       
  3131       $this->loadRoutes();
       
  3132     }
       
  3133     return $this->routes;
       
  3134   }
       
  3135   public function appendRoute($name, $route)
       
  3136   {
       
  3137     return $this->connect($name, $route);
       
  3138   }
       
  3139   public function insertRouteBefore($pivot, $name, $route)
       
  3140   {
       
  3141     if (!isset($this->routes[$pivot]))
       
  3142     {
       
  3143       throw new sfConfigurationException(sprintf('Unable to insert route "%s" before inexistent route "%s".', $name, $pivot));
       
  3144     }
       
  3145     $routes = $this->routes;
       
  3146     $this->routes = array();
       
  3147     $newroutes = array();
       
  3148     foreach ($routes as $key => $value)
       
  3149     {
       
  3150       if ($key == $pivot)
       
  3151       {
       
  3152         $newroutes = array_merge($newroutes, $this->connect($name, $route));
       
  3153       }
       
  3154       $newroutes[$key] = $value;
       
  3155     }
       
  3156     $this->routes = $newroutes;
       
  3157     if (!$this->routesFullyLoaded)
       
  3158     {
       
  3159       $this->loadRoutes();
       
  3160     }
       
  3161     return $this->routes;
       
  3162   }
       
  3163   public function connect($name, $route)
       
  3164   {
       
  3165     $routes = $route instanceof sfRouteCollection ? $route : array($name => $route);
       
  3166     foreach (self::flattenRoutes($routes) as $name => $route)
       
  3167     {
       
  3168       $this->routes[$name] = $route;
       
  3169       $this->configureRoute($route);
       
  3170       if ($this->options['logging'])
       
  3171       {
       
  3172         $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Connect %s "%s" (%s)', get_class($route), $name, $route->getPattern()))));
       
  3173       }
       
  3174     }
       
  3175     if (!$this->routesFullyLoaded)
       
  3176     {
       
  3177       $this->loadRoutes();
       
  3178     }
       
  3179     return $this->routes;
       
  3180   }
       
  3181   public function configureRoute(sfRoute $route)
       
  3182   {
       
  3183     $route->setDefaultParameters($this->defaultParameters);
       
  3184     $route->setDefaultOptions($this->options);
       
  3185   }
       
  3186   public function generate($name, $params = array(), $absolute = false)
       
  3187   {
       
  3188         if (!is_null($this->cache))
       
  3189     {
       
  3190       $cacheKey = 'generate_'.$name.'_'.md5(serialize(array_merge($this->defaultParameters, $params))).'_'.md5(serialize($this->options['context']));
       
  3191       if ($this->options['lookup_cache_dedicated_keys'] && $url = $this->cache->get('symfony.routing.data.'.$cacheKey))
       
  3192       {
       
  3193         return $this->fixGeneratedUrl($url, $absolute);
       
  3194       }
       
  3195       elseif (isset($this->cacheData[$cacheKey]))
       
  3196       {
       
  3197         return $this->fixGeneratedUrl($this->cacheData[$cacheKey], $absolute);
       
  3198       }
       
  3199     }
       
  3200     if ($name)
       
  3201     {
       
  3202             if (!isset($this->routes[$name]))
       
  3203       {
       
  3204         throw new sfConfigurationException(sprintf('The route "%s" does not exist.', $name));
       
  3205       }
       
  3206       $route = $this->routes[$name];
       
  3207       if (is_string($route))
       
  3208       {
       
  3209         $route = $this->loadRoute($name);
       
  3210       }
       
  3211       $route->setDefaultParameters($this->defaultParameters);
       
  3212     }
       
  3213     else
       
  3214     {
       
  3215             if (false === $route = $this->getRouteThatMatchesParameters($params, $this->options['context']))
       
  3216       {
       
  3217         throw new sfConfigurationException(sprintf('Unable to find a matching route to generate url for params "%s".', is_object($params) ? 'Object('.get_class($params).')' : str_replace("\n", '', var_export($params, true))));
       
  3218       }
       
  3219     }
       
  3220     $url = $route->generate($params, $this->options['context'], $absolute);
       
  3221         if (!is_null($this->cache))
       
  3222     {
       
  3223       if ($this->options['lookup_cache_dedicated_keys'])
       
  3224       {
       
  3225         $this->cache->set('symfony.routing.data.'.$cacheKey, $url);
       
  3226       }
       
  3227       else
       
  3228       {
       
  3229         $this->cacheChanged = true;
       
  3230         $this->cacheData[$cacheKey] = $url;
       
  3231       }
       
  3232     }
       
  3233     return $this->fixGeneratedUrl($url, $absolute);
       
  3234   }
       
  3235   public function parse($url)
       
  3236   {
       
  3237     if (false === $info = $this->findRoute($url))
       
  3238     {
       
  3239       $this->currentRouteName = null;
       
  3240       $this->currentInternalUri = array();
       
  3241       return false;
       
  3242     }
       
  3243     if ($this->options['logging'])
       
  3244     {
       
  3245       $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Match route "%s" (%s) for %s with parameters %s', $info['name'], $info['pattern'], $url, str_replace("\n", '', var_export($info['parameters'], true))))));
       
  3246     }
       
  3247         $this->updateCurrentInternalUri($info['name'], $info['parameters']);
       
  3248     $route = $this->routes[$info['name']];
       
  3249     if (is_string($route))
       
  3250     {
       
  3251       $route = $this->loadRoute($info['name']);
       
  3252     }
       
  3253     $route->setDefaultParameters($this->defaultParameters);
       
  3254     $route->bind($this->options['context'], $info['parameters']);
       
  3255     $info['parameters']['_sf_route'] = $route;
       
  3256     return $info['parameters'];
       
  3257   }
       
  3258   protected function updateCurrentInternalUri($name, array $parameters)
       
  3259   {
       
  3260         $this->currentRouteName = $name;
       
  3261     $internalUri = array('@'.$this->currentRouteName, $parameters['module'].'/'.$parameters['action']);
       
  3262     unset($parameters['module'], $parameters['action']);
       
  3263     $params = array();
       
  3264     foreach ($parameters as $key => $value)
       
  3265     {
       
  3266       $params[] = $key.'='.$value;
       
  3267     }
       
  3268         sort($params);
       
  3269     $params = $params ? '?'.implode('&', $params) : '';
       
  3270     $this->currentInternalUri = array($internalUri[0].$params, $internalUri[1].$params);
       
  3271   }
       
  3272   public function findRoute($url)
       
  3273   {
       
  3274     $url = $this->normalizeUrl($url);
       
  3275         if (!is_null($this->cache))
       
  3276     {
       
  3277       $cacheKey = 'parse_'.$url.'_'.md5(serialize($this->options['context']));
       
  3278       if ($this->options['lookup_cache_dedicated_keys'] && $info = $this->cache->get('symfony.routing.data.'.$cacheKey))
       
  3279       {
       
  3280         return unserialize($info);
       
  3281       }
       
  3282       elseif (isset($this->cacheData[$cacheKey]))
       
  3283       {
       
  3284         return $this->cacheData[$cacheKey];
       
  3285       }
       
  3286     }
       
  3287     $info = $this->getRouteThatMatchesUrl($url);
       
  3288         if (!is_null($this->cache))
       
  3289     {
       
  3290       if ($this->options['lookup_cache_dedicated_keys'])
       
  3291       {
       
  3292         $this->cache->set('symfony.routing.data.'.$cacheKey, serialize($info));
       
  3293       }
       
  3294       else
       
  3295       {
       
  3296         $this->cacheChanged = true;
       
  3297         $this->cacheData[$cacheKey] = $info;
       
  3298       }
       
  3299     }
       
  3300     return $info;
       
  3301   }
       
  3302   static public function flattenRoutes($routes)
       
  3303   {
       
  3304     $flattenRoutes = array();
       
  3305     foreach ($routes as $name => $route)
       
  3306     {
       
  3307       if ($route instanceof sfRouteCollection)
       
  3308       {
       
  3309         $flattenRoutes = array_merge($flattenRoutes, self::flattenRoutes($route));
       
  3310       }
       
  3311       else
       
  3312       {
       
  3313         $flattenRoutes[$name] = $route;
       
  3314       }
       
  3315     }
       
  3316     return $flattenRoutes;
       
  3317   }
       
  3318   protected function getRouteThatMatchesUrl($url)
       
  3319   {
       
  3320     foreach ($this->routes as $name => $route)
       
  3321     {
       
  3322       if (is_string($route))
       
  3323       {
       
  3324         $route = $this->loadRoute($name);
       
  3325       }
       
  3326       $route->setDefaultParameters($this->defaultParameters);
       
  3327       if (false === $parameters = $route->matchesUrl($url, $this->options['context']))
       
  3328       {
       
  3329         continue;
       
  3330       }
       
  3331       return array('name' => $name, 'pattern' => $route->getPattern(), 'parameters' => $parameters);
       
  3332     }
       
  3333     return false;
       
  3334   }
       
  3335   protected function getRouteThatMatchesParameters($parameters)
       
  3336   {
       
  3337     foreach ($this->routes as $name => $route)
       
  3338     {
       
  3339       if (is_string($route))
       
  3340       {
       
  3341         $route = $this->loadRoute($name);
       
  3342       }
       
  3343       $route->setDefaultParameters($this->defaultParameters);
       
  3344       if ($route->matchesParameters($parameters, $this->options['context']))
       
  3345       {
       
  3346         return $route;
       
  3347       }
       
  3348     }
       
  3349     return false;
       
  3350   }
       
  3351   protected function normalizeUrl($url)
       
  3352   {
       
  3353         if ('/' != substr($url, 0, 1))
       
  3354     {
       
  3355       $url = '/'.$url;
       
  3356     }
       
  3357         if (false !== $pos = strpos($url, '?'))
       
  3358     {
       
  3359       $url = substr($url, 0, $pos);
       
  3360     }
       
  3361         $url = preg_replace('#/+#', '/', $url);
       
  3362     return $url;
       
  3363   }
       
  3364   public function shutdown()
       
  3365   {
       
  3366     if (!is_null($this->cache) && $this->cacheChanged)
       
  3367     {
       
  3368       $this->cacheChanged = false;
       
  3369       $this->cache->set('symfony.routing.data', serialize($this->cacheData));
       
  3370     }
       
  3371   }
       
  3372 }
       
  3373 
       
  3374 
       
  3375 class sfWebResponse extends sfResponse
       
  3376 {
       
  3377   const
       
  3378     FIRST  = 'first',
       
  3379     MIDDLE = '',
       
  3380     LAST   = 'last',
       
  3381     ALL    = 'ALL',
       
  3382     RAW    = 'RAW';
       
  3383   protected
       
  3384     $cookies     = array(),
       
  3385     $statusCode  = 200,
       
  3386     $statusText  = 'OK',
       
  3387     $headerOnly  = false,
       
  3388     $headers     = array(),
       
  3389     $metas       = array(),
       
  3390     $httpMetas   = array(),
       
  3391     $positions   = array('first', '', 'last'),
       
  3392     $stylesheets = array(),
       
  3393     $javascripts = array(),
       
  3394     $slots       = array();
       
  3395   static protected $statusTexts = array(
       
  3396     '100' => 'Continue',
       
  3397     '101' => 'Switching Protocols',
       
  3398     '200' => 'OK',
       
  3399     '201' => 'Created',
       
  3400     '202' => 'Accepted',
       
  3401     '203' => 'Non-Authoritative Information',
       
  3402     '204' => 'No Content',
       
  3403     '205' => 'Reset Content',
       
  3404     '206' => 'Partial Content',
       
  3405     '300' => 'Multiple Choices',
       
  3406     '301' => 'Moved Permanently',
       
  3407     '302' => 'Found',
       
  3408     '303' => 'See Other',
       
  3409     '304' => 'Not Modified',
       
  3410     '305' => 'Use Proxy',
       
  3411     '306' => '(Unused)',
       
  3412     '307' => 'Temporary Redirect',
       
  3413     '400' => 'Bad Request',
       
  3414     '401' => 'Unauthorized',
       
  3415     '402' => 'Payment Required',
       
  3416     '403' => 'Forbidden',
       
  3417     '404' => 'Not Found',
       
  3418     '405' => 'Method Not Allowed',
       
  3419     '406' => 'Not Acceptable',
       
  3420     '407' => 'Proxy Authentication Required',
       
  3421     '408' => 'Request Timeout',
       
  3422     '409' => 'Conflict',
       
  3423     '410' => 'Gone',
       
  3424     '411' => 'Length Required',
       
  3425     '412' => 'Precondition Failed',
       
  3426     '413' => 'Request Entity Too Large',
       
  3427     '414' => 'Request-URI Too Long',
       
  3428     '415' => 'Unsupported Media Type',
       
  3429     '416' => 'Requested Range Not Satisfiable',
       
  3430     '417' => 'Expectation Failed',
       
  3431     '500' => 'Internal Server Error',
       
  3432     '501' => 'Not Implemented',
       
  3433     '502' => 'Bad Gateway',
       
  3434     '503' => 'Service Unavailable',
       
  3435     '504' => 'Gateway Timeout',
       
  3436     '505' => 'HTTP Version Not Supported',
       
  3437   );
       
  3438   public function initialize(sfEventDispatcher $dispatcher, $options = array())
       
  3439   {
       
  3440     parent::initialize($dispatcher, $options);
       
  3441     $this->javascripts = array_combine($this->positions, array_fill(0, count($this->positions), array()));
       
  3442     $this->stylesheets = array_combine($this->positions, array_fill(0, count($this->positions), array()));
       
  3443     if (!isset($this->options['charset']))
       
  3444     {
       
  3445       $this->options['charset'] = 'utf-8';
       
  3446     }
       
  3447     if (!isset($this->options['send_http_headers']))
       
  3448     {
       
  3449       $this->options['send_http_headers'] = true;
       
  3450     }
       
  3451     if (!isset($this->options['http_protocol']))
       
  3452     {
       
  3453       $this->options['http_protocol'] = 'HTTP/1.0';
       
  3454     }
       
  3455     $this->options['content_type'] = $this->fixContentType(isset($this->options['content_type']) ? $this->options['content_type'] : 'text/html');
       
  3456   }
       
  3457   public function setHeaderOnly($value = true)
       
  3458   {
       
  3459     $this->headerOnly = (boolean) $value;
       
  3460   }
       
  3461   public function isHeaderOnly()
       
  3462   {
       
  3463     return $this->headerOnly;
       
  3464   }
       
  3465   public function setCookie($name, $value, $expire = null, $path = '/', $domain = '', $secure = false, $httpOnly = false)
       
  3466   {
       
  3467     if ($expire !== null)
       
  3468     {
       
  3469       if (is_numeric($expire))
       
  3470       {
       
  3471         $expire = (int) $expire;
       
  3472       }
       
  3473       else
       
  3474       {
       
  3475         $expire = strtotime($expire);
       
  3476         if ($expire === false || $expire == -1)
       
  3477         {
       
  3478           throw new sfException('Your expire parameter is not valid.');
       
  3479         }
       
  3480       }
       
  3481     }
       
  3482     $this->cookies[$name] = array(
       
  3483       'name'     => $name,
       
  3484       'value'    => $value,
       
  3485       'expire'   => $expire,
       
  3486       'path'     => $path,
       
  3487       'domain'   => $domain,
       
  3488       'secure'   => $secure ? true : false,
       
  3489       'httpOnly' => $httpOnly,
       
  3490     );
       
  3491   }
       
  3492   public function setStatusCode($code, $name = null)
       
  3493   {
       
  3494     $this->statusCode = $code;
       
  3495     $this->statusText = null !== $name ? $name : self::$statusTexts[$code];
       
  3496   }
       
  3497   public function getStatusText()
       
  3498   {
       
  3499     return $this->statusText;
       
  3500   }
       
  3501   public function getStatusCode()
       
  3502   {
       
  3503     return $this->statusCode;
       
  3504   }
       
  3505   public function setHttpHeader($name, $value, $replace = true)
       
  3506   {
       
  3507     $name = $this->normalizeHeaderName($name);
       
  3508     if (is_null($value))
       
  3509     {
       
  3510       unset($this->headers[$name]);
       
  3511       return;
       
  3512     }
       
  3513     if ('Content-Type' == $name)
       
  3514     {
       
  3515       if ($replace || !$this->getHttpHeader('Content-Type', null))
       
  3516       {
       
  3517         $this->setContentType($value);
       
  3518       }
       
  3519       return;
       
  3520     }
       
  3521     if (!$replace)
       
  3522     {
       
  3523       $current = isset($this->headers[$name]) ? $this->headers[$name] : '';
       
  3524       $value = ($current ? $current.', ' : '').$value;
       
  3525     }
       
  3526     $this->headers[$name] = $value;
       
  3527   }
       
  3528   public function getHttpHeader($name, $default = null)
       
  3529   {
       
  3530     $name = $this->normalizeHeaderName($name);
       
  3531     return isset($this->headers[$name]) ? $this->headers[$name] : $default;
       
  3532   }
       
  3533   public function hasHttpHeader($name)
       
  3534   {
       
  3535     return array_key_exists($this->normalizeHeaderName($name), $this->headers);
       
  3536   }
       
  3537   public function setContentType($value)
       
  3538   {
       
  3539     $this->headers['Content-Type'] = $this->fixContentType($value);
       
  3540   }
       
  3541   public function getCharset()
       
  3542   {
       
  3543     return $this->options['charset'];
       
  3544   }
       
  3545   public function getContentType()
       
  3546   {
       
  3547     return $this->getHttpHeader('Content-Type', $this->options['content_type']);
       
  3548   }
       
  3549   public function sendHttpHeaders()
       
  3550   {
       
  3551     if (!$this->options['send_http_headers'])
       
  3552     {
       
  3553       return;
       
  3554     }
       
  3555         $status = $this->options['http_protocol'].' '.$this->statusCode.' '.$this->statusText;
       
  3556     header($status);
       
  3557     if ($this->options['logging'])
       
  3558     {
       
  3559       $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Send status "%s"', $status))));
       
  3560     }
       
  3561         if (!$this->getHttpHeader('Content-Type'))
       
  3562     {
       
  3563       $this->setContentType($this->options['content_type']);
       
  3564     }
       
  3565     foreach ($this->headers as $name => $value)
       
  3566     {
       
  3567       header($name.': '.$value);
       
  3568       if ($value != '' && $this->options['logging'])
       
  3569       {
       
  3570         $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Send header "%s: %s"', $name, $value))));
       
  3571       }
       
  3572     }
       
  3573         foreach ($this->cookies as $cookie)
       
  3574     {
       
  3575       setrawcookie($cookie['name'], $cookie['value'], $cookie['expire'], $cookie['path'], $cookie['domain'], $cookie['secure'], $cookie['httpOnly']);
       
  3576       if ($this->options['logging'])
       
  3577       {
       
  3578         $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Send cookie "%s": "%s"', $cookie['name'], $cookie['value']))));
       
  3579       }
       
  3580     }
       
  3581   }
       
  3582   public function sendContent()
       
  3583   {
       
  3584     if (!$this->headerOnly)
       
  3585     {
       
  3586       parent::sendContent();
       
  3587     }
       
  3588   }
       
  3589   public function send()
       
  3590   {
       
  3591     $this->sendHttpHeaders();
       
  3592     $this->sendContent();
       
  3593   }
       
  3594   protected function normalizeHeaderName($name)
       
  3595   {
       
  3596     return preg_replace('/\-(.)/e', "'-'.strtoupper('\\1')", strtr(ucfirst(strtolower($name)), '_', '-'));
       
  3597   }
       
  3598   static public function getDate($timestamp, $type = 'rfc1123')
       
  3599   {
       
  3600     $type = strtolower($type);
       
  3601     if ($type == 'rfc1123')
       
  3602     {
       
  3603       return substr(gmdate('r', $timestamp), 0, -5).'GMT';
       
  3604     }
       
  3605     else if ($type == 'rfc1036')
       
  3606     {
       
  3607       return gmdate('l, d-M-y H:i:s ', $timestamp).'GMT';
       
  3608     }
       
  3609     else if ($type == 'asctime')
       
  3610     {
       
  3611       return gmdate('D M j H:i:s', $timestamp);
       
  3612     }
       
  3613     else
       
  3614     {
       
  3615       throw new InvalidArgumentException('The second getDate() method parameter must be one of: rfc1123, rfc1036 or asctime.');
       
  3616     }
       
  3617   }
       
  3618   public function addVaryHttpHeader($header)
       
  3619   {
       
  3620     $vary = $this->getHttpHeader('Vary');
       
  3621     $currentHeaders = array();
       
  3622     if ($vary)
       
  3623     {
       
  3624       $currentHeaders = preg_split('/\s*,\s*/', $vary);
       
  3625     }
       
  3626     $header = $this->normalizeHeaderName($header);
       
  3627     if (!in_array($header, $currentHeaders))
       
  3628     {
       
  3629       $currentHeaders[] = $header;
       
  3630       $this->setHttpHeader('Vary', implode(', ', $currentHeaders));
       
  3631     }
       
  3632   }
       
  3633   public function addCacheControlHttpHeader($name, $value = null)
       
  3634   {
       
  3635     $cacheControl = $this->getHttpHeader('Cache-Control');
       
  3636     $currentHeaders = array();
       
  3637     if ($cacheControl)
       
  3638     {
       
  3639       foreach (preg_split('/\s*,\s*/', $cacheControl) as $tmp)
       
  3640       {
       
  3641         $tmp = explode('=', $tmp);
       
  3642         $currentHeaders[$tmp[0]] = isset($tmp[1]) ? $tmp[1] : null;
       
  3643       }
       
  3644     }
       
  3645     $currentHeaders[strtr(strtolower($name), '_', '-')] = $value;
       
  3646     $headers = array();
       
  3647     foreach ($currentHeaders as $key => $value)
       
  3648     {
       
  3649       $headers[] = $key.(null !== $value ? '='.$value : '');
       
  3650     }
       
  3651     $this->setHttpHeader('Cache-Control', implode(', ', $headers));
       
  3652   }
       
  3653   public function getHttpMetas()
       
  3654   {
       
  3655     return $this->httpMetas;
       
  3656   }
       
  3657   public function addHttpMeta($key, $value, $replace = true)
       
  3658   {
       
  3659     $key = $this->normalizeHeaderName($key);
       
  3660         $this->setHttpHeader($key, $value, $replace);
       
  3661     if (is_null($value))
       
  3662     {
       
  3663       unset($this->httpMetas[$key]);
       
  3664       return;
       
  3665     }
       
  3666     if ('Content-Type' == $key)
       
  3667     {
       
  3668       $value = $this->getContentType();
       
  3669     }
       
  3670     elseif (!$replace)
       
  3671     {
       
  3672       $current = isset($this->httpMetas[$key]) ? $this->httpMetas[$key] : '';
       
  3673       $value = ($current ? $current.', ' : '').$value;
       
  3674     }
       
  3675     $this->httpMetas[$key] = $value;
       
  3676   }
       
  3677   public function getMetas()
       
  3678   {
       
  3679     return $this->metas;
       
  3680   }
       
  3681   public function addMeta($key, $value, $replace = true, $escape = true)
       
  3682   {
       
  3683     $key = strtolower($key);
       
  3684     if (is_null($value))
       
  3685     {
       
  3686       unset($this->metas[$key]);
       
  3687       return;
       
  3688     }
       
  3689             if ($escape)
       
  3690     {
       
  3691       $value = htmlspecialchars($value, ENT_QUOTES, $this->options['charset']);
       
  3692     }
       
  3693     $current = isset($this->metas[$key]) ? $this->metas[$key] : null;
       
  3694     if ($replace || !$current)
       
  3695     {
       
  3696       $this->metas[$key] = $value;
       
  3697     }
       
  3698   }
       
  3699   public function getTitle()
       
  3700   {
       
  3701     return isset($this->metas['title']) ? $this->metas['title'] : '';
       
  3702   }
       
  3703   public function setTitle($title, $escape = true)
       
  3704   {
       
  3705     $this->addMeta('title', $title, true, $escape);
       
  3706   }
       
  3707   public function getPositions()
       
  3708   {
       
  3709     return $this->positions;
       
  3710   }
       
  3711   public function getStylesheets($position = self::ALL)
       
  3712   {
       
  3713     if (self::ALL === $position)
       
  3714     {
       
  3715       $stylesheets = array();
       
  3716       foreach ($this->getPositions() as $position)
       
  3717       {
       
  3718         foreach ($this->stylesheets[$position] as $file => $options)
       
  3719         {
       
  3720           $stylesheets[$file] = $options;
       
  3721         }
       
  3722       }
       
  3723       return $stylesheets;
       
  3724     }
       
  3725     else if (self::RAW === $position)
       
  3726     {
       
  3727       return $this->stylesheets;
       
  3728     }
       
  3729     $this->validatePosition($position);
       
  3730     return $this->stylesheets[$position];
       
  3731   }
       
  3732   public function addStylesheet($file, $position = '', $options = array())
       
  3733   {
       
  3734     $this->validatePosition($position);
       
  3735     $this->stylesheets[$position][$file] = $options;
       
  3736   }
       
  3737   public function removeStylesheet($file)
       
  3738   {
       
  3739     foreach ($this->getPositions() as $position)
       
  3740     {
       
  3741       unset($this->stylesheets[$position][$file]);
       
  3742     }
       
  3743   }
       
  3744   public function getJavascripts($position = self::ALL)
       
  3745   {
       
  3746     if (self::ALL === $position)
       
  3747     {
       
  3748       $javascripts = array();
       
  3749       foreach ($this->getPositions() as $position)
       
  3750       {
       
  3751         foreach ($this->javascripts[$position] as $file => $options)
       
  3752         {
       
  3753           $javascripts[$file] = $options;
       
  3754         }
       
  3755       }
       
  3756       return $javascripts;
       
  3757     }
       
  3758     else if (self::RAW === $position)
       
  3759     {
       
  3760       return $this->javascripts;
       
  3761     }
       
  3762     $this->validatePosition($position);
       
  3763     return $this->javascripts[$position];
       
  3764   }
       
  3765   public function addJavascript($file, $position = '', $options = array())
       
  3766   {
       
  3767     $this->validatePosition($position);
       
  3768     $this->javascripts[$position][$file] = $options;
       
  3769   }
       
  3770   public function removeJavascript($file)
       
  3771   {
       
  3772     foreach ($this->getPositions() as $position)
       
  3773     {
       
  3774       unset($this->javascripts[$position][$file]);
       
  3775     }
       
  3776   }
       
  3777   public function getSlots()
       
  3778   {
       
  3779     return $this->slots;
       
  3780   }
       
  3781   public function setSlot($name, $content)
       
  3782   {
       
  3783     $this->slots[$name] = $content;
       
  3784   }
       
  3785   public function getCookies()
       
  3786   {
       
  3787     return $this->cookies;
       
  3788   }
       
  3789   public function getHttpHeaders()
       
  3790   {
       
  3791     return $this->headers;
       
  3792   }
       
  3793   public function clearHttpHeaders()
       
  3794   {
       
  3795     $this->headers = array();
       
  3796   }
       
  3797   public function copyProperties(sfWebResponse $response)
       
  3798   {
       
  3799     $this->options     = $response->getOptions();
       
  3800     $this->headers     = $response->getHttpHeaders();
       
  3801     $this->metas       = $response->getMetas();
       
  3802     $this->httpMetas   = $response->getHttpMetas();
       
  3803     $this->stylesheets = $response->getStylesheets(self::RAW);
       
  3804     $this->javascripts = $response->getJavascripts(self::RAW);
       
  3805     $this->slots       = $response->getSlots();
       
  3806   }
       
  3807   public function merge(sfWebResponse $response)
       
  3808   {
       
  3809     foreach ($this->getPositions() as $position)
       
  3810     {
       
  3811       $this->javascripts[$position] = array_merge($this->getJavascripts($position), $response->getJavascripts($position));
       
  3812       $this->stylesheets[$position] = array_merge($this->getStylesheets($position), $response->getStylesheets($position));
       
  3813     }
       
  3814     $this->slots = array_merge($this->getSlots(), $response->getSlots());
       
  3815   }
       
  3816   public function serialize()
       
  3817   {
       
  3818     return serialize(array($this->content, $this->statusCode, $this->statusText, $this->options, $this->cookies, $this->headerOnly, $this->headers, $this->metas, $this->httpMetas, $this->stylesheets, $this->javascripts, $this->slots));
       
  3819   }
       
  3820   public function unserialize($serialized)
       
  3821   {
       
  3822     list($this->content, $this->statusCode, $this->statusText, $this->options, $this->cookies, $this->headerOnly, $this->headers, $this->metas, $this->httpMetas, $this->stylesheets, $this->javascripts, $this->slots) = unserialize($serialized);
       
  3823   }
       
  3824   protected function validatePosition($position)
       
  3825   {
       
  3826     if (!in_array($position, $this->positions, true))
       
  3827     {
       
  3828       throw new InvalidArgumentException(sprintf('The position "%s" does not exist (available positions: %s).', $position, implode(', ', $this->positions)));
       
  3829     }
       
  3830   }
       
  3831   protected function fixContentType($contentType)
       
  3832   {
       
  3833         if (false === stripos($contentType, 'charset') && (0 === stripos($contentType, 'text/') || strlen($contentType) - 3 === strripos($contentType, 'xml')))
       
  3834     {
       
  3835       $contentType .= '; charset='.$this->options['charset'];
       
  3836     }
       
  3837         if (preg_match('/charset\s*=\s*(.+)\s*$/', $contentType, $match))
       
  3838     {
       
  3839       $this->options['charset'] = $match[1];
       
  3840     }
       
  3841     return $contentType;
       
  3842   }
       
  3843 }
       
  3844 
       
  3845 
       
  3846 class sfSessionStorage extends sfStorage
       
  3847 {
       
  3848   static protected
       
  3849     $sessionIdRegenerated = false,
       
  3850     $sessionStarted       = false;
       
  3851   public function initialize($options = null)
       
  3852   {
       
  3853     $cookieDefaults = session_get_cookie_params();
       
  3854     $options = array_merge(array(
       
  3855       'session_name'            => 'symfony',
       
  3856       'session_id'              => null,
       
  3857       'auto_start'              => true,
       
  3858       'session_cookie_lifetime' => $cookieDefaults['lifetime'],
       
  3859       'session_cookie_path'     => $cookieDefaults['path'],
       
  3860       'session_cookie_domain'   => $cookieDefaults['domain'],
       
  3861       'session_cookie_secure'   => $cookieDefaults['secure'],
       
  3862       'session_cookie_httponly' => isset($cookieDefaults['httponly']) ? $cookieDefaults['httponly'] : false,
       
  3863       'session_cache_limiter'   => 'none',
       
  3864     ), $options);
       
  3865         parent::initialize($options);
       
  3866         $sessionName = $this->options['session_name'];
       
  3867     session_name($sessionName);
       
  3868     if (!(boolean) ini_get('session.use_cookies') && $sessionId = $this->options['session_id'])
       
  3869     {
       
  3870       session_id($sessionId);
       
  3871     }
       
  3872     $lifetime = $this->options['session_cookie_lifetime'];
       
  3873     $path     = $this->options['session_cookie_path'];
       
  3874     $domain   = $this->options['session_cookie_domain'];
       
  3875     $secure   = $this->options['session_cookie_secure'];
       
  3876     $httpOnly = $this->options['session_cookie_httponly'];
       
  3877     session_set_cookie_params($lifetime, $path, $domain, $secure, $httpOnly);
       
  3878     if (!is_null($this->options['session_cache_limiter']))
       
  3879     {
       
  3880       session_cache_limiter($this->options['session_cache_limiter']);
       
  3881     }
       
  3882     if ($this->options['auto_start'] && !self::$sessionStarted)
       
  3883     {
       
  3884       session_start();
       
  3885       self::$sessionStarted = true;
       
  3886     }
       
  3887   }
       
  3888   public function read($key)
       
  3889   {
       
  3890     $retval = null;
       
  3891     if (isset($_SESSION[$key]))
       
  3892     {
       
  3893       $retval = $_SESSION[$key];
       
  3894     }
       
  3895     return $retval;
       
  3896   }
       
  3897   public function remove($key)
       
  3898   {
       
  3899     $retval = null;
       
  3900     if (isset($_SESSION[$key]))
       
  3901     {
       
  3902       $retval = $_SESSION[$key];
       
  3903       unset($_SESSION[$key]);
       
  3904     }
       
  3905     return $retval;
       
  3906   }
       
  3907   public function write($key, $data)
       
  3908   {
       
  3909     $_SESSION[$key] = $data;
       
  3910   }
       
  3911   public function regenerate($destroy = false)
       
  3912   {
       
  3913     if (self::$sessionIdRegenerated)
       
  3914     {
       
  3915       return;
       
  3916     }
       
  3917         session_regenerate_id($destroy);
       
  3918     self::$sessionIdRegenerated = true;
       
  3919   }
       
  3920   public function shutdown()
       
  3921   {
       
  3922         session_write_close();
       
  3923   }
       
  3924 }
       
  3925 
       
  3926 
       
  3927 class sfPHPView extends sfView
       
  3928 {
       
  3929   public function execute()
       
  3930   {
       
  3931   }
       
  3932   protected function loadCoreAndStandardHelpers()
       
  3933   {
       
  3934     static $coreHelpersLoaded = 0;
       
  3935     if ($coreHelpersLoaded)
       
  3936     {
       
  3937       return;
       
  3938     }
       
  3939     $coreHelpersLoaded = 1;
       
  3940     $helpers = array_unique(array_merge(array('Helper', 'Url', 'Asset', 'Tag', 'Escaping'), sfConfig::get('sf_standard_helpers')));
       
  3941         if (!sfConfig::get('sf_compat_10') && false !== $i = array_search('Form', $helpers))
       
  3942     {
       
  3943       unset($helpers[$i]);
       
  3944     }
       
  3945     $this->context->getConfiguration()->loadHelpers($helpers);
       
  3946   }
       
  3947   protected function renderFile($_sfFile)
       
  3948   {
       
  3949     if (sfConfig::get('sf_logging_enabled'))
       
  3950     {
       
  3951       $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Render "%s"', $_sfFile))));
       
  3952     }
       
  3953     $this->loadCoreAndStandardHelpers();
       
  3954         extract($this->attributeHolder->toArray());
       
  3955         ob_start();
       
  3956     ob_implicit_flush(0);
       
  3957     require($_sfFile);
       
  3958     return ob_get_clean();
       
  3959   }
       
  3960   public function getEngine()
       
  3961   {
       
  3962     return null;
       
  3963   }
       
  3964   public function configure()
       
  3965   {
       
  3966         $this->context->set('view_instance', $this);
       
  3967         require($this->context->getConfigCache()->checkConfig('modules/'.$this->moduleName.'/config/view.yml'));
       
  3968         if (!$this->directory)
       
  3969     {
       
  3970       $this->setDirectory($this->context->getConfiguration()->getTemplateDir($this->moduleName, $this->getTemplate()));
       
  3971     }
       
  3972   }
       
  3973   protected function decorate($content)
       
  3974   {
       
  3975     if (sfConfig::get('sf_logging_enabled'))
       
  3976     {
       
  3977       $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Decorate content with "%s/%s"', $this->getDecoratorDirectory(), $this->getDecoratorTemplate()))));
       
  3978     }
       
  3979         $attributeHolder = $this->attributeHolder;
       
  3980     $this->attributeHolder = $this->initializeAttributeHolder(array('sf_content' => new sfOutputEscaperSafe($content)));
       
  3981     $this->attributeHolder->set('sf_type', 'layout');
       
  3982         $ret = $this->renderFile($this->getDecoratorDirectory().'/'.$this->getDecoratorTemplate());
       
  3983     $this->attributeHolder = $attributeHolder;
       
  3984     return $ret;
       
  3985   }
       
  3986   public function render()
       
  3987   {
       
  3988     $content = null;
       
  3989     if (sfConfig::get('sf_cache'))
       
  3990     {
       
  3991       $viewCache = $this->context->getViewCacheManager();
       
  3992       $uri = $this->context->getRouting()->getCurrentInternalUri();
       
  3993       if (!is_null($uri))
       
  3994       {
       
  3995         list($content, $decoratorTemplate) = $viewCache->getActionCache($uri);
       
  3996         if (!is_null($content))
       
  3997         {
       
  3998           $this->setDecoratorTemplate($decoratorTemplate);
       
  3999         }
       
  4000       }
       
  4001     }
       
  4002         if (is_null($content))
       
  4003     {
       
  4004             $this->preRenderCheck();
       
  4005       $this->attributeHolder->set('sf_type', 'action');
       
  4006             $content = $this->renderFile($this->getDirectory().'/'.$this->getTemplate());
       
  4007       if (sfConfig::get('sf_cache') && !is_null($uri))
       
  4008       {
       
  4009         $content = $viewCache->setActionCache($uri, $content, $this->isDecorator() ? $this->getDecoratorDirectory().'/'.$this->getDecoratorTemplate() : false);
       
  4010       }
       
  4011     }
       
  4012         if ($this->isDecorator())
       
  4013     {
       
  4014       $content = $this->decorate($content);
       
  4015     }
       
  4016     return $content;
       
  4017   }
       
  4018 }
       
  4019 
       
  4020 
       
  4021 class sfOutputEscaperSafe extends ArrayIterator
       
  4022 {
       
  4023   protected
       
  4024     $value = null;
       
  4025   public function __construct($value)
       
  4026   {
       
  4027     $this->value = $value;
       
  4028     if (is_array($value) || is_object($value))
       
  4029     {
       
  4030       parent::__construct($value);
       
  4031     }
       
  4032   }
       
  4033   public function __toString()
       
  4034   {
       
  4035     return (string) $this->value;
       
  4036   }
       
  4037   public function __get($key)
       
  4038   {
       
  4039     return $this->value->$key;
       
  4040   }
       
  4041   public function __set($key, $value)
       
  4042   {
       
  4043     $this->value->$key = $value;
       
  4044   }
       
  4045   public function __call($method, $arguments)
       
  4046   {
       
  4047     return call_user_func_array(array($this->value, $method), $arguments);
       
  4048   }
       
  4049   public function __isset($key)
       
  4050   {
       
  4051     return isset($this->value->$key);
       
  4052   }
       
  4053   public function __unset($key)
       
  4054   {
       
  4055     unset($this->value->$key);
       
  4056   }
       
  4057   public function getValue()
       
  4058   {
       
  4059     return $this->value;
       
  4060   }
       
  4061 }
       
  4062