Skip to content

Commit

Permalink
[Yaml] renamed load() to parse()
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jun 14, 2011
1 parent 9b1b937 commit 3859589
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 18 deletions.
2 changes: 2 additions & 0 deletions UPDATE.md
Expand Up @@ -9,6 +9,8 @@ timeline closely anyway.
beta4 to beta5
--------------

* `Yaml::load()` has been renamed to `Yaml::parse()`

* The `extensions` setting for Twig has been removed. There is now only one
way to register Twig extensions, via the `twig.extension` tag.

Expand Down
Expand Up @@ -228,7 +228,7 @@ private function parseDefinition($id, $service, $file)
*/
private function loadFile($file)
{
return $this->validate(Yaml::load($file), $file);
return $this->validate(Yaml::parse($file), $file);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Routing/Loader/YamlFileLoader.php
Expand Up @@ -46,7 +46,7 @@ public function load($file, $type = null)
{
$path = $this->locator->locate($file);

$config = Yaml::load($path);
$config = Yaml::parse($path);

$collection = new RouteCollection();
$collection->addResource(new FileResource($path));
Expand Down
Expand Up @@ -30,7 +30,7 @@ class YamlFileLoader extends ArrayLoader implements LoaderInterface
*/
public function load($resource, $locale, $domain = 'messages')
{
$messages = Yaml::load($resource);
$messages = Yaml::parse($resource);

// empty file
if (null === $messages) {
Expand Down
Expand Up @@ -29,7 +29,7 @@ class YamlFileLoader extends FileLoader
public function loadClassMetadata(ClassMetadata $metadata)
{
if (null === $this->classes) {
$this->classes = Yaml::load($this->file);
$this->classes = Yaml::parse($this->file);

// empty file
if (null === $this->classes) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Inline.php
Expand Up @@ -26,7 +26,7 @@ class Inline
*
* @return array A PHP array representing the YAML string
*/
static public function load($value)
static public function parse($value)
{
$value = trim($value);

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Yaml/Parser.php
Expand Up @@ -168,7 +168,7 @@ public function parse($value)
} else {
// 1-liner followed by newline
if (2 == count($this->lines) && empty($this->lines[1])) {
$value = Inline::load($this->lines[0]);
$value = Inline::parse($this->lines[0]);
if (is_array($value)) {
$first = reset($value);
if (is_string($first) && '*' === substr($first, 0, 1)) {
Expand Down Expand Up @@ -350,7 +350,7 @@ private function parseValue($value)
return $this->parseFoldedScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), intval(abs($modifiers)));
}

return Inline::load($value);
return Inline::parse($value);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Yaml/Yaml.php
Expand Up @@ -49,14 +49,14 @@ static public function getSpecVersion()
}

/**
* Loads YAML into a PHP array.
* Parses YAML into a PHP array.
*
* The load method, when supplied with a YAML stream (string or file),
* The parse method, when supplied with a YAML stream (string or file),
* will do its best to convert YAML in a file into a PHP array.
*
* Usage:
* <code>
* $array = Yaml::load('config.yml');
* $array = Yaml::parse('config.yml');
* print_r($array);
* </code>
*
Expand All @@ -68,7 +68,7 @@ static public function getSpecVersion()
*
* @api
*/
static public function load($input)
static public function parse($input)
{
$file = '';

Expand Down
14 changes: 7 additions & 7 deletions tests/Symfony/Tests/Component/Yaml/InlineTest.php
Expand Up @@ -21,10 +21,10 @@ static public function setUpBeforeClass()
Yaml::setSpecVersion('1.1');
}

public function testLoad()
public function testParse()
{
foreach ($this->getTestsForLoad() as $yaml => $value) {
$this->assertEquals($value, Inline::load($yaml), sprintf('::load() converts an inline YAML to a PHP structure (%s)', $yaml));
foreach ($this->getTestsForParse() as $yaml => $value) {
$this->assertEquals($value, Inline::parse($yaml), sprintf('::parse() converts an inline YAML to a PHP structure (%s)', $yaml));
}
}

Expand All @@ -36,24 +36,24 @@ public function testDump()
$this->assertEquals($yaml, Inline::dump($value), sprintf('::dump() converts a PHP structure to an inline YAML (%s)', $yaml));
}

foreach ($this->getTestsForLoad() as $yaml => $value) {
foreach ($this->getTestsForParse() as $yaml => $value) {
if ($value == 1230) {
continue;
}

$this->assertEquals($value, Inline::load(Inline::dump($value)), 'check consistency');
$this->assertEquals($value, Inline::parse(Inline::dump($value)), 'check consistency');
}

foreach ($testsForDump as $yaml => $value) {
if ($value == 1230) {
continue;
}

$this->assertEquals($value, Inline::load(Inline::dump($value)), 'check consistency');
$this->assertEquals($value, Inline::parse(Inline::dump($value)), 'check consistency');
}
}

protected function getTestsForLoad()
protected function getTestsForParse()
{
return array(
'' => '',
Expand Down

3 comments on commit 3859589

@llsousa
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit breaks symfony-stantard vendors on doctrine2@2.0.5 at lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php:
--- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php
+++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php
@@ -450,6 +450,6 @@ class YamlDriver extends AbstractFileDriver
*/
protected function _loadMappingFile($file)
{

  •    return \Symfony\Component\Yaml\Yaml::load($file);
    
  •    return \Symfony\Component\Yaml\Yaml::parse($file);
    
    }
    }

@stof
Copy link
Member

@stof stof commented on 3859589 Jun 15, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@llsousa This is why symfony-standard has been updated to use the 2.0.x branch instead of the 2.0.5 tag

@llsousa
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof You are right. Let me update my symfony-standard repository!

Please sign in to comment.