فهرست منبع

Merge branch 'master' into experimental

Conflicts:
	src/Symfony/Component/Form/Resources/config/validation.xml
Bernhard Schussek 14 سال پیش
والد
کامیت
18b98353d5

+ 55 - 32
src/Symfony/Bundle/AsseticBundle/Templating/AsseticHelper.php

@@ -25,6 +25,7 @@ class AsseticHelper extends Helper
     protected $debug;
     protected $defaultJavascriptsOutput;
     protected $defaultStylesheetsOutput;
+    protected $defaultImageOutput;
 
     /**
      * Constructor.
@@ -33,13 +34,60 @@ class AsseticHelper extends Helper
      * @param Boolean      $debug                    The debug mode
      * @param string       $defaultJavascriptsOutput The default {@link javascripts()} output string
      * @param string       $defaultStylesheetsOutput The default {@link stylesheets()} output string
+     * @param string       $defaultImageOutput       The default {@link image()} output string
      */
-    public function __construct(AssetFactory $factory, $debug = false, $defaultJavascriptsOutput = 'js/*.js', $defaultStylesheetsOutput = 'css/*.css')
+    public function __construct(AssetFactory $factory, $debug = false, $defaultJavascriptsOutput = 'js/*.js', $defaultStylesheetsOutput = 'css/*.css', $defaultImageOutput = 'images/*')
     {
         $this->factory = $factory;
         $this->debug = $debug;
         $this->defaultJavascriptsOutput = $defaultJavascriptsOutput;
         $this->defaultStylesheetsOutput = $defaultStylesheetsOutput;
+        $this->defaultImageOutput = $defaultImageOutput;
+    }
+
+    /**
+     * Returns an array of javascript urls.
+     *
+     * This convenience method wraps {@link assets()} and provides a default
+     * output string.
+     */
+    public function javascripts($inputs = array(), $filters = array(), array $options = array())
+    {
+        if (!isset($options['output'])) {
+            $options['output'] = $this->defaultJavascriptsOutput;
+        }
+
+        return $this->getAssetUrls($inputs, $filters, $options);
+    }
+
+    /**
+     * Returns an array of stylesheet urls.
+     *
+     * This convenience method wraps {@link assets()} and provides a default
+     * output string.
+     */
+    public function stylesheets($inputs = array(), $filters = array(), array $options = array())
+    {
+        if (!isset($options['output'])) {
+            $options['output'] = $this->defaultStylesheetsOutput;
+        }
+
+        return $this->getAssetUrls($inputs, $filters, $options);
+    }
+
+    /**
+     * Returns an array of one image url.
+     *
+     * This convenience method wraps {@link assets()} and provides a default
+     * output string.
+     */
+    public function image($inputs = array(), $filters = array(), array $options = array())
+    {
+        if (!isset($options['output'])) {
+            $options['output'] = $this->defaultImageOutput;
+        }
+
+        return $this->getAssetUrls($inputs, $filters, $options, true);
     }
 
     /**
@@ -57,10 +105,11 @@ class AsseticHelper extends Helper
      * @param array|string $inputs  An array or comma-separated list of input strings
      * @param array|string $filters An array or comma-separated list of filter names
      * @param array        $options An array of options
+     * @param Boolean      $single  Use only the last input string
      *
      * @return array An array of URLs for the asset
      */
-    public function assets($inputs = array(), $filters = array(), array $options = array())
+    private function getAssetUrls($inputs = array(), $filters = array(), array $options = array(), $single = false)
     {
         $explode = function($value)
         {
@@ -79,6 +128,10 @@ class AsseticHelper extends Helper
             $options['debug'] = $this->debug;
         }
 
+        if ($single && 1 < count($inputs)) {
+            $inputs = array_slice($inputs, -1);
+        }
+
         $coll = $this->factory->createAsset($inputs, $filters, $options);
 
         if (!$options['debug']) {
@@ -93,36 +146,6 @@ class AsseticHelper extends Helper
         return $urls;
     }
 
-    /**
-     * Returns an array of javascript urls.
-     *
-     * This convenience method wraps {@link assets()} and provides a default
-     * output string.
-     */
-    public function javascripts($inputs = array(), $filters = array(), array $options = array())
-    {
-        if (!isset($options['output'])) {
-            $options['output'] = $this->defaultJavascriptsOutput;
-        }
-
-        return $this->assets($inputs, $filters, $options);
-    }
-
-    /**
-     * Returns an array of stylesheet urls.
-     *
-     * This convenience method wraps {@link assets()} and provides a default
-     * output string.
-     */
-    public function stylesheets($inputs = array(), $filters = array(), array $options = array())
-    {
-        if (!isset($options['output'])) {
-            $options['output'] = $this->defaultStylesheetsOutput;
-        }
-
-        return $this->assets($inputs, $filters, $options);
-    }
-
     public function getName()
     {
         return 'assetic';

+ 5 - 10
src/Symfony/Bundle/AsseticBundle/Tests/FunctionalTest.php

@@ -50,11 +50,8 @@ class FunctionalTest extends \PHPUnit_Framework_TestCase
     {
         $kernel = new TestKernel('test', $debug);
         $kernel->boot();
-        $container = $kernel->getContainer();
-
-        $names = $container->get('assetic.asset_manager')->getNames();
 
-        $this->assertEquals($count, count($names));
+        $this->assertEquals($count, count($kernel->getContainer()->get('assetic.asset_manager')->getNames()));
     }
 
     /**
@@ -64,12 +61,9 @@ class FunctionalTest extends \PHPUnit_Framework_TestCase
     {
         $kernel = new TestKernel('test', $debug);
         $kernel->boot();
-        $container = $kernel->getContainer();
-
-        $routes = $container->get('router')->getRouteCollection()->all();
 
         $matches = 0;
-        foreach (array_keys($routes) as $name) {
+        foreach (array_keys($kernel->getContainer()->get('router')->getRouteCollection()->all()) as $name) {
             if (0 === strpos($name, 'assetic_')) {
                 ++$matches;
             }
@@ -110,9 +104,10 @@ class FunctionalTest extends \PHPUnit_Framework_TestCase
 
     public function provideDebugAndAssetCount()
     {
+        // totals include assets defined in both php and twig templates
         return array(
-            array(true, 5),
-            array(false, 2),
+            array(true, 8),
+            array(false, 3),
         );
     }
 }

+ 6 - 0
src/Symfony/Bundle/AsseticBundle/Tests/Resources/Resources/views/layout.html.twig

@@ -11,3 +11,9 @@
         <script src="{{ asset_url }}"></script>
     {% endjavascripts %}
 {% endblock %}
+
+{% block content %}
+    {% image 'logo.png' %}
+        <img src="{{ asset_url }}">
+    {% endimage %}
+{% endblock %}

+ 1 - 0
src/Symfony/Bundle/AsseticBundle/Tests/Resources/config/config.yml

@@ -19,3 +19,4 @@ twig:
 assetic:
     use_controller: true
     read_from:      "%kernel.root_dir%/web"
+    bundles:        [TestBundle]

+ 4 - 4
src/Symfony/Bundle/AsseticBundle/Tests/Templating/AsseticHelperTest.php

@@ -31,17 +31,17 @@ class AsseticHelperTest extends \PHPUnit_Framework_TestCase
     public function testUrls($debug, $count, $message)
     {
         $helper = new AsseticHelper(new AssetFactory('/foo', $debug), $debug);
-        $urls = $helper->assets(array('js/jquery.js', 'js/jquery.plugin.js'));
+        $urls = $helper->javascripts(array('js/jquery.js', 'js/jquery.plugin.js'));
 
-        $this->assertInternalType('array', $urls, '->assets() returns an array');
+        $this->assertInternalType('array', $urls, '->javascripts() returns an array');
         $this->assertEquals($count, count($urls), $message);
     }
 
     public function getDebugAndCount()
     {
         return array(
-            array(false, 1, '->assets() returns one url when not in debug mode'),
-            array(true, 2, '->assets() returns many urls when in debug mode'),
+            array(false, 1, '->javascripts() returns one url when not in debug mode'),
+            array(true, 2, '->javascripts() returns many urls when in debug mode'),
         );
     }
 }

+ 4 - 4
src/Symfony/Bundle/AsseticBundle/Twig/DynamicExtension.php

@@ -15,7 +15,7 @@ use Assetic\Extension\Twig\AsseticExtension;
 use Assetic\Factory\AssetFactory;
 
 /**
- * Assetic integration.
+ * The dynamic extension is used when use_controllers is enabled.
  *
  * @author Kris Wallsmith <kris.wallsmith@symfony.com>
  */
@@ -24,9 +24,9 @@ class DynamicExtension extends AsseticExtension
     public function getTokenParsers()
     {
         return array(
-            new DynamicTokenParser($this->factory, $this->debug),
-            new DynamicTokenParser($this->factory, $this->debug, $this->defaultJavascriptsOutput, 'javascripts'),
-            new DynamicTokenParser($this->factory, $this->debug, $this->defaultStylesheetsOutput, 'stylesheets'),
+            new DynamicTokenParser($this->factory, 'javascripts', 'js/*.js', $this->debug),
+            new DynamicTokenParser($this->factory, 'stylesheets', 'css/*.css', $this->debug),
+            new DynamicTokenParser($this->factory, 'image', 'images/*', $this->debug, true),
         );
     }
 }

+ 4 - 4
src/Symfony/Bundle/AsseticBundle/Twig/StaticExtension.php

@@ -15,7 +15,7 @@ use Assetic\Extension\Twig\AsseticExtension;
 use Assetic\Factory\AssetFactory;
 
 /**
- * Assetic integration.
+ * The Static extension is used when use_controllers is disabled.
  *
  * @author Kris Wallsmith <kris.wallsmith@symfony.com>
  */
@@ -24,9 +24,9 @@ class StaticExtension extends AsseticExtension
     public function getTokenParsers()
     {
         return array(
-            new StaticTokenParser($this->factory, $this->debug),
-            new StaticTokenParser($this->factory, $this->debug, $this->defaultJavascriptsOutput, 'javascripts'),
-            new StaticTokenParser($this->factory, $this->debug, $this->defaultStylesheetsOutput, 'stylesheets'),
+            new StaticTokenParser($this->factory, 'javascripts', 'js/*.js', $this->debug),
+            new StaticTokenParser($this->factory, 'stylesheets', 'css/*.css', $this->debug),
+            new StaticTokenParser($this->factory, 'image', 'images/*', $this->debug, true),
         );
     }
 }

+ 2 - 2
src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/CreateHydratorDirectoryPass.php

@@ -20,10 +20,10 @@ class CreateHydratorDirectoryPass implements CompilerPassInterface
         $hydratorCacheDir = $container->getParameter('doctrine.odm.mongodb.hydrator_dir');
         if (!is_dir($hydratorCacheDir)) {
             if (false === @mkdir($hydratorCacheDir, 0777, true)) {
-                die(sprintf('Unable to create the Doctrine Hydrator directory (%s)', dirname($hydratorCacheDir)));
+                exit(sprintf('Unable to create the Doctrine Hydrator directory (%s)', dirname($hydratorCacheDir)));
             }
         } elseif (!is_writable($hydratorCacheDir)) {
-            die(sprintf('Unable to write in the Doctrine Hydrator directory (%s)', $hydratorCacheDir));
+            exit(sprintf('Unable to write in the Doctrine Hydrator directory (%s)', $hydratorCacheDir));
         }
     }
 

+ 2 - 2
src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/CreateProxyDirectoryPass.php

@@ -20,10 +20,10 @@ class CreateProxyDirectoryPass implements CompilerPassInterface
         $proxyCacheDir = $container->getParameter('doctrine.odm.mongodb.proxy_dir');
         if (!is_dir($proxyCacheDir)) {
             if (false === @mkdir($proxyCacheDir, 0777, true)) {
-                die(sprintf('Unable to create the Doctrine Proxy directory (%s)', dirname($proxyCacheDir)));
+                exit(sprintf('Unable to create the Doctrine Proxy directory (%s)', dirname($proxyCacheDir)));
             }
         } elseif (!is_writable($proxyCacheDir)) {
-            die(sprintf('Unable to write in the Doctrine Proxy directory (%s)', $proxyCacheDir));
+            exit(sprintf('Unable to write in the Doctrine Proxy directory (%s)', $proxyCacheDir));
         }
     }
 

+ 2 - 2
src/Symfony/Bundle/FrameworkBundle/Tests/Kernel.php

@@ -23,10 +23,10 @@ class Kernel extends BaseKernel
         $this->rootDir = sys_get_temp_dir().'/sf2_'.rand(1, 9999);
         if (!is_dir($this->rootDir)) {
             if (false === @mkdir($this->rootDir)) {
-                die(sprintf('Unable to create a temporary directory (%s)', $this->rootDir));
+                exit(sprintf('Unable to create a temporary directory (%s)', $this->rootDir));
             }
         } elseif (!is_writable($this->rootDir)) {
-            die(sprintf('Unable to write in a temporary directory (%s)', $this->rootDir));
+            exit(sprintf('Unable to write in a temporary directory (%s)', $this->rootDir));
         }
 
         parent::__construct('env', true);

+ 30 - 1
src/Symfony/Component/Finder/Finder.php

@@ -41,6 +41,7 @@ class Finder implements \IteratorAggregate
     private $ignoreVCS   = true;
     private $dirs        = array();
     private $dates       = array();
+    private $iterators   = array();
 
     /**
      * Restricts the matching to directories only.
@@ -356,7 +357,7 @@ class Finder implements \IteratorAggregate
             throw new \LogicException('You must call the in() method before iterating over a Finder.');
         }
 
-        if (1 === count($this->dirs)) {
+        if (1 === count($this->dirs) && 0 === count($this->iterators)) {
             return $this->searchInDirectory($this->dirs[0]);
         }
 
@@ -365,9 +366,37 @@ class Finder implements \IteratorAggregate
             $iterator->append($this->searchInDirectory($dir));
         }
 
+        foreach ($this->iterators as $it) {
+            $iterator->append($it);
+        }
+
         return $iterator;
     }
 
+    /**
+     * Appends an existing set of files/directories to the finder.
+     *
+     * The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array.
+     *
+     * @param mixed $iterator
+     */
+    public function append($iterator)
+    {
+        if ($iterator instanceof \IteratorAggregate) {
+            $this->iterators[] = $iterator->getIterator();
+        } elseif ($iterator instanceof \Iterator) {
+            $this->iterators[] = $iterator;
+        } elseif ($iterator instanceof \Traversable || is_array($iterator)) {
+            $it = new \ArrayIterator();
+            foreach ($iterator as $file) {
+                $it->append($file instanceof \SplFileInfo ? $file : new \SplFileInfo($file));
+            }
+            $this->iterators[] = $it;
+        } else {
+            throw new \InvalidArgumentException('Finder::append() method wrong argument type.');
+        }
+    }
+
     private function searchInDirectory($dir)
     {
         $flags = \RecursiveDirectoryIterator::SKIP_DOTS;

+ 2 - 2
src/Symfony/Component/HttpKernel/Kernel.php

@@ -520,10 +520,10 @@ abstract class Kernel implements KernelInterface
             $dir = $container->getParameter(sprintf('kernel.%s_dir', $name));
             if (!is_dir($dir)) {
                 if (false === @mkdir($dir, 0777, true)) {
-                    die(sprintf("Unable to create the %s directory (%s)\n", $name, dirname($dir)));
+                    exit(sprintf("Unable to create the %s directory (%s)\n", $name, dirname($dir)));
                 }
             } elseif (!is_writable($dir)) {
-                die(sprintf("Unable to write in the %s directory (%s)\n", $name, $dir));
+                exit(sprintf("Unable to write in the %s directory (%s)\n", $name, $dir));
             }
         }
 

+ 1 - 1
src/Symfony/Component/Locale/Resources/data/update-data.php

@@ -11,7 +11,7 @@
 
 function bailout($message)
 {
-    die($message."\n");
+    exit($message."\n");
 }
 
 function check_dir($source)

+ 8 - 3
src/Symfony/Component/Translation/Loader/CsvFileLoader.php

@@ -30,12 +30,17 @@ class CsvFileLoader extends ArrayLoader implements LoaderInterface
     public function load($resource, $locale, $domain = 'messages')
     {
         $messages = array();
-        $file = @fopen($resource, 'rb');
-        if (!$file) {
+        
+        try {
+            $file = new \SplFileObject($resource, 'rb');
+        } catch(\RuntimeException $e) {
             throw new \InvalidArgumentException(sprintf('Error opening file "%s".', $resource));
         }
+        
+        $file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
+        $file->setCsvControl(';');
 
-        while (($data = fgetcsv($file, 0, ';')) !== false) {
+        foreach($file as $data) {
             if (substr($data[0], 0, 1) === '#') {
                 continue;
             }

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

@@ -262,6 +262,29 @@ class FinderTest extends Iterator\RealIteratorTestCase
         $this->assertEquals($paths, $ref);
     }
 
+    public function testAppendWithAFinder()
+    {
+        $finder = new Finder();
+        $finder->files()->in(self::$tmpDir.'/foo');
+
+        $finder1 = new Finder();
+        $finder1->directories()->in(self::$tmpDir);
+
+        $finder->append($finder1);
+
+        $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator());
+    }
+
+    public function testAppendWithAnArray()
+    {
+        $finder = new Finder();
+        $finder->files()->in(self::$tmpDir.'/foo');
+
+        $finder->append($this->toAbsolute(array('foo', 'toto')));
+
+        $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator());
+    }
+
     protected function toAbsolute($files)
     {
         $f = array();