From a03f1d05e6df85ac155a8674e4bee97ddd82977e Mon Sep 17 00:00:00 2001 From: coderstephen Date: Sun, 30 Mar 2014 15:46:30 -0500 Subject: [PATCH] Fixed access for has() and remove() --- src/Settings.php | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/Settings.php b/src/Settings.php index b358f5a..2b3176f 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -9,7 +9,7 @@ class Settings /** * The configuration tree of the settings. * - * @var ConfigurationNode + * @var ConfigurationProperty */ protected $configuration; protected $provider; @@ -40,22 +40,20 @@ public function __construct(ProviderInterface $provider = null) */ public function has($name) { - $names = explode('.', $name, 2); + $names = explode('.', $name); + $node = $this->configuration; - foreach ($this->children as $property) + for ($i = 0; $i < count($names); $i++) { - if ($property->getName() === $names[0]) + if (!$node->hasProperty($names[$i])) { - if (isset($names[1])) - { - return $property->has($names[1]); - } - - return true; + return false; } + + $node = $node->getProperty($names[$i]); } - return false; + return true; } /** @@ -118,10 +116,18 @@ public function remove($name) for ($i = 0; $i < count($names) - 1; $i++) { - $property = $property->getProperty($names[$i]); - } + if (!$node->hasProperty($names[$i])) + { + $node->appendChild(new ConfigurationProperty($names[$i])); + } - $property->removeProperty($names[count($names) - 1]); + $node = $node->getProperty($names[$i]); + } + + if ($node->hasProperty($names[count($names) - 1])) + { + $node->removeProperty($names[count($names) - 1]); + } } /**