PageRenderTime 56ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/cache/frontend/prod/config/config_core_compile.yml.php

https://bitbucket.org/vasyabigi/underconstruction
PHP | 4063 lines | 3994 code | 67 blank | 2 comment | 443 complexity | c16621464255fd6c3c6c28760344d955 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, AGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // auto-generated by sfCompileConfigHandler
  3. // date: 2009/11/25 13:31:30
  4. class sfAutoload
  5. {
  6. static protected
  7. $freshCache = false,
  8. $instance = null;
  9. protected
  10. $overriden = array(),
  11. $classes = array();
  12. protected function __construct()
  13. {
  14. }
  15. static public function getInstance()
  16. {
  17. if (!isset(self::$instance))
  18. {
  19. self::$instance = new sfAutoload();
  20. }
  21. return self::$instance;
  22. }
  23. static public function register()
  24. {
  25. ini_set('unserialize_callback_func', 'spl_autoload_call');
  26. if (false === spl_autoload_register(array(self::getInstance(), 'autoload')))
  27. {
  28. throw new sfException(sprintf('Unable to register %s::autoload as an autoloading method.', get_class(self::getInstance())));
  29. }
  30. }
  31. static public function unregister()
  32. {
  33. spl_autoload_unregister(array(self::getInstance(), 'autoload'));
  34. }
  35. public function setClassPath($class, $path)
  36. {
  37. $this->overriden[$class] = $path;
  38. $this->classes[$class] = $path;
  39. }
  40. public function getClassPath($class)
  41. {
  42. return isset($this->classes[$class]) ? $this->classes[$class] : null;
  43. }
  44. public function reloadClasses($force = false)
  45. {
  46. if (self::$freshCache)
  47. {
  48. return;
  49. }
  50. $configuration = sfProjectConfiguration::getActive();
  51. if (!$configuration || !$configuration instanceof sfApplicationConfiguration)
  52. {
  53. return;
  54. }
  55. self::$freshCache = true;
  56. if (file_exists($configuration->getConfigCache()->getCacheName('config/autoload.yml')))
  57. {
  58. self::$freshCache = false;
  59. if ($force)
  60. {
  61. unlink($configuration->getConfigCache()->getCacheName('config/autoload.yml'));
  62. }
  63. }
  64. $file = $configuration->getConfigCache()->checkConfig('config/autoload.yml');
  65. $this->classes = include($file);
  66. foreach ($this->overriden as $class => $path)
  67. {
  68. $this->classes[$class] = $path;
  69. }
  70. }
  71. public function autoload($class)
  72. {
  73. if (!$this->classes)
  74. {
  75. self::reloadClasses();
  76. }
  77. return self::loadClass($class);
  78. }
  79. public function autoloadAgain($class)
  80. {
  81. self::reloadClasses(true);
  82. return self::loadClass($class);
  83. }
  84. public function loadClass($class)
  85. {
  86. if (class_exists($class, false) || interface_exists($class, false))
  87. {
  88. return true;
  89. }
  90. if (isset($this->classes[$class]))
  91. {
  92. require($this->classes[$class]);
  93. return true;
  94. }
  95. if (sfContext::hasInstance() && ($module = sfContext::getInstance()->getModuleName()) && isset($this->classes[$module.'/'.$class]))
  96. {
  97. require($this->classes[$module.'/'.$class]);
  98. return true;
  99. }
  100. return false;
  101. }
  102. }
  103. abstract class sfComponent
  104. {
  105. protected
  106. $moduleName = '',
  107. $actionName = '',
  108. $context = null,
  109. $dispatcher = null,
  110. $request = null,
  111. $response = null,
  112. $varHolder = null,
  113. $requestParameterHolder = null;
  114. public function __construct($context, $moduleName, $actionName)
  115. {
  116. $this->initialize($context, $moduleName, $actionName);
  117. }
  118. public function initialize($context, $moduleName, $actionName)
  119. {
  120. $this->moduleName = $moduleName;
  121. $this->actionName = $actionName;
  122. $this->context = $context;
  123. $this->dispatcher = $context->getEventDispatcher();
  124. $this->varHolder = new sfParameterHolder();
  125. $this->request = $context->getRequest();
  126. $this->response = $context->getResponse();
  127. $this->requestParameterHolder = $this->request->getParameterHolder();
  128. }
  129. abstract function execute($request);
  130. public function getModuleName()
  131. {
  132. return $this->moduleName;
  133. }
  134. public function getActionName()
  135. {
  136. return $this->actionName;
  137. }
  138. public final function getContext()
  139. {
  140. return $this->context;
  141. }
  142. public final function getLogger()
  143. {
  144. return $this->context->getLogger();
  145. }
  146. public function logMessage($message, $priority = 'info')
  147. {
  148. if (sfConfig::get('sf_logging_enabled'))
  149. {
  150. $this->dispatcher->notify(new sfEvent($this, 'application.log', array($message, 'priority' => constant('sfLogger::'.strtoupper($priority)))));
  151. }
  152. }
  153. public function debugMessage($message)
  154. {
  155. if (sfConfig::get('sf_web_debug') && sfConfig::get('sf_logging_enabled'))
  156. {
  157. $this->dispatcher->notify(new sfEvent(null, 'application.log', array('This function is deprecated in favor of the logMessage function.', 'priority' => sfLogger::ERR)));
  158. }
  159. }
  160. public function getRequestParameter($name, $default = null)
  161. {
  162. return $this->requestParameterHolder->get($name, $default);
  163. }
  164. public function hasRequestParameter($name)
  165. {
  166. return $this->requestParameterHolder->has($name);
  167. }
  168. public function getRequest()
  169. {
  170. return $this->request;
  171. }
  172. public function getResponse()
  173. {
  174. return $this->response;
  175. }
  176. public function getController()
  177. {
  178. return $this->context->getController();
  179. }
  180. public function generateUrl($route, $params = array(), $absolute = false)
  181. {
  182. return $this->context->getRouting()->generate($route, $params, $absolute);
  183. }
  184. public function getUser()
  185. {
  186. return $this->context->getUser();
  187. }
  188. public function setVar($name, $value, $safe = false)
  189. {
  190. $this->varHolder->set($name, $safe ? new sfOutputEscaperSafe($value) : $value);
  191. }
  192. public function getVar($name)
  193. {
  194. return $this->varHolder->get($name);
  195. }
  196. public function getVarHolder()
  197. {
  198. return $this->varHolder;
  199. }
  200. public function __set($key, $value)
  201. {
  202. return $this->varHolder->setByRef($key, $value);
  203. }
  204. public function & __get($key)
  205. {
  206. return $this->varHolder->get($key);
  207. }
  208. public function __isset($name)
  209. {
  210. return $this->varHolder->has($name);
  211. }
  212. public function __unset($name)
  213. {
  214. $this->varHolder->remove($name);
  215. }
  216. public function __call($method, $arguments)
  217. {
  218. $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'component.method_not_found', array('method' => $method, 'arguments' => $arguments)));
  219. if (!$event->isProcessed())
  220. {
  221. throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
  222. }
  223. return $event->getReturnValue();
  224. }
  225. }
  226. abstract class sfAction extends sfComponent
  227. {
  228. protected
  229. $security = array();
  230. public function initialize($context, $moduleName, $actionName)
  231. {
  232. parent::initialize($context, $moduleName, $actionName);
  233. if ($file = $context->getConfigCache()->checkConfig('modules/'.$this->getModuleName().'/config/security.yml', true))
  234. {
  235. require($file);
  236. }
  237. }
  238. public function preExecute()
  239. {
  240. }
  241. public function postExecute()
  242. {
  243. }
  244. public function forward404($message = null)
  245. {
  246. throw new sfError404Exception($this->get404Message($message));
  247. }
  248. public function forward404Unless($condition, $message = null)
  249. {
  250. if (!$condition)
  251. {
  252. throw new sfError404Exception($this->get404Message($message));
  253. }
  254. }
  255. public function forward404If($condition, $message = null)
  256. {
  257. if ($condition)
  258. {
  259. throw new sfError404Exception($this->get404Message($message));
  260. }
  261. }
  262. public function redirect404()
  263. {
  264. return $this->redirect('/'.sfConfig::get('sf_error_404_module').'/'.sfConfig::get('sf_error_404_action'));
  265. }
  266. public function forward($module, $action)
  267. {
  268. if (sfConfig::get('sf_logging_enabled'))
  269. {
  270. $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Forward to action "%s/%s"', $module, $action))));
  271. }
  272. $this->getController()->forward($module, $action);
  273. throw new sfStopException();
  274. }
  275. public function forwardIf($condition, $module, $action)
  276. {
  277. if ($condition)
  278. {
  279. $this->forward($module, $action);
  280. }
  281. }
  282. public function forwardUnless($condition, $module, $action)
  283. {
  284. if (!$condition)
  285. {
  286. $this->forward($module, $action);
  287. }
  288. }
  289. public function redirect($url, $statusCode = 302)
  290. {
  291. $this->getController()->redirect($url, 0, $statusCode);
  292. throw new sfStopException();
  293. }
  294. public function redirectIf($condition, $url, $statusCode = 302)
  295. {
  296. if ($condition)
  297. {
  298. $this->redirect($url, $statusCode);
  299. }
  300. }
  301. public function redirectUnless($condition, $url, $statusCode = 302)
  302. {
  303. if (!$condition)
  304. {
  305. $this->redirect($url, $statusCode);
  306. }
  307. }
  308. public function renderText($text)
  309. {
  310. $this->getResponse()->setContent($this->getResponse()->getContent().$text);
  311. return sfView::NONE;
  312. }
  313. public function getPartial($templateName, $vars = null)
  314. {
  315. $this->getContext()->getConfiguration()->loadHelpers('Partial');
  316. $vars = !is_null($vars) ? $vars : $this->varHolder->getAll();
  317. return get_partial($templateName, $vars);
  318. }
  319. public function renderPartial($templateName, $vars = null)
  320. {
  321. return $this->renderText($this->getPartial($templateName, $vars));
  322. }
  323. public function getComponent($moduleName, $componentName, $vars = null)
  324. {
  325. $this->getContext()->getConfiguration()->loadHelpers('Partial');
  326. $vars = !is_null($vars) ? $vars : $this->varHolder->getAll();
  327. return get_component($moduleName, $componentName, $vars);
  328. }
  329. public function renderComponent($moduleName, $componentName, $vars = null)
  330. {
  331. return $this->renderText($this->getComponent($moduleName, $componentName, $vars));
  332. }
  333. public function getDefaultView()
  334. {
  335. if (!sfConfig::get('sf_compat_10'))
  336. {
  337. throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');
  338. }
  339. return sfView::INPUT;
  340. }
  341. public function handleError()
  342. {
  343. if (!sfConfig::get('sf_compat_10'))
  344. {
  345. throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');
  346. }
  347. return sfView::ERROR;
  348. }
  349. public function validate()
  350. {
  351. if (!sfConfig::get('sf_compat_10'))
  352. {
  353. throw new sfConfigurationException('You must set "compat_10" to true if you want to use this method which is deprecated.');
  354. }
  355. return true;
  356. }
  357. public function getSecurityConfiguration()
  358. {
  359. return $this->security;
  360. }
  361. public function setSecurityConfiguration($security)
  362. {
  363. $this->security = $security;
  364. }
  365. public function isSecure()
  366. {
  367. $actionName = strtolower($this->getActionName());
  368. if (isset($this->security[$actionName]['is_secure']))
  369. {
  370. return $this->security[$actionName]['is_secure'];
  371. }
  372. if (isset($this->security['all']['is_secure']))
  373. {
  374. return $this->security['all']['is_secure'];
  375. }
  376. return false;
  377. }
  378. public function getCredential()
  379. {
  380. $actionName = strtolower($this->getActionName());
  381. if (isset($this->security[$actionName]['credentials']))
  382. {
  383. $credentials = $this->security[$actionName]['credentials'];
  384. }
  385. else if (isset($this->security['all']['credentials']))
  386. {
  387. $credentials = $this->security['all']['credentials'];
  388. }
  389. else
  390. {
  391. $credentials = null;
  392. }
  393. return $credentials;
  394. }
  395. public function setTemplate($name, $module = null)
  396. {
  397. if (sfConfig::get('sf_logging_enabled'))
  398. {
  399. $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Change template to "%s/%s"', is_null($module) ? 'CURRENT' : $module, $name))));
  400. }
  401. if (!is_null($module))
  402. {
  403. $name = sfConfig::get('sf_app_dir').'/modules/'.$module.'/templates/'.$name;
  404. }
  405. sfConfig::set('symfony.view.'.$this->getModuleName().'_'.$this->getActionName().'_template', $name);
  406. }
  407. public function getTemplate()
  408. {
  409. return sfConfig::get('symfony.view.'.$this->getModuleName().'_'.$this->getActionName().'_template');
  410. }
  411. public function setLayout($name)
  412. {
  413. if (sfConfig::get('sf_logging_enabled'))
  414. {
  415. $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Change layout to "%s"', $name))));
  416. }
  417. sfConfig::set('symfony.view.'.$this->getModuleName().'_'.$this->getActionName().'_layout', $name);
  418. }
  419. public function getLayout()
  420. {
  421. return sfConfig::get('symfony.view.'.$this->getModuleName().'_'.$this->getActionName().'_layout');
  422. }
  423. public function setViewClass($class)
  424. {
  425. sfConfig::set('mod_'.strtolower($this->getModuleName()).'_view_class', $class);
  426. }
  427. public function getRoute()
  428. {
  429. return $this->getRequest()->getAttribute('sf_route');
  430. }
  431. protected function get404Message($message = null)
  432. {
  433. 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;
  434. }
  435. }
  436. abstract class sfActions extends sfAction
  437. {
  438. public function execute($request)
  439. {
  440. $actionToRun = 'execute'.ucfirst($this->getActionName());
  441. if ($actionToRun === 'execute')
  442. {
  443. throw new sfInitializationException(sprintf('sfAction initialization failed for module "%s". There was no action given.', $this->getModuleName()));
  444. }
  445. if (!is_callable(array($this, $actionToRun)))
  446. {
  447. throw new sfInitializationException(sprintf('sfAction initialization failed for module "%s", action "%s". You must create a "%s" method.', $this->getModuleName(), $this->getActionName(), $actionToRun));
  448. }
  449. if (sfConfig::get('sf_logging_enabled'))
  450. {
  451. $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Call "%s->%s()"', get_class($this), $actionToRun))));
  452. }
  453. return $this->$actionToRun($request);
  454. }
  455. }
  456. class sfActionStack
  457. {
  458. protected
  459. $stack = array();
  460. public function addEntry($moduleName, $actionName, $actionInstance)
  461. {
  462. $actionEntry = new sfActionStackEntry($moduleName, $actionName, $actionInstance);
  463. $this->stack[] = $actionEntry;
  464. return $actionEntry;
  465. }
  466. public function getEntry($index)
  467. {
  468. $retval = null;
  469. if ($index > -1 && $index < count($this->stack))
  470. {
  471. $retval = $this->stack[$index];
  472. }
  473. return $retval;
  474. }
  475. public function popEntry()
  476. {
  477. return array_pop($this->stack);
  478. }
  479. public function getFirstEntry()
  480. {
  481. $retval = null;
  482. if (isset($this->stack[0]))
  483. {
  484. $retval = $this->stack[0];
  485. }
  486. return $retval;
  487. }
  488. public function getLastEntry()
  489. {
  490. $count = count($this->stack);
  491. $retval = null;
  492. if (isset($this->stack[0]))
  493. {
  494. $retval = $this->stack[$count - 1];
  495. }
  496. return $retval;
  497. }
  498. public function getSize()
  499. {
  500. return count($this->stack);
  501. }
  502. }
  503. class sfActionStackEntry
  504. {
  505. protected
  506. $actionInstance = null,
  507. $actionName = null,
  508. $moduleName = null,
  509. $presentation = null;
  510. public function __construct($moduleName, $actionName, $actionInstance)
  511. {
  512. $this->actionName = $actionName;
  513. $this->actionInstance = $actionInstance;
  514. $this->moduleName = $moduleName;
  515. }
  516. public function getActionName()
  517. {
  518. return $this->actionName;
  519. }
  520. public function getActionInstance()
  521. {
  522. return $this->actionInstance;
  523. }
  524. public function getModuleName()
  525. {
  526. return $this->moduleName;
  527. }
  528. public function & getPresentation()
  529. {
  530. return $this->presentation;
  531. }
  532. public function setPresentation(&$presentation)
  533. {
  534. $this->presentation =& $presentation;
  535. }
  536. }
  537. class sfLoader
  538. {
  539. static public function getHelperDirs($moduleName = '')
  540. {
  541. $configuration = sfProjectConfiguration::getActive();
  542. $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)));
  543. return $configuration->getHelperDirs($moduleName);
  544. }
  545. static public function loadHelpers($helpers, $moduleName = '')
  546. {
  547. $configuration = sfProjectConfiguration::getActive();
  548. $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)));
  549. return $configuration->loadHelpers($helpers, $moduleName);
  550. }
  551. }
  552. abstract class sfController
  553. {
  554. protected
  555. $context = null,
  556. $dispatcher = null,
  557. $controllerClasses = array(),
  558. $maxForwards = 5,
  559. $renderMode = sfView::RENDER_CLIENT;
  560. public function __construct($context)
  561. {
  562. $this->initialize($context);
  563. }
  564. public function initialize($context)
  565. {
  566. $this->context = $context;
  567. $this->dispatcher = $context->getEventDispatcher();
  568. $this->maxForwards = sfConfig::get('sf_max_forwards', $this->maxForwards);
  569. }
  570. public function componentExists($moduleName, $componentName)
  571. {
  572. return $this->controllerExists($moduleName, $componentName, 'component', false);
  573. }
  574. public function actionExists($moduleName, $actionName)
  575. {
  576. return $this->controllerExists($moduleName, $actionName, 'action', false);
  577. }
  578. protected function controllerExists($moduleName, $controllerName, $extension, $throwExceptions)
  579. {
  580. $dirs = $this->context->getConfiguration()->getControllerDirs($moduleName);
  581. foreach ($dirs as $dir => $checkEnabled)
  582. {
  583. if ($checkEnabled && !in_array($moduleName, sfConfig::get('sf_enabled_modules')) && is_readable($dir))
  584. {
  585. throw new sfConfigurationException(sprintf('The module "%s" is not enabled.', $moduleName));
  586. }
  587. $classFile = strtolower($extension);
  588. $classSuffix = ucfirst(strtolower($extension));
  589. $file = $dir.'/'.$controllerName.$classSuffix.'.class.php';
  590. if (is_readable($file))
  591. {
  592. require_once($file);
  593. $this->controllerClasses[$moduleName.'_'.$controllerName.'_'.$classSuffix] = $controllerName.$classSuffix;
  594. return true;
  595. }
  596. $module_file = $dir.'/'.$classFile.'s.class.php';
  597. if (is_readable($module_file))
  598. {
  599. require_once($module_file);
  600. if (!class_exists($moduleName.$classSuffix.'s', false))
  601. {
  602. if ($throwExceptions)
  603. {
  604. throw new sfControllerException(sprintf('There is no "%s" class in your action file "%s".', $moduleName.$classSuffix.'s', $module_file));
  605. }
  606. return false;
  607. }
  608. if (!in_array('execute'.ucfirst($controllerName), get_class_methods($moduleName.$classSuffix.'s')))
  609. {
  610. if ($throwExceptions)
  611. {
  612. throw new sfControllerException(sprintf('There is no "%s" method in your action class "%s".', 'execute'.ucfirst($controllerName), $moduleName.$classSuffix.'s'));
  613. }
  614. return false;
  615. }
  616. $this->controllerClasses[$moduleName.'_'.$controllerName.'_'.$classSuffix] = $moduleName.$classSuffix.'s';
  617. return true;
  618. }
  619. }
  620. if ($throwExceptions && sfConfig::get('sf_debug'))
  621. {
  622. $dirs = array_keys($dirs);
  623. foreach ($dirs as &$dir)
  624. {
  625. $dir = str_replace(sfConfig::get('sf_root_dir'), '%SF_ROOT_DIR%', $dir);
  626. }
  627. throw new sfControllerException(sprintf('Controller "%s/%s" does not exist in: %s.', $moduleName, $controllerName, implode(', ', $dirs)));
  628. }
  629. return false;
  630. }
  631. public function forward($moduleName, $actionName)
  632. {
  633. $moduleName = preg_replace('/[^a-z0-9_]+/i', '', $moduleName);
  634. $actionName = preg_replace('/[^a-z0-9_]+/i', '', $actionName);
  635. if ($this->getActionStack()->getSize() >= $this->maxForwards)
  636. {
  637. throw new sfForwardException(sprintf('Too many forwards have been detected for this request (> %d).', $this->maxForwards));
  638. }
  639. $this->context->getConfigCache()->import('modules/'.$moduleName.'/config/generator.yml', false, true);
  640. if (!$this->actionExists($moduleName, $actionName))
  641. {
  642. if (sfConfig::get('sf_logging_enabled'))
  643. {
  644. $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Action "%s/%s" does not exist', $moduleName, $actionName))));
  645. }
  646. throw new sfError404Exception(sprintf('Action "%s/%s" does not exist.', $moduleName, $actionName));
  647. }
  648. $actionInstance = $this->getAction($moduleName, $actionName);
  649. $this->getActionStack()->addEntry($moduleName, $actionName, $actionInstance);
  650. require($this->context->getConfigCache()->checkConfig('modules/'.$moduleName.'/config/module.yml'));
  651. if ($this->getActionStack()->getSize() == 1 && sfConfig::get('mod_'.strtolower($moduleName).'_is_internal') && !sfConfig::get('sf_test'))
  652. {
  653. throw new sfConfigurationException(sprintf('Action "%s" from module "%s" cannot be called directly.', $actionName, $moduleName));
  654. }
  655. if (sfConfig::get('mod_'.strtolower($moduleName).'_enabled'))
  656. {
  657. $moduleConfig = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/config/config.php';
  658. if (is_readable($moduleConfig))
  659. {
  660. require_once($moduleConfig);
  661. }
  662. $filterChain = new sfFilterChain();
  663. $filterChain->loadConfiguration($actionInstance);
  664. $this->context->getEventDispatcher()->notify(new sfEvent($this, 'controller.change_action', array('module' => $moduleName, 'action' => $actionName)));
  665. if ($moduleName == sfConfig::get('sf_error_404_module') && $actionName == sfConfig::get('sf_error_404_action'))
  666. {
  667. $this->context->getResponse()->setStatusCode(404);
  668. $this->context->getResponse()->setHttpHeader('Status', '404 Not Found');
  669. $this->dispatcher->notify(new sfEvent($this, 'controller.page_not_found', array('module' => $moduleName, 'action' => $actionName)));
  670. }
  671. $filterChain->execute();
  672. }
  673. else
  674. {
  675. $moduleName = sfConfig::get('sf_module_disabled_module');
  676. $actionName = sfConfig::get('sf_module_disabled_action');
  677. if (!$this->actionExists($moduleName, $actionName))
  678. {
  679. throw new sfConfigurationException(sprintf('Invalid configuration settings: [sf_module_disabled_module] "%s", [sf_module_disabled_action] "%s".', $moduleName, $actionName));
  680. }
  681. $this->forward($moduleName, $actionName);
  682. }
  683. }
  684. public function getAction($moduleName, $actionName)
  685. {
  686. return $this->getController($moduleName, $actionName, 'action');
  687. }
  688. public function getComponent($moduleName, $componentName)
  689. {
  690. return $this->getController($moduleName, $componentName, 'component');
  691. }
  692. protected function getController($moduleName, $controllerName, $extension)
  693. {
  694. $classSuffix = ucfirst(strtolower($extension));
  695. if (!isset($this->controllerClasses[$moduleName.'_'.$controllerName.'_'.$classSuffix]))
  696. {
  697. $this->controllerExists($moduleName, $controllerName, $extension, true);
  698. }
  699. $class = $this->controllerClasses[$moduleName.'_'.$controllerName.'_'.$classSuffix];
  700. $moduleClass = $moduleName.'_'.$class;
  701. if (class_exists($moduleClass, false))
  702. {
  703. $class = $moduleClass;
  704. }
  705. return new $class($this->context, $moduleName, $controllerName);
  706. }
  707. public function getActionStack()
  708. {
  709. return $this->context->getActionStack();
  710. }
  711. public function getRenderMode()
  712. {
  713. return $this->renderMode;
  714. }
  715. public function getView($moduleName, $actionName, $viewName)
  716. {
  717. $file = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/view/'.$actionName.$viewName.'View.class.php';
  718. if (is_readable($file))
  719. {
  720. require_once($file);
  721. $class = $actionName.$viewName.'View';
  722. $moduleClass = $moduleName.'_'.$class;
  723. if (class_exists($moduleClass, false))
  724. {
  725. $class = $moduleClass;
  726. }
  727. }
  728. else
  729. {
  730. $class = sfConfig::get('mod_'.strtolower($moduleName).'_view_class', 'sfPHP').'View';
  731. }
  732. return new $class($this->context, $moduleName, $actionName, $viewName);
  733. }
  734. public function sendEmail($module, $action)
  735. {
  736. if (sfConfig::get('sf_logging_enabled'))
  737. {
  738. $this->dispatcher->notify(new sfEvent($this, 'application.log', array('sendEmail method is deprecated', 'priority' => sfLogger::ERR)));
  739. }
  740. return $this->getPresentationFor($module, $action, 'sfMail');
  741. }
  742. public function getPresentationFor($module, $action, $viewName = null)
  743. {
  744. if (sfConfig::get('sf_logging_enabled'))
  745. {
  746. $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Get presentation for action "%s/%s" (view class: "%s")', $module, $action, $viewName))));
  747. }
  748. $renderMode = $this->getRenderMode();
  749. $this->setRenderMode(sfView::RENDER_VAR);
  750. $actionStack = $this->getActionStack();
  751. $index = $actionStack->getSize();
  752. if ($viewName)
  753. {
  754. $currentViewName = sfConfig::get('mod_'.strtolower($module).'_view_class');
  755. sfConfig::set('mod_'.strtolower($module).'_view_class', $viewName);
  756. }
  757. try
  758. {
  759. $this->forward($module, $action);
  760. }
  761. catch (Exception $e)
  762. {
  763. $this->setRenderMode($renderMode);
  764. if ($viewName)
  765. {
  766. sfConfig::set('mod_'.strtolower($module).'_view_class', $currentViewName);
  767. }
  768. throw $e;
  769. }
  770. $actionEntry = $actionStack->getEntry($index);
  771. $presentation =& $actionEntry->getPresentation();
  772. $this->setRenderMode($renderMode);
  773. $nb = $actionStack->getSize() - $index;
  774. while ($nb-- > 0)
  775. {
  776. $actionEntry = $actionStack->popEntry();
  777. if ($actionEntry->getModuleName() == sfConfig::get('sf_login_module') && $actionEntry->getActionName() == sfConfig::get('sf_login_action'))
  778. {
  779. throw new sfException('Your action is secured, but the user is not authenticated.');
  780. }
  781. else if ($actionEntry->getModuleName() == sfConfig::get('sf_secure_module') && $actionEntry->getActionName() == sfConfig::get('sf_secure_action'))
  782. {
  783. throw new sfException('Your action is secured, but the user does not have access.');
  784. }
  785. }
  786. if ($viewName)
  787. {
  788. sfConfig::set('mod_'.strtolower($module).'_view_class', $currentViewName);
  789. }
  790. return $presentation;
  791. }
  792. public function setRenderMode($mode)
  793. {
  794. if ($mode == sfView::RENDER_CLIENT || $mode == sfView::RENDER_VAR || $mode == sfView::RENDER_NONE)
  795. {
  796. $this->renderMode = $mode;
  797. return;
  798. }
  799. throw new sfRenderException(sprintf('Invalid rendering mode: %s.', $mode));
  800. }
  801. public function inCLI()
  802. {
  803. return 0 == strncasecmp(PHP_SAPI, 'cli', 3);
  804. }
  805. public function __call($method, $arguments)
  806. {
  807. $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'controller.method_not_found', array('method' => $method, 'arguments' => $arguments)));
  808. if (!$event->isProcessed())
  809. {
  810. throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
  811. }
  812. return $event->getReturnValue();
  813. }
  814. }
  815. class sfDatabaseManager
  816. {
  817. protected
  818. $configuration = null,
  819. $databases = array();
  820. public function __construct(sfProjectConfiguration $configuration, $options = array())
  821. {
  822. $this->initialize($configuration);
  823. if (!isset($options['auto_shutdown']) || $options['auto_shutdown'])
  824. {
  825. register_shutdown_function(array($this, 'shutdown'));
  826. }
  827. }
  828. public function initialize(sfProjectConfiguration $configuration)
  829. {
  830. $this->configuration = $configuration;
  831. $this->loadConfiguration();
  832. }
  833. public function loadConfiguration()
  834. {
  835. if ($this->configuration instanceof sfApplicationConfiguration)
  836. {
  837. $databases = include($this->configuration->getConfigCache()->checkConfig('config/databases.yml'));
  838. }
  839. else
  840. {
  841. $configHandler = new sfDatabaseConfigHandler();
  842. $databases = $configHandler->evaluate(array($this->configuration->getRootDir().'/config/databases.yml'));
  843. }
  844. foreach ($databases as $name => $database)
  845. {
  846. $this->setDatabase($name, $database);
  847. }
  848. }
  849. public function setDatabase($name, sfDatabase $database)
  850. {
  851. $this->databases[$name] = $database;
  852. }
  853. public function getDatabase($name = 'default')
  854. {
  855. if (isset($this->databases[$name]))
  856. {
  857. return $this->databases[$name];
  858. }
  859. throw new sfDatabaseException(sprintf('Database "%s" does not exist.', $name));
  860. }
  861. public function getNames()
  862. {
  863. return array_keys($this->databases);
  864. }
  865. public function shutdown()
  866. {
  867. foreach ($this->databases as $database)
  868. {
  869. $database->shutdown();
  870. }
  871. }
  872. }
  873. class sfEvent implements ArrayAccess
  874. {
  875. protected
  876. $value = null,
  877. $processed = false,
  878. $subject = null,
  879. $name = '',
  880. $parameters = null;
  881. public function __construct($subject, $name, $parameters = array())
  882. {
  883. $this->subject = $subject;
  884. $this->name = $name;
  885. $this->parameters = $parameters;
  886. }
  887. public function getSubject()
  888. {
  889. return $this->subject;
  890. }
  891. public function getName()
  892. {
  893. return $this->name;
  894. }
  895. public function setReturnValue($value)
  896. {
  897. $this->value = $value;
  898. }
  899. public function getReturnValue()
  900. {
  901. return $this->value;
  902. }
  903. public function setProcessed($processed)
  904. {
  905. $this->processed = (boolean) $processed;
  906. }
  907. public function isProcessed()
  908. {
  909. return $this->processed;
  910. }
  911. public function getParameters()
  912. {
  913. return $this->parameters;
  914. }
  915. public function offsetExists($name)
  916. {
  917. return array_key_exists($name, $this->parameters);
  918. }
  919. public function offsetGet($name)
  920. {
  921. if (!array_key_exists($name, $this->parameters))
  922. {
  923. throw new InvalidArgumentException(sprintf('The event "%s" has no "%s" parameter.', $this->name, $name));
  924. }
  925. return $this->parameters[$name];
  926. }
  927. public function offsetSet($name, $value)
  928. {
  929. $this->parameters[$name] = $value;
  930. }
  931. public function offsetUnset($name)
  932. {
  933. unset($this->parameters[$name]);
  934. }
  935. }
  936. abstract class sfFilter
  937. {
  938. protected
  939. $parameterHolder = null,
  940. $context = null;
  941. public static
  942. $filterCalled = array();
  943. public function __construct($context, $parameters = array())
  944. {
  945. $this->initialize($context, $parameters);
  946. }
  947. public function initialize($context, $parameters = array())
  948. {
  949. $this->context = $context;
  950. $this->parameterHolder = new sfParameterHolder();
  951. $this->parameterHolder->add($parameters);
  952. return true;
  953. }
  954. protected function isFirstCall()
  955. {
  956. $class = get_class($this);
  957. if (isset(self::$filterCalled[$class]))
  958. {
  959. return false;
  960. }
  961. else
  962. {
  963. self::$filterCalled[$class] = true;
  964. return true;
  965. }
  966. }
  967. public final function getContext()
  968. {
  969. return $this->context;
  970. }
  971. public function getParameterHolder()
  972. {
  973. return $this->parameterHolder;
  974. }
  975. public function getParameter($name, $default = null)
  976. {
  977. return $this->parameterHolder->get($name, $default);
  978. }
  979. public function hasParameter($name)
  980. {
  981. return $this->parameterHolder->has($name);
  982. }
  983. public function setParameter($name, $value)
  984. {
  985. return $this->parameterHolder->set($name, $value);
  986. }
  987. }
  988. class sfCommonFilter extends sfFilter
  989. {
  990. public function execute($filterChain)
  991. {
  992. $filterChain->execute();
  993. $response = $this->context->getResponse();
  994. $content = $response->getContent();
  995. if (false !== ($pos = strpos($content, '</head>')))
  996. {
  997. $this->context->getConfiguration()->loadHelpers(array('Tag', 'Asset'));
  998. $html = '';
  999. if (!sfConfig::get('symfony.asset.javascripts_included', false))
  1000. {
  1001. $html .= get_javascripts($response);
  1002. }
  1003. if (!sfConfig::get('symfony.asset.stylesheets_included', false))
  1004. {
  1005. $html .= get_stylesheets($response);
  1006. }
  1007. if ($html)
  1008. {
  1009. $response->setContent(substr($content, 0, $pos).$html.substr($content, $pos));
  1010. }
  1011. }
  1012. sfConfig::set('symfony.asset.javascripts_included', false);
  1013. sfConfig::set('symfony.asset.stylesheets_included', false);
  1014. }
  1015. }
  1016. class sfExecutionFilter extends sfFilter
  1017. {
  1018. public function execute($filterChain)
  1019. {
  1020. $actionInstance = $this->context->getController()->getActionStack()->getLastEntry()->getActionInstance();
  1021. if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled'))
  1022. {
  1023. $timer = sfTimerManager::getTimer(sprintf('Action "%s/%s"', $actionInstance->getModuleName(), $actionInstance->getActionName()));
  1024. $viewName = $this->handleAction($filterChain, $actionInstance);
  1025. $timer->addTime();
  1026. $timer = sfTimerManager::getTimer(sprintf('View "%s" for "%s/%s"', $viewName, $actionInstance->getModuleName(), $actionInstance->getActionName()));
  1027. $this->handleView($filterChain, $actionInstance, $viewName);
  1028. $timer->addTime();
  1029. }
  1030. else
  1031. {
  1032. $viewName = $this->handleAction($filterChain, $actionInstance);
  1033. $this->handleView($filterChain, $actionInstance, $viewName);
  1034. }
  1035. }
  1036. protected function handleAction($filterChain, $actionInstance)
  1037. {
  1038. $uri = $this->context->getRouting()->getCurrentInternalUri();
  1039. if (sfConfig::get('sf_cache') && !is_null($uri) && $this->context->getViewCacheManager()->hasActionCache($uri))
  1040. {
  1041. return sfView::SUCCESS;
  1042. }
  1043. return $this->executeAction($actionInstance);
  1044. }
  1045. protected function executeAction($actionInstance)
  1046. {
  1047. $actionInstance->preExecute();
  1048. $viewName = $actionInstance->execute($this->context->getRequest());
  1049. $actionInstance->postExecute();
  1050. return is_null($viewName) ? sfView::SUCCESS : $viewName;
  1051. }
  1052. protected function handleView($filterChain, $actionInstance, $viewName)
  1053. {
  1054. switch ($viewName)
  1055. {
  1056. case sfView::HEADER_ONLY:
  1057. $this->context->getResponse()->setHeaderOnly(true);
  1058. return;
  1059. case sfView::NONE:
  1060. return;
  1061. }
  1062. $this->executeView($actionInstance->getModuleName(), $actionInstance->getActionName(), $viewName, $actionInstance->getVarHolder()->getAll());
  1063. }
  1064. protected function executeView($moduleName, $actionName, $viewName, $viewAttributes)
  1065. {
  1066. $controller = $this->context->getController();
  1067. $view = $controller->getView($moduleName, $actionName, $viewName);
  1068. $view->execute();
  1069. $view->getAttributeHolder()->add($viewAttributes);
  1070. switch ($controller->getRenderMode())
  1071. {
  1072. case sfView::RENDER_NONE:
  1073. break;
  1074. case sfView::RENDER_CLIENT:
  1075. $viewData = $view->render();
  1076. $this->context->getResponse()->setContent($viewData);
  1077. break;
  1078. case sfView::RENDER_VAR:
  1079. $viewData = $view->render();
  1080. $controller->getActionStack()->getLastEntry()->setPresentation($viewData);
  1081. break;
  1082. }
  1083. }
  1084. }
  1085. class sfRenderingFilter extends sfFilter
  1086. {
  1087. public function execute($filterChain)
  1088. {
  1089. $filterChain->execute();
  1090. $response = $this->context->getResponse();
  1091. if (sfForm::hasToStringException())
  1092. {
  1093. throw sfForm::getToStringException();
  1094. }
  1095. else if (sfFormField::hasToStringException())
  1096. {
  1097. throw sfFormField::getToStringException();
  1098. }
  1099. $response->send();
  1100. }
  1101. }
  1102. class sfFilterChain
  1103. {
  1104. protected
  1105. $chain = array(),
  1106. $index = -1;
  1107. public function loadConfiguration($actionInstance)
  1108. {
  1109. require(sfContext::getInstance()->getConfigCache()->checkConfig('modules/'.$actionInstance->getModuleName().'/config/filters.yml'));
  1110. }
  1111. public function execute()
  1112. {
  1113. ++$this->index;
  1114. if ($this->index < count($this->chain))
  1115. {
  1116. if (sfConfig::get('sf_logging_enabled'))
  1117. {
  1118. sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array(sprintf('Executing filter "%s"', get_class($this->chain[$this->index])))));
  1119. }
  1120. $this->chain[$this->index]->execute($this);
  1121. }
  1122. }
  1123. public function hasFilter($class)
  1124. {
  1125. foreach ($this->chain as $filter)
  1126. {
  1127. if ($filter instanceof $class)
  1128. {
  1129. return true;
  1130. }
  1131. }
  1132. return false;
  1133. }
  1134. public function register($filter)
  1135. {
  1136. $this->chain[] = $filter;
  1137. }
  1138. }
  1139. abstract class sfLogger
  1140. {
  1141. const EMERG = 0; const ALERT = 1; const CRIT = 2; const ERR = 3; const WARNING = 4; const NOTICE = 5; const INFO = 6; const DEBUG = 7;
  1142. protected
  1143. $level = self::INFO;
  1144. public function __construct(sfEventDispatcher $dispatcher, $options = array())
  1145. {
  1146. $this->initialize($dispatcher, $options);
  1147. if (!isset($options['auto_shutdown']) || $options['auto_shutdown'])
  1148. {
  1149. register_shutdown_function(array($this, 'shutdown'));
  1150. }
  1151. }
  1152. public function initialize(sfEventDispatcher $dispatcher, $options = array())
  1153. {
  1154. if (isset($options['level']))
  1155. {
  1156. $this->setLogLevel($options['level']);
  1157. }
  1158. $dispatcher->connect('application.log', array($this, 'listenToLogEvent'));
  1159. }
  1160. public function getLogLevel()
  1161. {
  1162. return $this->level;
  1163. }
  1164. public function setLogLevel($level)
  1165. {
  1166. if (!is_int($level))
  1167. {
  1168. $level = constant('sfLogger::'.strtoupper($level));
  1169. }
  1170. $this->level = $level;
  1171. }
  1172. public function log($message, $priority = self::INFO)
  1173. {
  1174. if ($this->getLogLevel() < $priority)
  1175. {
  1176. return false;
  1177. }
  1178. return $this->doLog($message, $priority);
  1179. }
  1180. abstract protected function doLog($message, $priority);
  1181. public function emerg($message)
  1182. {
  1183. $this->log($message, self::EMERG);
  1184. }
  1185. public function alert($message)
  1186. {
  1187. $this->log($message, self::ALERT);
  1188. }
  1189. public function crit($message)
  1190. {
  1191. $this->log($message, self::CRIT);
  1192. }
  1193. public function err($message)
  1194. {
  1195. $this->log($message, self::ERR);
  1196. }
  1197. public function warning($message)
  1198. {
  1199. $this->log($message, self::WARNING);
  1200. }
  1201. public function notice($message)
  1202. {
  1203. $this->log($message, self::NOTICE);
  1204. }
  1205. public function info($message)
  1206. {
  1207. $this->log($message, self::INFO);
  1208. }
  1209. public function debug($message)
  1210. {
  1211. $this->log($message, self::DEBUG);
  1212. }
  1213. public function listenToLogEvent(sfEvent $event)
  1214. {
  1215. $priority = isset($event['priority']) ? $event['priority'] : self::INFO;
  1216. $subject = $event->getSubject();
  1217. $subject = is_object($subject) ? get_class($subject) : (is_string($subject) ? $subject : 'main');
  1218. foreach ($event->getParameters() as $key => $message)
  1219. {
  1220. if ('priority' === $key)
  1221. {
  1222. continue;
  1223. }
  1224. $this->log(sprintf('{%s} %s', $subject, $message), $priority);
  1225. }
  1226. }
  1227. public function shutdown()
  1228. {
  1229. }
  1230. static public function getPriorityName($priority)
  1231. {
  1232. static $levels = array(
  1233. self::EMERG => 'emerg',
  1234. self::ALERT => 'alert',
  1235. self::CRIT => 'crit',
  1236. self::ERR => 'err',
  1237. self::WARNING => 'warning',
  1238. self::NOTICE => 'notice',
  1239. self::INFO => 'info',
  1240. self::DEBUG => 'debug',
  1241. );
  1242. if (!isset($levels[$priority]))
  1243. {
  1244. throw new sfException(sprintf('The priority level "%s" does not exist.', $priority));
  1245. }
  1246. return $levels[$priority];
  1247. }
  1248. }
  1249. class sfNoLogger extends sfLogger
  1250. {
  1251. public function initialize(sfEventDispatcher $dispatcher, $options = array())
  1252. {
  1253. }
  1254. protected function doLog($message, $priority)
  1255. {
  1256. }
  1257. }
  1258. abstract class sfRequest
  1259. {
  1260. const GET = 'GET';
  1261. const POST = 'POST';
  1262. const PUT = 'PUT';
  1263. const DELETE = 'DELETE';
  1264. const HEAD = 'HEAD';
  1265. protected
  1266. $dispatcher = null,
  1267. $method = null,
  1268. $options = array(),
  1269. $parameterHolder = null,
  1270. $attributeHolder = null;
  1271. public function __construct(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array(), $options = array())
  1272. {
  1273. $this->initialize($dispatcher, $parameters, $attributes, $options);
  1274. }
  1275. public function initialize(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array(), $options = array())
  1276. {
  1277. $this->dispatcher = $dispatcher;
  1278. $this->options = $options;
  1279. if (!isset($this->options['logging']))
  1280. {
  1281. $this->options['logging'] = false;
  1282. }
  1283. $this->parameterHolder = new sfParameterHolder();
  1284. $this->attributeHolder = new sfParameterHolder();
  1285. $this->parameterHolder->add($parameters);
  1286. $this->attributeHolder->add($attributes);
  1287. }
  1288. public function extractParameters($names)
  1289. {
  1290. $array = array();
  1291. $parameters = $this->parameterHolder->getAll();
  1292. foreach ($parameters as $key => $value)
  1293. {
  1294. if (in_array($key, $names))
  1295. {
  1296. $array[$key] = $value;
  1297. }
  1298. }
  1299. return $array;
  1300. }
  1301. public function getMethod()
  1302. {
  1303. return $this->method;
  1304. }
  1305. public function setMethod($method)
  1306. {
  1307. if (!in_array(strtoupper($method), array(self::GET, self::POST, self::PUT, self::DELETE, self::HEAD)))
  1308. {
  1309. throw new sfException(sprintf('Invalid request method: %s.', $method));
  1310. }
  1311. $this->method = strtoupper($method);
  1312. }
  1313. public function getParameterHolder()
  1314. {
  1315. return $this->parameterHolder;
  1316. }
  1317. public function getAttributeHolder()
  1318. {
  1319. return $this->attributeHolder;
  1320. }
  1321. public function getAttribute($name, $default = null)
  1322. {
  1323. return $this->attributeHolder->get($name, $default);
  1324. }
  1325. public function hasAttribute($name)
  1326. {
  1327. return $this->attributeHolder->has($name);
  1328. }
  1329. public function setAttribute($name, $value)
  1330. {
  1331. $this->attributeHolder->set($name, $value);
  1332. }
  1333. public function getParameter($name, $default = null)
  1334. {
  1335. return $this->parameterHolder->get($name, $default);
  1336. }
  1337. public function hasParameter($name)
  1338. {
  1339. return $this->parameterHolder->has($name);
  1340. }
  1341. public function setParameter($name, $value)
  1342. {
  1343. $this->parameterHolder->set($name, $value);
  1344. }
  1345. public function __call($method, $arguments)
  1346. {
  1347. $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'request.method_not_found', array('method' => $method, 'arguments' => $arguments)));
  1348. if (!$event->isProcessed())
  1349. {
  1350. throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
  1351. }
  1352. return $event->getReturnValue();
  1353. }
  1354. public function __clone()
  1355. {
  1356. $this->parameterHolder = clone $this->parameterHolder;
  1357. $this->attributeHolder = clone $this->attributeHolder;
  1358. }
  1359. }
  1360. abstract class sfResponse implements Serializable
  1361. {
  1362. protected
  1363. $options = array(),
  1364. $dispatcher = null,
  1365. $content = '';
  1366. public function __construct(sfEventDispatcher $dispatcher, $options = array())
  1367. {
  1368. $this->initialize($dispatcher, $options);
  1369. }
  1370. public function initialize(sfEventDispatcher $dispatcher, $options = array())
  1371. {
  1372. $this->dispatcher = $dispatcher;
  1373. $this->options = $options;
  1374. if (!isset($this->options['logging']))
  1375. {
  1376. $this->options['logging'] = false;
  1377. }
  1378. }
  1379. public function setEventDispatcher(sfEventDispatcher $dispatcher)
  1380. {
  1381. $this->dispatcher = $dispatcher;
  1382. }
  1383. public function setContent($content)
  1384. {
  1385. $this->content = $content;
  1386. }
  1387. public function getContent()
  1388. {
  1389. return $this->content;
  1390. }
  1391. public function sendContent()
  1392. {
  1393. $event = $this->dispatcher->filter(new sfEvent($this, 'response.filter_content'), $this->getContent());
  1394. $content = $event->getReturnValue();
  1395. if ($this->options['logging'])
  1396. {
  1397. $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Send content (%s o)', strlen($content)))));
  1398. }
  1399. echo $content;
  1400. }
  1401. public function send()
  1402. {
  1403. $this->sendContent();
  1404. }
  1405. public function getOptions()
  1406. {
  1407. return $this->options;
  1408. }
  1409. public function __call($method, $arguments)
  1410. {
  1411. $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'response.method_not_found', array('method' => $method, 'arguments' => $arguments)));
  1412. if (!$event->isProcessed())
  1413. {
  1414. throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
  1415. }
  1416. return $event->getReturnValue();
  1417. }
  1418. public function serialize()
  1419. {
  1420. return serialize($this->content);
  1421. }
  1422. public function unserialize($serialized)
  1423. {
  1424. $this->content = unserialize($serialized);
  1425. }
  1426. }
  1427. abstract class sfRouting
  1428. {
  1429. protected
  1430. $dispatcher = null,
  1431. $cache = null,
  1432. $defaultParameters = array(),
  1433. $options = array();
  1434. public function __construct(sfEventDispatcher $dispatcher, sfCache $cache = null, $options = array())
  1435. {
  1436. $this->initialize($dispatcher, $cache, $options);
  1437. if (!isset($this->options['auto_shutdown']) || $this->options['auto_shutdown'])
  1438. {
  1439. register_shutdown_function(array($this, 'shutdown'));
  1440. }
  1441. }
  1442. public function getCache()
  1443. {
  1444. return $this->cache;
  1445. }
  1446. public function initialize(sfEventDispatcher $dispatcher, sfCache $cache = null, $options = array())
  1447. {
  1448. $this->dispatcher = $dispatcher;
  1449. $options['debug'] = isset($options['debug']) ? (boolean) $options['debug'] : false;
  1450. $this->cache = $options['debug'] ? null : $cache;
  1451. $this->setDefaultParameter('module', isset($options['default_module']) ? $options['default_module'] : 'default');
  1452. $this->setDefaultParameter('action', isset($options['default_action']) ? $options['default_action'] : 'index');
  1453. if (!isset($options['logging']))
  1454. {
  1455. $options['logging'] = false;
  1456. }
  1457. if (!isset($options['context']))
  1458. {
  1459. $options['context'] = array();
  1460. }
  1461. $this->options = $options;
  1462. $this->dispatcher->connect('user.change_culture', array($this, 'listenToChangeCultureEvent'));
  1463. $this->dispatcher->connect('request.filter_parameters', array($this, 'filterParametersEvent'));
  1464. $this->loadConfiguration();
  1465. }
  1466. public function getOptions()
  1467. {
  1468. return $this->options;
  1469. }
  1470. public function loadConfiguration()
  1471. {
  1472. $this->dispatcher->notify(new sfEvent($this, 'routing.load_configuration'));
  1473. }
  1474. abstract public function getCurrentInternalUri($with_route_name = false);
  1475. abstract public function getRoutes();
  1476. abstract public function setRoutes($routes);
  1477. abstract public function hasRoutes();
  1478. abstract public function clearRoutes();
  1479. abstract public function generate($name, $params = array(), $absolute = false);
  1480. abstract public function parse($url);
  1481. public function getDefaultParameters()
  1482. {
  1483. return $this->defaultParameters;
  1484. }
  1485. public function getDefaultParameter($key)
  1486. {
  1487. return isset($this->defaultParameters[$key]) ? $this->defaultParameters[$key] : null;
  1488. }
  1489. public function setDefaultParameter($key, $value)
  1490. {
  1491. $this->defaultParameters[$key] = $value;
  1492. }
  1493. public function setDefaultParameters($parameters)
  1494. {
  1495. $this->defaultParameters = $parameters;
  1496. }
  1497. protected function mergeArrays($arr1, $arr2)
  1498. {
  1499. foreach ($arr2 as $key => $value)
  1500. {
  1501. $arr1[$key] = $value;
  1502. }
  1503. return $arr1;
  1504. }
  1505. public function listenToChangeCultureEvent(sfEvent $event)
  1506. {
  1507. $this->setDefaultParameter('sf_culture', $event['culture']);
  1508. }
  1509. public function filterParametersEvent(sfEvent $event, $parameters)
  1510. {
  1511. $context = $event->getParameters();
  1512. $this->options['context'] = $context;
  1513. if (false === $params = $this->parse($event['path_info']))
  1514. {
  1515. return $parameters;
  1516. }
  1517. return array_merge($parameters, $params);
  1518. }
  1519. protected function fixGeneratedUrl($url, $absolute = false)
  1520. {
  1521. if (isset($this->options['context']['prefix']))
  1522. {
  1523. if (0 === strpos($url, 'http'))
  1524. {
  1525. $url = preg_replace('#https?\://[^/]+#', '$0'.$this->options['context']['prefix'], $url);
  1526. }
  1527. else
  1528. {
  1529. $url = $this->options['context']['prefix'].$url;
  1530. }
  1531. }
  1532. if ($absolute && isset($this->options['context']['host']) && 0 !== strpos($url, 'http'))
  1533. {
  1534. $url = 'http'.(isset($this->options['context']['is_secure']) && $this->options['context']['is_secure'] ? 's' : '').'://'.$this->options['context']['host'].$url;
  1535. }
  1536. return $url;
  1537. }
  1538. public function shutdown()
  1539. {
  1540. }
  1541. }
  1542. abstract class sfStorage
  1543. {
  1544. protected
  1545. $options = array();
  1546. public function __construct($options = array())
  1547. {
  1548. $this->initialize($options);
  1549. if ($this->options['auto_shutdown'])
  1550. {
  1551. register_shutdown_function(array($this, 'shutdown'));
  1552. }
  1553. }
  1554. public function initialize($options = array())
  1555. {
  1556. $this->options = array_merge(array(
  1557. 'auto_shutdown' => true,
  1558. ), $options);
  1559. }
  1560. public function getOptions()
  1561. {
  1562. return $this->options;
  1563. }
  1564. abstract public function read($key);
  1565. abstract public function regenerate($destroy = false);
  1566. abstract public function remove($key);
  1567. abstract public function shutdown();
  1568. abstract public function write($key, $data);
  1569. }
  1570. class sfUser
  1571. {
  1572. const ATTRIBUTE_NAMESPACE = 'symfony/user/sfUser/attributes';
  1573. const CULTURE_NAMESPACE = 'symfony/user/sfUser/culture';
  1574. protected
  1575. $options = array(),
  1576. $attributeHolder = null,
  1577. $culture = null,
  1578. $storage = null,
  1579. $dispatcher = null;
  1580. public function __construct(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array())
  1581. {
  1582. $this->initialize($dispatcher, $storage, $options);
  1583. if ($this->options['auto_shutdown'])
  1584. {
  1585. register_shutdown_function(array($this, 'shutdown'));
  1586. }
  1587. }
  1588. public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array())
  1589. {
  1590. $this->dispatcher = $dispatcher;
  1591. $this->storage = $storage;
  1592. $this->options = array_merge(array(
  1593. 'auto_shutdown' => true,
  1594. 'culture' => null,
  1595. 'default_culture' => 'en',
  1596. 'use_flash' => false,
  1597. 'logging' => false,
  1598. ), $options);
  1599. $this->attributeHolder = new sfNamespacedParameterHolder(self::ATTRIBUTE_NAMESPACE);
  1600. $attributes = $storage->read(self::ATTRIBUTE_NAMESPACE);
  1601. if (is_array($attributes))
  1602. {
  1603. foreach ($attributes as $namespace => $values)
  1604. {
  1605. $this->attributeHolder->add($values, $namespace);
  1606. }
  1607. }
  1608. $currentCulture = $storage->read(self::CULTURE_NAMESPACE);
  1609. $this->setCulture(!is_null($this->options['culture']) ? $this->options['culture'

Large files files are truncated, but you can click here to view the full file