Skip to content

Commit 913a0ee

Browse files
committed
Merge pull request #1349 from xabbuh/pr-1339
some tweaks to the directory route loader
2 parents ed99e9a + 2070441 commit 913a0ee

File tree

4 files changed

+9
-17
lines changed

4 files changed

+9
-17
lines changed

Routing/Loader/DirectoryRouteLoader.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace FOS\RestBundle\Routing\Loader;
1313

1414
use Symfony\Component\Config\Loader\Loader;
15+
use Symfony\Component\Finder\Finder;
1516
use Symfony\Component\Routing\RouteCollection;
1617

1718
/**
@@ -39,14 +40,10 @@ public function load($resource, $type = null)
3940

4041
$collection = new RouteCollection();
4142

42-
$directoryIterator = new \DirectoryIterator($resource);
43+
$finder = new Finder();
4344

44-
foreach ($directoryIterator as $file) {
45-
if ($file->getFilename() === '.' || $file->getFilename() === '..') {
46-
continue;
47-
}
48-
49-
$imported = $this->processor->importResource($this, ClassUtils::findClassInFile($file->getPathname()), array(), null, null, 'rest');
45+
foreach ($finder->in($resource)->name('*.php')->files() as $file) {
46+
$imported = $this->processor->importResource($this, ClassUtils::findClassInFile($file), array(), null, null, 'rest');
5047
$collection->addCollection($imported);
5148
}
5249

Routing/Loader/RestRouteLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ private function getControllerLocator($controller)
162162
*/
163163
protected function findClass($file)
164164
{
165-
@trigger_error('The '.__METHOD__.' method is deprecated since version 1.8 and will be removed in 2.0. Use '.__NAMESPACE__.'\ClassUtils::findClassInFile() instead.', E_USER_DEPRECATED);
165+
@trigger_error(sprintf('The %s method is deprecated since version 1.8 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED);
166166

167167
return ClassUtils::findClassInFile($file);
168168
}

Tests/Routing/Loader/DirectoryRouteLoaderTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,9 @@ public function testLoad()
2323

2424
$this->assertCount(9, $collection);
2525

26-
$this->assertInstanceOf('Symfony\Component\Routing\Route', $collection->get('get_users'));
27-
$this->assertInstanceOf('Symfony\Component\Routing\Route', $collection->get('get_user'));
28-
$this->assertInstanceOf('Symfony\Component\Routing\Route', $collection->get('post_users'));
29-
$this->assertInstanceOf('Symfony\Component\Routing\Route', $collection->get('put_user'));
30-
$this->assertInstanceOf('Symfony\Component\Routing\Route', $collection->get('get_comments'));
31-
$this->assertInstanceOf('Symfony\Component\Routing\Route', $collection->get('put_comment'));
32-
$this->assertInstanceOf('Symfony\Component\Routing\Route', $collection->get('get_topics'));
33-
$this->assertInstanceOf('Symfony\Component\Routing\Route', $collection->get('get_topic'));
34-
$this->assertInstanceOf('Symfony\Component\Routing\Route', $collection->get('put_topic'));
26+
foreach ($collection as $route) {
27+
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
28+
}
3529
}
3630

3731
/**

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"require": {
2424
"php": "^5.3.9|~7.0",
2525
"psr/log": "~1.0",
26+
"symfony/finder": "~2.3|~3.0",
2627
"symfony/framework-bundle": "~2.3|~3.0",
2728
"symfony/http-kernel": "^2.3.24|~3.0",
2829
"doctrine/inflector": "~1.0",

0 commit comments

Comments
 (0)