protected function execute($arguments = array(), $options = array()) { $file = sfConfig::get('sf_apps_dir') . '/' . $options['app'] . '/config/app.yml'; $config = file_exists($file) ? sfYaml::load($file) : array(); $config = $this->switchConfig($config, strtolower($options['option']), strtolower($options['status'])); file_put_contents($file, sfYaml::dump($config, 4)); }
/** * Dumps a collection to a YAML file. * * By convention, each collection is dumped to its own YAML file, * named collection.yml. Any existing file with this name will be crushed * without notice. * * @param string $collection The collection name * @param integer $inline The level where you switch to inline YAML * @return MongoYaml */ public function dump($collection, $inline = 10) { $data = iterator_to_array($this->database->{$collection}->find()); $yaml = sfYaml::dump(array($collection => $data), $inline); file_put_contents($collection . '.yml', $yaml); return $this; }
protected function addParameters() { if (!$this->container->getParameters()) { return ''; } return sfYaml::dump(array('parameters' => $this->prepareParameters($this->container->getParameters())), 2); }
/** * ESCRIBE EN EL FICHERO lastConnection.yml LOS DATOS DE LA * ULTIMA CONEXIÓN QUE ESTAN EN $_POST */ public function saveCurrentParametersConnection() { $texto = sfYaml::dump($this->connection); $archivo = new Archivo("lastConnection.yml"); $archivo->write($texto); unset($archivo); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { // update databases.yml if (!is_null($options['app'])) { $file = sfConfig::get('sf_apps_dir') . '/' . $options['app'] . '/config/databases.yml'; } else { $file = sfConfig::get('sf_config_dir') . '/databases.yml'; } $config = file_exists($file) ? sfYaml::load($file) : array(); $config[$options['env']][$options['name']] = array('class' => $options['class'], 'param' => array_merge(isset($config[$options['env']][$options['name']]['param']) ? $config[$options['env']][$options['name']]['param'] : array(), array('dsn' => $arguments['dsn'], 'username' => $arguments['username'], 'password' => $arguments['password']))); file_put_contents($file, sfYaml::dump($config, 4)); // update propel.ini if (is_null($options['app']) && false !== strpos($options['class'], 'Propel') && 'all' == $options['env']) { $propelini = sfConfig::get('sf_config_dir') . '/propel.ini'; if (file_exists($propelini)) { $content = file_get_contents($propelini); if (preg_match('/^(.+?):/', $arguments['dsn'], $match)) { $content = preg_replace('/^propel\\.database(\\s*)=(\\s*)(.+?)$/m', 'propel.database$1=${2}' . $match[1], $content); $content = preg_replace('/^propel\\.database.driver(\\s*)=(\\s*)(.+?)$/m', 'propel.database.driver$1=${2}' . $match[1], $content); $content = preg_replace('/^propel\\.database\\.createUrl(\\s*)=(\\s*)(.+?)$/m', 'propel.database.createUrl$1=${2}' . $arguments['dsn'], $content); $content = preg_replace('/^propel\\.database\\.url(\\s*)=(\\s*)(.+?)$/m', 'propel.database.url$1=${2}' . $arguments['dsn'], $content); $content = preg_replace('/^propel\\.database\\.user(\\s*)=(\\s*)(.+?)$/m', 'propel.database.user$1=${2}' . $arguments['username'], $content); $content = preg_replace('/^propel\\.database\\.password(\\s*)=(\\s*)(.+?)$/m', 'propel.database.password$1=${2}' . $arguments['password'], $content); file_put_contents($propelini, $content); } } } }
/** * Executes this filter. * * @param sfFilterChain $filterChain A sfFilterChain instance */ public function execute($filterChain) { // disable security on login and secure actions if (sfConfig::get('sf_login_module') == $this->context->getModuleName() && sfConfig::get('sf_login_action') == $this->context->getActionName() || sfConfig::get('sf_secure_module') == $this->context->getModuleName() && sfConfig::get('sf_secure_action') == $this->context->getActionName()) { $filterChain->execute(); return; } // NOTE: the nice thing about the Action class is that getCredential() // is vague enough to describe any level of security and can be // used to retrieve such data and should never have to be altered if (!$this->context->getUser()->isAuthenticated()) { if (sfConfig::get('sf_logging_enabled')) { $this->context->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array(sprintf('Action "%s/%s" requires authentication, forwarding to "%s/%s"', $this->context->getModuleName(), $this->context->getActionName(), sfConfig::get('sf_login_module'), sfConfig::get('sf_login_action'))))); } // the user is not authenticated $this->forwardToLoginAction(); } // the user is authenticated $credential = $this->getUserCredential(); if (null !== $credential && !$this->context->getUser()->hasCredential($credential)) { if (sfConfig::get('sf_logging_enabled')) { $this->context->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array(sprintf('Action "%s/%s" requires credentials "%s", forwarding to "%s/%s"', $this->context->getModuleName(), $this->context->getActionName(), sfYaml::dump($credential, 0), sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action'))))); } // the user doesn't have access $this->forwardToSecureAction(); } // the user has access, continue $filterChain->execute(); }
public function getTransformed($generator) { $yaml = sfYaml::load($generator); $yaml['generator']['param']['config'] = $this->getConfig(); $transformed = sfYaml::dump($yaml, 6, 0); $transformed = preg_replace("|('~')|um", "~", $transformed); return $transformed; }
/** * Dumps a PHP array to a YAML string. * * The dump method, when supplied with an array, will do its best * to convert the array into friendly YAML. * * @param array $array PHP array * @param string $file YAML file path * @param integer $inline The level where you switch to inline YAML * @return mixed string when sucess or false when fail */ public static function dump($data, $file = null, $inline = 2) { $yaml = sfYaml::dump($data, $inline); if (empty($file) || file_put_contents($yaml, $file)) { return $yaml; } return false; }
/** * Converts an array to HTML. * * @param string $id The identifier to use * @param array $values The array of values * * @return string An HTML string */ protected function formatArrayAsHtml($id, $values) { $id = ucfirst(strtolower($id)); return ' <h2>' . $id . ' <a href="#" onclick="sfWebDebugToggle(\'sfWebDebug' . $id . '\'); return false;"><img src="' . $this->webDebug->getOption('image_root_path') . '/toggle.gif" /></a></h2> <div id="sfWebDebug' . $id . '" style="display: none"><pre>' . htmlspecialchars(sfYaml::dump(self::removeObjects($values)), ENT_QUOTES, sfConfig::get('sf_charset')) . '</pre></div> '; }
public function dump($array) { try { return sfYaml::dump($array); } catch (Exception $e) { throw new YamlParserException($e->getMessage(), $e->getCode(), $e); } }
/** * Converts an array to HTML. * * @param string $id The identifier to use * @param array $values The array of values * * @return string An HTML string */ protected function formatArrayAsHtml($id, $values) { $id = ucfirst(strtolower($id)); return ' <h2>' . $id . ' ' . $this->getToggler('sfWebDebug' . $id) . '</h2> <div id="sfWebDebug' . $id . '" style="display: none"><pre>' . htmlspecialchars(sfYaml::dump(sfDebug::removeObjects($values)), ENT_QUOTES, sfConfig::get('sf_charset')) . '</pre></div> '; }
public static function dump($object) { // using the slow (but very compatible) symfony YAML dumper $ret = sfYaml::dump($object, 999); if (substr($string, 0, 3) == '---') { return substr($ret, 4); } return $ret; }
function updateAppYaml(array $app) { $appYaml = sfYaml::load(sfConfig::get('sf_app_config_dir') . '/app.yml'); if (null == $appYaml) { $appYaml = array(); } $appYaml = array_merge($appYaml, $app); file_put_contents(sfConfig::get('sf_app_config_dir') . '/app.yml', sfYaml::dump($appYaml, 15)); }
public function save() { $array = $this->_buildArrayToWrite(); $this->_path = sfConfig::get('sf_app_dir') . '/config/app.yml'; file_put_contents($this->_path, sfYaml::dump($array, 4)); chdir(sfConfig::get('sf_root_dir')); $task = new sfCacheClearTask(sfApplicationConfiguration::getActive()->getEventDispatcher(), new sfFormatter()); $task->run(array(), array('type' => 'config')); }
public function getSlotValueFromRequest($request) { $params = array(); $params['src'] = $request->getParameter('src'); $params['width'] = $request->getParameter('width'); $params['height'] = $request->getParameter('height'); $params['legend'] = $request->getParameter('legend'); $params['url'] = $request->getParameter('url'); return sfYaml::dump($params); }
/** * Removes excess routes from the app's routing.yml file */ protected function removeRoutes() { $this->logSection('sympal', sprintf('...removing default routes for app "%s"', sfConfig::get('sf_app')), null, 'COMMENT'); $path = sfConfig::get('sf_app_dir') . '/config/routing.yml'; // don't do anything if the routing.yml file has been removed if (file_exists($path)) { $array = sfYaml::load($path); unset($array['homepage'], $array['default'], $array['default_index']); file_put_contents($path, sfYaml::dump($array)); } }
public static function editSecurity() { $security = sfYaml::load(ProjectConfiguration::guessRootDir() . '/apps/install/config/security.yml'); $security['default']['is_secure'] = true; //Dump this php variable to a yaml string: $text = sfYaml::dump($security); //Write this string into the yaml file: $security_yaml = fopen(ProjectConfiguration::guessRootDir() . '/apps/install/config/security.yml', 'w+'); fwrite($security_yaml, $text); fclose($security_yaml); }
/** * dumpData * * Dump an array of data to a specified path or return * * @throws Doctrine_Parser_Exception dumping error * @param string $array Array of data to dump to yaml * @param string $path Path to dump the yaml to * @return string $yaml * @return void */ public function dumpData($array, $path = null) { try { $data = sfYaml::dump($array, 6); return $this->doDump($data, $path); } catch (InvalidArgumentException $e) { // rethrow the exceptions $rethrowed_exception = new Doctrine_Parser_Exception($e->getMessage(), $e->getCode()); throw $rethrowed_exception; } }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { // update databases.yml if (null !== $options['app']) { $file = sfConfig::get('sf_apps_dir') . '/' . $options['app'] . '/config/databases.yml'; } else { $file = sfConfig::get('sf_config_dir') . '/databases.yml'; } $config = file_exists($file) ? sfYaml::load($file) : array(); $config[$options['env']][$options['name']] = array('class' => $options['class'], 'param' => array_merge(isset($config[$options['env']][$options['name']]['param']) ? $config[$options['env']][$options['name']]['param'] : array(), array('dsn' => $arguments['dsn'], 'username' => $arguments['username'], 'password' => $arguments['password']))); file_put_contents($file, sfYaml::dump($config, 4)); }
/** * Dump slot fields but value into the options entry. * @param sfValidatorBase $validator * @param array $values * @param Array $arguments * @return Array */ public function dumpOptions(sfValidatorBase $validator, array $values, $arguments) { $options = array(); foreach ($arguments['slot_fields'] as $field) { if ($field != 'value') { $options[$field] = $values[$field]; unset($values[$field]); } } $values['options'] = sfYaml::dump($options); return $values; }
private function creaYAML() { $array = array(); $sinPrefijo = str_replace($this->prefijo, "", $this->filename); $cabecera = "# Module: " . $sinPrefijo . "\n"; $cabecera .= "# Document : modules\\" . $sinPrefijo . "\\listados.yml\n#\n"; $cabecera .= "# @copyright: ALBATRONIC\n# @date " . date('d.m.Y H:i:s') . "\n"; $cabecera .= "#\n---\n"; $array['listados'][] = array('title' => ucwords($sinPrefijo), 'order_by' => $this->td->getPrimaryKey(), 'break_field' => null, 'idPerfil' => null, 'orientation' => 'P', 'unit' => 'mm', 'format' => 'A4', 'margins' => '10, 10, 15, 10', 'body_font' => 'Courier, , 8', 'line_height' => 4, 'print_interline' => null, 'legend_bottom' => null, 'columns' => $this->getArrayColumns()); $yml = sfYaml::dump($array, 4); $this->buffer = $cabecera . $yml; }
public function save() { $ok = false; $stream = sfYaml::dump($this->Traspasos, 3); $fp = fopen($this->ArchivoLogTraspasos, "w"); if ($fp) { fwrite($fp, $stream); fclose($fp); $ok = true; } return $ok; }
public function getTransformed($generator) { $yaml = sfYaml::load($generator); $config = $yaml['generator']['param']['config']; unset($yaml['generator']['param']['config']); $yaml['generator']['param']['i18n_catalogue'] = $this->module->getOption('i18n_catalogue', 'dm'); $yaml['generator']['param']['config'] = $config; $yaml['generator']['param']['config'] = $this->getConfig(); $transformed = sfYaml::dump($yaml, 6, 0); $transformed = preg_replace("|('~')|um", "~", $transformed); return $transformed; }
protected function execute($arguments = array(), $options = array()) { $root = sfConfig::get('sf_root_dir'); $flavor = $root . '/flavors/' . $arguments['flavor']; if (!is_dir($flavor)) { $this->logSection('Error', 'The provided flavor does not exist the flavors/ directory', null, 'ERROR'); return false; } $web = sfConfig::get('sf_web_dir'); $web_css = $web . '/css'; $web_img = $web . '/images'; $pm_pdf_kit_cfg = sfConfig::get('sf_apps_dir') . '/backend/config/pm_pdf_kit.yml'; $files = array(); foreach (array($web_css, $web_img, $pm_pdf_kit_cfg) as $file) { if (file_exists($file)) { $files[] = $file; } } if (!empty($files)) { $this->logSection('Assets', 'Deleting the existing assets'); $this->getFilesystem()->remove($files); } else { $this->logSection('Assets', 'No existing assets found'); } $this->logSection('Assets', 'Linking the chosen flavor: ' . $arguments['flavor']); $flavor_css = $flavor . '/web/css'; $flavor_img = $flavor . '/web/images'; $pm_pdf_kit = $flavor . '/config/pm_pdf_kit.yml'; $this->getFilesystem()->symlink($flavor_css, $web_css, true); $this->getFilesystem()->symlink($flavor_img, $web_img, true); $this->getFilesystem()->symlink($pm_pdf_kit, $pm_pdf_kit_cfg, true); $this->logSection('Config', 'Updating configuration'); $cfg_dir = sfConfig::get('sf_config_dir'); $configuration = array('nc_flavor' => array('flavors' => array('root_dir' => 'flavors', 'current' => $arguments['flavor']))); $updated = @file_put_contents($cfg_dir . '/nc_flavor.yml', sfYaml::dump($configuration)); if ($updated === false) { $this->logSection('Config', 'Unable to update configuration', null, 'ERROR'); $this->logSection('Config', "Please update your configuration file {$cfg_dir}/nc_flavor.yml with this contents:"); $this->logBlock(sfYamlInline::dump($configuration), 'COMMENT'); } else { $this->logSection('Flavor', 'Successfully updated flavor configuration file'); } if ($updated === false) { $this->logSection('Config', 'Unable to update configuration', null, 'ERROR'); $this->logBlock($school_behavior, 'COMMENT'); } else { $this->logSection('Behavior', 'Successfully updated school_behavior configuration file'); } $cc = new sfCacheClearTask($this->dispatcher, $this->formatter); $cc->run(); $this->logSection('Done', ':)'); }
static function escribeLog() { $log[self::$idRemesa] = array('parametros' => self::$parametros, 'ficheroRemesa' => self::$fileName, 'ordenante' => self::$ordenante, 'nRegistros' => self::$nRegistros, 'nOrdenantes' => self::$nOrdenantes, 'nDomiciliaciones' => self::$nDomiciliaciones, 'total' => self::$total, 'nRegistrosOrdenante' => self::$nRegistrosOrdenante, 'nDomiciliacionesOrdenante' => self::$nDomiciliacionesOrdenante, 'totalOrdenante' => self::$totalOrdenante); $archivo = "docs/docs{$_SESSION['emp']}/remesas/log.yml"; if (!file_exists($archivo)) { $fp = fopen($archivo, "w"); } else { $fp = fopen($archivo, "a"); } $yml = sfYaml::dump($log); fwrite($fp, $yml); fclose($fp); }
static function escribeLog($arrayRemesa) { $log[self::$idRemesa] = $arrayRemesa; $archivo = "docs/docs{$_SESSION['emp']}/remesas/log.yml"; if (!file_exists($archivo)) { $fp = fopen($archivo, "w"); } else { $fp = fopen($archivo, "a"); } $yml = sfYaml::dump($log, 4); fwrite($fp, $yml); fclose($fp); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $filesystem = $this->get('filesystem'); $uploadDir = dmOs::join(sfConfig::get('sf_web_dir'), 'uploads'); if (!$filesystem->mkdir($uploadDir)) { throw new dmException(dmProject::unRootify($uploadDir) . ' is not writable'); } $cacheDir = dmOs::join(sfConfig::get('sf_cache_dir'), 'open_package', dmProject::getKey()); if (!$filesystem->mkdir($cacheDir)) { throw new dmException(dmProject::unRootify($cacheDir) . ' is not writable'); } $filesystem->deleteDirContent($cacheDir); if (file_exists(dmOs::join($uploadDir, dmProject::getKey() . '.tgz'))) { $filesystem->unlink(dmOs::join($uploadDir, dmProject::getKey() . '.tgz')); } $this->log('Building the package, please wait...'); $finder = sfFinder::type('all')->prune(array('.thumbs'))->discard(array('.thumbs')); foreach (array('apps', 'config', 'lib', 'plugins', 'public_html', 'test') as $dir) { $filesystem->mirror(dmOs::join(sfConfig::get('sf_root_dir'), $dir), dmOs::join($cacheDir, $dir), $finder); } $filesystem->copy(dmOs::join(sfConfig::get('sf_root_dir'), 'symfony'), dmOs::join($cacheDir, 'symfony')); foreach (array('cache', 'data') as $dir) { $filesystem->mkdir(dmOs::join($cacheDir, $dir)); } if (file_exists(dmOs::join(sfConfig::get('sf_data_dir'), 'mysql'))) { $filesystem->mirror(dmOs::join(sfConfig::get('sf_data_dir'), 'mysql'), dmOs::join($cacheDir, 'data/mysql'), sfFinder::type('all')); } $databasesFile = dmOs::join($cacheDir, 'config/databases.yml'); $databasesConfig = sfYaml::load($databasesFile); foreach ($databasesConfig as $namespace => $nsConfig) { foreach ($nsConfig as $dbName => $config) { $dsn = $databasesConfig[$namespace][$dbName]['param']['dsn']; $databasesConfig[$namespace][$dbName]['param']['dsn'] = preg_replace('#//(.+)\\:(.*)@#', '//#DB_USER#:#DB_PASSWORD#@', $dsn); foreach (array('username', 'password') as $key) { if (isset($databasesConfig[$namespace][$dbName]['param'][$key])) { unset($databasesConfig[$namespace][$dbName]['param'][$key]); } } } file_put_contents($databasesFile, sfYaml::dump($databasesConfig, 5)); } $filesystem->unlink(dmOs::join($cacheDir, 'test/functional')); $command = 'cd ' . dirname($cacheDir) . '; tar -czf ' . dmProject::getKey() . '.tgz ' . dmProject::getKey(); $this->logSection('Compression', $command); if (!$filesystem->exec($command)) { throw new dmException($filesystem->getLastExec('output')); } rename(dmOs::join(dirname($cacheDir), dmProject::getKey() . '.tgz'), dmOs::join($uploadDir, dmProject::getKey() . '.tgz')); $filesystem->unlink($cacheDir); $this->logBlock('Done !', 'INFO'); }
public function execute($arguments = array(), $options = array()) { $file = sfConfig::get('sf_apps_dir') . DIRECTORY_SEPARATOR . $arguments['application'] . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'settings.yml'; if (file_exists($file)) { $config = sfYaml::load($file); if (!is_array($config['all']['.settings']['enabled_modules'])) { $config['all']['.settings']['enabled_modules'] = array(); } if (!in_array($arguments['module'], $config['all']['.settings']['enabled_modules'])) { $config['all']['.settings']['enabled_modules'][] = $arguments['module']; } file_put_contents($file, sfYaml::dump($config, 4)); } }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $model = $arguments['model']; $query = $arguments['query']; $limit = $options['limit']; if (!Doctrine_Core::getTable($model)->isSearchAvailable()) { throw new RuntimeException('Search is unavailable. Make sure Solr is started'); } $this->logSection('solr', 'Running search'); $q = Doctrine_Core::getTable($model)->createSearchQuery($query, $limit); $results = $q->fetchArray(); $this->log(array(sprintf('found %s results', count($results)), sfYaml::dump($results, 4))); }
protected function execute(array $arguments = array(), array $options = array()) { $allPluginsDir = nbConfig::get('nb_plugins_dir'); $pluginName = $arguments['plugin-name']; $projectDir = $arguments['project-dir']; $configDir = $projectDir . '/.bee'; $beeConfig = $configDir . '/bee.yml'; $force = isset($options['force']); $pluginPath = $allPluginsDir . '/' . $pluginName; $verbose = isset($options['verbose']); if (!file_exists($pluginPath)) { throw new Exception('plugin ' . $pluginName . ' not found in ' . nbConfig::get('nb_plugins_dir')); } if (!file_exists($beeConfig)) { throw new Exception($beeConfig . ' not found'); } $configParser = sfYaml::load($beeConfig); $plugins = $configParser['project']['bee']['enabled_plugins']; $plugins = isset($configParser['project']['bee']['enabled_plugins']) ? $configParser['project']['bee']['enabled_plugins'] : array(); if (!is_array($plugins)) { $plugins = array(); } if (!in_array($pluginName, $plugins)) { array_push($plugins, $pluginName); $configParser['project']['bee']['enabled_plugins'] = $plugins; $yml = sfYaml::dump($configParser, 99); file_put_contents($beeConfig, $yml); $this->logLine('Installing plugin ' . $pluginName); } else { $this->logLine('Plugin ' . $pluginName . ' already installed'); } // Configuration will not generated if (isset($options['no-configuration'])) { return true; } // Configure plugin $pluginConfigDir = sprintf('%s/%s/config', $allPluginsDir, $pluginName); $files = nbFileFinder::create('file')->add('*.template.yml')->in($pluginConfigDir); $generator = new nbConfigurationGenerator(); $this->getFileSystem()->mkdir($configDir, true); foreach ($files as $file) { $target = sprintf('%s/%s', $configDir, str_replace('.template.yml', '.yml', basename($file))); $generator->generate($file, $target, $force); if ($verbose) { $this->logLine('file+: ' . $target, nbLogger::INFO); } } return true; }