merged branch Tobion/pp-refactor (PR #4418)
Commits -------e673a04
[OptionsResolver] clarify phpdoc0cac404
[Form] refactored PropertyPth Discussion ---------- PropertyPath refactoring + CS fix --------------------------------------------------------------------------- by travisbot at 2012-05-25T21:49:01Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1437257) (mergede673a041
intoff4d446c
).
This commit is contained in:
commit
0a473895c8
@ -427,7 +427,7 @@ class PropertyPath implements \IteratorAggregate, PropertyPathInterface
|
||||
*
|
||||
* @param object|array $objectOrArray The object or array to write to.
|
||||
* @param string $property The property to write.
|
||||
* @param string $singular The singular form of the property name or null.
|
||||
* @param string|null $singular The singular form of the property name or null.
|
||||
* @param Boolean $isIndex Whether to interpret the property as index.
|
||||
* @param mixed $value The value to write.
|
||||
*
|
||||
@ -526,7 +526,7 @@ class PropertyPath implements \IteratorAggregate, PropertyPathInterface
|
||||
* Searches for add and remove methods.
|
||||
*
|
||||
* @param \ReflectionClass $reflClass The reflection class for the given object
|
||||
* @param string $singular The singular form of the property name or null.
|
||||
* @param string|null $singular The singular form of the property name or null.
|
||||
*
|
||||
* @return array|null An array containin the adder and remover when found, null otherwise.
|
||||
*
|
||||
@ -555,7 +555,8 @@ class PropertyPath implements \IteratorAggregate, PropertyPathInterface
|
||||
}
|
||||
|
||||
return array($addMethod, $removeMethod);
|
||||
} else {
|
||||
}
|
||||
|
||||
// The plural form is the last element of the property path
|
||||
$plural = ucfirst($this->elements[$this->length - 1]);
|
||||
|
||||
@ -563,36 +564,25 @@ class PropertyPath implements \IteratorAggregate, PropertyPathInterface
|
||||
$singulars = (array) FormUtil::singularify($plural);
|
||||
|
||||
foreach ($singulars as $singular) {
|
||||
$methodsFound = 0;
|
||||
$addMethodFound = false;
|
||||
$addMethodName = 'add' . $singular;
|
||||
$removeMethodName = 'remove' . $singular;
|
||||
$addMethod = 'add' . $singular;
|
||||
$removeMethod = 'remove' . $singular;
|
||||
|
||||
if ($this->isAccessible($reflClass, $addMethodName, 1)) {
|
||||
$addMethod = $addMethodName;
|
||||
$addMethodFound = true;
|
||||
$methodsFound++;
|
||||
}
|
||||
$addMethodFound = $this->isAccessible($reflClass, $addMethod, 1);
|
||||
$removeMethodFound = $this->isAccessible($reflClass, $removeMethod, 1);
|
||||
|
||||
if ($this->isAccessible($reflClass, $removeMethodName, 1)) {
|
||||
$removeMethod = $removeMethodName;
|
||||
$methodsFound++;
|
||||
}
|
||||
|
||||
if (2 == $methodsFound) {
|
||||
if ($addMethodFound && $removeMethodFound) {
|
||||
return array($addMethod, $removeMethod);
|
||||
}
|
||||
|
||||
if (1 == $methodsFound) {
|
||||
if ($addMethodFound xor $removeMethodFound) {
|
||||
throw new InvalidPropertyException(sprintf(
|
||||
'Found the public method "%s", but did not find a public "%s" on class %s',
|
||||
$addMethodFound ? $addMethodName : $removeMethodName,
|
||||
$addMethodFound ? $removeMethodName : $addMethodName,
|
||||
$addMethodFound ? $addMethod : $removeMethod,
|
||||
$addMethodFound ? $removeMethod : $addMethod,
|
||||
$reflClass->getName()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -59,10 +59,11 @@ interface OptionsResolverInterface
|
||||
/**
|
||||
* Sets optional options.
|
||||
*
|
||||
* This method is identical to {@ĺink setDefaults()}, only that no default values
|
||||
* are configured for the options. If these options are not passed to
|
||||
* {@link resolve()}, they will be missing in the final options array. This can be
|
||||
* helpful if you want to determine whether an option has been set or not.
|
||||
* This method declares valid option names without setting default values for them.
|
||||
* If these options are not passed to {@link resolve()} and no default has been set
|
||||
* for them, they will be missing in the final options array. This can be helpful
|
||||
* if you want to determine whether an option has been set or not because otherwise
|
||||
* {@link resolve()} would trigger an exception for unknown options.
|
||||
*
|
||||
* @param array $optionNames A list of option names.
|
||||
*
|
||||
@ -95,8 +96,9 @@ interface OptionsResolverInterface
|
||||
*
|
||||
* @return OptionsResolverInterface The resolver instance.
|
||||
*
|
||||
* @throws Exception\InvalidOptionsException If an option has not been defined for
|
||||
* which an allowed value is set.
|
||||
* @throws Exception\InvalidOptionsException If an option has not been defined
|
||||
* (see {@link isKnown()}) for which
|
||||
* an allowed value is set.
|
||||
*/
|
||||
function setAllowedValues(array $allowedValues);
|
||||
|
||||
|
Reference in New Issue
Block a user