/** * Executes the filter */ public function execute($filterChain) { $filterChain->execute(); $response = $this->getContext()->getResponse(); $request = $this->getContext()->getRequest(); $controller = $this->getContext()->getController(); // don't highlight: // * for XHR requests // * if 304 // * if not rendering to the client // * if HTTP headers only if ($request->isXmlHttpRequest() || strpos($response->getContentType(), 'html') === false || $response->getStatusCode() == 304 || $controller->getRenderMode() != sfView::RENDER_CLIENT || $response->isHeaderOnly()) { return; } $timer = sfTimerManager::getTimer('Highlight Filter'); try { $this->highlight(); } catch (sfLuceneHighlighterException $e) { $timer->addTime(); $this->getContext()->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array($e->getMessage(), 'priority' => sfLogger::WARNING))); if ($e instanceof sfLuceneHighlighterXMLException) { $errors = $e->getProblems(); $errors['priority'] = sfLogger::ERR; $this->getContext()->getEventDispatcher()->notify(new sfEvent($this, 'application.log', $errors)); } } catch (Exception $e) { $timer->addTime(); throw $e; } $timer->addTime(); }
public function execute($filterChain) { $filterChain->execute(); $response = $this->getContext()->getResponse(); $request = $this->getContext()->getRequest(); $controller = $this->getContext()->getController(); // don't highlight: // * for XHR requests // * if 304 // * if not rendering to the client // * if HTTP headers only if ($request->isXmlHttpRequest() || strpos($response->getContentType(), 'html') === false || $response->getStatusCode() == 304 || $controller->getRenderMode() != sfView::RENDER_CLIENT || $response->isHeaderOnly()) { return; } $timer = sfTimerManager::getTimer('Highlight Filter'); try { if (!$this->highlight()) { $this->removeNotice(); } } catch (sfSolrHighlighterException $e) { sfLogger::getInstance()->err('{sfSolrHighlightFilter} silently ignoring exception: ' . $e->getMessage()); if ($this->testMode) { $timer->addTime(); throw $e; } } catch (Exception $e) { $timer->addTime(); throw $e; } $timer->addTime(); }
protected function execute($arguments = array(), $options = array()) { if (!$this->safeToRun()) { print "Process already running!\n"; die; } $timer = sfTimerManager::getTimer('execute'); $databaseManager = new sfDatabaseManager($this->configuration); $databaseManager->initialize($this->configuration); //set up index $index = EntityTable::getLuceneIndex(); //delete deleted entities $q = LsDoctrineQuery::create()->from('Entity e')->where('e.is_deleted = ?', true)->setHydrationMode(Doctrine::HYDRATE_ARRAY); foreach ($q->execute() as $entity) { if ($hits = $index->find('key:' . $entity['id'])) { if ($options['debug_mode']) { printf("Deleting index for Entity %s\n", $entity['id']); } foreach ($hits as $hit) { $index->delete($hit->id); } } } printf("Memory used: %s\n", LsNumber::makeBytesReadable(memory_get_usage())); printf("Index size: %s\n", $index->count()); $timer->addTime(); printf("Run time: %s\n", $timer->getElapsedTime()); sfTimerManager::clearTimers(); }
/** * Renders the presentation. * * @return string Current template content */ public function render() { if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer = sfTimerManager::getTimer(sprintf('Partial "%s/%s"', $this->moduleName, $this->actionName)); } if (sfConfig::get('sf_cache')) { $viewCache = $this->context->getViewCacheManager(); $viewCache->registerConfiguration($this->moduleName); $cacheKey = $viewCache->computeCacheKey($this->partialVars); if ($retval = $viewCache->getPartialCache($this->moduleName, $this->actionName, $cacheKey)) { return $retval; } else { $mainResponse = $this->context->getResponse(); $responseClass = get_class($mainResponse); $this->context->setResponse($response = new $responseClass($this->context->getEventDispatcher(), $mainResponse->getOptions())); } } // execute pre-render check $this->preRenderCheck(); $this->getAttributeHolder()->set('sf_type', 'partial'); // render template $retval = $this->renderFile($this->getDirectory() . '/' . $this->getTemplate()); if (sfConfig::get('sf_cache')) { $retval = $viewCache->setPartialCache($this->moduleName, $this->actionName, $cacheKey, $retval); $this->context->setResponse($mainResponse); $mainResponse->merge($response); } if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } return $retval; }
/** * Listens to the routing.load_configuration event. Finds & compiles LESS files to CSS * * @param sfEvent $event an sfEvent instance */ public static function findAndCompile(sfEvent $event) { // Start compilation timer for debug info $timer = sfTimerManager::getTimer('Less compilation'); // Create new helper object & compile LESS stylesheets with it $less = new sfLESS(); foreach ($less->findLessFiles() as $lessFile) { $less->compile($lessFile); } // Stop timer $timer->addTime(); }
/** * Compile the source files and fix permissions * * @param string $in Input directory containing sass files * @param string $out Output directory where to write the css files * @param string $cache Cache folder (null if cache is not used) * @param array $params Sass compiler parameters */ public function compile($in, $out, $cache, array $params = array()) { $timer = sfTimerManager::getTimer('Sass compilation'); $this->createFolderIfNeeded($out); if (!empty($cache)) { $this->createFolderIfNeeded($cache); } $this->driver->compile($in, $out, $params); $this->fixPermissions($out); if (!empty($cache)) { $this->fixPermissions($cache); } $timer->addTime(); }
/** * Renders the presentation. * * @return string Current template content */ public function render() { if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer = sfTimerManager::getTimer(sprintf('Partial "%s/%s"', $this->moduleName, $this->actionName)); } if ($retval = $this->getCache()) { return $retval; } else { if ($this->checkCache) { $mainResponse = $this->context->getResponse(); $responseClass = get_class($mainResponse); $this->context->setResponse($response = new $responseClass($this->context->getEventDispatcher(), array_merge($mainResponse->getOptions(), array('content_type' => $mainResponse->getContentType())))); } } try { // PHP FALLBACK try { // execute pre-render check $this->preRenderCheck(); } catch (sfRenderException $e) { if (null === $this->template) { throw new sfRenderException('A template has not been set.'); } $view = new sfPartialView($this->context, $this->moduleName, $this->actionName, $this->viewName); return $view->render(); } catch (Exception $e) { throw $e; } $this->getAttributeHolder()->set('sf_type', 'partial'); // render template $retval = $this->renderFile($this->getDirectory(), $this->getTemplate()); } catch (Exception $e) { if ($this->checkCache) { $this->context->setResponse($mainResponse); $mainResponse->merge($response); } throw $e; } if ($this->checkCache) { $retval = $this->viewCache->setPartialCache($this->moduleName, $this->actionName, $this->cacheKey, $retval); $this->context->setResponse($mainResponse); $mainResponse->merge($response); } if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } return $retval; }
protected function execute($arguments = array(), $options = array()) { if (!$this->safeToRun()) { print "Process already running!\n"; die; } $timer = sfTimerManager::getTimer('execute'); //get index and optimize $index = EntityTable::getLuceneIndex(); $index->optimize(); printf("Memory used: %s\n", LsNumber::makeBytesReadable(memory_get_usage())); printf("Index size: %s\n", $index->count()); $timer->addTime(); printf("Run time: %s\n", $timer->getElapsedTime()); sfTimerManager::clearTimers(); }
/** * Executes this filter. * * @param sfFilterChain $filterChain 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 current action instance $actionInstance = $this->context->getController()->getActionStack()->getLastEntry()->getActionInstance(); // execute the action, execute and render the view if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer = sfTimerManager::getTimer(sprintf('Action "%s/%s"', $actionInstance->getModuleName(), $actionInstance->getActionName())); $viewName = $this->handleAction($filterChain, $actionInstance); $timer->addTime(); $timer = sfTimerManager::getTimer(sprintf('View "%s" for "%s/%s"', $viewName, $actionInstance->getModuleName(), $actionInstance->getActionName())); $this->handleView($filterChain, $actionInstance, $viewName); $timer->addTime(); } else { $viewName = $this->handleAction($filterChain, $actionInstance); $this->handleView($filterChain, $actionInstance, $viewName); } }
/** * Renders the presentation. * * @param array Template attributes * * @return string Current template content */ public function render($templateVars = array()) { if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer = sfTimerManager::getTimer(sprintf('Partial "%s/%s"', $this->moduleName, $this->actionName)); } // execute pre-render check $this->preRenderCheck(); // assigns some variables to the template $this->attributeHolder->add($this->getGlobalVars()); $this->attributeHolder->add($templateVars); // render template $retval = $this->renderFile($this->getDirectory() . '/' . $this->getTemplate()); if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } return $retval; }
private function init() { if (sfContext::getInstance()->has('profiler')) { $timer = sfTimerManager::getTimer('afRead'); // this time will be stopeed inside XmlParser constructor } $parser = new XmlParser(); $this->type = $parser->getType(); $this->layout = $parser->getLayout(); if (method_exists($this->layout, 'beforeEnd')) { $this->layout->beforeEnd(); } if (sfContext::getInstance()->has('profiler')) { $timer = sfTimerManager::getTimer('afRender'); $timer->addTime(); // this one closes afRender timer that was started inside XmlParser constructor } }
/** * Renders the presentation. * * @return string Current template content */ public function render() { if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer = sfTimerManager::getTimer(sprintf('Partial "%s/%s"', $this->moduleName, $this->actionName)); } if ($retval = $this->getCache()) { if ($this->isFlavorPartial(ncFlavorFlavors::getModulePath($module_name) . '/templates', $this->getTemplate())) { $retval = $this->renderFile($this->getFlavorDirectory($this->getModuleName(), $this->getTemplate()) . '/' . $this->getTemplate()); } return $retval; } else { if ($this->checkCache) { $mainResponse = $this->context->getResponse(); $responseClass = get_class($mainResponse); $this->context->setResponse($response = new $responseClass($this->context->getEventDispatcher(), array_merge($mainResponse->getOptions(), array('content_type' => $mainResponse->getContentType())))); } } try { // execute pre-render check $this->preRenderCheck(); $this->getAttributeHolder()->set('sf_type', 'partial'); // render template $retval = $this->renderFile($this->getFlavorDirectory($this->getModuleName(), $this->getTemplate()) . '/' . $this->getTemplate()); } catch (Exception $e) { if ($this->checkCache) { $this->context->setResponse($mainResponse); $mainResponse->merge($response); } throw $e; } if ($this->checkCache) { if ($this->isFlavorPartial(ncFlavorFlavors::getModulePath($module_name) . '/templates', $this->getTemplate())) { $retval = $this->renderFile($this->getFlavorDirectory($this->getModuleName(), $this->getTemplate()) . '/' . $this->getTemplate()); } else { $retval = $this->viewCache->setPartialCache($this->moduleName, $this->actionName, $this->cacheKey, $retval); } $this->context->setResponse($mainResponse); $mainResponse->merge($response); } if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } return $retval; }
/** * Renders the presentation. * * @return string Current template content */ public function render() { if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer = sfTimerManager::getTimer(sprintf('Partial "%s/%s"', $this->moduleName, $this->actionName)); } if ($retval = $this->getCache()) { return $retval; } if ($this->checkCache) { $mainResponse = $this->context->getResponse(); $responseClass = get_class($mainResponse); $response = new $responseClass($this->context->getEventDispatcher(), $mainResponse->getOptions()); // the inner response has access to different properties, depending on whether it is marked as contextual in cache.yml if ($this->viewCache->isContextual($this->viewCache->getPartialUri($this->moduleName, $this->actionName, $this->cacheKey))) { $response->copyProperties($mainResponse); } else { $response->setContentType($mainResponse->getContentType()); } $this->context->setResponse($response); } try { // execute pre-render check $this->preRenderCheck(); $this->getAttributeHolder()->set('sf_type', 'partial'); // render template $retval = $this->renderFile($this->getDirectory() . '/' . $this->getTemplate()); } catch (Exception $e) { if ($this->checkCache) { $this->context->setResponse($mainResponse); $mainResponse->merge($response); } throw $e; } if ($this->checkCache) { $retval = $this->viewCache->setPartialCache($this->moduleName, $this->actionName, $this->cacheKey, $retval); $this->context->setResponse($mainResponse); $mainResponse->merge($response); } if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } return $retval; }
protected function execute($arguments = array(), $options = array()) { if (!$this->safeToRun()) { print "Process already running!\n"; die; } $timer = sfTimerManager::getTimer('execute'); $databaseManager = new sfDatabaseManager($this->configuration); $databaseManager->initialize($this->configuration); //get id of last-indexed entity $index = EntityTable::getLuceneIndex($options['index_file']); $index->setMergeFactor(200); $index->setMaxBufferedDocs(20); if ($count = $index->count()) { if (!($lastDoc = $index->getDocument($count - 1))) { throw new Exception("Can't find last document in index"); } $maxEntityId = $lastDoc->key; } else { $maxEntityId = 0; } //find non-deleted entities with greater IDs $q = LsDoctrineQuery::create()->from('Entity e')->leftJoin('e.Alias a')->where('e.id > ? AND e.is_deleted = ?', array($maxEntityId, false))->andWhere('a.context IS NULL')->offset($options['offset'])->limit($options['limit'])->orderBy('e.id ASC'); //index entities $optimize = 0; foreach ($q->fetchArray() as $entity) { if (EntityTable::updateLuceneIndex($entity, $index, $batchMode = true)) { if ($options['debug_mode']) { printf("Indexed entity with ID %s\n", $entity['id']); } } else { if ($options['debug_mode']) { printf("Skipped entity with ID %s\n", $entity['id']); } } } printf("Memory used: %s\n", LsNumber::makeBytesReadable(memory_get_usage())); printf("Index size: %s\n", $index->count()); $timer->addTime(); printf("Run time: %s\n", $timer->getElapsedTime()); sfTimerManager::clearTimers(); }
/** * 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 current action instance $actionInstance = $this->context->getController()->getActionStack()->getLastEntry()->getActionInstance(); // validate and execute the action if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer = sfTimerManager::getTimer(sprintf('Action "%s/%s"', $actionInstance->getModuleName(), $actionInstance->getActionName())); } $viewName = $this->handleAction($filterChain, $actionInstance); if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } // execute and render the view if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer = sfTimerManager::getTimer(sprintf('View "%s" for "%s/%s"', $viewName, $actionInstance->getModuleName(), $actionInstance->getActionName())); } $this->handleView($filterChain, $actionInstance, $viewName); if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } // execute the filter chain (needed if fill-in filter is activated by the validation system) $filterChain->execute(); }
/** * Add the time to the log * * @return void */ protected function sfAddTime() { sfTimerManager::getTimer('Database (Doctrine)')->addTime(); }
/** * 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(); } } } }
<?php /* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once __DIR__ . '/../../bootstrap/unit.php'; $t = new lime_test(6); $t->diag('sfTimer starting and stopping'); $timer = new sfTimer(); $timer->addTime(); sleep(1); $timer->addTime(); $t->is($timer->getCalls(), 2, '->getCalls() returns the amount of addTime() calls'); $t->ok($timer->getElapsedTime() > 0, '->getElapsedTime() returns a value greater than zero. No precision is tested by the unit test to avoid false alarms'); $t->diag('sfTimerManager'); $timerA = sfTimerManager::getTimer('timerA'); $timerB = sfTimerManager::getTimer('timerB'); $t->isa_ok($timerA, 'sfTimer', '::getTimer() returns an sfTimer instance'); $timers = sfTimerManager::getTimers(); $t->is(count($timers), 2, '::getTimers() returns an array with the timers created by the timer manager'); $t->is($timers['timerA'], $timerA, '::getTimers() returns an array with keys being the timer name'); sfTimerManager::clearTimers(); $t->is(count(sfTimerManager::getTimers()), 0, '::clearTimers() empties the list of the timer instances');
/** * Loads the symfony factories. */ public function loadFactories() { if (sfConfig::get('sf_use_database')) { // setup our database connections $this->factories['databaseManager'] = new sfDatabaseManager($this->configuration, array('auto_shutdown' => false)); } // create a new action stack $this->factories['actionStack'] = new sfActionStack(); if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer = sfTimerManager::getTimer('Factories'); } // include the factories configuration require $this->configuration->getConfigCache()->checkConfig('config/factories.yml'); $this->dispatcher->notify(new sfEvent($this, 'context.load_factories')); if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } }
function _call_component($moduleName, $componentName, $vars) { $context = sfContext::getInstance(); $controller = $context->getController(); if (!$controller->componentExists($moduleName, $componentName)) { // cannot find component throw new sfConfigurationException(sprintf('The component does not exist: "%s", "%s".', $moduleName, $componentName)); } // create an instance of the action $componentInstance = $controller->getComponent($moduleName, $componentName); // load component's module config file require $context->getConfigCache()->checkConfig('modules/' . $moduleName . '/config/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 throw new sfInitializationException(sprintf('sfComponent initialization failed for module "%s", component "%s".', $moduleName, $componentName)); } $componentToRun = 'execute'; } if (sfConfig::get('sf_logging_enabled')) { $context->getEventDispatcher()->notify(new sfEvent(null, 'application.log', array(sprintf('Call "%s->%s()' . '"', $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}($context->getRequest()); if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } return sfView::NONE == $retval ? null : $componentInstance->getVarHolder()->getAll(); }
/** * Checks to see if a configuration file has been modified and if so * recompile the cache file associated with it. * * The recompilation only occurs in a non debug environment. * * If the configuration file path is relative, symfony will look in directories * defined in the sfLoader::getConfigPaths() method. * * @param string A filesystem path to a configuration file * * @return string An absolute filesystem path to the cache filename associated with this specified configuration file * * @throws <b>sfConfigurationException</b> If a requested configuration file does not exist * * @see sfLoader::getConfigPaths() */ public function checkConfig($configPath, $optional = false) { static $process_cache_cleared = false; if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer = sfTimerManager::getTimer('Configuration'); } // the cache filename we'll be using $cache = $this->getCacheName($configPath); if (sfConfig::get('sf_in_bootstrap') && is_readable($cache)) { if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } return $cache; } if (!sfToolkit::isPathAbsolute($configPath)) { $files = sfLoader::getConfigPaths($configPath); } else { $files = is_readable($configPath) ? array($configPath) : array(); } if (!isset($files[0])) { if ($optional) { return null; } // configuration does not exist $error = sprintf('Configuration "%s" does not exist or is unreadable', $configPath); throw new sfConfigurationException($error); } // find the more recent configuration file last modification time $mtime = 0; foreach ($files as $file) { if (filemtime($file) > $mtime) { $mtime = filemtime($file); } } if (!is_readable($cache) || $mtime > filemtime($cache)) { // configuration has changed so we need to reparse it $this->callHandler($configPath, $files, $cache); // clear process cache if ('config/config_handlers.yml' != $configPath && sfConfig::get('sf_use_process_cache') && !$process_cache_cleared) { sfProcessCache::clear(); $process_cache_cleared = true; } } if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } return $cache; }
/** * 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(); } } } }
/** * @see Connection::executeQuery() */ public function executeQuery($sql, $fetchmode = null) { $this->lastExecutedQuery = $sql; $this->numQueriesExecuted++; $elapsedTime = 0; if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $sqlTimer = sfTimerManager::getTimer('Database'); $timer = new sfTimer(); } $retval = $this->childConnection->executeQuery($sql, $fetchmode); if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $sqlTimer->addTime(); $elapsedTime = $timer->getElapsedTime(); } $this->log(sprintf("executeQuery(): [%.2f ms] %s", $elapsedTime * 1000, $sql)); return $retval; }
/** * Log a Doctrine_Query * * @param string $message * @param string $event * @return void */ protected function sfLogQuery($message, $event, $time) { $message .= $event->getQuery(); if ($params = $event->getParams()) { foreach ($params as $key => $param) { if (strlen($param) >= 255) { $len = strlen($param); $kb = '[' . number_format($len / 1024, 2) . 'Kb]'; $params[$key] = $kb; } } $message .= ' - (' . implode(', ', $params) . ' )'; } $message = sprintf('{sfDoctrineLogger} [%.2f ms] %s', $time * 1000, $message); if (sfContext::hasInstance()) { sfContext::getInstance()->getLogger()->log($message); } $sqlTimer = sfTimerManager::getTimer('Database (Doctrine)'); }
/** * Wrapper for Lucene's find() * @param mixed $query The query * @return array The array of results */ public function find($query) { $this->configure(); $timer = sfTimerManager::getTimer('Zend Search Lucene Find'); $sort = array(); $scoring = null; if ($query instanceof sfLuceneCriteria) { foreach ($query->getSorts() as $sortable) { $sort[] = $sortable['field']; $sort[] = $sortable['type']; $sort[] = $sortable['order']; } $scoring = $query->getScoringAlgorithm(); $query = $query->getQuery(); } elseif (is_string($query)) { $query = sfLuceneCriteria::newInstance($this)->addString($query)->getQuery(); } $defaultScoring = Zend_Search_Lucene_Search_Similarity::getDefault(); if ($scoring) { Zend_Search_Lucene_Search_Similarity::setDefault($scoring); } try { // as we rarely sort, we can avoid the overhead of call_user_func() with this conditional if (count($sort)) { $args = array_merge(array($query), $sort); $results = call_user_func_array(array($this->getLucene(), 'find'), $args); } else { $results = $this->getLucene()->find($query); } } catch (Exception $e) { Zend_Search_Lucene_Search_Similarity::setDefault($defaultScoring); $timer->addTime(); throw $e; } Zend_Search_Lucene_Search_Similarity::setDefault($defaultScoring); $timer->addTime(); return $results; }
/** * Checks to see if a configuration file has been modified and if so * recompile the cache file associated with it. * * The recompilation only occurs in a non debug environment. * * If the configuration file path is relative, symfony will look in directories * defined in the sfConfiguration::getConfigPaths() method. * * @param string $configPath A filesystem path to a configuration file * @param boolean $optional If true, config path does not need to exist * * @return string An absolute filesystem path to the cache filename associated with this specified configuration file * * @throws <b>sfConfigurationException</b> If a requested configuration file does not exist * * @see sfConfiguration::getConfigPaths() */ public function checkConfig($configPath, $optional = false) { if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer = sfTimerManager::getTimer('Configuration'); } // the cache filename we'll be using $cache = $this->getCacheName($configPath); if (!sfConfig::get('sf_debug') && !sfConfig::get('sf_test') && is_readable($cache)) { return $cache; } if (!sfToolkit::isPathAbsolute($configPath)) { $files = $this->configuration->getConfigPaths($configPath); } else { $files = is_readable($configPath) ? array($configPath) : array(); } if (!isset($files[0])) { if ($optional) { return null; } // configuration does not exist throw new sfConfigurationException(sprintf('Configuration "%s" does not exist or is unreadable.', $configPath)); } // find the more recent configuration file last modification time $mtime = 0; foreach ($files as $file) { if (filemtime($file) > $mtime) { $mtime = filemtime($file); } } if (!is_readable($cache) || $mtime > filemtime($cache)) { // configuration has changed so we need to reparse it $this->callHandler($configPath, $files, $cache); } if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } return $cache; }
public function execute($filterChain) { $context = $this->getContext(); $controller = $context->getController(); $actionEntry = $controller->getActionStack()->getLastEntry(); $actionInstance = $actionEntry->getActionInstance(); $moduleName = $context->getModuleName(); $actionName = $context->getActionName(); $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')) { $viewName = sfView::SUCCESS; } } if (!$viewName) { if (($actionInstance->getRequestMethods() & $method) != $method) { $viewName = $actionInstance->getDefaultView(); } else { $validated = true; $validationConfig = $moduleName . '/' . sfConfig::get('sf_app_module_validate_dir_name') . '/' . $actionName . '.yml'; if (null !== ($validateFile = sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name') . '/' . $validationConfig, true))) { $validatorManager = new sfValidatorManager(); $validatorManager->initialize($context); require $validateFile; $validated = $validatorManager->execute(); } $validateToRun = 'validate' . ucfirst($actionName); $manualValidated = method_exists($actionInstance, $validateToRun) ? $actionInstance->{$validateToRun}() : $actionInstance->validate(); $validated = $manualValidated && $validated || $manualValidated && !$validated && !$context->getRequest()->hasErrors(); 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)); } $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'); } $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); $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)); } $viewInstance = $controller->getView($moduleName, $actionName, $viewName); $viewInstance->initialize($context, $moduleName, $actionName, $viewName); $viewInstance->execute(); $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 { $filterChain->execute(); } } } }
/** * Logs to the timer. * * @param Doctrine_Event $event */ public function postStmtExecute(Doctrine_Event $event) { sfTimerManager::getTimer('Database (Doctrine)')->addTime(); $args = func_get_args(); $this->__call(__FUNCTION__, $args); if ($event->getElapsedSecs() > $this->options['slow_query_threshold']) { $event->slowQuery = 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; } }
/** * @see Connection::executeUpdate() **/ public function executeUpdate($sql) { $this->lastExecutedQuery = $sql; $this->numQueriesExecuted++; $boolLog = sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled') || nyProfiler::getInstance()->isStarted(); $elapsedTime = 0; if ($boolLog) { $sqlTimer = sfTimerManager::getTimer('Database'); $timer = new sfTimer(); } // endif $intResult = $this->childConnection->executeUpdate($sql); if ($boolLog) { $sqlTimer->addTime(); $elapsedTime = $timer->getElapsedTime(); } // endif $this->log(sprintf("{sfCreole} executeUpdate(): [%.2f ms] %s", $elapsedTime * 1000, $sql), true); return $intResult; }