Skip to content

Commit 075002a

Browse files
committed
minor #13754 [PropertyAccess] unify and fix doc (Tobion)
This PR was merged into the 2.6 branch. Discussion ---------- [PropertyAccess] unify and fix doc | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | - Commits ------- d1c8c5d [PropertyAccess] unify and fix doc
2 parents 51a2240 + d1c8c5d commit 075002a

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,19 @@ private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $pr
200200
if (!is_array($objectOrArray)) {
201201
if (!$objectOrArray instanceof \Traversable) {
202202
throw new NoSuchIndexException(sprintf(
203-
'Cannot read property "%s".',
204-
$property
203+
'Cannot read index "%s" while trying to traverse path "%s".',
204+
$property,
205+
(string) $propertyPath
205206
));
206207
}
207208

208209
$objectOrArray = iterator_to_array($objectOrArray);
209210
}
210211

211212
throw new NoSuchIndexException(sprintf(
212-
'Cannot read property "%s". Available properties are "%s"',
213+
'Cannot read index "%s" while trying to traverse path "%s". Available indices are "%s".',
213214
$property,
215+
(string) $propertyPath,
214216
print_r(array_keys($objectOrArray), true)
215217
));
216218
}
@@ -250,7 +252,7 @@ private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $pr
250252
private function &readIndex(&$array, $index)
251253
{
252254
if (!$array instanceof \ArrayAccess && !is_array($array)) {
253-
throw new NoSuchIndexException(sprintf('Index "%s" cannot be read from object of type "%s" because it doesn\'t implement \ArrayAccess', $index, get_class($array)));
255+
throw new NoSuchIndexException(sprintf('Cannot read index "%s" from object of type "%s" because it doesn\'t implement \ArrayAccess.', $index, get_class($array)));
254256
}
255257

256258
// Use an array instead of an object since performance is very crucial here
@@ -294,7 +296,7 @@ private function &readProperty(&$object, $property)
294296
);
295297

296298
if (!is_object($object)) {
297-
throw new NoSuchPropertyException(sprintf('Cannot read property "%s" from an array. Maybe you should write the property path as "[%s]" instead?', $property, $property));
299+
throw new NoSuchPropertyException(sprintf('Cannot read property "%s" from an array. Maybe you intended to write the property path as "[%s]" instead.', $property, $property));
298300
}
299301

300302
$camelized = $this->camelize($property);
@@ -364,7 +366,7 @@ private function &readProperty(&$object, $property)
364366
private function writeIndex(&$array, $index, $value)
365367
{
366368
if (!$array instanceof \ArrayAccess && !is_array($array)) {
367-
throw new NoSuchIndexException(sprintf('Index "%s" cannot be modified in object of type "%s" because it doesn\'t implement \ArrayAccess', $index, get_class($array)));
369+
throw new NoSuchIndexException(sprintf('Cannot modify index "%s" in object of type "%s" because it doesn\'t implement \ArrayAccess', $index, get_class($array)));
368370
}
369371

370372
$array[$index] = $value;

src/Symfony/Component/PropertyAccess/PropertyAccessorBuilder.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\PropertyAccess;
1313

1414
/**
15-
* A configurable builder for PropertyAccessorInterface objects.
15+
* A configurable builder to create a PropertyAccessor.
1616
*
1717
* @author Jérémie Augustin <[email protected]>
1818
*/
@@ -53,15 +53,18 @@ public function disableMagicCall()
5353
}
5454

5555
/**
56-
* @return bool true if the use of "__call" by the PropertyAccessor is enabled
56+
* @return bool whether the use of "__call" by the PropertyAccessor is enabled
5757
*/
5858
public function isMagicCallEnabled()
5959
{
6060
return $this->magicCall;
6161
}
6262

6363
/**
64-
* Enables exceptions in read context for array by PropertyAccessor
64+
* Enables exceptions when reading a non-existing index.
65+
*
66+
* This has no influence on writing non-existing indices with PropertyAccessorInterface::setValue()
67+
* which are always created on-the-fly.
6568
*
6669
* @return PropertyAccessorBuilder The builder object
6770
*/
@@ -73,7 +76,9 @@ public function enableExceptionOnInvalidIndex()
7376
}
7477

7578
/**
76-
* Disables exceptions in read context for array by PropertyAccessor
79+
* Disables exceptions when reading a non-existing index.
80+
*
81+
* Instead, null is returned when calling PropertyAccessorInterface::getValue() on a non-existing index.
7782
*
7883
* @return PropertyAccessorBuilder The builder object
7984
*/
@@ -85,17 +90,17 @@ public function disableExceptionOnInvalidIndex()
8590
}
8691

8792
/**
88-
* @return bool true is exceptions in read context for array is enabled
93+
* @return bool whether an exception is thrown or null is returned when reading a non-existing index
8994
*/
9095
public function isExceptionOnInvalidIndexEnabled()
9196
{
9297
return $this->throwExceptionOnInvalidIndex;
9398
}
9499

95100
/**
96-
* Builds and returns a new propertyAccessor object.
101+
* Builds and returns a new PropertyAccessor object.
97102
*
98-
* @return PropertyAccessorInterface The built propertyAccessor
103+
* @return PropertyAccessorInterface The built PropertyAccessor
99104
*/
100105
public function getPropertyAccessor()
101106
{

0 commit comments

Comments
 (0)