Skip to content

[Config] Some tweaks in the component #127

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
8 commits merged into from
Mar 9, 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
66 changes: 24 additions & 42 deletions src/Symfony/Component/Config/Definition/ArrayNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public function __construct($name, NodeInterface $parent = null)
* Sets the xml remappings that should be performed.
*
* @param array $remappings an array of the form array(array(string, string))
* @return void
*/
public function setXmlRemappings(array $remappings)
{
Expand All @@ -73,15 +72,14 @@ public function setXmlRemappings(array $remappings)
* contain. By default this is zero, meaning no elements.
*
* @param integer $number
* @return void
*/
public function setMinNumberOfElements($number)
{
$this->minNumberOfElements = $number;
}

/**
* The name of the attribute that should be used as key.
* The name of the attribute which value should be used as key.
*
* This is only relevant for XML configurations, and only in combination
* with a prototype based node.
Expand All @@ -92,14 +90,13 @@ public function setMinNumberOfElements($number)
*
* becomes
*
* 'id' => array('foo' => 'bar')
* 'my_name' => array('foo' => 'bar')
*
* If $remove is false, the resulting array will still have the
* "'id' => 'my_name'" item in it.
*
* @param string $attribute The name of the attribute to use as a key
* @param string $attribute The name of the attribute which value is to be used as a key
* @param Boolean $remove Whether or not to remove the key
* @return void
*/
public function setKeyAttribute($attribute, $remove = true)
{
Expand All @@ -112,7 +109,6 @@ public function setKeyAttribute($attribute, $remove = true)
* defined in any of the configuration files.
*
* @param Boolean $boolean
* @return void
*/
public function setAddIfNotSet($boolean)
{
Expand All @@ -124,7 +120,6 @@ public function setAddIfNotSet($boolean)
* be unset.
*
* @param Boolean $allow
* @return void
*/
public function setAllowFalse($allow)
{
Expand All @@ -135,7 +130,6 @@ public function setAllowFalse($allow)
* Sets whether new keys can be defined in subsequent configurations.
*
* @param Boolean $allow
* @return void
*/
public function setAllowNewKeys($allow)
{
Expand Down Expand Up @@ -238,7 +232,7 @@ public function getDefaultValue()
* Sets the node prototype.
*
* @param PrototypeNodeInterface $node
* @throws \RuntimeException if the node doesn't have concrete children
* @throws \RuntimeException if the node has concrete children
*/
public function setPrototype(PrototypeNodeInterface $node)
{
Expand Down Expand Up @@ -356,10 +350,10 @@ protected function validateType($value)
}

/**
* Normalises the value.
* Normalizes the value.
*
* @param mixed $value The value to normalise
* @return mixed The normalised value
* @param mixed $value The value to normalize
* @return mixed The normalized value
*/
protected function normalizeValue($value)
{
Expand All @@ -378,16 +372,13 @@ protected function normalizeValue($value)
unset($value[$singular]);
}

if (null !== $this->prototype) {
$normalized = array();
$normalized = array();
if (null !== $this->prototype) {
foreach ($value as $k => $v) {
if (null !== $this->keyAttribute && is_array($v)) {
if (!isset($v[$this->keyAttribute]) && is_int($k)) {
throw new InvalidConfigurationException(sprintf(
'You must set a "%s" attribute for path "%s".',
$this->keyAttribute,
$this->getPath()
));
$msg = sprintf('The attribute "%s" must be set for path "%s".', $this->keyAttribute, $this->getPath());
throw new InvalidConfigurationException($msg);
} else if (isset($v[$this->keyAttribute])) {
$k = $v[$this->keyAttribute];

Expand All @@ -398,11 +389,8 @@ protected function normalizeValue($value)
}

if (array_key_exists($k, $normalized)) {
throw new DuplicateKeyException(sprintf(
'Duplicate key "%s" for path "%s".',
$k,
$this->getPath()
));
$msg = sprintf('Duplicate key "%s" for path "%s".', $k, $this->getPath());
throw new DuplicateKeyException($msg);
}
}

Expand All @@ -413,25 +401,19 @@ protected function normalizeValue($value)
$normalized[] = $this->prototype->normalize($v);
}
}

return $normalized;
}

$normalized = array();
foreach ($this->children as $name => $child) {
if (!array_key_exists($name, $value)) {
continue;
} else {
foreach ($this->children as $name => $child) {
if (array_key_exists($name, $value)) {
$normalized[$name] = $child->normalize($value[$name]);
unset($value[$name]);
}
}

$normalized[$name] = $child->normalize($value[$name]);
unset($value[$name]);
}

// if extra fields are present, throw exception
if (count($value) && !$this->ignoreExtraKeys) {
$msg = sprintf('Unrecognized options "%s" under "%s"', implode(', ', array_keys($value)), $this->getPath());

throw new InvalidConfigurationException($msg);
// if extra fields are present, throw exception
if (count($value) && !$this->ignoreExtraKeys) {
$msg = sprintf('Unrecognized options "%s" under "%s"', implode(', ', array_keys($value)), $this->getPath());
throw new InvalidConfigurationException($msg);
}
}

return $normalized;
Expand Down
14 changes: 4 additions & 10 deletions src/Symfony/Component/Config/Definition/BaseNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public function __construct($name, NodeInterface $parent = null)
*
* @param mixed $originalValue
* @param mixed $equivalentValue
* @return void
*/
public function addEquivalentValue($originalValue, $equivalentValue)
{
Expand All @@ -67,8 +66,7 @@ public function addEquivalentValue($originalValue, $equivalentValue)
/**
* Set this node as required.
*
* @param boolean $boolean Required node
* @return void
* @param Boolean $boolean Required node
*/
public function setRequired($boolean)
{
Expand All @@ -78,8 +76,7 @@ public function setRequired($boolean)
/**
* Sets if this node can be overridden.
*
* @param boolean $allow
* @return void
* @param Boolean $allow
*/
public function setAllowOverwrite($allow)
{
Expand All @@ -90,7 +87,6 @@ public function setAllowOverwrite($allow)
* Sets the closures used for normalization.
*
* @param array $closures An array of Closures used for normalization
* @return void
*/
public function setNormalizationClosures(array $closures)
{
Expand All @@ -101,7 +97,6 @@ public function setNormalizationClosures(array $closures)
* Sets the closures used for final validation.
*
* @param array $closures An array of Closures used for final validation
* @return void
*/
public function setFinalValidationClosures(array $closures)
{
Expand All @@ -111,7 +106,7 @@ public function setFinalValidationClosures(array $closures)
/**
* Checks if this node is required.
*
* @return boolean
* @return Boolean
*/
public function isRequired()
{
Expand Down Expand Up @@ -232,8 +227,7 @@ public final function finalize($value)
* Validates the type of a Node.
*
* @param mixed $value The value to validate
* @return void
* @throws \InvalidTypeException when the value is invalid
* @throws InvalidTypeException when the value is invalid
*/
abstract protected function validateType($value);

Expand Down
2 changes: 0 additions & 2 deletions src/Symfony/Component/Config/Definition/BooleanNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class BooleanNode extends ScalarNode
*/
protected function validateType($value)
{
parent::validateType($value);

if (!is_bool($value)) {
throw new InvalidTypeException(sprintf(
'Invalid type for path "%s". Expected boolean, but got %s.',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Config\Definition\Builder;

/**
* Defines a common interface for node & tree builders
*
* @author Victor Berchet <victor@suumit.com>
*/
interface BuilderInterface
{
}

28 changes: 14 additions & 14 deletions src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ class ExprBuilder
/**
* Constructor
*
* @param Symfony\Component\Config\Definition\Builder\NodeBuilder $parent The parent node
* @param NodeBuilder $parent The parent node
*/
public function __construct($parent)
public function __construct(NodeBuilder $parent)
{
$this->parent = $parent;
}

/**
* Mark the expression as being always used.
*
* @return Symfony\Component\Config\Definition\Builder\ExprBuilder
* @return ExprBuilder
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the FQCN in the PHPdoc was intended as some IDEs does not autocomplete correctly when the short name is given as the PHPdoc does not refers to the use statement. This would maje the autocompletion painful with these IDE.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well then again it can also become a problem if the data gets out of sync and any change will lead to potentially unnecessarily long diff's. imho those IDE's need to get fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix is also for consistency...
And to second Lukas, Sf2 is powerful but not meant to fix IDEs !

& everything is not very consistent yet, I have some more modifs in the pipe

*/
public function always()
{
Expand All @@ -51,7 +51,7 @@ public function always()
* The default one tests if the value is true.
*
* @param \Closure $closure
* @return Symfony\Component\Config\Definition\Builder\ExprBuilder
* @return ExprBuilder
*/
public function ifTrue(\Closure $closure = null)
{
Expand All @@ -67,7 +67,7 @@ public function ifTrue(\Closure $closure = null)
/**
* Tests if the value is a string.
*
* @return Symfony\Component\Config\Definition\Builder\ExprBuilder
* @return ExprBuilder
*/
public function ifString()
{
Expand All @@ -79,7 +79,7 @@ public function ifString()
/**
* Tests if the value is null.
*
* @return Symfony\Component\Config\Definition\Builder\ExprBuilder
* @return ExprBuilder
*/
public function ifNull()
{
Expand All @@ -91,7 +91,7 @@ public function ifNull()
/**
* Tests if the value is an array.
*
* @return Symfony\Component\Config\Definition\Builder\ExprBuilder
* @return ExprBuilder
*/
public function ifArray()
{
Expand All @@ -105,7 +105,7 @@ public function ifArray()
*
* @param array $array
*
* @return Symfony\Component\Config\Definition\Builder\ExprBuilder
* @return ExprBuilder
*/
public function ifInArray(array $array)
{
Expand All @@ -119,7 +119,7 @@ public function ifInArray(array $array)
*
* @param array $array
*
* @return Symfony\Component\Config\Definition\Builder\ExprBuilder
* @return ExprBuilder
*/
public function ifNotInArray(array $array)
{
Expand All @@ -133,7 +133,7 @@ public function ifNotInArray(array $array)
*
* @param \Closure $closure
*
* @return Symfony\Component\Config\Definition\Builder\ExprBuilder
* @return ExprBuilder
*/
public function then(\Closure $closure)
{
Expand All @@ -145,7 +145,7 @@ public function then(\Closure $closure)
/**
* Sets a closure returning an empty array.
*
* @return Symfony\Component\Config\Definition\Builder\ExprBuilder
* @return ExprBuilder
*/
public function thenEmptyArray()
{
Expand All @@ -161,7 +161,7 @@ public function thenEmptyArray()
*
* @param string $message
*
* @return Symfony\Component\Config\Definition\Builder\ExprBuilder
* @return ExprBuilder
*/
public function thenInvalid($message)
{
Expand All @@ -173,7 +173,7 @@ public function thenInvalid($message)
/**
* Sets a closure unsetting this key of the array at validation time.
*
* @return Symfony\Component\Config\Definition\Builder\ExprBuilder
* @return ExprBuilder
*/
public function thenUnset()
{
Expand All @@ -185,7 +185,7 @@ public function thenUnset()
/**
* Returns the parent node
*
* @return Symfony\Component\Config\Definition\Builder\NodeBuilder
* @return NodeBuilder
*/
public function end()
{
Expand Down
Loading