Skip to content

Commit

Permalink
switch from 4 spaces to 2 spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
yalesov committed Jul 5, 2016
1 parent a013163 commit 3608e00
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 120 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
@@ -1,10 +1,10 @@
language: php
php:
- "5.3"
- "5.4"
- "5.3"
- "5.4"
before_script: composer install
script: phpunit --configuration test/phpunit.xml
notifications:
email:
on_success: always
on_failure: always
email:
on_success: always
on_failure: always
64 changes: 32 additions & 32 deletions composer.json
@@ -1,35 +1,35 @@
{
"name": "yalesov/yaml",
"description": "Wrapper around Symfony's Yaml parser - added __DIR__ support.",
"keywords": ["yaml", "yml"],
"authors": [
{
"name": "Yulij Andreevich Lesov",
"email": "yalesov@gmail.com"
}
],
"require": {
"php": ">=5.3.3",
"yalesov/arg-validator": "2.*",
"symfony/yaml": "*"
},
"require-dev": {
"phpunit/phpunit": "*"
},
"autoload": {
"psr-0": {
"Yalesov\\Yaml": "src/"
}
},
"license": "ISC",
"homepage": "https://github.com/yalesov/php-yaml",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/yalesov/php-yaml"
}
],
"support": {
"issues": "https://github.com/yalesov/php-yaml/issues"
"name": "yalesov/yaml",
"description": "Wrapper around Symfony's Yaml parser - added __DIR__ support.",
"keywords": ["yaml", "yml"],
"authors": [
{
"name": "Yulij Andreevich Lesov",
"email": "yalesov@gmail.com"
}
],
"require": {
"php": ">=5.3.3",
"yalesov/arg-validator": "2.*",
"symfony/yaml": "*"
},
"require-dev": {
"phpunit/phpunit": "*"
},
"autoload": {
"psr-0": {
"Yalesov\\Yaml": "src/"
}
},
"license": "ISC",
"homepage": "https://github.com/yalesov/php-yaml",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/yalesov/php-yaml"
}
],
"support": {
"issues": "https://github.com/yalesov/php-yaml/issues"
}
}
46 changes: 23 additions & 23 deletions src/Yalesov/Yaml/Yaml.php
Expand Up @@ -6,28 +6,28 @@

class Yaml
{
/**
* Yaml parser
*
* __DIR__ support: (only available for Yaml files, of course!)
* - '__DIR__' will behave as expected
* - '___DIR___' (an extra underscore around) will be translated as a literal '__DIR__'
*
* @param mixed $yaml
* @return self
*/
public static function parse($yaml)
{
ArgValidator::assert($yaml, 'string');
if (is_file($yaml) && is_readable($yaml)) {
$dir = realpath(dirname($yaml));
$yaml = file_get_contents($yaml);
$yaml = strtr($yaml, array(
'___DIR___' => '__DIR__',
'__DIR__' => $dir,
));
}

return SymfonyYaml::parse($yaml);
/**
* Yaml parser
*
* __DIR__ support: (only available for Yaml files, of course!)
* - '__DIR__' will behave as expected
* - '___DIR___' (an extra underscore around) will be translated as a literal '__DIR__'
*
* @param mixed $yaml
* @return self
*/
public static function parse($yaml)
{
ArgValidator::assert($yaml, 'string');
if (is_file($yaml) && is_readable($yaml)) {
$dir = realpath(dirname($yaml));
$yaml = file_get_contents($yaml);
$yaml = strtr($yaml, array(
'___DIR___' => '__DIR__',
'__DIR__' => $dir,
));
}

return SymfonyYaml::parse($yaml);
}
}
110 changes: 55 additions & 55 deletions test/Yalesov/Test/Yaml/YamlTest.php
Expand Up @@ -5,68 +5,68 @@

class YamlTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->tmpFile = '.yaml';
$this->tmpPath = realpath(dirname($this->tmpFile));
}
public function setUp()
{
$this->tmpFile = '.yaml';
$this->tmpPath = realpath(dirname($this->tmpFile));
}

public function tearDown()
{
unlink($this->tmpFile);
}
public function tearDown()
{
unlink($this->tmpFile);
}

public function testParse()
{
// yaml stream
$yaml = 'foo: bar';
$this->assertSame(
array('foo' => 'bar'),
Yaml::parse($yaml));
public function testParse()
{
// yaml stream
$yaml = 'foo: bar';
$this->assertSame(
array('foo' => 'bar'),
Yaml::parse($yaml));

// yaml file
file_put_contents($this->tmpFile, 'foo: bar');
$this->assertSame(
array('foo' => 'bar'),
Yaml::parse($this->tmpFile));
// yaml file
file_put_contents($this->tmpFile, 'foo: bar');
$this->assertSame(
array('foo' => 'bar'),
Yaml::parse($this->tmpFile));

// __DIR__
file_put_contents($this->tmpFile, 'foo: __DIR__/bar');
$this->assertSame(
array('foo' => "{$this->tmpPath}/bar"),
Yaml::parse($this->tmpFile));
// __DIR__
file_put_contents($this->tmpFile, 'foo: __DIR__/bar');
$this->assertSame(
array('foo' => "{$this->tmpPath}/bar"),
Yaml::parse($this->tmpFile));

// ___DIR___
file_put_contents($this->tmpFile, 'foo: ___DIR___/bar');
$this->assertSame(
array('foo' => '__DIR__/bar'),
Yaml::parse($this->tmpFile));
// ___DIR___
file_put_contents($this->tmpFile, 'foo: ___DIR___/bar');
$this->assertSame(
array('foo' => '__DIR__/bar'),
Yaml::parse($this->tmpFile));

// multiple __DIR__
file_put_contents($this->tmpFile, '__DIR__/foo: __DIR__/bar');
$this->assertSame(
array("{$this->tmpPath}/foo" => "{$this->tmpPath}/bar"),
Yaml::parse($this->tmpFile));
// multiple __DIR__
file_put_contents($this->tmpFile, '__DIR__/foo: __DIR__/bar');
$this->assertSame(
array("{$this->tmpPath}/foo" => "{$this->tmpPath}/bar"),
Yaml::parse($this->tmpFile));

// multiple ___DIR___
file_put_contents($this->tmpFile, '___DIR___/foo: ___DIR___/bar');
$this->assertSame(
array('__DIR__/foo' => '__DIR__/bar'),
Yaml::parse($this->tmpFile));
// multiple ___DIR___
file_put_contents($this->tmpFile, '___DIR___/foo: ___DIR___/bar');
$this->assertSame(
array('__DIR__/foo' => '__DIR__/bar'),
Yaml::parse($this->tmpFile));

// altogether
file_put_contents($this->tmpFile, "__DIR__/foo: ___DIR___/bar\n___DIR___/bar: __DIR__/foo");
$this->assertSame(
array(
"{$this->tmpPath}/foo" => '__DIR__/bar',
'__DIR__/bar' => "{$this->tmpPath}/foo",
),
Yaml::parse($this->tmpFile));
// altogether
file_put_contents($this->tmpFile, "__DIR__/foo: ___DIR___/bar\n___DIR___/bar: __DIR__/foo");
$this->assertSame(
array(
"{$this->tmpPath}/foo" => '__DIR__/bar',
'__DIR__/bar' => "{$this->tmpPath}/foo",
),
Yaml::parse($this->tmpFile));

// neither available when passed in a string
$yaml = '__DIR__/foo: ___DIR___/bar';
$this->assertSame(
array('__DIR__/foo' => '___DIR___/bar'),
Yaml::parse($yaml));
}
// neither available when passed in a string
$yaml = '__DIR__/foo: ___DIR___/bar';
$this->assertSame(
array('__DIR__/foo' => '___DIR___/bar'),
Yaml::parse($yaml));
}
}
10 changes: 5 additions & 5 deletions test/phpunit.xml
@@ -1,7 +1,7 @@
<phpunit bootstrap="./bootstrap.php" colors="true">
<testsuites>
<testsuite>
<directory>./</directory>
</testsuite>
</testsuites>
<testsuites>
<testsuite>
<directory>./</directory>
</testsuite>
</testsuites>
</phpunit>

0 comments on commit 3608e00

Please sign in to comment.