@@ -31,10 +31,10 @@ class PropertyPathBuilder
31
31
/**
32
32
* Creates a new property path builder.
33
33
*
34
- * @param null|PropertyPathInterface $path The path to initially store
35
- * in the builder. Optional.
34
+ * @param null|PropertyPathInterface|string $path The path to initially store
35
+ * in the builder. Optional.
36
36
*/
37
- public function __construct (PropertyPathInterface $ path = null )
37
+ public function __construct ($ path = null )
38
38
{
39
39
if (null !== $ path ) {
40
40
$ this ->append ($ path );
@@ -44,14 +44,18 @@ public function __construct(PropertyPathInterface $path = null)
44
44
/**
45
45
* Appends a (sub-) path to the current path.
46
46
*
47
- * @param PropertyPathInterface $path The path to append
48
- * @param integer $offset The offset where the appended piece
49
- * starts in $path
50
- * @param integer $length The length of the appended piece.
51
- * If 0, the full path is appended.
47
+ * @param PropertyPathInterface|string $path The path to append.
48
+ * @param integer $offset The offset where the appended
49
+ * piece starts in $path.
50
+ * @param integer $length The length of the appended piece.
51
+ * If 0, the full path is appended.
52
52
*/
53
- public function append (PropertyPathInterface $ path , $ offset = 0 , $ length = 0 )
53
+ public function append ($ path , $ offset = 0 , $ length = 0 )
54
54
{
55
+ if (is_string ($ path )) {
56
+ $ path = new PropertyPath ($ path );
57
+ }
58
+
55
59
if (0 === $ length ) {
56
60
$ end = $ path ->getLength ();
57
61
} else {
@@ -106,20 +110,26 @@ public function remove($offset, $length = 1)
106
110
/**
107
111
* Replaces a sub-path by a different (sub-) path.
108
112
*
109
- * @param integer $offset The offset at which to replace
110
- * @param integer $length The length of the piece to replace
111
- * @param PropertyPathInterface $path The path to insert
112
- * @param integer $pathOffset The offset where the inserted piece
113
- * starts in $path
114
- * @param integer $pathLength The length of the inserted piece.
115
- * If 0, the full path is inserted.
113
+ * @param integer $offset The offset at which to replace.
114
+ * @param integer $length The length of the piece to replace.
115
+ * @param PropertyPathInterface|string $path The path to insert.
116
+ * @param integer $pathOffset The offset where the inserted piece
117
+ * starts in $path.
118
+ * @param integer $pathLength The length of the inserted piece.
119
+ * If 0, the full path is inserted.
116
120
*
117
121
* @throws OutOfBoundsException If the offset is invalid
118
122
*/
119
- public function replace ($ offset , $ length , PropertyPathInterface $ path , $ pathOffset = 0 , $ pathLength = 0 )
123
+ public function replace ($ offset , $ length , $ path , $ pathOffset = 0 , $ pathLength = 0 )
120
124
{
121
- if (!isset ($ this ->elements [$ offset ])) {
122
- throw new OutOfBoundsException (sprintf ('The offset %s is not within the property path ' , $ offset ));
125
+ if (is_string ($ path )) {
126
+ $ path = new PropertyPath ($ path );
127
+ }
128
+
129
+ if ($ offset < 0 && abs ($ offset ) <= $ this ->getLength ()) {
130
+ $ offset = $ this ->getLength () + $ offset ;
131
+ } elseif (!isset ($ this ->elements [$ offset ])) {
132
+ throw new OutOfBoundsException ('The offset ' . $ offset . ' is not within the property path ' );
123
133
}
124
134
125
135
if (0 === $ pathLength ) {
0 commit comments