[PropertyAccess] unify and fix doc
This commit is contained in:
parent
f9ddaebe09
commit
d1c8c5d22f
@ -200,8 +200,9 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
if (!is_array($objectOrArray)) {
|
||||
if (!$objectOrArray instanceof \Traversable) {
|
||||
throw new NoSuchIndexException(sprintf(
|
||||
'Cannot read property "%s".',
|
||||
$property
|
||||
'Cannot read index "%s" while trying to traverse path "%s".',
|
||||
$property,
|
||||
(string) $propertyPath
|
||||
));
|
||||
}
|
||||
|
||||
@ -209,8 +210,9 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
}
|
||||
|
||||
throw new NoSuchIndexException(sprintf(
|
||||
'Cannot read property "%s". Available properties are "%s"',
|
||||
'Cannot read index "%s" while trying to traverse path "%s". Available indices are "%s".',
|
||||
$property,
|
||||
(string) $propertyPath,
|
||||
print_r(array_keys($objectOrArray), true)
|
||||
));
|
||||
}
|
||||
@ -250,7 +252,7 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
private function &readIndex(&$array, $index)
|
||||
{
|
||||
if (!$array instanceof \ArrayAccess && !is_array($array)) {
|
||||
throw new NoSuchIndexException(sprintf('Index "%s" cannot be read from object of type "%s" because it doesn\'t implement \ArrayAccess', $index, get_class($array)));
|
||||
throw new NoSuchIndexException(sprintf('Cannot read index "%s" from object of type "%s" because it doesn\'t implement \ArrayAccess.', $index, get_class($array)));
|
||||
}
|
||||
|
||||
// Use an array instead of an object since performance is very crucial here
|
||||
@ -294,7 +296,7 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
);
|
||||
|
||||
if (!is_object($object)) {
|
||||
throw new NoSuchPropertyException(sprintf('Cannot read property "%s" from an array. Maybe you should write the property path as "[%s]" instead?', $property, $property));
|
||||
throw new NoSuchPropertyException(sprintf('Cannot read property "%s" from an array. Maybe you intended to write the property path as "[%s]" instead.', $property, $property));
|
||||
}
|
||||
|
||||
$camelized = $this->camelize($property);
|
||||
@ -364,7 +366,7 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
private function writeIndex(&$array, $index, $value)
|
||||
{
|
||||
if (!$array instanceof \ArrayAccess && !is_array($array)) {
|
||||
throw new NoSuchIndexException(sprintf('Index "%s" cannot be modified in object of type "%s" because it doesn\'t implement \ArrayAccess', $index, get_class($array)));
|
||||
throw new NoSuchIndexException(sprintf('Cannot modify index "%s" in object of type "%s" because it doesn\'t implement \ArrayAccess', $index, get_class($array)));
|
||||
}
|
||||
|
||||
$array[$index] = $value;
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace Symfony\Component\PropertyAccess;
|
||||
|
||||
/**
|
||||
* A configurable builder for PropertyAccessorInterface objects.
|
||||
* A configurable builder to create a PropertyAccessor.
|
||||
*
|
||||
* @author Jérémie Augustin <jeremie.augustin@pixel-cookers.com>
|
||||
*/
|
||||
@ -53,7 +53,7 @@ class PropertyAccessorBuilder
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool true if the use of "__call" by the PropertyAccessor is enabled
|
||||
* @return bool whether the use of "__call" by the PropertyAccessor is enabled
|
||||
*/
|
||||
public function isMagicCallEnabled()
|
||||
{
|
||||
@ -61,7 +61,10 @@ class PropertyAccessorBuilder
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables exceptions in read context for array by PropertyAccessor
|
||||
* Enables exceptions when reading a non-existing index.
|
||||
*
|
||||
* This has no influence on writing non-existing indices with PropertyAccessorInterface::setValue()
|
||||
* which are always created on-the-fly.
|
||||
*
|
||||
* @return PropertyAccessorBuilder The builder object
|
||||
*/
|
||||
@ -73,7 +76,9 @@ class PropertyAccessorBuilder
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables exceptions in read context for array by PropertyAccessor
|
||||
* Disables exceptions when reading a non-existing index.
|
||||
*
|
||||
* Instead, null is returned when calling PropertyAccessorInterface::getValue() on a non-existing index.
|
||||
*
|
||||
* @return PropertyAccessorBuilder The builder object
|
||||
*/
|
||||
@ -85,7 +90,7 @@ class PropertyAccessorBuilder
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool true is exceptions in read context for array is enabled
|
||||
* @return bool whether an exception is thrown or null is returned when reading a non-existing index
|
||||
*/
|
||||
public function isExceptionOnInvalidIndexEnabled()
|
||||
{
|
||||
@ -93,9 +98,9 @@ class PropertyAccessorBuilder
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and returns a new propertyAccessor object.
|
||||
* Builds and returns a new PropertyAccessor object.
|
||||
*
|
||||
* @return PropertyAccessorInterface The built propertyAccessor
|
||||
* @return PropertyAccessorInterface The built PropertyAccessor
|
||||
*/
|
||||
public function getPropertyAccessor()
|
||||
{
|
||||
|
Reference in New Issue
Block a user