Browse Source

Merge remote branch 'symfony/master' into experimental

Bernhard Schussek 14 years ago
parent
commit
a396f8fdc8
23 changed files with 109 additions and 63 deletions
  1. 1 1
      src/Symfony/Bundle/AsseticBundle/Tests/FunctionalTest.php
  2. 1 1
      src/Symfony/Bundle/DoctrineBundle/Command/CreateDatabaseDoctrineCommand.php
  3. 1 1
      src/Symfony/Bundle/DoctrineBundle/Command/DropDatabaseDoctrineCommand.php
  4. 1 1
      src/Symfony/Bundle/DoctrineBundle/Command/LoadDataFixturesDoctrineCommand.php
  5. 1 1
      src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php
  6. 2 2
      src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php
  7. 1 1
      src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
  8. 1 1
      src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml
  9. 2 2
      src/Symfony/Bundle/FrameworkBundle/Resources/translations/validators.ru.xliff
  10. 1 0
      src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.html.twig
  11. 1 1
      src/Symfony/Bundle/FrameworkBundle/Tests/Kernel.php
  12. 1 1
      src/Symfony/Bundle/FrameworkBundle/Tests/Util/MustacheTest.php
  13. 1 0
      src/Symfony/Bundle/SecurityBundle/Resources/config/security_rememberme.xml
  14. 35 44
      src/Symfony/Bundle/FrameworkBundle/Util/Filesystem.php
  15. 1 1
      src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php
  16. 1 1
      src/Symfony/Component/Routing/Generator/UrlGenerator.php
  17. 1 1
      src/Symfony/Component/Routing/Generator/UrlGeneratorInterface.php
  18. 4 1
      src/Symfony/Component/Security/Acl/Voter/AclVoter.php
  19. 1 0
      src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php
  20. 1 0
      src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php
  21. 3 1
      tests/Symfony/Tests/Component/HttpKernel/HttpCache/HttpCacheTest.php
  22. 46 0
      tests/Symfony/Tests/Component/Security/Acl/Voter/AclVoterTest.php
  23. 1 1
      vendors.sh

+ 1 - 1
src/Symfony/Bundle/AsseticBundle/Tests/FunctionalTest.php

@@ -13,7 +13,7 @@ namespace Symfony\Bundle\AsseticBundle\Tests;
 
 use Symfony\Component\DomCrawler\Crawler;
 use Symfony\Component\HttpFoundation\Request;
-use Symfony\Bundle\FrameworkBundle\Util\Filesystem;
+use Symfony\Component\HttpKernel\Util\Filesystem;
 
 /**
  * @group functional

+ 1 - 1
src/Symfony/Bundle/DoctrineBundle/Command/CreateDatabaseDoctrineCommand.php

@@ -16,7 +16,7 @@ use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Output\Output;
-use Symfony\Bundle\FrameworkBundle\Util\Filesystem;
+use Symfony\Component\HttpKernel\Util\Filesystem;
 use Doctrine\DBAL\Connection;
 
 /**

+ 1 - 1
src/Symfony/Bundle/DoctrineBundle/Command/DropDatabaseDoctrineCommand.php

@@ -16,7 +16,7 @@ use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Output\Output;
-use Symfony\Bundle\FrameworkBundle\Util\Filesystem;
+use Symfony\Component\HttpKernel\Util\Filesystem;
 use Doctrine\DBAL\Connection;
 
 /**

+ 1 - 1
src/Symfony/Bundle/DoctrineBundle/Command/LoadDataFixturesDoctrineCommand.php

@@ -17,7 +17,7 @@ use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Output\Output;
 use Symfony\Component\Finder\Finder;
-use Symfony\Bundle\FrameworkBundle\Util\Filesystem;
+use Symfony\Component\HttpKernel\Util\Filesystem;
 use Symfony\Bundle\DoctrineAbstractBundle\Common\DataFixtures\Loader as DataFixturesLoader;
 use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
 use Doctrine\Common\DataFixtures\Purger\ORMPurger;

+ 1 - 1
src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php

@@ -17,7 +17,7 @@ use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Output\Output;
 use Symfony\Component\Finder\Finder;
-use Symfony\Bundle\FrameworkBundle\Util\Filesystem;
+use Symfony\Component\HttpKernel\Util\Filesystem;
 use Symfony\Bundle\DoctrineAbstractBundle\Common\DataFixtures\Loader as DataFixturesLoader;
 use Doctrine\Common\DataFixtures\Executor\MongoDBExecutor;
 use Doctrine\Common\DataFixtures\Purger\MongoDBPurger;

+ 2 - 2
src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php

@@ -52,7 +52,7 @@ class AssetsInstallCommand extends Command
         $filesystem = $this->container->get('filesystem');
 
         // Create the bundles directory otherwise symlink will fail.
-        $filesystem->mkdirs($input->getArgument('target').'/bundles/', 0777);
+        $filesystem->mkdir($input->getArgument('target').'/bundles/', 0777);
 
         foreach ($this->container->get('kernel')->getBundles() as $bundle) {
             if (is_dir($originDir = $bundle->getPath().'/Resources/public')) {
@@ -65,7 +65,7 @@ class AssetsInstallCommand extends Command
                 if ($input->getOption('symlink')) {
                     $filesystem->symlink($originDir, $targetDir);
                 } else {
-                    $filesystem->mkdirs($targetDir, 0777);
+                    $filesystem->mkdir($targetDir, 0777);
                     $filesystem->mirror($originDir, $targetDir);
                 }
             }

+ 1 - 1
src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

@@ -132,7 +132,7 @@ namespace $namespace
     }
 }
 EOF;
-        $this->container->get('filesystem')->mkdirs($warmupDir);
+        $this->container->get('filesystem')->mkdir($warmupDir);
         file_put_contents($file = $warmupDir.'/kernel.tmp', $code);
         require_once $file;
         @unlink($file);

+ 1 - 1
src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml

@@ -9,7 +9,7 @@
         <parameter key="http_kernel.class">Symfony\Bundle\FrameworkBundle\HttpKernel</parameter>
         <parameter key="error_handler.class">Symfony\Component\HttpKernel\Debug\ErrorHandler</parameter>
         <parameter key="error_handler.level">null</parameter>
-        <parameter key="filesystem.class">Symfony\Bundle\FrameworkBundle\Util\Filesystem</parameter>
+        <parameter key="filesystem.class">Symfony\Component\HttpKernel\Util\Filesystem</parameter>
         <parameter key="cache_warmer.class">Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate</parameter>
         <parameter key="cache_warmer.autoloader_map.class">Symfony\Bundle\FrameworkBundle\CacheWarmer\ClassMapCacheWarmer</parameter>
         <parameter key="file_locator.class">Symfony\Component\HttpKernel\Config\FileLocator</parameter>

+ 2 - 2
src/Symfony/Bundle/FrameworkBundle/Resources/translations/validators.ru.xliff

@@ -8,7 +8,7 @@
             </trans-unit>
             <trans-unit id="2">
                 <source>This value should be true</source>
-                <target>Значение должно быть точным</target>
+                <target>Значение должно быть истинным</target>
             </trans-unit>
             <trans-unit id="3">
                 <source>This value should be of type {{ type }}</source>
@@ -40,7 +40,7 @@
             </trans-unit>
             <trans-unit id="10">
                 <source>This value is not a valid date</source>
-                <target>Значение даты недопустимо</target>
+                <target>Значение не является правильной датой</target>
             </trans-unit>
             <trans-unit id="11">
                 <source>This value is not a valid datetime</source>

+ 1 - 0
src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.html.twig

@@ -2,6 +2,7 @@
 <html>
     <head>
         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+        <title>An Error Occurred: {{ status_text }}</title>
     </head>
     <body>
         <h1>Oops! An Error Occurred</h1>

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

@@ -12,7 +12,7 @@
 namespace Symfony\Bundle\FrameworkBundle\Tests;
 
 use Symfony\Component\HttpKernel\Kernel as BaseKernel;
-use Symfony\Bundle\FrameworkBundle\Util\Filesystem;
+use Symfony\Component\HttpKernel\Util\Filesystem;
 use Symfony\Component\ClassLoader\UniversalClassLoader;
 use Symfony\Component\Config\Loader\LoaderInterface;
 

+ 1 - 1
src/Symfony/Bundle/FrameworkBundle/Tests/Util/MustacheTest.php

@@ -13,7 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Util;
 
 use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
 use Symfony\Bundle\FrameworkBundle\Util\Mustache;
-use Symfony\Bundle\FrameworkBundle\Util\Filesystem;
+use Symfony\Component\HttpKernel\Util\Filesystem;
 
 class MustacheTest extends TestCase
 {

+ 1 - 0
src/Symfony/Bundle/SecurityBundle/Resources/config/security_rememberme.xml

@@ -22,6 +22,7 @@
             <argument type="service" id="security.authentication.rememberme" />
             <argument type="service" id="security.authentication.manager" />
             <argument type="service" id="logger" on-invalid="null" />
+            <argument type="service" id="event_dispatcher" on-invalid="null"/>
         </service>
         
         <service id="security.authentication.provider.rememberme" class="%security.authentication.provider.rememberme.class%" abstract="true" public="false">

+ 35 - 44
src/Symfony/Bundle/FrameworkBundle/Util/Filesystem.php

@@ -9,7 +9,7 @@
  * file that was distributed with this source code.
  */
 
-namespace Symfony\Bundle\FrameworkBundle\Util;
+namespace Symfony\Component\HttpKernel\Util;
 
 /**
  * Provides basic utility to manipulate the file system.
@@ -25,19 +25,13 @@ class Filesystem
      *
      * By default, if the target already exists, it is not overridden.
      *
-     * To override existing files, pass the "override" option.
-     *
      * @param string $originFile  The original filename
      * @param string $targetFile  The target filename
-     * @param array  $options     An array of options
+     * @param array  $override    Whether to override an existing file or not
      */
-    public function copy($originFile, $targetFile, $options = array())
+    public function copy($originFile, $targetFile, $override = false)
     {
-        if (!array_key_exists('override', $options)) {
-            $options['override'] = false;
-        }
-
-        $this->mkdirs(dirname($targetFile));
+        $this->mkdir(dirname($targetFile));
 
         $mostRecent = false;
         if (file_exists($targetFile)) {
@@ -46,7 +40,7 @@ class Filesystem
             $mostRecent = $statOrigin['mtime'] > $statTarget['mtime'];
         }
 
-        if ($options['override'] || !file_exists($targetFile) || $mostRecent) {
+        if ($override || !file_exists($targetFile) || $mostRecent) {
             copy($originFile, $targetFile);
         }
     }
@@ -54,32 +48,33 @@ class Filesystem
     /**
      * Creates a directory recursively.
      *
-     * @param  string $path  The directory path
-     * @param  int    $mode  The directory mode
+     * @param  string|array|\Traversable $dirs The directory path
+     * @param  int                       $mode The directory mode
      *
      * @return Boolean true if the directory has been created, false otherwise
      */
-    public function mkdirs($path, $mode = 0777)
+    public function mkdir($dirs, $mode = 0777)
     {
-        if (is_dir($path)) {
-            return true;
+        $ret = false;
+        foreach ($this->toIterator($dirs) as $dir) {
+            if (is_dir($dir)) {
+                continue;
+            }
+
+            $ret = @mkdir($dir, $mode, true) && $ret;
         }
 
-        return @mkdir($path, $mode, true);
+        return $ret;
     }
 
     /**
      * Creates empty files.
      *
-     * @param mixed $files  The filename, or an array of filenames
+     * @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to remove
      */
     public function touch($files)
     {
-        if (!is_array($files)) {
-            $files = array($files);
-        }
-
-        foreach ($files as $file) {
+        foreach ($this->toIterator($files) as $file) {
             touch($file);
         }
     }
@@ -87,14 +82,11 @@ class Filesystem
     /**
      * Removes files or directories.
      *
-     * @param mixed $files  A filename or an array of files to remove
+     * @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to remove
      */
     public function remove($files)
     {
-        if (!is_array($files)) {
-            $files = array($files);
-        }
-
+        $files = iterator_to_array($this->toIterator($files));
         $files = array_reverse($files);
         foreach ($files as $file) {
             if (!file_exists($file)) {
@@ -102,13 +94,7 @@ class Filesystem
             }
 
             if (is_dir($file) && !is_link($file)) {
-                $fp = opendir($file);
-                while (false !== $item = readdir($fp)) {
-                    if (!in_array($item, array('.', '..'))) {
-                        $this->remove($file.'/'.$item);
-                    }
-                }
-                closedir($fp);
+                $this->remove(new \FilesystemIterator($file));
 
                 rmdir($file);
             } else {
@@ -120,20 +106,16 @@ class Filesystem
     /**
      * Change mode for an array of files or directories.
      *
-     * @param array   $files  An array of files or directories
-     * @param integer $mode   The new mode
-     * @param integer $umask  The mode mask (octal)
+     * @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to remove
+     * @param integer                   $mode  The new mode
+     * @param integer                   $umask The mode mask (octal)
      */
     public function chmod($files, $mode, $umask = 0000)
     {
         $currentUmask = umask();
         umask($umask);
 
-        if (!is_array($files)) {
-            $files = array($files);
-        }
-
-        foreach ($files as $file) {
+        foreach ($this->toIterator($files) as $file) {
             chmod($file, $mode);
         }
 
@@ -215,7 +197,7 @@ class Filesystem
             $target = $targetDir.'/'.str_replace($originDir.DIRECTORY_SEPARATOR, '', $file->getPathname());
 
             if (is_dir($file)) {
-                $this->mkdirs($target);
+                $this->mkdir($target);
             } else if (is_file($file)) {
                 $this->copy($file, $target, $options);
             } else if (is_link($file)) {
@@ -225,4 +207,13 @@ class Filesystem
             }
         }
     }
+
+    private function toIterator($files)
+    {
+        if (!$files instanceof \Traversable) {
+            $files = new \ArrayObject(is_array($files) ? $files : array($files));
+        }
+
+        return $files;
+    }
 }

+ 1 - 1
src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php

@@ -79,7 +79,7 @@ EOF
 
         return <<<EOF
 
-    public function generate(\$name, array \$parameters, \$absolute = false)
+    public function generate(\$name, array \$parameters = array(), \$absolute = false)
     {
         if (!isset(self::\$declaredRouteNames[\$name])) {
             throw new \InvalidArgumentException(sprintf('Route "%s" does not exist.', \$name));

+ 1 - 1
src/Symfony/Component/Routing/Generator/UrlGenerator.php

@@ -63,7 +63,7 @@ class UrlGenerator implements UrlGeneratorInterface
      *
      * @throws \InvalidArgumentException When route doesn't exist
      */
-    public function generate($name, array $parameters, $absolute = false)
+    public function generate($name, array $parameters = array(), $absolute = false)
     {
         if (null === $route = $this->routes->get($name)) {
             throw new \InvalidArgumentException(sprintf('Route "%s" does not exist.', $name));

+ 1 - 1
src/Symfony/Component/Routing/Generator/UrlGeneratorInterface.php

@@ -27,5 +27,5 @@ interface UrlGeneratorInterface
      *
      * @return string The generated URL
      */
-    function generate($name, array $parameters, $absolute = false);
+    function generate($name, array $parameters = array(), $absolute = false);
 }

+ 4 - 1
src/Symfony/Component/Security/Acl/Voter/AclVoter.php

@@ -18,6 +18,7 @@ use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
 use Symfony\Component\Security\Acl\Exception\NoAceFoundException;
 use Symfony\Component\Security\Acl\Exception\AclNotFoundException;
 use Symfony\Component\Security\Acl\Model\AclProviderInterface;
+use Symfony\Component\Security\Acl\Model\ObjectIdentityInterface;
 use Symfony\Component\Security\Acl\Permission\PermissionMapInterface;
 use Symfony\Component\Security\Acl\Model\SecurityIdentityRetrievalStrategyInterface;
 use Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface;
@@ -78,7 +79,9 @@ class AclVoter implements VoterInterface
                     $field = null;
                 }
 
-                if (null === $oid = $this->objectIdentityRetrievalStrategy->getObjectIdentity($object)) {
+                if ($object instanceof ObjectIdentityInterface) {
+                    $oid = $object;
+                } else if (null === $oid = $this->objectIdentityRetrievalStrategy->getObjectIdentity($object)) {
                     if (null !== $this->logger) {
                         $this->logger->debug(sprintf('Object identity unavailable. Voting to %s', $this->allowIfObjectIdentityUnavailable? 'grant access' : 'abstain'));
                     }

+ 1 - 0
src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php

@@ -67,6 +67,7 @@ abstract class AbstractAuthenticationListener implements ListenerInterface
      * @param AuthenticationManagerInterface $authenticationManager An AuthenticationManagerInterface instance
      * @param array                          $options               An array of options for the processing of a successful, or failed authentication attempt
      * @param LoggerInterface                $logger                A LoggerInterface instance
+     * @param EventDispatcherInterface       $dispatcher            An EventDispatcherInterface instance
      */
     public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, $providerKey, array $options = array(), AuthenticationSuccessHandlerInterface $successHandler = null, AuthenticationFailureHandlerInterface $failureHandler = null, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null)
     {

+ 1 - 0
src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php

@@ -47,6 +47,7 @@ class RememberMeListener implements ListenerInterface
      * @param RememberMeServicesInterface $rememberMeServices
      * @param AuthenticationManagerInterface $authenticationManager
      * @param LoggerInterface $logger
+     * @param EventDispatcherInterface $dispatcher
      */
     public function __construct(SecurityContext $securityContext, RememberMeServicesInterface $rememberMeServices, AuthenticationManagerInterface $authenticationManager, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null)
     {

+ 3 - 1
tests/Symfony/Tests/Component/HttpKernel/HttpCache/HttpCacheTest.php

@@ -923,7 +923,9 @@ class HttpCacheTest extends HttpCacheTestCase
 
         $this->request('GET', '/', array(), array(), true);
         $this->assertEquals("Hello World! My name is Bobby.", $this->response->getContent());
-        $this->assertEquals(100, $this->response->getTtl());
+
+        // check for 100 or 99 as the test can be executed after a second change
+        $this->assertTrue(in_array($this->response->getTtl(), array(99, 100)));
     }
 
     public function testEsiCacheForceValidation()

+ 46 - 0
tests/Symfony/Tests/Component/Security/Acl/Voter/AclVoterTest.php

@@ -360,6 +360,52 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
 
         $this->assertSame(VoterInterface::ACCESS_DENIED, $voter->vote($this->getToken(), new FieldVote(new \stdClass(), 'foo'), array('VIEW')));
     }
+    
+    public function testWhenReceivingAnObjectIdentityInterfaceWeDontRetrieveANewObjectIdentity()
+    {
+        list($voter, $provider, $permissionMap, $oidStrategy, $sidStrategy) = $this->getVoter();
+        
+        $oid = new ObjectIdentity('someID','someType');
+        
+        $permissionMap
+            ->expects($this->once())
+            ->method('contains')
+            ->will($this->returnValue(true))
+        ;
+        $permissionMap
+            ->expects($this->once())
+            ->method('getMasks')
+            ->with($this->equalTo('VIEW'))
+            ->will($this->returnValue($masks = array(1, 2, 3)))
+        ;
+
+        $oidStrategy
+            ->expects($this->never())
+            ->method('getObjectIdentity')
+        ;
+
+        $sidStrategy
+            ->expects($this->once())
+            ->method('getSecurityIdentities')
+            ->will($this->returnValue($sids = array(new UserSecurityIdentity('johannes', 'Foo'), new RoleSecurityIdentity('ROLE_FOO'))))
+        ;
+
+        $provider
+            ->expects($this->once())
+            ->method('findAcl')
+            ->with($this->equalTo($oid), $this->equalTo($sids))
+            ->will($this->returnValue($acl = $this->getMock('Symfony\Component\Security\Acl\Model\AclInterface')))
+        ;
+
+        $acl
+            ->expects($this->once())
+            ->method('isGranted')
+            ->with($this->identicalTo($masks), $this->equalTo($sids), $this->isFalse())
+            ->will($this->throwException(new NoAceFoundException('No ACE')))
+        ;
+
+        $voter->vote($this->getToken(), $oid, array('VIEW'));
+    }
 
     protected function getToken()
     {

+ 1 - 1
vendors.sh

@@ -35,7 +35,7 @@ install_git()
 }
 
 # Assetic
-install_git assetic git://github.com/kriswallsmith/assetic.git v1.0.0alpha1
+install_git assetic git://github.com/kriswallsmith/assetic.git
 
 # Doctrine ORM
 install_git doctrine git://github.com/doctrine/doctrine2.git