Browse Source

Remove reliance on App::objects() from Plugin::loadAll()

App::objects() is going away as it has a number of annoying flaws that
are not easily fixable. It cannot:

* Find prefix controllers.
* Find vendor namespaced plugins.
* Find entity classes etc.

In light of all this, it would be better if each of the callers
implemented the directory scanning logic they needed and App::objects()
was not a source of lies.

Refs #4256
mark_story 11 years ago
parent
commit
3f10889ed8
1 changed files with 14 additions and 1 deletions
  1. 14 1
      src/Core/Plugin.php

+ 14 - 1
src/Core/Plugin.php

@@ -15,6 +15,7 @@
 namespace Cake\Core;
 
 use Cake\Core\ClassLoader;
+use \DirectoryIterator;
 
 /**
  * Plugin is used to load and locate plugins.
@@ -188,7 +189,19 @@ class Plugin {
  * @return void
  */
 	public static function loadAll(array $options = []) {
-		$plugins = App::objects('Plugin');
+		$plugins = [];
+		foreach (App::path('Plugin') as $path) {
+			if (!is_dir($path)) {
+				continue;
+			}
+			$dir = new DirectoryIterator($path);
+			foreach ($dir as $path) {
+				if ($path->isDir() && !$path->isDot()) {
+					$plugins[] = $path->getBaseName();
+				}
+			}
+		}
+
 		foreach ($plugins as $p) {
 			$opts = isset($options[$p]) ? $options[$p] : null;
 			if ($opts === null && isset($options[0])) {