From f3e2c0835ff364cdda9f4fdb52eabb0ef21ba2f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Lorenzo=20Rodri=CC=81guez?= Date: Tue, 21 Dec 2010 23:45:22 -0430 Subject: [PATCH] First attempt at trying to fix App::objects() --- lib/Cake/Core/App.php | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index e541c5f51..1208603a2 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -421,13 +421,27 @@ class App { */ public static function objects($type, $path = null, $cache = true) { $objects = array(); - $extension = false; + $extension = '/\.php$/'; + $directories = false; $name = $type; + if (isset(self::$legacy[$type . 's'])) { + $type = self::$legacy[$type . 's']; + } + + if ($type === 'plugin') { + $type = 'plugins'; + } + + if ($type == 'plugins') { + $extension = '/.*/'; + $includeDirectories = true; + } + if ($type === 'file' && !$path) { return false; } elseif ($type === 'file') { - $extension = true; + $extension = '/.*/'; $name = $type . str_replace(DS, '', $path); } @@ -436,25 +450,21 @@ class App { } if (!isset(self::$__objects[$name]) || $cache !== true) { - $types = self::$types; - - if (!isset($types[$type])) { - return false; - } $objects = array(); if (empty($path)) { - $path = self::${"{$type}s"}; - if (isset($types[$type]['core']) && $types[$type]['core'] === false) { - array_pop($path); - } + $path = self::path($type); } $items = array(); foreach ((array)$path as $dir) { if ($dir != APP) { - $items = self::__list($dir, $types[$type]['suffix'], $extension); - $objects = array_merge($items, array_diff($objects, $items)); + $files = new RegexIterator(new DirectoryIterator($dir), $extension); + foreach ($files as $file) { + if (!$file->isDot() && (!$file->isDir() || $includeDirectories)) { + $objects[] = basename($file); + } + } } }