Skip to content

Commit

Permalink
Adding in XML parser for file
Browse files Browse the repository at this point in the history
  • Loading branch information
nark3d committed Jan 1, 2016
1 parent 9056d7c commit e52bc41
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 13 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"require-dev": {
"phpunit/phpunit": "~4.0",
"mockery/mockery": "^0.9.4",
"phpdocumentor/phpdocumentor": "^2.8"
"phpdocumentor/phpdocumentor": "^2.8",
"squizlabs/php_codesniffer": "2.*",
"phpmd/phpmd" : "@stable"
},
"autoload": {
"psr-4": {"BestServedCold\\PhalueObjects\\": "src"}
Expand Down
10 changes: 5 additions & 5 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
</exclude>
</whitelist>
</filter>
<!--<logging>-->
<!--<log type="coverage-html" target="./coverage" charset="UTF-8"-->
<!--yui="true" highlight="true" LowUpperBound="50"-->
<!--highLowerBound="80" />-->
<!--</logging>-->
<logging>
<log type="coverage-html" target="./coverage" charset="UTF-8"
yui="true" highlight="true" LowUpperBound="50"
highLowerBound="80" />
</logging>
</phpunit>

2 changes: 1 addition & 1 deletion src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getContents()
*/
public function getExtension()
{
return pathinfo($this->getValue(), PATHINFO_EXTENSION);
return pathinfo($this->getValue(), PATHINFO_EXTENSION);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/File/Json.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php namespace BestServedCold\PhalueObjects;
<?php namespace BestServedCold\PhalueObjects\File;

final class Json extends File
{
Expand Down
16 changes: 16 additions & 0 deletions src/File/Xml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php namespace BestServedCold\PhalueObjects\File;

use BestServedCold\PhalueObjects\File;

final class Xml extends File
{
public function parse()
{
return $this->xmlJsonFix(simplexml_load_string($this->getContents(), 'SimpleXMLElement', LIBXML_NOCDATA));
}

private function xmlJsonFix($xml)
{
return json_decode(str_replace(':[]', ':null', str_replace(':{}', ':null', json_encode((array) $xml))), 1);
}
}
9 changes: 9 additions & 0 deletions src/File/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
use BestServedCold\PhalueObjects\File;
use Symfony\Component\Yaml\Yaml as SymfonyYaml;

/**
* Class Yaml
* @package BestServedCold\PhalueObjects\File
*/
final class Yaml extends File
{
/**
* Parse
*
* @return array
*/
public function parse()
{
return SymfonyYaml::parse($this->getContents());
Expand Down
6 changes: 3 additions & 3 deletions src/Utility/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ class Configuration extends Singleton
*/
public static function get($key)
{
empty(self::$configuration) ? self::setConfiguration() : null;
empty(self::$configuration) ? self::getConfiguration() : null;
return self::getFromArrayUsingJsonNotation(self::$configuration, $key);
}

/**
* Set Configuration
* Get Configuration
*
* @return array
*/
private static function setConfiguration()
public static function getConfiguration()
{
return self::$configuration = Yaml::fromString(__DIR__ . self::$file)->parse();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ExtendedArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function testConstructor()

$this->assertSame($array, $extendedArray->getValue());
$this->setExpectedException(
'BestServedCold\PhalueObjects\Exception\InvalidTypeException'
'BestServedCold\PhalueObjects\Exception\InvalidTypeException'
);
new ExtendedArray('this is the wrong type');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/IdentityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ public function testToString()
(string) new Identity('identity')
);
}
}
}

0 comments on commit e52bc41

Please sign in to comment.