Permalink
Browse files

Reduce dependency on JFolder and JFile.

  • Loading branch information...
1 parent 2aa4739 commit fda2d9b4688b6db18669fe20717fbd332a5b3c43 @realityking realityking committed Aug 27, 2012
View
38 libraries/joomla/base/adapter.php
@@ -9,9 +9,6 @@
defined('JPATH_PLATFORM') or die;
-jimport('joomla.filesystem.file');
-jimport('joomla.filesystem.folder');
-
/**
* Adapter Class
* Retains common adapter pattern functions
@@ -165,27 +162,34 @@ public function getAdapter($name, $options = array())
*/
public function loadAllAdapters($options = array())
{
- $list = JFolder::files($this->_basepath . '/' . $this->_adapterfolder);
+ $files = new DirectoryIterator($this->_basepath . '/' . $this->_adapterfolder);
- foreach ($list as $filename)
+ foreach ($files as $file)
{
- if (JFile::getExt($filename) == 'php')
+ $fileName = $file->getFilename();
+
+ // Only load for php files.
+ // Note: DirectoryIterator::getExtension only available PHP >= 5.3.6
+ if (!$file->isFile() || substr($fileName, strrpos($fileName, '.') + 1) != 'php')
{
- // Try to load the adapter object
- require_once $this->_basepath . '/' . $this->_adapterfolder . '/' . $filename;
+ continue;
+ }
- $name = JFile::stripExt($filename);
- $class = $this->_classprefix . ucfirst($name);
+ // Try to load the adapter object
+ require_once $this->_basepath . '/' . $this->_adapterfolder . '/' . $fileName;
- if (!class_exists($class))
- {
- // Skip to next one
- continue;
- }
+ // Derive the class name from the filename.
+ $name = str_ireplace('.php', '', ucfirst(trim($fileName)));
+ $class = $this->_classprefix . ucfirst($name);
- $adapter = new $class($this, $this->_db, $options);
- $this->_adapters[$name] = clone $adapter;
+ if (!class_exists($class))
+ {
+ // Skip to next one
+ continue;
}
+
+ $adapter = new $class($this, $this->_db, $options);
+ $this->_adapters[$name] = clone $adapter;
}
}
}
View
25 libraries/joomla/cache/storage/cachelite.php
@@ -111,21 +111,34 @@ public function getAll()
parent::getAll();
$path = $this->_root;
- jimport('joomla.filesystem.folder');
- $folders = JFolder::folders($path);
+ $folders = new DirectoryIterator($path);
$data = array();
foreach ($folders as $folder)
{
- $files = JFolder::files($path . '/' . $folder);
- $item = new JCacheStorageHelper($folder);
+ if (!$folder->isDir() || $folder->isDot())
+ {
+ continue;
+ }
+
+ $foldername = $folder->getFilename();
+
+ $files = new DirectoryIterator($path . '/' . $foldername);
+ $item = new JCacheStorageHelper($foldername);
foreach ($files as $file)
{
- $item->updateSize(filesize($path . '/' . $folder . '/' . $file) / 1024);
+ if (!$file->isFile())
+ {
+ continue;
+ }
+
+ $filename = $file->getFilename();
+
+ $item->updateSize(filesize($path . '/' . $foldername . '/' . $filename) / 1024);
}
- $data[$folder] = $item;
+ $data[$foldername] = $item;
}
return $data;
View
21 libraries/joomla/filesystem/helper.php
@@ -9,9 +9,6 @@
defined('JPATH_PLATFORM') or die;
-jimport('joomla.filesystem.file');
-jimport('joomla.filesystem.folder');
-
/**
* File system helper
*
@@ -263,11 +260,25 @@ public static function getFilters()
*/
public static function getJStreams()
{
- static $streams;
+ static $streams = array();
if (!$streams)
{
- $streams = array_map(array('JFile', 'stripExt'), JFolder::files(__DIR__ . '/streams', '.php'));
+ $files = new DirectoryIterator(__DIR__ . '/streams');
+
+ foreach ($files as $file)
+ {
+ $filename = $file->getFilename();
+
+ // Only load for php files.
+ // Note: DirectoryIterator::getExtension only available PHP >= 5.3.6
+ if (!$file->isFile() || substr($filename, strrpos($filename, '.') + 1) != 'php')
+ {
+ continue;
+ }
+
+ $streams[] = $file->getBasename('.php');
+ }
}
return $streams;
View
14 libraries/joomla/html/list.php
@@ -45,15 +45,21 @@ public static function images($name, $active = null, $javascript = null, $direct
. ".options[selectedIndex].value} else {document.imagelib.src='media/system/images/blank.png'}\"";
}
- jimport('joomla.filesystem.folder');
- $imageFiles = JFolder::files(JPATH_SITE . '/' . $directory);
+ $imageFiles = new DirectoryIterator(JPATH_SITE . '/' . $directory);
$images = array(JHtml::_('select.option', '', JText::_('JOPTION_SELECT_IMAGE')));
foreach ($imageFiles as $file)
{
- if (preg_match('#(' . $extensions . ')$#', $file))
+ $fileName = $file->getFilename();
+
+ if (!$file->isFile())
+ {
+ continue;
+ }
+
+ if (preg_match('#(' . $extensions . ')$#', $fileName))
{
- $images[] = JHtml::_('select.option', $file);
+ $images[] = JHtml::_('select.option', $fileName);
}
}

0 comments on commit fda2d9b

Please sign in to comment.