/** * Retrieves the singleton instance of this class. * * @return sfConfigCache A sfConfigCache instance */ public static function getInstance() { if (!self::$instance) { self::$instance = new sfConfigCache(); } return self::$instance; }
public function __construct(limeade_sf_app $app, $file) { $file = sfConfigCache::getInstance()->checkConfig($file); $this->app = $app; $this->file = $file; $this->backup = $file . '~' . md5($file . __FILE__); }
/** * Initializes this action. * * @param sfContext The current application context. * * @return bool true, if initialization completes successfully, otherwise false */ public function initialize($context) { parent::initialize($context); // include security configuration require sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name') . '/' . $this->getModuleName() . '/' . sfConfig::get('sf_app_module_config_dir_name') . '/security.yml', true); return true; }
/** * Callback for configuration file insertion in the cache. * */ protected function insertConfigFileCallback($matches) { $configFile = sfConfig::get('sf_app_config_dir_name') . '/' . $matches[4]; sfConfigCache::getInstance()->checkConfig($configFile); $config = "// '{$configFile}' config file\n" . file_get_contents(sfConfigCache::getInstance()->getCacheName($configFile)); return $config; }
/** * Configures template for this view. * * @throws <b>sfActionException</b> If the configure fails */ public function configure() { // view.yml configure parent::configure(); // require our configuration $moduleName = $this->moduleName; require sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name') . '/' . $this->moduleName . '/' . sfConfig::get('sf_app_module_config_dir_name') . '/mailer.yml'); }
public function initialize($parameters = array(), $name = null) { parent::initialize($parameters); // if a default connection is defined we only open that one if ($defaultDatabase = sfConfig::get('sf_default_database')) { if ($name != $defaultDatabase) { return; } } // load doctrine config require sfConfigCache::getInstance()->checkConfig('config/doctrine.yml'); $db_attributes = $default_attributes; if (isset($attributes[$name])) { $db_attributes = array_merge($default_attributes, $attributes[$name]); } $this->setParameter('attributes', $db_attributes); $this->setParameter('name', $name); // take care of the component binding // suppress errors from include_once // because config/schemas.yml is optional. @(include_once sfConfigCache::getInstance()->checkConfig('config/schemas.yml', true)); // opening the doctrine connection // determine how to get our parameters $method = $this->getParameter('method', 'dsn'); // get parameters switch ($method) { case 'dsn': $dsn = $this->getParameter('dsn'); if ($dsn == null) { // missing required dsn parameter $error = 'Database configuration specifies method "dsn", but is missing dsn parameter'; throw new sfDatabaseException($error); } break; } try { // Make sure we pass non-PEAR style DSNs as an array if (!strpos($dsn, '://')) { $dsn = array($dsn, $this->getParameter('username'), $this->getParameter('password')); } $this->doctrineConnection = Doctrine_Manager::connection($dsn, $name); // figure out the encoding $encoding = $this->getParameter('encoding', 'UTF8'); // set up the connection parameters from the doctrine.yml config file foreach ($this->getParameter('attributes') as $k => $v) { $this->doctrineConnection->setAttribute(constant('Doctrine::' . $k), $v); } // we add the listener that sets up encoding and date formats $eventListener = new sfDoctrineConnectionListener($this->doctrineConnection, $encoding); $this->doctrineConnection->addListener($eventListener); // add the query logger if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $this->doctrineConnection->addListener(new sfDoctrineQueryLogger()); } } catch (PDOException $e) { throw new sfDatabaseException($e->getMessage()); } }
/** * @see sfConfigCache::checkConfig() * @return string The cached file that was just written */ public function checkConfig($config_path, $optional = false) { if ($config_path === 'config/databases.yml') { if (!$this->configuration->isFresh()) { $this->writeDatabaseCache($config_path); } return $this->getCacheName($config_path); } return parent::checkConfig($config_path, $optional); }
public function __construct($search, $module, $action) { parent::__construct($search); $this->module = $module; $this->action = $action; $config = sfConfig::get('sf_app_dir') . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'search.yml'; include sfConfigCache::getInstance()->checkConfig($config); if (!isset($actions[$this->getSearch()->getParameter('name')][$action])) { throw new sfLuceneIndexerException('Specified action is not registered for indexing'); } $this->properties = $actions[$this->getSearch()->getParameter('name')][$action]; }
protected function initialize() { $this->logger = sfLogger::getInstance(); if (sfConfig::get('sf_logging_enabled')) { $this->logger->info('{sfContext} initialization'); } if (sfConfig::get('sf_use_database')) { // setup our database connections $this->databaseManager = new sfDatabaseManager(); $this->databaseManager->initialize(); } // create a new action stack $this->actionStack = new sfActionStack(); // include the factories configuration require sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_config_dir_name') . '/factories.yml'); // register our shutdown function register_shutdown_function(array($this, 'shutdown')); }
public function rebuildModule($module) { $config = sfConfig::get('sf_app_dir') . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'search.yml'; if (!is_readable($config)) { throw new sfLuceneIndexerException(sprintf('Unable to read "%s"', $config)); } include sfConfigCache::getInstance()->checkConfig($config); if (!isset($actions) || !is_array($actions)) { throw new sfLuceneIndexerException(sprintf('No actions were defined for module "%s", but a search.yml file was found', $module)); } elseif (count($actions) == 0) { return; } if (isset($actions[$this->getSearch()->getParameter('name')])) { $this->getSearch()->getEventDispatcher()->notify(new sfEvent($this, 'indexer.log', array('Discovered %d actions in module "%s"', count($actions[$this->getSearch()->getParameter('name')]), $module))); foreach ($actions[$this->getSearch()->getParameter('name')] as $action => $properties) { $this->getFactory()->getAction($module, $action)->save(); } } }
/** * connectServers. * */ private function connectServers() { // Our config/memcache.yml file includes all of our hosts that we should connect to. include sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_config_dir_name') . '/memcache.yml'); $conf = sfConfig::get('memcache_servers'); // Clear our connection list self::$mem = array(); // Add servers to our pool foreach ($conf as $bucket => $servers) { if ($bucket != '') { if (!isset(self::$mem[$bucket])) { self::$mem[$bucket] = new Memcache(); } foreach ($servers['servers'] as $server) { self::$mem[$bucket]->addServer($server['host'], $server['port'], $server['persistent'], $server['weight']); } } } $this->bucket = 'default'; }
/** * Registers configuration options for the cache. * * @param string Module name */ public function registerConfiguration($moduleName) { if (!isset($this->loaded[$moduleName])) { require sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name') . '/' . $moduleName . '/' . sfConfig::get('sf_app_module_config_dir_name') . '/cache.yml'); $this->loaded[$moduleName] = true; } }
/** * Initializes this sfDatabaseManager object * * @return bool true, if initialization completes successfully, otherwise false * * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfDatabaseManager object */ public function initialize() { // load database configuration require sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_config_dir_name') . '/databases.yml'); }
<?php // Load InterWiki config files $interwiki_config_file = sfConfig::get('sf_app_config_dir_name') . '/interwiki.yml'; require_once sfConfigCache::getInstance()->checkConfig($interwiki_config_file); // app_nahoWikiPlugin_interwiki // Automatic routes $routes_register = sfConfig::get('app_nahoWikiPlugin_routes_register', true); $enabled_module = in_array('nahoWiki', sfConfig::get('sf_enabled_modules', array())); if ($routes_register && $enabled_module) { $r = sfRouting::getInstance(); // preprend our routes $r->prependRoute('wiki_home', '/wiki', array('module' => 'nahoWiki', 'action' => 'index')); $r->prependRoute('wiki_view_revision', '/wiki/view/:page/:revision', array('module' => 'nahoWiki', 'action' => 'view')); $r->prependRoute('wiki_view', '/wiki/view/:page', array('module' => 'nahoWiki', 'action' => 'view')); $r->prependRoute('wiki_edit_revision', '/wiki/edit/:page/:revision', array('module' => 'nahoWiki', 'action' => 'edit')); $r->prependRoute('wiki_edit', '/wiki/edit/:page', array('module' => 'nahoWiki', 'action' => 'edit')); $r->prependRoute('wiki_history', '/wiki/history/:page', array('module' => 'nahoWiki', 'action' => 'history')); $r->prependRoute('wiki_diff', '/wiki/diff/*', array('module' => 'nahoWiki', 'action' => 'diff')); $r->prependRoute('wiki_index', '/wiki/index/*', array('module' => 'nahoWiki', 'action' => 'browse')); }
/** * */ private function complexSecureRequest() { $start = microtime(true); $configCache = sfConfigCache::getInstance(); // get config instance $sf_app_config_dir_name = sfConfig::get('sf_app_config_dir_name'); include $configCache->checkConfig($sf_app_config_dir_name . '/rules.yml'); // Filters don't have direct access to the request and user objects. // You will need to use the context object to get them $request = $this->getContext()->getRequest(); $user = $this->getContext()->getUser(); $stop_at_first = false; $invalid_params = array(); $all_valid = true; foreach ($_REQUEST as $param_name => $param_value) { $all_valid &= $this->validateParam($param_name, $param_value, self::TYPE_REQUEST, $invalid_params); if (!$all_valid && $stop_at_first) { // TODO - remove the bad parameter $this->handleBadParameter($param_name, $param_value); return $all_valid; } } echo "complexSecureRequest: " . (microtime(true) - $start); return $all_valid; }
/** * Returns the rich text editor as HTML. * * @return string Rich text editor HTML representation */ public function toHTML() { $options = $this->options; // we need to know the id for things the rich text editor // in advance of building the tag $id = _get_option($options, 'id', $this->name); // use tinymce's gzipped js? $tinymce_file = _get_option($options, 'tinymce_gzip') ? '/tiny_mce_gzip.php' : '/tiny_mce.js'; // tinymce installed? $js_path = sfConfig::get('sf_rich_text_js_dir') ? '/' . sfConfig::get('sf_rich_text_js_dir') . $tinymce_file : '/sf/tinymce/js' . $tinymce_file; if (!is_readable(sfConfig::get('sf_web_dir') . $js_path)) { throw new sfConfigurationException('You must install TinyMCE to use this helper (see rich_text_js_dir settings).'); } sfContext::getInstance()->getResponse()->addJavascript($js_path); use_helper('Javascript'); $tinymce_options = ''; $style_selector = ''; // custom CSS file? if ($css_file = _get_option($options, 'css')) { $css_path = stylesheet_path($css_file); sfContext::getInstance()->getResponse()->addStylesheet($css_path); $css = file_get_contents(sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . $css_path); $styles = array(); preg_match_all('#^/\\*\\s*user:\\s*(.+?)\\s*\\*/\\s*\\015?\\012\\s*\\.([^\\s]+)#Smi', $css, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $styles[] = $match[1] . '=' . $match[2]; } $tinymce_options .= ' content_css: "' . $css_path . '",' . "\n"; $tinymce_options .= ' theme_advanced_styles: "' . implode(';', $styles) . '"' . "\n"; $style_selector = 'styleselect,separator,'; } $config = sfConfig::get('sf_config_dir_name'); $path = sfConfigCache::getInstance()->checkConfig($config . DIRECTORY_SEPARATOR . 'tiny_mce.yml'); $config = sfYaml::load($path); $culture = isset($config['culture']) ? $config['culture'] : sfContext::getInstance()->getUser()->getCulture(); $mode = $config['options']['mode']; $plugins = implode(',', $config['options']['plugins']); $theme = $config['options']['theme']; $tbLocation = $config['options']['theme_settings']['theme_' . $theme . '_toolbar_location']; $tbAlign = $config['options']['theme_settings']['theme_' . $theme . '_toolbar_align']; $pathLocation = $config['options']['theme_settings']['theme_' . $theme . '_path_location']; $buttons = array(); reset($config['options']['theme_settings']['buttons']); while (($key = key($config['options']['theme_settings']['buttons'])) !== null) { $current = current($config['options']['theme_settings']['buttons']); $buttons[] = $key . ': "' . implode(',', $current) . '"'; next($config['options']['theme_settings']['buttons']); } $buttons = implode(",\n", $buttons); $extendedValidElements = array(); reset($config['options']['theme_settings']['extended_valid_elements']); while (($key = key($config['options']['theme_settings']['extended_valid_elements'])) !== null) { $current = current($config['options']['theme_settings']['extended_valid_elements']); $extendedValidElements[] = $key . '[' . implode('|', $current) . ']'; next($config['options']['theme_settings']['extended_valid_elements']); } $extendedValidElements = '"' . implode(",\n", $extendedValidElements) . '"'; $relativeUrls = $config['options']['relative_urls'] ? 'true' : 'false'; $debug = $config['options']['debug'] ? 'true' : 'false'; $tinymce_js = 'tinyMCE.init({'; // Mode $tinymce_js .= "mode: '{$mode}'"; // Language $tinymce_js .= ', language: "' . strtolower(substr($culture, 0, 2)) . '"'; // Elements $tinymce_js .= ', elements: "' . $id . '"'; // Plugins if ($plugins) { $tinymce_js .= ', plugins: "' . $plugins . '"'; } // Theme $tinymce_js .= ", theme: '{$theme}'"; // Toolbar $tinymce_js .= ', theme_' . $theme . '_toolbar_location: "' . $tbLocation . '"'; $tinymce_js .= ', theme_' . $theme . '_toolbar_align: "' . $tbAlign . '"'; $tinymce_js .= ', theme_' . $theme . '_path_location: "' . $pathLocation . '"'; // Buttons if ($buttons) { $tinymce_js .= ', ' . $buttons; } // Extended Valid Elements $tinymce_js .= ', extended_valid_elements: ' . $extendedValidElements; // Relative Urls $tinymce_js .= ', relative_urls: ' . $relativeUrls; // Debug $tinymce_js .= ', debug: ' . $debug; // Custom Options $tinymce_js .= $tinymce_options ? ',' . $tinymce_options : ''; $tinymce_js .= isset($options['tinymce_options']) ? ',' . $options['tinymce_options'] : ''; if (isset($config['options']['misc'])) { foreach ($config['options']['misc'] as $name => $value) { $tinymce_js .= ", {$name}: \"{$value}\""; } } if (isset($options['tinymce_options'])) { unset($options['tinymce_options']); } $tinymce_js .= '});'; return content_tag('script', javascript_cdata_section($tinymce_js), array('type' => 'text/javascript')) . content_tag('textarea', $this->content, array_merge(array('name' => $this->name, 'id' => get_id_from_name($id, null)), _convert_options($options))); }
/** * Generates classes and templates in cache. * * @param array $params The parameters * * @throws sfConfigurationException * @throws sfException * @throws sfInitializationException * @throws sfParseException * @return string The data to put in configuration cache */ public function generate($params = array()) { $this->params = $params; $required_parameters = array('model_class', 'moduleName'); foreach ($required_parameters as $entry) { if (!isset($this->params[$entry])) { $error = 'You must specify a "%s"'; $error = sprintf($error, $entry); throw new sfParseException($error); } } // include security configuration include(sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name').'/'.$this->params['moduleName'].'/'.sfConfig::get('sf_app_module_config_dir_name').'/security.yml', true)); $modelClass = $this->params['model_class']; if (!class_exists($modelClass)) { $error = 'Unable to scaffold nonexistent model "%s"'; $error = sprintf($error, $modelClass); throw new sfInitializationException($error); } $this->setScaffoldingClassName($modelClass); // generated module name $this->setGeneratedModuleName('auto'.ucfirst($this->params['moduleName'])); $this->setModuleName($this->params['moduleName']); // get some model metadata $this->loadMapBuilderClasses(); // load all primary keys $this->loadPrimaryKeys(); // theme exists? $theme = isset($this->params['theme']) ? $this->params['theme'] : 'default'; $themeDir = sfLoader::getGeneratorTemplate($this->getGeneratorClass(), $theme, ''); if (!is_dir($themeDir)) { $error = 'The theme "%s" does not exist.'; $error = sprintf($error, $theme); throw new sfConfigurationException($error); } $this->setTheme($theme); $templateFiles = sfFinder::type('file')->ignore_version_control()->name('*.php')->relative()->in($themeDir.'/templates'); $configFiles = sfFinder::type('file')->ignore_version_control()->name('*.yml')->relative()->in($themeDir.'/config'); $this->generatePhpFiles($this->generatedModuleName, $templateFiles, $configFiles); // require generated action class $data = "require_once(sfConfig::get('sf_module_cache_dir').'/".$this->generatedModuleName."/actions/actions.class.php');\n"; return $data; }
/** * Executes this filter. * * @param sfFilterChain The filter chain * * @throws <b>sfInitializeException</b> If an error occurs during view initialization. * @throws <b>sfViewException</b> If an error occurs while executing the view. */ public function execute($filterChain) { // get the context and controller $context = $this->getContext(); $controller = $context->getController(); // get the current action instance $actionEntry = $controller->getActionStack()->getLastEntry(); $actionInstance = $actionEntry->getActionInstance(); // get the current action information $moduleName = $context->getModuleName(); $actionName = $context->getActionName(); // get the request method $method = $context->getRequest()->getMethod(); $viewName = null; $statsdPrefix = c2cActions::statsdPrefix($moduleName, $actionName); if (sfConfig::get('sf_cache')) { // get current uri adapted for cache $uri = MyCacheFilter::getCurrentCacheUri(); // best way would be to modify uri (and not the whole cache management system) // but we have no way to extend getCurrentInternalUri method in sfRouting class just for cache if (null !== $context->getResponse()->getParameter($uri . '_action', null, 'symfony/cache')) { // action in cache, so go to the view $viewName = sfView::SUCCESS; } } if (!$viewName) { if (($actionInstance->getRequestMethods() & $method) != $method) { // this action will skip validation/execution for this method // get the default view $viewName = $actionInstance->getDefaultView(); } else { // set default validated status $validated = true; // get the current action validation configuration $validationConfig = $moduleName . '/' . sfConfig::get('sf_app_module_validate_dir_name') . '/' . $actionName . '.yml'; // load validation configuration // do NOT use require_once if (null !== ($validateFile = sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name') . '/' . $validationConfig, true))) { // create validator manager $validatorManager = new sfValidatorManager(); $validatorManager->initialize($context); require $validateFile; // process validators $validated = $validatorManager->execute(); } // process manual validation $validateToRun = 'validate' . ucfirst($actionName); $manualValidated = method_exists($actionInstance, $validateToRun) ? $actionInstance->{$validateToRun}() : $actionInstance->validate(); // action is validated if: // - all validation methods (manual and automatic) return true // - or automatic validation returns false but errors have been 'removed' by manual validation $validated = $manualValidated && $validated || $manualValidated && !$validated && !$context->getRequest()->hasErrors(); // register fill-in filter if (null !== ($parameters = $context->getRequest()->getAttribute('fillin', null, 'symfony/filter'))) { $this->registerFillInFilter($filterChain, $parameters); } if ($validated) { if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer = sfTimerManager::getTimer(sprintf('Action "%s/%s"', $moduleName, $actionName)); } // execute the action $statsdTimer = new sfTimer(); $actionInstance->preExecute(); c2cActions::statsdTiming('execution.action.preExecute', $statsdTimer->getElapsedTime(), $statsdPrefix); $statsdTimer = new sfTimer(); $viewName = $actionInstance->execute(); c2cActions::statsdTiming('execution.action.execute', $statsdTimer->getElapsedTime(), $statsdPrefix); if ($viewName == '') { $viewName = sfView::SUCCESS; } $statsdTimer = new sfTimer(); $actionInstance->postExecute(); c2cActions::statsdTiming('execution.action.postExecute', $statsdTimer->getElapsedTime(), $statsdPrefix); if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } } else { if (sfConfig::get('sf_logging_enabled')) { $this->context->getLogger()->info('{sfFilter} action validation failed'); } // validation failed $handleErrorToRun = 'handleError' . ucfirst($actionName); $viewName = method_exists($actionInstance, $handleErrorToRun) ? $actionInstance->{$handleErrorToRun}() : $actionInstance->handleError(); if ($viewName == '') { $viewName = sfView::ERROR; } } } } if ($viewName == sfView::HEADER_ONLY) { $context->getResponse()->setHeaderOnly(true); // execute next filter $filterChain->execute(); } else { if ($viewName != sfView::NONE) { if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer = sfTimerManager::getTimer(sprintf('View "%s" for "%s/%s"', $viewName, $moduleName, $actionName)); } // get the view instance $statsdTimer = new sfTimer(); $viewInstance = $controller->getView($moduleName, $actionName, $viewName); c2cActions::statsdTiming("execution.view.{$viewName}.getView", $statsdTimer->getElapsedTime(), $statsdPrefix); $statsdTimer = new sfTimer(); $viewInstance->initialize($context, $moduleName, $actionName, $viewName); c2cActions::statsdTiming("execution.view.{$viewName}.initialize", $statsdTimer->getElapsedTime(), $statsdPrefix); $statsdTimer = new sfTimer(); $viewInstance->execute(); c2cActions::statsdTiming("execution.view.{$viewName}.execute", $statsdTimer->getElapsedTime(), $statsdPrefix); // render the view and if data is returned, stick it in the // action entry which was retrieved from the execution chain $statsdTimer = new sfTimer(); $viewData = $viewInstance->render(); c2cActions::statsdTiming("execution.view.{$viewName}.render", $statsdTimer->getElapsedTime(), $statsdPrefix); if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } if ($controller->getRenderMode() == sfView::RENDER_VAR) { $actionEntry->setPresentation($viewData); } else { // execute next filter $filterChain->execute(); } } } }
require_once $sf_symfony_lib_dir . '/config/sfLoader.class.php'; // basic exception classes require_once $sf_symfony_lib_dir . '/exception/sfException.class.php'; require_once $sf_symfony_lib_dir . '/exception/sfAutoloadException.class.php'; require_once $sf_symfony_lib_dir . '/exception/sfCacheException.class.php'; require_once $sf_symfony_lib_dir . '/exception/sfConfigurationException.class.php'; require_once $sf_symfony_lib_dir . '/exception/sfParseException.class.php'; // utils require_once $sf_symfony_lib_dir . '/util/sfParameterHolder.class.php'; } else { require_once $sf_symfony_lib_dir . '/config/sfConfigCache.class.php'; } // autoloading sfCore::initAutoload(); try { $configCache = sfConfigCache::getInstance(); // force setting default timezone if not set if (function_exists('date_default_timezone_get')) { if ($default_timezone = sfConfig::get('sf_default_timezone')) { date_default_timezone_set($default_timezone); } else { if (sfConfig::get('sf_force_default_timezone', true)) { date_default_timezone_set(@date_default_timezone_get()); } } } // get config instance $sf_app_config_dir_name = sfConfig::get('sf_app_config_dir_name'); $sf_debug = sfConfig::get('sf_debug'); // load timer classes if in debug mode if ($sf_debug) {
<?php // this check prevents access to debug front controllers that are deployed by accident to production servers. // feel free to remove this, extend it or make something more sophisticated. //if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) //{ // die('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.'); //} require_once dirname(__FILE__) . '/../config/ProjectConfiguration.class.php'; $configuration = ProjectConfiguration::getApplicationConfiguration('app', 'dev', true); $configCache = new sfConfigCache($configuration); include $configCache->checkConfig('config/config.yml'); sfContext::createInstance($configuration)->dispatch();
/** * Load the models config from from apps/APP/config/search.yml * @return hash - route and partial are specified for each model */ protected function loadModelsConfig() { include_once sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_config_dir_name') . DIRECTORY_SEPARATOR . 'search.yml'); if (!isset($config['SolrIndex'])) { return false; } $this->models = $config['SolrIndex']['models']; return true; }
/** * Evaluates and returns a component. * The syntax is similar to the one of include_component. * * <b>Example:</b> * <code> * echo get_component('mymodule', 'mypartial', array('myvar' => 12345)); * </code> * * @param string module name * @param string component name * @param array variables to be made accessible to the component * @return string result of the component execution * @see include_component */ function get_component($moduleName, $componentName, $vars = array()) { $context = sfContext::getInstance(); $actionName = '_' . $componentName; // check cache if ($cacheManager = $context->getViewCacheManager()) { if ($retval = _get_cache($cacheManager, $moduleName, $actionName, $vars)) { return $retval; } } $controller = $context->getController(); if (!$controller->componentExists($moduleName, $componentName)) { // cannot find component $error = 'The component does not exist: "%s", "%s"'; $error = sprintf($error, $moduleName, $componentName); throw new sfConfigurationException($error); } // create an instance of the action $componentInstance = $controller->getComponent($moduleName, $componentName); // initialize the action if (!$componentInstance->initialize($context)) { // component failed to initialize $error = 'Component initialization failed for module "%s", component "%s"'; $error = sprintf($error, $moduleName, $componentName); throw new sfInitializationException($error); } // load component's module config file require sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name') . '/' . $moduleName . '/' . sfConfig::get('sf_app_module_config_dir_name') . '/module.yml'); $componentInstance->getVarHolder()->add($vars); // dispatch component $componentToRun = 'execute' . ucfirst($componentName); if (!method_exists($componentInstance, $componentToRun)) { if (!method_exists($componentInstance, 'execute')) { // component not found $error = 'sfComponent initialization failed for module "%s", component "%s"'; $error = sprintf($error, $moduleName, $componentName); throw new sfInitializationException($error); } $componentToRun = 'execute'; } if (sfConfig::get('sf_logging_enabled')) { $context->getLogger()->info('{PartialHelper} call "' . $moduleName . '->' . $componentToRun . '()' . '"'); } // run component if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer = sfTimerManager::getTimer(sprintf('Component "%s/%s"', $moduleName, $componentName)); } $retval = $componentInstance->{$componentToRun}(); if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } if ($retval != sfView::NONE) { // render $view = new sfPartialView(); $view->initialize($context, $moduleName, $actionName, ''); $retval = $view->render($componentInstance->getVarHolder()->getAll()); if ($cacheManager && (!sfConfig::get('sf_lazy_cache_key') || $cacheManager->isActionCacheable($moduleName, $actionName))) { $uri = _get_cache_uri($moduleName, $actionName, $vars); $retval = _set_cache($cacheManager, $uri, $retval); } return $retval; } }
/** * Loads application nad module filters. * * @param sfFilterChain A sfFilterChain instance * @param sfAction A sfAction instance */ public function loadFilters($filterChain, $actionInstance) { $moduleName = $this->context->getModuleName(); require sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name') . '/' . $moduleName . '/' . sfConfig::get('sf_app_module_config_dir_name') . '/filters.yml'); }
<?php // include project configuration include SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; // symfony bootstraping require_once $sf_symfony_lib_dir . '/util/sfCore.class.php'; sfCore::bootstrap($sf_symfony_lib_dir, $sf_symfony_data_dir); // wikifiable behavior: hook per metodi preSave e postSave // aggiunge descrizione in pagina wiki dopo la creazione di un atto o votazione // la descrizione è aggiunta solo se si tratta di un nuovo oggetto (non per update) sfPropelBehavior::registerHooks('wikifiableBehavior', array(':save:pre' => array('wikifiableBehavior', 'preSave'), ':save:post' => array('wikifiableBehavior', 'postSave'), ':delete:pre' => array('wikifiableBehavior', 'preDelete'))); // need to include this to use the api.yml config file require_once sfConfigCache::getInstance()->checkConfig('config/api.yml');
public function configure() { $actionStackEntry = $this->getContext()->getActionStack()->getLastEntry(); if (!$actionStackEntry->getViewInstance()) { $actionStackEntry->setViewInstance($this); } $viewConfigFile = $this->moduleName . '/' . sfConfig::get('sf_app_module_config_dir_name') . '/view.yml'; require sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name') . '/' . $viewConfigFile); if (!$this->directory) { $this->setDirectory(sfLoader::getTemplateDir($this->moduleName, $this->getTemplate())); } }
/** * Executes this filter. * * @param sfFilterChain The filter chain * * @throws <b>sfInitializeException</b> If an error occurs during view initialization. * @throws <b>sfViewException</b> If an error occurs while executing the view. */ public function execute($filterChain) { // get the context and controller $context = $this->getContext(); $controller = $context->getController(); // get the current action instance $actionEntry = $controller->getActionStack()->getLastEntry(); $actionInstance = $actionEntry->getActionInstance(); // get the current action information $moduleName = $context->getModuleName(); $actionName = $context->getActionName(); // get the request method $method = $context->getRequest()->getMethod(); $viewName = null; if (sfConfig::get('sf_cache')) { $uri = sfRouting::getInstance()->getCurrentInternalUri(); if (null !== $context->getResponse()->getParameter($uri . '_action', null, 'symfony/cache')) { // action in cache, so go to the view $viewName = sfView::SUCCESS; } } if (!$viewName) { if (($actionInstance->getRequestMethods() & $method) != $method) { // this action will skip validation/execution for this method // get the default view $viewName = $actionInstance->getDefaultView(); } else { // set default validated status $validated = true; // the case of the first letter of the action is insignificant // get the current action validation configuration $validationConfigWithFirstLetterLower = $moduleName . '/' . sfConfig::get('sf_app_module_validate_dir_name') . '/' . strtolower(substr($actionName, 0, 1)) . substr($actionName, 1) . '.yml'; $validationConfigWithFirstLetterUpper = $moduleName . '/' . sfConfig::get('sf_app_module_validate_dir_name') . '/' . ucfirst($actionName) . '.yml'; // determine $validateFile by testing both the uppercase and lowercase // types of validation configurations. $validateFile = null; if (!is_null($testValidateFile = sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name') . '/' . $validationConfigWithFirstLetterLower, true))) { $validateFile = $testValidateFile; } else { if (!is_null($testValidateFile = sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name') . '/' . $validationConfigWithFirstLetterUpper, true))) { $validateFile = $testValidateFile; } } // load validation configuration // do NOT use require_once if (!is_null($validateFile)) { // create validator manager $validatorManager = new sfValidatorManager(); $validatorManager->initialize($context); require $validateFile; // process validators $validated = $validatorManager->execute(); } // process manual validation $validateToRun = 'validate' . ucfirst($actionName); $manualValidated = method_exists($actionInstance, $validateToRun) ? $actionInstance->{$validateToRun}() : $actionInstance->validate(); // action is validated if: // - all validation methods (manual and automatic) return true // - or automatic validation returns false but errors have been 'removed' by manual validation $validated = $manualValidated && $validated || $manualValidated && !$validated && !$context->getRequest()->hasErrors(); // register fill-in filter if (null !== ($parameters = $context->getRequest()->getAttribute('fillin', null, 'symfony/filter'))) { $this->registerFillInFilter($filterChain, $parameters); } if ($validated) { if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer = sfTimerManager::getTimer(sprintf('Action "%s/%s"', $moduleName, $actionName)); } // execute the action $actionInstance->preExecute(); $viewName = $actionInstance->execute(); if ($viewName == '') { $viewName = sfView::SUCCESS; } $actionInstance->postExecute(); if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } } else { if (sfConfig::get('sf_logging_enabled')) { $this->context->getLogger()->info('{sfFilter} action validation failed'); } // validation failed $handleErrorToRun = 'handleError' . ucfirst($actionName); $viewName = method_exists($actionInstance, $handleErrorToRun) ? $actionInstance->{$handleErrorToRun}() : $actionInstance->handleError(); if ($viewName == '') { $viewName = sfView::ERROR; } } } } if ($viewName == sfView::HEADER_ONLY) { $context->getResponse()->setHeaderOnly(true); // execute next filter $filterChain->execute(); } else { if ($viewName != sfView::NONE) { if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer = sfTimerManager::getTimer(sprintf('View "%s" for "%s/%s"', $viewName, $moduleName, $actionName)); } // get the view instance $viewInstance = $controller->getView($moduleName, $actionName, $viewName); $viewInstance->initialize($context, $moduleName, $actionName, $viewName); $viewInstance->execute(); // render the view and if data is returned, stick it in the // action entry which was retrieved from the execution chain $viewData = $viewInstance->render(); if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } if ($controller->getRenderMode() == sfView::RENDER_VAR) { $actionEntry->setPresentation($viewData); } else { // execute next filter $filterChain->execute(); } } } }
/** * Handles autoloading of classes that have been specified in autoload.yml. * * @param string A class name. * * @return boolean Returns true if the class has been loaded */ public static function splAutoload($class) { // load the list of autoload classes if (!self::$classes) { $file = sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_config_dir_name') . '/autoload.yml'); self::$classes = (include $file); } // class already exists if (class_exists($class, false)) { return true; } // we have a class path, let's include it if (isset(self::$classes[$class])) { require self::$classes[$class]; return true; } // see if the file exists in the current module lib directory // must be in a module context if (sfContext::hasInstance() && ($module = sfContext::getInstance()->getModuleName()) && isset(self::$classes[$module . '/' . $class])) { require self::$classes[$module . '/' . $class]; return true; } return false; }
/** * @see sfConfigCache */ protected function writeCacheFile($config, $cache, $data) { parent::writeCacheFile($config, $cache, $data); @chmod($cache, 0666); }