ソースを参照

[Finder] added a convenience method Finder::create()

Fabien Potencier 14 年 前
コミット
b76a1c3077

+ 16 - 2
src/Symfony/Component/Finder/Finder.php

@@ -20,8 +20,7 @@ namespace Symfony\Component\Finder;
  *
  * All methods return the current Finder object to allow easy chaining:
  *
- * $finder = new Finder();
- * $finder = $finder->files()->name('*.php')->in(__DIR__);
+ * $finder = Finder::create()->files()->name('*.php')->in(__DIR__);
  *
  * @author Fabien Potencier <fabien@symfony.com>
  *
@@ -48,11 +47,26 @@ class Finder implements \IteratorAggregate
 
     static private $vcsPatterns = array('.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg');
 
+    /**
+     * Constructor.
+     */
     public function __construct()
     {
         $this->ignore = static::IGNORE_VCS_FILES | static::IGNORE_DOT_FILES;
     }
 
+    /**
+     * Creates a new Finder.
+     *
+     * @return Finder A new Finder instance
+     *
+     * @api
+     */
+    static public function create()
+    {
+        return new self();
+    }
+
     /**
      * Restricts the matching to directories only.
      *

+ 5 - 0
tests/Symfony/Tests/Component/Finder/FinderTest.php

@@ -26,6 +26,11 @@ class FinderTest extends Iterator\RealIteratorTestCase
         self::$tmpDir = sys_get_temp_dir().'/symfony2_finder';
     }
 
+    public function testCreate()
+    {
+        $this->assertInstanceOf('Symfony\Component\Finder\Finder', Finder::create());
+    }
+
     public function testDirectories()
     {
         $finder = new Finder();