public function process(array $assets) { if (empty($assets)) { return array(); } $timer = dmDebug::timerOrNull('dmAssetCompressor::process(' . $this->type . ')'); $this->assets = $assets; $this->cachedAssets = array(); $this->cdnAssets = array(); $this->preservedAssets = array(); $this->processedAssets = array(); $this->cacheKey = ''; $this->webDir = sfConfig::get('sf_web_dir'); $this->preProcess(); foreach ($this->assets as $webPath => $options) { if ($this->isOnFilesystem($webPath)) { if (!file_exists($this->webDir . $webPath)) { $this->log('Missing ' . $this->type . ' : ' . $this->webDir . $webPath); $this->cacheKey .= $webPath; } elseif ($this->isCachable($webPath, $options)) { $this->cachedAssets[$webPath] = $options; $this->cacheKey .= $webPath . filemtime($this->webDir . $webPath); } else { $this->preservedAssets[$webPath] = $options; } } else { $this->cdnAssets[$webPath] = $options; } } if (!empty($this->cachedAssets)) { $this->cacheKey = md5($this->processCacheKey($this->cacheKey)); $cacheWebPath = '/cache/' . $this->type; $cacheDirPath = $this->webDir . $cacheWebPath; $cacheFilePath = $cacheDirPath . '/' . $this->cacheKey . '.' . $this->type; $this->filesystem->mkdir($cacheDirPath); if (!file_exists($cacheFilePath)) { $cacheContent = ''; foreach ($this->cachedAssets as $webPath => $options) { $cacheContent .= $this->processAssetContent(file_get_contents($this->webDir . $webPath), $webPath); } $cacheContent = $this->processCacheContent($cacheContent); file_put_contents($cacheFilePath, $cacheContent); chmod($cacheFilePath, 0666); if ($this->options['gz_compression']) { file_put_contents($cacheFilePath . '.gz', gzencode($cacheContent)); chmod($cacheFilePath . '.gz', 0666); } $message = sprintf('%s : compressed %d assets ( %s )', get_class($this), count($this->cachedAssets), dmOs::humanizeSize($cacheFilePath)); $this->dispatcher->notify(new sfEvent($this, 'application.log', array($message, 'priority' => sfLogger::INFO))); } $this->processedAssets = array_merge($this->cdnAssets, array($cacheWebPath . '/' . $this->cacheKey . '.' . $this->type => array()), $this->preservedAssets); } else { $this->processedAssets = array_merge($this->cdnAssets, $this->preservedAssets); } $this->postProcess(); $timer && $timer->addTime(); return $this->processedAssets; }
public function execute(array $attributes = array('slug')) { $timer = dmDebug::timerOrNull('dmSeoValidationService::execute'); $this->attributes = $attributes; $this->checkAttributesExist(); $duplicated = $this->validateAttributes(); $timer && $timer->addTime(); return $duplicated; }
/** * Diem code size * returns array(files, lines, characters) */ public static function getDiemSize() { $timer = dmDebug::timerOrNull('dm::getDiemSize()'); $pluginsDir = sfConfig::get('sf_plugins_dir') . '/'; $files = sfFinder::type('file')->prune('om')->prune('map')->prune('base')->prune('vendor')->name('*\\.php', '*\\.css', '*\\.js', '*\\.yml')->in($pluginsDir . 'dmCorePlugin', $pluginsDir . 'dmAdminPlugin', $pluginsDir . 'dmFrontPlugin'); foreach ($files as $key => $file) { if (strpos($file, '/web/lib/')) { unset($files[$key]); } } $lines = 0; $characters = 0; foreach ($files as $file) { $content = file($file); $lines += count($content); $characters += strlen(implode(' ', $content)); } $response = array('nb_files' => count($files), 'lines' => $lines, 'characters' => $characters); $timer && $timer->addTime(); return $response; }
public function render() { $t = dmDebug::timerOrNull('dmAdminBreadCrumb::render'); $links = $this->renderLinksArray($this->getLinks()); if (empty($links)) { $html = ''; } else { $html = $this->helper->open('div#breadCrumb.mt10.clearfix') . $this->helper->tag('ol', '<li>' . implode('</li><li class="sep">></li><li>', $links) . '</li>'); if ($miniSearchForm = dmArray::get($this->context->getResponse()->getSlots(), 'dm.mini_search_form')) { $html .= $this->helper->tag('div.dm_mini_search_form', $miniSearchForm); } $html .= $this->helper->close('div'); } $t && $t->addTime(); return $html; }