svn: /pear2/sandbox/Loader/trunk/src/PEAR2/Loader/ PEAR2Svn.php

From: Date: Mon, 08 Mar 2010 00:32:36 +0000
Subject: svn: /pear2/sandbox/Loader/trunk/src/PEAR2/Loader/ PEAR2Svn.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-cvs+get-59017@lists.php.net to get a copy of this message
dufuz Mon, 08 Mar 2010 00:32:36 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=295948 Log: Fix ups, consolidation and readability. Changed paths: U pear2/sandbox/Loader/trunk/src/PEAR2/Loader/PEAR2Svn.php Modified: pear2/sandbox/Loader/trunk/src/PEAR2/Loader/PEAR2Svn.php =================================================================== --- pear2/sandbox/Loader/trunk/src/PEAR2/Loader/PEAR2Svn.php 2010-03-08 00:31:50 UTC (rev 295947) +++ pear2/sandbox/Loader/trunk/src/PEAR2/Loader/PEAR2Svn.php 2010-03-08 00:32:36 UTC (rev 295948) @@ -35,22 +35,24 @@ * Automatically finds the location of the PEAR2 code and the PEAR2 sandbox * based on the current location of the loader file */ - public function __construct() { + public function __construct() + { // assumes we're in the sandbox if (basename(realpath(__DIR__ . '/../../../')) == 'trunk') { $this->sandbox = realpath(__DIR__ . '/../../../../../'); - $this->pear2 = realpath(__DIR__ . '/../../../../../../'); + $this->pear2 = realpath(__DIR__ . '/../../../../../../'); } else { - $this->sandbox = realpath(dirname(__FILE__)."/../../../../"); - $this->pear2 = dirname($this->sandbox); + $this->sandbox = realpath(__DIR__ . '/../../../../'); + $this->pear2 = dirname($this->sandbox); } - $this->pear2Packages = $this->_dirList($this->pear2); + $this->pear2Packages = $this->_dirList($this->pear2); $this->sandboxPackages = $this->_dirList($this->sandbox); } - public static function autoload($class_name) { - PEAR2_Loader_PEAR2Svn::getInstance()->loadClassWithoutCheck($class_name); + public static function autoload($class) + { + PEAR2_Loader_PEAR2Svn::getInstance()->loadClassWithoutCheck($class); } public function loadClassWithoutCheck($class_name) @@ -58,7 +60,8 @@ if (!preg_match("/^PEAR2/i",$class_name)) { return false; } - $this->_filename = str_replace(array('\\', '_'), DIRECTORY_SEPARATOR, + + $this->_filename = str_replace(array('\\', '_'), DIRECTORY_SEPARATOR, str_replace(array('pear2\\', 'PEAR2_'),'',$class_name)) . '.php'; // find the package @@ -70,22 +73,20 @@ break; } } + if ($_package) { - if (file_exists($this->pear2.DIRECTORY_SEPARATOR.$_package. - DIRECTORY_SEPARATOR.'trunk')) { - $this->_filename = $this->pear2.DIRECTORY_SEPARATOR.$_package. - DIRECTORY_SEPARATOR.'trunk'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.$this->_filename; + $path = $this->pear2 . DIRECTORY_SEPARATOR . $_package . DIRECTORY_SEPARATOR; + if (file_exists($path . 'trunk')) { + $this->_filename = $path . 'trunk'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.$this->_filename; } else { - $this->_filename = $this->pear2.DIRECTORY_SEPARATOR.$_package. - DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.$this->_filename; + $this->_filename = $path .'src'.DIRECTORY_SEPARATOR.$this->_filename; } - unset($_p); - unset($_package); - unset($class_name); + unset($_p, $_package, $class_name); if (!file_exists($this->_filename)) { return; } + include $this->_filename; } else { foreach ($this->sandboxPackages as $_p) { @@ -94,21 +95,20 @@ break; } } + if ($_package) { - if (file_exists($this->sandbox.DIRECTORY_SEPARATOR.$_package. - DIRECTORY_SEPARATOR.'trunk')) { - $this->_filename = $this->sandbox.DIRECTORY_SEPARATOR.$_package. - DIRECTORY_SEPARATOR.'trunk'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.$this->_filename; + $path = $this->sandbox . DIRECTORY_SEPARATOR . $_package . DIRECTORY_SEPARATOR; + if (file_exists($path . 'trunk')) { + $this->_filename = $path.'trunk'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.$this->_filename; } else { - $this->_filename = $this->sandbox.DIRECTORY_SEPARATOR.$_package. - DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.$this->_filename; + $this->_filename = $path.'src'.DIRECTORY_SEPARATOR.$this->_filename; } - unset($_p); - unset($_package); + unset($_p, $_package); if (!file_exists($this->_filename)) { return; } + include $this->_filename; } } @@ -126,43 +126,41 @@ if (!isset(self::$_instance)) { self::$_instance = new self(); } - + return self::$_instance; } - private function _dirList($dir) { + private function _dirList($dir) + { $dit = new DirectoryIterator($dir); $ret = array(); - foreach($dit as $d) { - if($d->isDir() && !$d->isDot()) { + foreach ($dit as $d) { + if ($d->isDir() && !$d->isDot()) { $ret[] = basename($d); } } + uasort($ret,array($this,'sizeCmp')); return $ret; } - protected function sizeCmp($a,$b) { + protected function sizeCmp($a,$b) + { $as = substr_count($a,'_'); $bs = substr_count($b,'_'); if ($as == $bs) { return 0; - } - elseif ($as > $bs) { + } elseif ($as > $bs) { return -1; } - else { - return 1; - } + + return 1; } } /** - * * Register with autoload stack - * * @ignore - * */ -spl_autoload_register(array( - 'PEAR2_Loader_PEAR2svn', - 'autoload' -)); + * Register with autoload stack + * @ignore + */ +spl_autoload_register(array('PEAR2_Loader_PEAR2svn', 'autoload')); /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

« previous php.pear.cvs (#59017) next »