/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { foreach ($arguments['configure'] as $value) { list($key, $value) = explode('=', $value); $e = explode('.', $key); $group = isset($e[1]) ? $e[0] : null; $key = isset($e[1]) ? $e[1] : $e[0]; $value = is_numeric($value) ? (int) $value : $value; $value = $value == 'false' ? false : $value; $value = $value == 'true' ? true : $value; $infoValue = $value; if (in_array(substr($value, 0, 1), array('[', '{'))) { $value = sfYamlInline::load($value); $infoValue = 'YAML: ' . $infoValue; } $writeToApp = isset($options['application']) && $options['application'] ? true : false; if ($group) { $this->logSection('sympal', sprintf('Writing setting "%s" with a value of "%s" under the "%s" group.', $key, $infoValue, $group)); sfSympalConfig::writeSetting($group, $key, $value, $writeToApp); } else { $this->logSection('sympal', sprintf('Writing setting "%s" with a value of "%s".', $key, $infoValue, $group)); sfSympalConfig::writeSetting($key, $value, null, $writeToApp); } } }
/** * Parses a YAML value. * * @param string $value A YAML value * * @return mixed A PHP value */ protected function parseValue($value) { if ('*' === substr($value, 0, 1)) { if (false !== ($pos = strpos($value, '#'))) { $value = substr($value, 1, $pos - 2); } else { $value = substr($value, 1); } if (!array_key_exists($value, $this->refs)) { throw new InvalidArgumentException(sprintf('Reference "%s" does not exist (%s).', $value, $this->currentLine)); } return $this->refs[$value]; } if (preg_match('/^(?P<separator>\\||>)(?P<modifiers>\\+|\\-|\\d+|\\+\\d+|\\-\\d+|\\d+\\+|\\d+\\-)?(?P<comments> +#.*)?$/', $value, $matches)) { $modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : ''; return $this->parseFoldedScalar($matches['separator'], preg_replace('#\\d+#', '', $modifiers), intval(abs($modifiers))); } else { return sfYamlInline::load($value); } }
* * 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'); }
/** * Parses validator arguments. * * @param string $string The string to parse * @param integer $i The indice to start the parsing * * @return array An array of parameters */ protected function parseArguments($string, &$i) { $len = strlen($string); if ($i + 1 > $len || '(' != $string[$i]) { return array(array(), array()); } ++$i; $args = ''; $opened = 0; while ($i < $len) { if ('(' == $string[$i]) { ++$opened; } else { if (')' == $string[$i]) { if (!$opened) { break; } --$opened; } } $args .= $string[$i++]; } ++$i; return sfYamlInline::load('[' . (!$args ? '{}' : $args) . ']'); }
/** * @see sfYamlInline::load() * @param String $value * @return Mixed PHP */ public static function load($value) { return sfYamlInline::load($value); }