Development

Changeset 32431

You must first sign up to be able to contribute.

Changeset 32431

Show
Ignore:
Timestamp:
04/01/11 16:15:09 (3 years ago)
Author:
fabien
Message:

Merge branch 'master' of git://github.com/symfony/symfony

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

    r32378 r32431  
    138138        @unlink($file); 
    139139 
    140         $class = "$namespace\\$class";  
     140        $class = "$namespace\\$class"; 
    141141 
    142142        return new $class($parent->getEnvironment(), $debug); 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php

    r32299 r32431  
    6363        } 
    6464 
    65         foreach ((array)$events as $event) { 
     65        foreach ((array) $events as $event) { 
    6666            // Prevent duplicate entries 
    6767            $this->listenerIds[$event][$serviceId] = $priority; 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

    r32428 r32431  
    7777                $container 
    7878                    ->getDefinition('error_handler')->addMethodCall('register', array()) 
    79                     ->setParameter(0, $config['error_handler']) 
     79                    ->setArgument(0, $config['error_handler']) 
    8080                ; 
    8181            } 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml

    r32416 r32431  
    2020        </service> 
    2121 
    22         <service id="error_handler" class="%error_handler.class%" public="false"
     22        <service id="error_handler" class="%error_handler.class%"
    2323            <argument /> <!-- level (null by default) --> 
    2424        </service> 
  • branches/2.0/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

    r32428 r32431  
    128128        $this->assertContains( 
    129129            realpath(__DIR__.'/../../Resources/translations/validators.fr.xliff'), 
    130             array_map(function($resource) { return $resource[1]; }, $container->getParameter('translation.resources')), 
     130            array_map(function($resource) { return realpath($resource[1]); }, $container->getParameter('translation.resources')), 
    131131            '->registerTranslatorConfiguration() finds FrameworkExtension translation resources' 
    132132        ); 
  • branches/2.0/src/Symfony/Component/Config/Resource/DirectoryResource.php

    r32355 r32431  
    2020{ 
    2121    private $resource; 
    22     private $filterRegexList
     22    private $pattern
    2323 
    2424    /** 
     
    2626     * 
    2727     * @param string $resource The file path to the resource 
     28     * @param string $pattern  A pattern to restrict monitored files 
    2829     */ 
    29     public function __construct($resource
     30    public function __construct($resource, $pattern = null
    3031    { 
    3132        $this->resource = $resource; 
    32     } 
    33  
    34     /** 
    35      * Set a list of filter regex (to restrict the list of monitored files) 
    36      * 
    37      * @param array $filterRegexList An array of regular expressions 
    38      */ 
    39     public function setFilterRegexList(array $filterRegexList) 
    40     { 
    41         $this->filterRegexList = $filterRegexList; 
    42     } 
    43  
    44     /** 
    45      * Returns the list of filter regex 
    46      * 
    47      * @return array An array of regular expressions 
    48      */ 
    49     public function getFilterRegexList() 
    50     { 
    51         return $this->filterRegexList; 
     33        $this->pattern = $pattern; 
    5234    } 
    5335 
     
    8870        foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->resource), \RecursiveIteratorIterator::SELF_FIRST) as $file) { 
    8971            // if regex filtering is enabled only check matching files 
    90             if (isset($this->filterRegexList) && $file->isFile()) { 
    91                 $regexMatched = false; 
    92                 foreach ($this->filterRegexList as $regex) { 
    93                     if (preg_match($regex, $file->__toString())) { 
    94                         $regexMatched = true; 
    95                     } 
    96                 } 
    97                 if (!$regexMatched) { 
    98                   continue; 
    99                 } 
     72            if ($this->pattern && $file->isFile() && !preg_match($this->pattern, $file->getBasename())) { 
     73                continue; 
    10074            } 
     75 
    10176            // always monitor directories for changes, except the .. entries 
    10277            // (otherwise deleted files wouldn't get detected) 
     
    10479                continue; 
    10580            } 
     81 
    10682            $newestMTime = max($file->getMTime(), $newestMTime); 
    10783        } 
  • branches/2.0/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php

    r32341 r32431  
    3838 
    3939        $collection = new RouteCollection(); 
    40         $resource = new DirectoryResource($dir); 
    41         $resource->setFilterRegexList(array('/\.php$/')); 
    42         $collection->addResource($resource); 
     40        $collection->addResource(new DirectoryResource($dir, '/\.php$/')); 
    4341        foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { 
    4442            if (!$file->isFile() || '.php' !== substr($file->getFilename(), -4)) { 
  • branches/2.0/tests/Symfony/Tests/Component/Config/Resource/DirectoryResourceTest.php

    r32341 r32431  
    1616class DirectoryResourceTest extends \PHPUnit_Framework_TestCase 
    1717{ 
    18     protected $resource; 
    1918    protected $directory; 
    2019 
     
    2625        } 
    2726        touch($this->directory.'/tmp.xml'); 
    28         $this->resource = new DirectoryResource($this->directory); 
    2927    } 
    3028 
     
    5755    public function testGetResource() 
    5856    { 
    59         $this->assertEquals($this->directory, $this->resource->getResource(), '->getResource() returns the path to the resource'); 
     57        $resource = new DirectoryResource($this->directory); 
     58        $this->assertEquals($this->directory, $resource->getResource(), '->getResource() returns the path to the resource'); 
    6059    } 
    6160 
     
    6564    public function testIsFresh() 
    6665    { 
    67         $this->assertTrue($this->resource->isFresh(time() + 10), '->isFresh() returns true if the resource has not changed'); 
    68         $this->assertFalse($this->resource->isFresh(time() - 86400), '->isFresh() returns false if the resource has been updated'); 
     66        $resource = new DirectoryResource($this->directory); 
     67        $this->assertTrue($resource->isFresh(time() + 10), '->isFresh() returns true if the resource has not changed'); 
     68        $this->assertFalse($resource->isFresh(time() - 86400), '->isFresh() returns false if the resource has been updated'); 
    6969 
    7070        $resource = new DirectoryResource('/____foo/foobar'.rand(1, 999999)); 
     
    7777    public function testIsFreshUpdateFile() 
    7878    { 
     79        $resource = new DirectoryResource($this->directory); 
    7980        touch($this->directory.'/tmp.xml', time() + 20); 
    80         $this->assertFalse($this->resource->isFresh(time() + 10), '->isFresh() returns false if an existing file is modified'); 
     81        $this->assertFalse($resource->isFresh(time() + 10), '->isFresh() returns false if an existing file is modified'); 
    8182    } 
    8283 
     
    8687    public function testIsFreshNewFile() 
    8788    { 
     89        $resource = new DirectoryResource($this->directory); 
    8890        touch($this->directory.'/new.xml', time() + 20); 
    89         $this->assertFalse($this->resource->isFresh(time() + 10), '->isFresh() returns false if a new file is added'); 
     91        $this->assertFalse($resource->isFresh(time() + 10), '->isFresh() returns false if a new file is added'); 
    9092    } 
    9193 
     
    9597    public function testIsFreshDeleteFile() 
    9698    { 
     99        $resource = new DirectoryResource($this->directory); 
    97100        unlink($this->directory.'/tmp.xml'); 
    98         $this->assertFalse($this->resource->isFresh(time()), '->isFresh() returns false if an existing file is removed'); 
     101        $this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if an existing file is removed'); 
    99102    } 
    100103 
     
    104107    public function testIsFreshDeleteDirectory() 
    105108    { 
     109        $resource = new DirectoryResource($this->directory); 
    106110        $this->removeDirectory($this->directory); 
    107         $this->assertFalse($this->resource->isFresh(time()), '->isFresh() returns false if the whole resource is removed'); 
     111        $this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if the whole resource is removed'); 
    108112    } 
    109113 
     
    116120        mkdir($subdirectory); 
    117121 
    118         $this->assertTrue($this->resource->isFresh(time() + 10), '->isFresh() returns true if an unmodified subdirectory exists'); 
     122        $resource = new DirectoryResource($this->directory); 
     123        $this->assertTrue($resource->isFresh(time() + 10), '->isFresh() returns true if an unmodified subdirectory exists'); 
    119124 
    120125        touch($subdirectory.'/newfile.xml', time() + 20); 
    121         $this->assertFalse($this->resource->isFresh(time() + 10), '->isFresh() returns false if a new file in a subdirectory is added'); 
     126        $this->assertFalse($resource->isFresh(time() + 10), '->isFresh() returns false if a new file in a subdirectory is added'); 
    122127    } 
    123128 
     
    127132    public function testIsFreshModifySubdirectory() 
    128133    { 
     134        $resource = new DirectoryResource($this->directory); 
     135 
    129136        $subdirectory = $this->directory.'/subdirectory'; 
    130137        mkdir($subdirectory); 
    131          
    132138        touch($subdirectory, time() + 20); 
    133         $this->assertFalse($this->resource->isFresh(time() + 10), '->isFresh() returns false if a subdirectory is modified (e.g. a file gets deleted)'); 
    134     } 
    135139 
    136     /** 
    137      * @covers Symfony\Component\Config\Resource\DirectoryResource::setFilterRegexList 
    138      * @covers Symfony\Component\Config\Resource\DirectoryResource::getFilterRegexList 
    139      */ 
    140 public function testSetFilterRegexList() 
    141     { 
    142         $regexes = array('#\.foo$#', '#\.xml$#'); 
    143         $this->resource->setFilterRegexList($regexes); 
    144  
    145         $this->assertEquals($regexes, $this->resource->getFilterRegexList(), '->getFilterRegexList() returns the previously defined list of filter regexes'); 
     140        $this->assertFalse($resource->isFresh(time() + 10), '->isFresh() returns false if a subdirectory is modified (e.g. a file gets deleted)'); 
    146141    } 
    147142 
     
    151146    public function testFilterRegexListNoMatch() 
    152147    { 
    153         $regexes = array('#\.foo$#', '#\.xml$#'); 
    154         $this->resource->setFilterRegexList($regexes); 
     148        $resource = new DirectoryResource($this->directory, '/\.(foo|xml)$/'); 
    155149 
    156150        touch($this->directory.'/new.bar', time() + 20); 
    157         $this->assertTrue($this->resource->isFresh(time() + 10), '->isFresh() returns true if a new file not matching the filter regex is created'); 
     151        $this->assertTrue($resource->isFresh(time() + 10), '->isFresh() returns true if a new file not matching the filter regex is created'); 
    158152    } 
    159153 
     
    163157    public function testFilterRegexListMatch() 
    164158    { 
    165         $regexes = array('#\.foo$#', '#\.xml$#'); 
    166         $this->resource->setFilterRegexList($regexes); 
     159        $resource = new DirectoryResource($this->directory, '/\.(foo|xml)$/'); 
    167160 
    168161        touch($this->directory.'/new.xml', time() + 20); 
    169         $this->assertFalse($this->resource->isFresh(time() + 10), '->isFresh() returns false if an new file matching the filter regex is created '); 
     162        $this->assertFalse($resource->isFresh(time() + 10), '->isFresh() returns false if an new file matching the filter regex is created '); 
    170163    } 
    171  
    172164}