/** * @see sfTask */ public function execute($arguments = array(), $options = array()) { $this->logSection('i18n', sprintf('extracting i18n strings for the "%s" application', $arguments['application'])); // get i18n configuration from factories.yml $config = sfFactoryConfigHandler::getConfiguration($this->configuration->getConfigPaths('config/factories.yml')); $class = $config['i18n']['class']; $params = $config['i18n']['param']; unset($params['cache']); $extract = new sfI18nApplicationExtract(new $class($this->configuration, new sfNoCache(), $params), $arguments['culture']); $extract->extract(); $this->logSection('i18n', sprintf('found "%d" new i18n strings', count($extract->getNewMessages()))); $this->logSection('i18n', sprintf('found "%d" old i18n strings', count($extract->getOldMessages()))); if ($options['display-new']) { $this->logSection('i18n', sprintf('display "%d" new i18n strings', count($extract->getOldMessages()))); foreach ($extract->getNewMessages() as $message) { $this->log(' ' . $message . "\n"); } } if ($options['auto-save']) { $this->logSection('i18n', 'saving new i18n strings'); $extract->saveNewMessages(); } if ($options['display-old']) { $this->logSection('i18n', sprintf('display "%d" old i18n strings', count($extract->getOldMessages()))); foreach ($extract->getOldMessages() as $message) { $this->log(' ' . $message . "\n"); } } if ($options['auto-delete']) { $this->logSection('i18n', 'deleting old i18n strings'); $extract->deleteOldMessages(); } }
protected function initializeMailer() { require_once sfConfig::get('sf_symfony_lib_dir') . '/vendor/swiftmailer/classes/Swift.php'; Swift::registerAutoload(); sfMailer::initialize(); $config = sfFactoryConfigHandler::getConfiguration($this->configuration->getConfigPaths('config/factories.yml')); return new $config['mailer']['class']($this->dispatcher, $config['mailer']['param']); }
public function execute($configFiles) { $code = parent::execute($configFiles); if (!sfConfig::get('dm_performance_enable_mailer', true)) { $code = str_replace('Swift::registerAutoload();', '// Swift::registerAutoload();', $code); $code = str_replace('sfMailer::initialize();', '// sfMailer::initialize();', $code); } return $code; }
protected function getI18N() { if (!$this->i18n) { $config = sfFactoryConfigHandler::getConfiguration($this->configuration->getConfigPaths('config/factories.yml')); $class = $config['i18n']['class']; $this->i18n = new $class($this->configuration, null, $config['i18n']['param']); } $this->i18n->setCulture($this->commandManager->getOptionValue('culture')); return $this->i18n; }
/** * returns a storage param from the factories.yml * * @author Matthias Pfefferle * @param string $pParamKey * @return string|null */ public static function getStorageParam($pParamKey) { $lAppConfiguration = ProjectConfiguration::getApplicationConfiguration(sfConfig::get("sf_app"), sfConfig::get("sf_environment"), false); $lFactory = sfFactoryConfigHandler::getConfiguration($lAppConfiguration->getConfigPaths('config/factories.yml')); $lStorageParams = $lFactory['storage']['param']; if (array_key_exists($pParamKey, $lStorageParams)) { return $lStorageParams[$pParamKey]; } else { return null; } }
/** * @see sfTask * @see sfI18nExtract */ public function execute($arguments = array(), $options = array()) { $output = ""; if (strtolower($options['file']) != 'stdout') { $this->logSection('i18n', sprintf('Diff i18n strings for the "%s" application', $arguments['application'])); } // get i18n configuration from factories.yml $config = sfFactoryConfigHandler::getConfiguration($this->configuration->getConfigPaths('config/factories.yml')); $class = $config['i18n']['class']; $params = $config['i18n']['param']; unset($params['cache']); $this->i18n = new $class($this->configuration, new sfNoCache(), $params); $extract = new sfI18nApplicationExtract($this->i18n, $arguments['culture']); $extract->extract(); if (strtolower($options['file']) != 'stdout') { $this->logSection('i18n', sprintf('found "%d" new i18n strings', count($extract->getNewMessages()))); $this->logSection('i18n', sprintf('found "%d" old i18n strings', count($extract->getOldMessages()))); } // Column headers $rows[0] = array('Action', 'Source', 'Target'); // Old messages foreach ($this->getOldTranslations($extract) as $source => $target) { $rows[] = array('Removed', $source, $target); } // New messages foreach ($extract->getNewMessages() as $message) { $rows[] = array('Added', $message); } // Choose output format switch (strtolower($options['format'])) { case 'csv': foreach ($rows as $row) { $output .= '"' . implode('","', array_map('addslashes', $row)) . "\"\n"; } break; case 'tab': foreach ($rows as $row) { $output .= implode("\t", $row) . "\n"; } break; } // Output file if (strtolower($options['file']) != 'stdout') { echo "\n" . $options['file']; // Remove '=' if using -f="file.csv" notation $filename = substr($options['file'], 0, 1) == '=' ? substr($options['file'], 1) : $options['file']; file_put_contents($filename, $output); } else { echo $output; } }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { // get routes $config = sfFactoryConfigHandler::getConfiguration($this->configuration->getConfigPaths('config/factories.yml')); $params = array_merge($config['routing']['param'], array('load_configuration' => false, 'logging' => false)); $config = new sfRoutingConfigHandler(); $routes = $config->evaluate($this->configuration->getConfigPaths('config/routing.yml')); $routing = new sfPatternRouting($this->dispatcher, null, $params); $routing->setRoutes($routes); $this->dispatcher->notify(new sfEvent($routing, 'routing.load_configuration')); $this->routes = $routing->getRoutes(); // display $arguments['name'] ? $this->outputRoute($arguments['application'], $arguments['name']) : $this->outputRoutes($arguments['application']); }
/** * @see sfTask */ public function execute($arguments = array(), $options = array()) { $this->logSection('i18n', sprintf('extracting i18n strings for the "%s" application', $options['application'])); // get i18n configuration from factories.yml $config = sfFactoryConfigHandler::getConfiguration($this->configuration->getConfigPaths('config/factories.yml')); $class = $config['i18n']['class']; $params = $config['i18n']['param']; unset($params['cache']); $extract = new sfI18nApplicationExtract(new $class($this->configuration, new sfNoCache(), $params), $arguments['culture']); $extract->extract(); $this->logSection('i18n', sprintf('found "%d" new i18n strings', count($extract->getNewMessages()))); $this->logSection('i18n', sprintf('found "%d" old i18n strings', count($extract->getOldMessages()))); if ($options['display-new']) { $this->logSection('i18n', sprintf('display new i18n strings', count($extract->getOldMessages()))); foreach ($extract->getNewMessages() as $message) { $this->log(' ' . $message . "\n"); } } if ($options['auto-save']) { $this->logSection('i18n', 'saving new i18n strings'); $extract->saveNewMessages(); } if ($options['display-old']) { $this->logSection('i18n', sprintf('display old i18n strings', count($extract->getOldMessages()))); foreach ($extract->getOldMessages() as $message) { $this->log(' ' . $message . "\n"); } } if ($options['auto-delete']) { $this->logSection('i18n', 'deleting old i18n strings'); $extract->deleteOldMessages(); } // Extract plugin strings if ($options['plugins']) { unset($options['plugins']); $pluginNames = sfFinder::type('dir')->maxdepth(0)->relative()->not_name('.')->in(sfConfig::get('sf_plugins_dir')); foreach ($pluginNames as $pluginName) { $extractPlugin = new sfI18nExtractPluginTask($this->dispatcher, $this->formatter); $extractPlugin->setCommandApplication($this->commandApplication); $extractPlugin->setConfiguration($this->configuration); $ret = $extractPlugin->run(array('plugin' => $pluginName, 'culture' => $arguments['culture']), $options); if ($ret) { return $ret; } } } }
/** * Executes this configuration handler. * * @param array $configFiles An array of absolute filesystem path to a configuration file * * @return string Data to be written to a cache file * * @throws sfConfigurationException If a requested configuration file does not exist or is not readable * @throws sfParseException If a requested configuration file is improperly formatted */ public function execute($configFiles) { $config = sfFactoryConfigHandler::getConfiguration(sfContext::getInstance()->getConfiguration()->getConfigPaths('config/factories.yml')); $options = $config['routing']['param']; unset($options['cache']); $data = array(); foreach ($this->parse($configFiles) as $name => $routeConfig) { $r = new ReflectionClass($routeConfig[0]); $route = $r->newInstanceArgs($routeConfig[1]); $routes = $route instanceof sfRouteCollection ? $route : array($name => $route); foreach (sfPatternRouting::flattenRoutes($routes) as $name => $route) { $route->setDefaultOptions($options); $data[] = sprintf('$map[\'%s\'] = new %s(%s, %s, %s, %s);', $name, get_class($route), var_export($route->getPattern(), true), var_export($route->getDefaults(), true), var_export($route->getRequirements(), true), var_export($route->getOptions(), true)); $data[] = sprintf('$map[\'%s\']->setCompiledData(%s);', $name, var_export($route->getCompiledData(), true)); } } return sprintf("<?php\n" . "// auto-generated by sfRoutingConfigHandler\n" . "// date: %s\n\$map = array();\n%s\nreturn \$map;\n", date('Y/m/d H:i:s'), implode("\n", $data)); }
/** * Executes this configuration handler. * * @param array $configFiles An array of absolute filesystem path to a configuration file * * @return string Data to be written to a cache file * * @throws sfConfigurationException If a requested configuration file does not exist or is not readable * @throws sfParseException If a requested configuration file is improperly formatted */ public function execute($configFiles) { $config = sfFactoryConfigHandler::getConfiguration(ProjectConfiguration::getActive()->getConfigPaths('config/factories.yml')); $options = $config['module_manager']['param']; $managerClass = $config['module_manager']['class']; $this->parse($configFiles); $this->validate(); $this->processHierarchy(); $this->sortModuleTypes(); $data = array(); $data[] = sprintf('$manager = new %s();', $managerClass); $data[] = sprintf('$modules = $projectModules = $modelModules = $types = array();'); foreach ($this->config as $typeName => $typeConfig) { $data[] = sprintf('$types[\'%s\'] = new %s();', $typeName, $options['type_class']); $data[] = sprintf('$typeSpaces = array();'); foreach ($typeConfig as $spaceName => $modulesConfig) { $data[] = sprintf('$typeSpaces[\'%s\'] = new %s();', $spaceName, $options['space_class']); $data[] = sprintf('$spaceModules = array();'); foreach ($modulesConfig as $moduleKey => $moduleConfig) { $moduleClass = $options[$moduleConfig['is_project'] ? 'module_node_class' : 'module_base_class']; if ($moduleConfig['is_project']) { $moduleReceivers = sprintf('$modules[\'%s\'] = $projectModules[\'%s\'] = $spaceModules[\'%s\']', $moduleKey, $moduleKey, $moduleKey); } else { $moduleReceivers = sprintf('$modules[\'%s\'] = $spaceModules[\'%s\']', $moduleKey, $moduleKey); } $data[] = sprintf('%s = new %s(\'%s\', $typeSpaces[\'%s\'], %s);', $moduleReceivers, $moduleClass, $moduleKey, $spaceName, $this->getExportedModuleOptions($moduleKey, $moduleConfig)); if ($moduleConfig['model']) { $data[] = sprintf('$modelModules[\'%s\'] = \'%s\';', $moduleConfig['model'], $moduleKey); } } $data[] = sprintf('$typeSpaces[\'%s\']->initialize(\'%s\', $types[\'%s\'], $spaceModules);', $spaceName, $spaceName, $typeName); $data[] = 'unset($spaceModules);'; } $data[] = sprintf('$types[\'%s\']->initialize(\'%s\', $typeSpaces);', $typeName, $typeName); $data[] = 'unset($typeSpaces);'; } $data[] = sprintf('$manager->load($types, $modules, $projectModules, $modelModules);'); $data[] = 'unset($types, $modules, $projectModules, $modelModules);'; $data[] = 'return $manager;'; unset($this->config, $this->modules, $this->projectModules); return sprintf("<?php\n" . "// auto-generated by dmModuleManagerConfigHandler\n" . "// date: %s\n%s", date('Y/m/d H:i:s'), implode("\n", $data)); }
/** * @see sfTask */ public function execute($arguments = array(), $options = array()) { $this->logSection('i18n', sprintf('Rectifying existing i18n strings for the "%s" application', $options['application'])); // get i18n configuration from factories.yml $config = sfFactoryConfigHandler::getConfiguration($this->configuration->getConfigPaths('config/factories.yml')); $class = $config['i18n']['class']; $params = $config['i18n']['param']; unset($params['cache']); // Get current (saved) messages from ALL sources (app and plugin) $this->i18n = new $class($this->configuration, new sfNoCache(), $params); $this->i18n->getMessageSource()->setCulture($arguments['culture']); $this->i18n->getMessageSource()->load(); $currentMessages = array(); foreach ($this->i18n->getMessageSource()->read() as $catalogue => $translations) { foreach ($translations as $key => $value) { // Use first message that has a valid translation if (0 < strlen(trim($value[0])) && !isset($currentMessages[$key][0])) { $currentMessages[$key] = $value; } } } // Loop through plugins $pluginNames = sfFinder::type('dir')->maxdepth(0)->relative()->not_name('.')->in(sfConfig::get('sf_plugins_dir')); foreach ($pluginNames as $pluginName) { $this->logSection('i18n', sprintf('rectifying %s plugin strings', $pluginName)); $messageSource = sfMessageSource::factory($config['i18n']['param']['source'], sfConfig::get('sf_plugins_dir') . '/' . $pluginName . '/i18n'); $messageSource->setCulture($arguments['culture']); $messageSource->load(); // If the current plugin source *doesn't* have a translation, then try // and get translated value from $currentMessages foreach ($messageSource->read() as $catalogue => $translations) { foreach ($translations as $key => &$value) { if (0 == strlen(trim($value[0])) && isset($currentMessages[$key])) { $messageSource->update($key, $currentMessages[$key][0], $value[2]); } } } $messageSource->save(); } }
/** * @see sfTask */ public function execute($arguments = array(), $options = array()) { $path = sfConfig::get('sf_plugins_dir') . '/' . $arguments['plugin']; if (!is_dir($path)) { throw new sfException('The plugin you specified is not valid.'); } $this->logSection('i18n', sprintf('extracting i18n strings for the "%s" plugin', $arguments['plugin'])); // get i18n configuration from factories.yml $config = sfFactoryConfigHandler::getConfiguration($this->configuration->getConfigPaths('config/factories.yml')); $class = $config['i18n']['class']; $params = $config['i18n']['param']; unset($params['cache']); $extract = new sfI18nPluginExtract(new $class($this->configuration, new sfNoCache(), $params), $arguments['culture'], array('path' => $path)); $extract->extract(); $this->logSection('i18n', sprintf('found "%d" new i18n strings', count($extract->getNewMessages()))); $this->logSection('i18n', sprintf('found "%d" old i18n strings', count($extract->getOldMessages()))); if ($options['display-new']) { $this->logSection('i18n', sprintf('display new i18n strings', count($extract->getOldMessages()))); foreach ($extract->getNewMessages() as $message) { $this->log(' ' . $message . "\n"); } } if ($options['auto-save']) { $this->logSection('i18n', 'saving new i18n strings'); $extract->saveNewMessages(); } if ($options['display-old']) { $this->logSection('i18n', sprintf('display old i18n strings', count($extract->getOldMessages()))); foreach ($extract->getOldMessages() as $message) { $this->log(' ' . $message . "\n"); } } if ($options['auto-delete']) { $this->logSection('i18n', 'deleting old i18n strings'); $extract->deleteOldMessages(); } }
public function getFactoriesConfiguration(sfApplicationConfiguration $appConfiguration) { if (is_null($this->config)) { $this->config = sfFactoryConfigHandler::getConfiguration($appConfiguration->getConfigPaths('config/factories.yml')); } return $this->config; }
/** * Gets the factory configuration * * @return array */ protected function getFactoryConfiguration() { if (null === $this->factoryConfiguration) { $this->factoryConfiguration = sfFactoryConfigHandler::getConfiguration($this->configuration->getConfigPaths('config/factories.yml')); } return $this->factoryConfiguration; }
public function getFactoriesConfiguration(sfApplicationConfiguration $appConfiguration) { $app = $appConfiguration->getApplication(); $env = $appConfiguration->getEnvironment(); if (!isset($this->config[$app])) { $this->config[$app] = array(); } if (!isset($this->config[$app][$env])) { $this->config[$app][$env] = sfFactoryConfigHandler::getConfiguration($appConfiguration->getConfigPaths('config/factories.yml')); } return $this->config[$app][$env]; }
protected function initializeRouting() { $config = sfFactoryConfigHandler::getConfiguration($this->configuration->getConfigPaths('config/factories.yml')); $params = array_merge($config['routing']['param'], array('load_configuration' => false, 'logging' => false)); $handler = new sfRoutingConfigHandler(); $routes = $handler->evaluate($this->configuration->getConfigPaths('config/routing.yml')); $routing = new $config['routing']['class']($this->dispatcher, null, $params); $routing->setRoutes($routes); $this->dispatcher->notify(new sfEvent($routing, 'routing.load_configuration')); return $routing; }
protected function getOptions() { $config = sfFactoryConfigHandler::getConfiguration(sfContext::getInstance()->getConfiguration()->getConfigPaths('config/factories.yml')); return $config['routing']['param']; }