Skip to content

Config - simplify the code #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Feb 27, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 2 additions & 82 deletions src/Symfony/Component/Config/Definition/ScalarNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Component\Config\Definition;

use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\VariableNode;
use Symfony\Component\Config\Definition\Exception\InvalidTypeException;

/**
Expand All @@ -26,56 +26,8 @@
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class ScalarNode extends BaseNode implements PrototypeNodeInterface
class ScalarNode extends VariableNode
{
protected $defaultValueSet = false;
protected $defaultValue;
protected $allowEmptyValue = true;

/**
* {@inheritDoc}
*/
public function setDefaultValue($value)
{
$this->defaultValueSet = true;
$this->defaultValue = $value;
}

/**
* {@inheritDoc}
*/
public function hasDefaultValue()
{
return $this->defaultValueSet;
}

/**
* {@inheritDoc}
*/
public function getDefaultValue()
{
return $this->defaultValue;
}

/**
* Sets if this node is allowed to have an empty value.
*
* @param boolean $boolean True if this entity will accept empty values.
* @return void
*/
public function setAllowEmptyValue($boolean)
{
$this->allowEmptyValue = (Boolean) $boolean;
}

/**
* {@inheritDoc}
*/
public function setName($name)
{
$this->name = $name;
}

/**
* {@inheritDoc}
*/
Expand All @@ -89,36 +41,4 @@ protected function validateType($value)
));
}
}

/**
* {@inheritDoc}
*/
protected function finalizeValue($value)
{
if (!$this->allowEmptyValue && empty($value)) {
throw new InvalidConfigurationException(sprintf(
'The path "%s" cannot contain an empty value, but got %s.',
$this->getPath(),
json_encode($value)
));
}

return $value;
}

/**
* {@inheritDoc}
*/
protected function normalizeValue($value)
{
return $value;
}

/**
* {@inheritDoc}
*/
protected function mergeValues($leftSide, $rightSide)
{
return $rightSide;
}
}
6 changes: 3 additions & 3 deletions src/Symfony/Component/Config/Definition/VariableNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
/**
* This node represents a variable value in the config tree.
*
* This node is intended for arbitrary variables. It behaves similar to scalar
* nodes except that any PHP type is accepted as a value.
* This node is intended for arbitrary variables.
* Any PHP type is accepted as a value.
*
* @author Jeremy Mikola <jmikola@gmail.com>
*/
Expand Down Expand Up @@ -110,4 +110,4 @@ protected function mergeValues($leftSide, $rightSide)
{
return $rightSide;
}
}
}