Changeset 32431
- Timestamp:
- 04/01/11 16:15:09 (2 years ago)
- Files:
-
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml (modified) (1 diff)
- branches/2.0/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php (modified) (1 diff)
- branches/2.0/src/Symfony/Component/Config/Resource/DirectoryResource.php (modified) (4 diffs)
- branches/2.0/src/Symfony/Component/HttpKernel/Debug/ErrorException.php (deleted)
- branches/2.0/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php (modified) (1 diff)
- branches/2.0/tests/Symfony/Tests/Component/Config/Resource/DirectoryResourceTest.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/2.0/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
r32378 r32431 138 138 @unlink($file); 139 139 140 $class = "$namespace\\$class"; 140 $class = "$namespace\\$class"; 141 141 142 142 return new $class($parent->getEnvironment(), $debug); branches/2.0/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php
r32299 r32431 63 63 } 64 64 65 foreach ((array) $events as $event) {65 foreach ((array) $events as $event) { 66 66 // Prevent duplicate entries 67 67 $this->listenerIds[$event][$serviceId] = $priority; branches/2.0/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
r32428 r32431 77 77 $container 78 78 ->getDefinition('error_handler')->addMethodCall('register', array()) 79 ->set Parameter(0, $config['error_handler'])79 ->setArgument(0, $config['error_handler']) 80 80 ; 81 81 } branches/2.0/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml
r32416 r32431 20 20 </service> 21 21 22 <service id="error_handler" class="%error_handler.class%" public="false">22 <service id="error_handler" class="%error_handler.class%"> 23 23 <argument /> <!-- level (null by default) --> 24 24 </service> branches/2.0/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
r32428 r32431 128 128 $this->assertContains( 129 129 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')), 131 131 '->registerTranslatorConfiguration() finds FrameworkExtension translation resources' 132 132 ); branches/2.0/src/Symfony/Component/Config/Resource/DirectoryResource.php
r32355 r32431 20 20 { 21 21 private $resource; 22 private $ filterRegexList;22 private $pattern; 23 23 24 24 /** … … 26 26 * 27 27 * @param string $resource The file path to the resource 28 * @param string $pattern A pattern to restrict monitored files 28 29 */ 29 public function __construct($resource )30 public function __construct($resource, $pattern = null) 30 31 { 31 32 $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; 52 34 } 53 35 … … 88 70 foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->resource), \RecursiveIteratorIterator::SELF_FIRST) as $file) { 89 71 // 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; 100 74 } 75 101 76 // always monitor directories for changes, except the .. entries 102 77 // (otherwise deleted files wouldn't get detected) … … 104 79 continue; 105 80 } 81 106 82 $newestMTime = max($file->getMTime(), $newestMTime); 107 83 } branches/2.0/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php
r32341 r32431 38 38 39 39 $collection = new RouteCollection(); 40 $resource = new DirectoryResource($dir); 41 $resource->setFilterRegexList(array('/\.php$/')); 42 $collection->addResource($resource); 40 $collection->addResource(new DirectoryResource($dir, '/\.php$/')); 43 41 foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { 44 42 if (!$file->isFile() || '.php' !== substr($file->getFilename(), -4)) { branches/2.0/tests/Symfony/Tests/Component/Config/Resource/DirectoryResourceTest.php
r32341 r32431 16 16 class DirectoryResourceTest extends \PHPUnit_Framework_TestCase 17 17 { 18 protected $resource;19 18 protected $directory; 20 19 … … 26 25 } 27 26 touch($this->directory.'/tmp.xml'); 28 $this->resource = new DirectoryResource($this->directory);29 27 } 30 28 … … 57 55 public function testGetResource() 58 56 { 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'); 60 59 } 61 60 … … 65 64 public function testIsFresh() 66 65 { 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'); 69 69 70 70 $resource = new DirectoryResource('/____foo/foobar'.rand(1, 999999)); … … 77 77 public function testIsFreshUpdateFile() 78 78 { 79 $resource = new DirectoryResource($this->directory); 79 80 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'); 81 82 } 82 83 … … 86 87 public function testIsFreshNewFile() 87 88 { 89 $resource = new DirectoryResource($this->directory); 88 90 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'); 90 92 } 91 93 … … 95 97 public function testIsFreshDeleteFile() 96 98 { 99 $resource = new DirectoryResource($this->directory); 97 100 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'); 99 102 } 100 103 … … 104 107 public function testIsFreshDeleteDirectory() 105 108 { 109 $resource = new DirectoryResource($this->directory); 106 110 $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'); 108 112 } 109 113 … … 116 120 mkdir($subdirectory); 117 121 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'); 119 124 120 125 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'); 122 127 } 123 128 … … 127 132 public function testIsFreshModifySubdirectory() 128 133 { 134 $resource = new DirectoryResource($this->directory); 135 129 136 $subdirectory = $this->directory.'/subdirectory'; 130 137 mkdir($subdirectory); 131 132 138 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 }135 139 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)'); 146 141 } 147 142 … … 151 146 public function testFilterRegexListNoMatch() 152 147 { 153 $regexes = array('#\.foo$#', '#\.xml$#'); 154 $this->resource->setFilterRegexList($regexes); 148 $resource = new DirectoryResource($this->directory, '/\.(foo|xml)$/'); 155 149 156 150 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'); 158 152 } 159 153 … … 163 157 public function testFilterRegexListMatch() 164 158 { 165 $regexes = array('#\.foo$#', '#\.xml$#'); 166 $this->resource->setFilterRegexList($regexes); 159 $resource = new DirectoryResource($this->directory, '/\.(foo|xml)$/'); 167 160 168 161 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 '); 170 163 } 171 172 164 }