Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 89ed6ce

Browse files
committed
Implemented format option
1 parent 50526de commit 89ed6ce

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

AutoRoute/PathExists/AutoIncrementPath.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class AutoIncrementPath implements PathActionInterface
1616
{
1717
protected $dm;
1818
protected $routeMaker;
19+
protected $format = '%s-%d';
1920

2021
public function __construct(DocumentManager $dm, RouteMakerInterface $routeMaker)
2122
{
@@ -25,6 +26,9 @@ public function __construct(DocumentManager $dm, RouteMakerInterface $routeMaker
2526

2627
public function init(array $options)
2728
{
29+
if (isset($options['format'])) {
30+
$this->format = '%s'.$options['format'];
31+
}
2832
}
2933

3034
public function execute(RouteStack $routeStack)
@@ -42,7 +46,7 @@ public function execute(RouteStack $routeStack)
4246
}
4347

4448
do {
45-
$newPath = sprintf('%s-%d', $path, $inc++);
49+
$newPath = sprintf($this->format, $path, $inc++);
4650
} while (null !== $this->dm->find(null, $newPath));
4751

4852
$routeStack->replaceLastPathElement(PathHelper::getNodeName($newPath));

Tests/Unit/AutoRoute/PathExists/AutoIncrementPathTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,19 @@ public function testFormatOption()
124124

125125
$this->dm->expects($this->at(1))
126126
->method('find')
127-
->with(null, '/foo/bar/1')
127+
->with(null, '/foo/bar1')
128128
->will($this->returnValue(null));
129129

130130
$this->routeStack->expects($this->once())
131131
->method('replaceLastPathElement')
132-
->with('bar/2');
132+
->with('bar1');
133133

134134
$this->routeMaker->expects($this->once())
135135
->method('make')
136136
->with($this->routeStack);
137137

138138
$aiPath = new AutoIncrementPath($this->dm, $this->routeMaker);
139-
$aiPath->init(array('format' => '/%d'));
139+
$aiPath->init(array('format' => '%d'));
140140
$aiPath->execute($this->routeStack);
141141
}
142142
}

0 commit comments

Comments
 (0)