Skip to content

Commit

Permalink
Merge pull request #51 from kschroeder/develop
Browse files Browse the repository at this point in the history
Updated several internal workings, including better handling of sources
  • Loading branch information
kschroeder authored Mar 20, 2017
2 parents 1e63133 + dd140c9 commit 6b895f3
Show file tree
Hide file tree
Showing 23 changed files with 581 additions and 51 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"zendframework/zend-cache": "^2.7",
"psr/container": "^1.0@dev",
"zendframework/zend-db": "^2.8",
"symfony/console": "^3.2"
"symfony/console": "^3.2",
"psr/http-message": "^1.0",
"zendframework/zend-view": "^2.8",
"zendframework/zend-psr7bridge": "^0.2.2"
},
"bin": ["bin/magium-configuration"]
}
18 changes: 9 additions & 9 deletions lib/Config/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function build($context = ConfigurationRepository::CONTEXT_DEFAULT, Confi

$structure = $this->getMergedStructure();

if (!$structure instanceof \SimpleXMLElement) {
if (!$structure instanceof MergedStructure) {
throw new InvalidConfigurationException('No configuration files provided');
}

Expand Down Expand Up @@ -143,7 +143,7 @@ public function getMergedStructure()
}

$simpleXml = $file->toXml();
if (!$structure instanceof \SimpleXMLElement) {
if (!$structure instanceof MergedStructure) {
$structure = $simpleXml;
} else {
$this->mergeStructure($structure, $simpleXml);
Expand All @@ -160,15 +160,15 @@ public function getMergedStructure()
*/

public function buildConfigurationObject(
\SimpleXMLElement $structure,
MergedStructure $structure,
ConfigInterface $config,
$context = ConfigurationRepository::CONTEXT_DEFAULT
)
{
$structure->registerXPathNamespace('s', 'http://www.magiumlib.com/Configuration');
$elements = $structure->xpath('/*/s:section/s:group/s:element');
foreach ($elements as $element) {
if ($element instanceof \SimpleXMLElement) {
if ($element instanceof MergedStructure) {
$elementId = $element['identifier'];
$group = $element->xpath('..')[0];
$groupId = $group['identifier'];
Expand Down Expand Up @@ -209,7 +209,7 @@ public function buildConfigurationObject(
}
}

public function mergeStructure(\SimpleXMLElement $base, \SimpleXMLElement $new)
public function mergeStructure(MergedStructure $base, \SimpleXMLElement $new)
{
$base->registerXPathNamespace('s', 'http://www.magiumlib.com/Configuration');
foreach ($new as $item) {
Expand All @@ -224,7 +224,7 @@ public function mergeStructure(\SimpleXMLElement $base, \SimpleXMLElement $new)
}

foreach ($item->attributes() as $name => $value) {
$section[$name] = $value;
$section[$name] = (string)$value;
}
if ($item->group) {
$this->mergeGroup($section, $item->group);
Expand All @@ -247,7 +247,7 @@ protected function mergeGroup(\SimpleXMLElement $section, \SimpleXMLElement $new
$group = $section->addChild('group');
}
foreach ($newGroup->attributes() as $name => $value) {
$group[$name] = $value;
$group[$name] = (string)$value;
}
$this->mergeElements($group, $newGroup->element);
}
Expand All @@ -268,10 +268,10 @@ protected function mergeElements(\SimpleXMLElement $group, \SimpleXMLElement $ne
$element = $group->addChild('element');
}
foreach ($newElement->attributes() as $name => $value) {
$element[$name] = $value;
$element[$name] = (string)$value;
}
foreach ($newElement->children() as $key => $item) {
$element->$key = $item;
$element->$key = (string)$item;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Config/BuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface BuilderInterface
public function build($context = ConfigurationRepository::CONTEXT_DEFAULT, ConfigInterface $config = null);

/**
* @return \SimpleXMLElement
* @return MergedStructure
*/

public function getMergedStructure();
Expand Down
3 changes: 3 additions & 0 deletions lib/Config/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ public function getValue($path);
public function hasValue($path);

public function getValueFlag($path);

public function xpath($xpath);

}
1 change: 1 addition & 0 deletions lib/Config/ConfigurationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ public function getValueFlag($path)
}
return false;
}

}
8 changes: 8 additions & 0 deletions lib/Config/MergedStructure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Magium\Configuration\Config;

class MergedStructure extends \SimpleXMLElement
{

}
6 changes: 4 additions & 2 deletions lib/File/XmlFileToXmlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Magium\Configuration\File;

use Magium\Configuration\Config\MergedStructure;

trait XmlFileToXmlTrait
{

Expand All @@ -13,13 +15,13 @@ abstract public function validateSchema(\DOMDocument $doc);

public function toXml()
{
if (!$this->xml instanceof \SimpleXMLElement) {
if (!$this->xml instanceof MergedStructure) {
$file = $this->getFile();
$content = file_get_contents($file);
$doc = new \DOMDocument();
$doc->loadXML($content);
$this->validateSchema($doc);
$this->xml = new \SimpleXMLElement($content);
$this->xml = new MergedStructure($content);
}
return $this->xml;
}
Expand Down
28 changes: 28 additions & 0 deletions lib/Source/Datetime/MonthNumbers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Magium\Configuration\Source\Datetime;

use Magium\Configuration\Source\SourceInterface;

class MonthNumbers implements SourceInterface
{

public function getSourceData()
{
return [
'01' => '01',
'02' => '02',
'03' => '03',
'04' => '04',
'05' => '05',
'06' => '06',
'07' => '07',
'08' => '08',
'09' => '09',
'10' => '10',
'11' => '11',
'12' => '12',
];
}

}
28 changes: 28 additions & 0 deletions lib/Source/Datetime/Months.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Magium\Configuration\Source\Datetime;

use Magium\Configuration\Source\SourceInterface;

class Months implements SourceInterface
{

public function getSourceData()
{
return [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];
}

}
21 changes: 21 additions & 0 deletions lib/Source/Datetime/NextTenYears.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Magium\Configuration\Source\Datetime;

use Magium\Configuration\Source\SourceInterface;

class NextTenYears implements SourceInterface
{

public function getSourceData()
{
$now = date('Y');
$return = [];
do {
$return[] = $now++;
} while (count($return) < 10);
return $return;

}

}
29 changes: 29 additions & 0 deletions lib/Source/Political/CanadianProvinces.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Magium\Configuration\Source\Political;

use Magium\Configuration\Source\SourceInterface;

class CanadianProvinces implements SourceInterface
{

public function getSourceData()
{
return [
'AB' => 'Alberta',
'BC' => 'British Columbia',
'MB' => 'Manitoba',
'NB' => 'New Brunswick',
'NL' => 'Newfoundland and Labrador',
'NT' => 'Northwest Territories',
'NS' => 'Nova Scotia',
'NU' => 'Nunavut',
'ON' => 'Ontario',
'PE' => 'Prince Edward Island',
'QC' => 'Quebec',
'SK' => 'Saskatchewan',
'YT' => 'Yukon'
];
}

}
Loading

0 comments on commit 6b895f3

Please sign in to comment.