ソースを参照

Remove RouteCollection::addExtensions().

RouteCollection::extensions() can now be used to add/set extensions.
ADmad 11 年 前
コミット
de7cbdc154

+ 19 - 15
src/Routing/RouteCollection.php

@@ -99,7 +99,7 @@ class RouteCollection {
 
 		$extensions = $route->extensions();
 		if ($extensions) {
-			$this->addExtensions($extensions);
+			$this->extensions($extensions);
 		}
 	}
 
@@ -275,26 +275,30 @@ class RouteCollection {
 	}
 
 /**
- * Add one or more extensions.
- *
- * @param array $extensions The extensions to add.
- * @return void
- */
-	public function addExtensions(array $extensions) {
-		$this->_extensions = array_unique(array_merge($this->_extensions, $extensions));
-	}
-
-/**
  * Get/set the extensions that the route collection could handle.
  *
- * @param null|string|array $extensions Either the list of extensions to set, or null to get.
+ * @param null|string|array $extensions Either the list of extensions to set,
+ *   or null to get.
+ * @param array $options Valid options:
+ *   - `merge` - Default true will merge extensions. Set to false to override
+ *     current extensions
  * @return array The valid extensions.
  */
-	public function extensions($extensions = null) {
+	public function extensions($extensions = null, array $options = []) {
 		if ($extensions === null) {
-			return array_unique($this->_extensions);
+			return $this->_extensions;
+		}
+
+		$options += ['merge' => true];
+		$extensions = (array)$extensions;
+		if ($options['merge']) {
+			$extensions = array_unique(array_merge(
+				$this->_extensions,
+				$extensions
+			));
 		}
-		$this->_extensions = (array)$extensions;
+
+		return $this->_extensions = $extensions;
 	}
 
 }

+ 3 - 3
tests/TestCase/Routing/RouteCollectionTest.php

@@ -305,10 +305,10 @@ class RouteCollectionTest extends TestCase {
 		$this->assertEquals(['json'], $this->collection->extensions());
 
 		$this->collection->extensions(['rss', 'xml']);
-		$this->assertEquals(['rss', 'xml'], $this->collection->extensions());
+		$this->assertEquals(['json', 'rss', 'xml'], $this->collection->extensions());
 
-		$this->collection->addExtensions(['json']);
-		$this->assertEquals(['rss', 'xml', 'json'], $this->collection->extensions());
+		$this->collection->extensions(['csv'], ['merge' => false]);
+		$this->assertEquals(['csv'], $this->collection->extensions());
 	}
 
 }