Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

Commit

Permalink
Fixed access for has() and remove()
Browse files Browse the repository at this point in the history
  • Loading branch information
sagebind committed Mar 30, 2014
1 parent 361e8d9 commit a03f1d0
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/Settings.php
Expand Up @@ -9,7 +9,7 @@ class Settings
/**
* The configuration tree of the settings.
*
* @var ConfigurationNode
* @var ConfigurationProperty
*/
protected $configuration;
protected $provider;
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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]);
}
}

/**
Expand Down

0 comments on commit a03f1d0

Please sign in to comment.