/** * @see sfValidatorBase */ public function asString($indent = 0) { $options = $this->getOptionsWithoutDefaults(); $messages = $this->getMessagesWithoutDefaults(); unset($options['left_field'], $options['operator'], $options['right_field']); $arguments = ''; if ($options || $messages) { $arguments = sprintf('(%s%s)', $options ? sfYamlInline::dump($options) : ($messages ? '{}' : ''), $messages ? ', ' . sfYamlInline::dump($messages) : ''); } return sprintf('%s%s %s%s %s', str_repeat(' ', $indent), $this->getOption('left_field'), $this->getOption('operator'), $arguments, $this->getOption('right_field')); }
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', ':)'); }
/** * Dumps a PHP value to YAML. * * @param mixed $input The PHP value * @param integer $inline The level where you switch to inline YAML * @param integer $indent The level o indentation indentation (used internally) * * @return string The YAML representation of the PHP value */ public function dump($input, $inline = 0, $indent = 0) { $output = ''; $prefix = $indent ? str_repeat(' ', $indent) : ''; if ($inline <= 0 || !is_array($input) || empty($input)) { $output .= $prefix . sfYamlInline::dump($input); } else { $isAHash = array_keys($input) !== range(0, count($input) - 1); foreach ($input as $key => $value) { $willBeInlined = $inline - 1 <= 0 || !is_array($value) || empty($value); $output .= sprintf('%s%s%s%s', $prefix, $isAHash ? sfYamlInline::dump($key) . ':' : '-', $willBeInlined ? ' ' : "\n", $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + 2)) . ($willBeInlined ? "\n" : ''); } } return $output; }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $app = $arguments['app']; // Validate the application name if (!preg_match('/^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*$/', $app)) { throw new sfCommandException(sprintf('The application name "%s" is invalid.', $app)); } $appDir = sfConfig::get('sf_apps_dir') . '/' . $app; if (is_dir($appDir)) { throw new sfCommandException(sprintf('The application "%s" already exists.', $appDir)); } if (is_readable(sfConfig::get('sf_data_dir') . '/skeleton/app')) { $skeletonDir = sfConfig::get('sf_data_dir') . '/skeleton/app'; } else { $skeletonDir = __DIR__ . '/skeleton/app'; } // Create basic application structure $finder = sfFinder::type('any')->discard('.sf'); $this->getFilesystem()->mirror($skeletonDir . '/app', $appDir, $finder); // Create $app.php or index.php if it is our first app $indexName = 'index'; $firstApp = !file_exists(sfConfig::get('sf_web_dir') . '/index.php'); if (!$firstApp) { $indexName = $app; } if (true === $options['csrf-secret']) { $options['csrf-secret'] = sha1(mt_rand(11111111, 99999999) . getmypid()); } // Set no_script_name value in settings.yml for production environment $finder = sfFinder::type('file')->name('settings.yml'); $this->getFilesystem()->replaceTokens($finder->in($appDir . '/config'), '##', '##', array('NO_SCRIPT_NAME' => $firstApp ? 'true' : 'false', 'CSRF_SECRET' => sfYamlInline::dump(sfYamlInline::parseScalar($options['csrf-secret'])), 'ESCAPING_STRATEGY' => sfYamlInline::dump((bool) sfYamlInline::parseScalar($options['escaping-strategy'])), 'USE_DATABASE' => sfConfig::has('sf_orm') ? 'true' : 'false')); $this->getFilesystem()->copy($skeletonDir . '/web/index.php', sfConfig::get('sf_web_dir') . '/' . $indexName . '.php'); $this->getFilesystem()->copy($skeletonDir . '/web/index.php', sfConfig::get('sf_web_dir') . '/' . $app . '_dev.php'); $this->getFilesystem()->replaceTokens(sfConfig::get('sf_web_dir') . '/' . $indexName . '.php', '##', '##', array('APP_NAME' => $app, 'ENVIRONMENT' => 'prod', 'IS_DEBUG' => 'false', 'IP_CHECK' => '')); $this->getFilesystem()->replaceTokens(sfConfig::get('sf_web_dir') . '/' . $app . '_dev.php', '##', '##', array('APP_NAME' => $app, 'ENVIRONMENT' => 'dev', 'IS_DEBUG' => 'true', 'IP_CHECK' => '// this check prevents access to debug front controllers that are deployed by accident to production servers.' . PHP_EOL . '// feel free to remove this, extend it or make something more sophisticated.' . PHP_EOL . 'if (!in_array(@$_SERVER[\'REMOTE_ADDR\'], array(\'127.0.0.1\', \'::1\')))' . PHP_EOL . '{' . PHP_EOL . ' die(\'You are not allowed to access this file. Check \'.basename(__FILE__).\' for more information.\');' . PHP_EOL . '}' . PHP_EOL)); $this->getFilesystem()->rename($appDir . '/config/ApplicationConfiguration.class.php', $appDir . '/config/' . $app . 'Configuration.class.php'); $this->getFilesystem()->replaceTokens($appDir . '/config/' . $app . 'Configuration.class.php', '##', '##', array('APP_NAME' => $app)); $fixPerms = new sfProjectPermissionsTask($this->dispatcher, $this->formatter); $fixPerms->setCommandApplication($this->commandApplication); $fixPerms->setConfiguration($this->configuration); $fixPerms->run(); // Create test dir $this->getFilesystem()->mkdirs(sfConfig::get('sf_test_dir') . '/functional/' . $app); }
/** * Returns a string representation of this validator. * * @param int $indent Indentation (number of spaces before each line) * * @return string The string representation of the validator */ public function asString($indent = 0) { $options = $this->getOptionsWithoutDefaults(); $messages = $this->getMessagesWithoutDefaults(); return sprintf('%s%s(%s%s)', str_repeat(' ', $indent), str_replace('sfValidator', '', get_class($this)), $options ? sfYamlInline::dump($options) : ($messages ? '{}' : ''), $messages ? ', ' . sfYamlInline::dump($messages) : ''); }
* * 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'; sfYaml::setSpecVersion('1.1'); $t = new lime_test(124); // ::load() $t->diag('::load()'); $testsForLoad = array('' => '', 'null' => null, 'false' => false, 'true' => true, '12' => 12, '"quoted string"' => 'quoted string', "'quoted string'" => 'quoted string', '12.30e+02' => 1230.0, '0x4D2' => 0x4d2, '02333' => 02333, '.Inf' => -log(0), '-.Inf' => log(0), '123456789123456789000' => '123456789123456789000', '"foo\\r\\nbar"' => "foo\r\nbar", "'foo#bar'" => 'foo#bar', "'foo # bar'" => 'foo # bar', "'#cfcfcf'" => '#cfcfcf', '2007-10-30' => mktime(0, 0, 0, 10, 30, 2007), '2007-10-30T02:59:43Z' => gmmktime(2, 59, 43, 10, 30, 2007), '2007-10-30 02:59:43 Z' => gmmktime(2, 59, 43, 10, 30, 2007), '"a \\"string\\" with \'quoted strings inside\'"' => 'a "string" with \'quoted strings inside\'', "'a \"string\" with ''quoted strings inside'''" => 'a "string" with \'quoted strings inside\'', '[foo, http://urls.are/no/mappings, false, null, 12]' => array('foo', 'http://urls.are/no/mappings', false, null, 12), '[ foo , bar , false , null , 12 ]' => array('foo', 'bar', false, null, 12), '[\'foo,bar\', \'foo bar\']' => array('foo,bar', 'foo bar'), '{foo:bar,bar:foo,false:false,null:null,integer:12}' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), '{ foo : bar, bar : foo, false : false, null : null, integer : 12 }' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), '{foo: \'bar\', bar: \'foo: bar\'}' => array('foo' => 'bar', 'bar' => 'foo: bar'), '{\'foo\': \'bar\', "bar": \'foo: bar\'}' => array('foo' => 'bar', 'bar' => 'foo: bar'), '{\'foo\'\'\': \'bar\', "bar\\"": \'foo: bar\'}' => array('foo\'' => 'bar', "bar\"" => 'foo: bar'), '{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}' => array('foo: ' => 'bar', "bar: " => 'foo: bar'), '[foo, [bar, foo]]' => array('foo', array('bar', 'foo')), '[foo, {bar: foo}]' => array('foo', array('bar' => 'foo')), '{ foo: {bar: foo} }' => array('foo' => array('bar' => 'foo')), '{ foo: [bar, foo] }' => array('foo' => array('bar', 'foo')), '[ foo, [ bar, foo ] ]' => array('foo', array('bar', 'foo')), '[{ foo: {bar: foo} }]' => array(array('foo' => array('bar' => 'foo'))), '[foo, [bar, [foo, [bar, foo]], foo]]' => array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo')), '[foo, {bar: foo, foo: [foo, {bar: foo}]}, [foo, {bar: foo}]]' => array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo'))), '[foo, bar: { foo: bar }]' => array('foo', '1' => array('bar' => array('foo' => 'bar')))); foreach ($testsForLoad as $yaml => $value) { $t->is_deeply(sfYamlInline::load($yaml), $value, sprintf('::load() converts an inline YAML to a PHP structure (%s)', $yaml)); } $testsForDump = array('null' => null, 'false' => false, 'true' => true, '12' => 12, "'quoted string'" => 'quoted string', '12.30e+02' => 1230.0, '1234' => 0x4d2, '1243' => 02333, '.Inf' => -log(0), '-.Inf' => log(0), '"foo\\r\\nbar"' => "foo\r\nbar", "'foo#bar'" => 'foo#bar', "'foo # bar'" => 'foo # bar', "'#cfcfcf'" => '#cfcfcf', "'a \"string\" with ''quoted strings inside'''" => 'a "string" with \'quoted strings inside\'', '[foo, bar, false, null, 12]' => array('foo', 'bar', false, null, 12), '[\'foo,bar\', \'foo bar\']' => array('foo,bar', 'foo bar'), '{ foo: bar, bar: foo, \'false\': false, \'null\': null, integer: 12 }' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), '{ foo: bar, bar: \'foo: bar\' }' => array('foo' => 'bar', 'bar' => 'foo: bar'), '[foo, [bar, foo]]' => array('foo', array('bar', 'foo')), '[foo, [bar, [foo, [bar, foo]], foo]]' => array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo')), '{ foo: { bar: foo } }' => array('foo' => array('bar' => 'foo')), '[foo, { bar: foo }]' => array('foo', array('bar' => 'foo')), '[foo, { bar: foo, foo: [foo, { bar: foo }] }, [foo, { bar: foo }]]' => array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo')))); // ::dump() $t->diag('::dump()'); foreach ($testsForDump as $yaml => $value) { $t->is(sfYamlInline::dump($value), $yaml, sprintf('::dump() converts a PHP structure to an inline YAML (%s)', $yaml)); } foreach ($testsForLoad as $yaml => $value) { if ($value == 1230) { continue; } $t->is_deeply(sfYamlInline::load(sfYamlInline::dump($value)), $value, 'check consistency'); } foreach ($testsForDump as $yaml => $value) { if ($value == 1230) { continue; } $t->is_deeply(sfYamlInline::load(sfYamlInline::dump($value)), $value, 'check consistency'); }
/** * @see sfValidatorBase */ public function asString($indent = 0) { $validators = ''; for ($i = 0, $max = count($this->validators); $i < $max; $i++) { $validators .= "\n" . $this->validators[$i]->asString($indent + 2) . "\n"; if ($i < $max - 1) { $validators .= str_repeat(' ', $indent + 2) . 'or'; } if ($i == $max - 2) { $options = $this->getOptionsWithoutDefaults(); $messages = $this->getMessagesWithoutDefaults(); if ($options || $messages) { $validators .= sprintf('(%s%s)', $options ? sfYamlInline::dump($options) : ($messages ? '{}' : ''), $messages ? ', ' . sfYamlInline::dump($messages) : ''); } } } return sprintf("%s(%s%s)", str_repeat(' ', $indent), $validators, str_repeat(' ', $indent)); }
/** * @see sfValidatorBase */ public function asString($indent = 0) { $options = $this->getOptionsWithoutDefaults(); $messages = $this->getMessagesWithoutDefaults(); unset($options['control_field'], $options['validator_schema']); $arguments = ''; if ($options || $messages) { $arguments = sprintf('(%s%s)', $options ? sfYamlInline::dump($options) : ($messages ? '{}' : ''), $messages ? ', ' . sfYamlInline::dump($messages) : ''); } return sprintf('%s%s %s%s %s', str_repeat(' ', $indent), $this->getOption('control_field'), $this->getOption('validator_schema'), $arguments); }
/** * @see sfYamlInline::dump() * @param String $value * @return String Yaml value */ public static function dump($value) { return sfYamlInline::dump($value); }