Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved code to lib/ folder, added optional PSR-0 support, added PSR-0 …
…example and updated readme
- Loading branch information
Showing
33 changed files
with
276 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,11 @@ | |
} | ||
], | ||
"require": { | ||
"php": ">=5.3.0" | ||
"php": ">=5.3.2" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"Analog": "lib/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
|
||
/** | ||
* SplClassLoader implementation that implements the technical interoperability | ||
* standards for PHP 5.3 namespaces and class names. | ||
* | ||
* http://groups.google.com/group/php-standards/web/final-proposal | ||
* | ||
* // Example which loads classes for the Doctrine Common package in the | ||
* // Doctrine\Common namespace. | ||
* $classLoader = new SplClassLoader('Doctrine\Common', '/path/to/doctrine'); | ||
* $classLoader->register(); | ||
* | ||
* @author Jonathan H. Wage <jonwage@gmail.com> | ||
* @author Roman S. Borschel <roman@code-factory.org> | ||
* @author Matthew Weier O'Phinney <matthew@zend.com> | ||
* @author Kris Wallsmith <kris.wallsmith@gmail.com> | ||
* @author Fabien Potencier <fabien.potencier@symfony-project.org> | ||
*/ | ||
class SplClassLoader | ||
{ | ||
private $_fileExtension = '.php'; | ||
private $_namespace; | ||
private $_includePath; | ||
private $_namespaceSeparator = '\\'; | ||
|
||
/** | ||
* Creates a new <tt>SplClassLoader</tt> that loads classes of the | ||
* specified namespace. | ||
* | ||
* @param string $ns The namespace to use. | ||
*/ | ||
public function __construct($ns = null, $includePath = null) | ||
{ | ||
$this->_namespace = $ns; | ||
$this->_includePath = $includePath; | ||
} | ||
|
||
/** | ||
* Sets the namespace separator used by classes in the namespace of this class loader. | ||
* | ||
* @param string $sep The separator to use. | ||
*/ | ||
public function setNamespaceSeparator($sep) | ||
{ | ||
$this->_namespaceSeparator = $sep; | ||
} | ||
|
||
/** | ||
* Gets the namespace seperator used by classes in the namespace of this class loader. | ||
* | ||
* @return void | ||
*/ | ||
public function getNamespaceSeparator() | ||
{ | ||
return $this->_namespaceSeparator; | ||
} | ||
|
||
/** | ||
* Sets the base include path for all class files in the namespace of this class loader. | ||
* | ||
* @param string $includePath | ||
*/ | ||
public function setIncludePath($includePath) | ||
{ | ||
$this->_includePath = $includePath; | ||
} | ||
|
||
/** | ||
* Gets the base include path for all class files in the namespace of this class loader. | ||
* | ||
* @return string $includePath | ||
*/ | ||
public function getIncludePath() | ||
{ | ||
return $this->_includePath; | ||
} | ||
|
||
/** | ||
* Sets the file extension of class files in the namespace of this class loader. | ||
* | ||
* @param string $fileExtension | ||
*/ | ||
public function setFileExtension($fileExtension) | ||
{ | ||
$this->_fileExtension = $fileExtension; | ||
} | ||
|
||
/** | ||
* Gets the file extension of class files in the namespace of this class loader. | ||
* | ||
* @return string $fileExtension | ||
*/ | ||
public function getFileExtension() | ||
{ | ||
return $this->_fileExtension; | ||
} | ||
|
||
/** | ||
* Installs this class loader on the SPL autoload stack. | ||
*/ | ||
public function register() | ||
{ | ||
spl_autoload_register(array($this, 'loadClass')); | ||
} | ||
|
||
/** | ||
* Uninstalls this class loader from the SPL autoloader stack. | ||
*/ | ||
public function unregister() | ||
{ | ||
spl_autoload_unregister(array($this, 'loadClass')); | ||
} | ||
|
||
/** | ||
* Loads the given class or interface. | ||
* | ||
* @param string $className The name of the class to load. | ||
* @return void | ||
*/ | ||
public function loadClass($className) | ||
{ | ||
if (null === $this->_namespace || $this->_namespace.$this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace.$this->_namespaceSeparator))) { | ||
$fileName = ''; | ||
$namespace = ''; | ||
if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) { | ||
$namespace = substr($className, 0, $lastNsPos); | ||
$className = substr($className, $lastNsPos + 1); | ||
$fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; | ||
} | ||
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension; | ||
|
||
require ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
require '../Analog.php'; | ||
require '../lib/Analog.php'; | ||
|
||
Analog::log ('foo'); | ||
Analog::log ('bar'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
require '../Analog.php'; | ||
require '../lib/Analog.php'; | ||
|
||
$log_file = 'log.txt'; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
require '../Analog.php'; | ||
require '../lib/Analog.php'; | ||
|
||
Analog::handler (Analog\Handler\FirePHP::init ()); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
require '../Analog.php'; | ||
require '../lib/Analog.php'; | ||
|
||
$errors = "Errors:\n"; | ||
$warnings = "Warnings:\n"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
require '../Analog.php'; | ||
require '../lib/Analog.php'; | ||
|
||
Analog::handler (Analog\Handler\Null::init ()); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
require '../Analog.php'; | ||
require '../lib/Analog.php'; | ||
|
||
$log = ''; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
require 'SplClassLoader.php'; | ||
|
||
$loader = new SplClassLoader ('Analog', '../lib'); | ||
$loader->register (); | ||
|
||
use \Analog\Analog; | ||
|
||
$log = ''; | ||
|
||
Analog::handler (\Analog\Handler\Variable::init ($log)); | ||
|
||
Analog::log ('Test one'); | ||
Analog::log ('Test two'); | ||
|
||
echo $log; | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
require '../Analog.php'; | ||
require '../lib/Analog.php'; | ||
|
||
Analog::handler (Analog\Handler\Stderr::init ()); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
require '../Analog.php'; | ||
require '../lib/Analog.php'; | ||
|
||
$log = ''; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/** | ||
* Register a very simple autoloader for the pre-built handlers | ||
* based on the current working directory. | ||
*/ | ||
spl_autoload_register (function ($class) { | ||
$file = str_replace ('\\', DIRECTORY_SEPARATOR, ltrim ($class, '\\')) . '.php'; | ||
if (file_exists (__DIR__ . DIRECTORY_SEPARATOR . $file)) { | ||
require_once $file; | ||
return true; | ||
} | ||
return false; | ||
}); | ||
|
||
/** | ||
* We simply extend the main class so that Analog is | ||
* available as a global class. This saves us adding | ||
* `use \Analog\Analog` at the top of every file, | ||
* or worse, typeing `\Analog\Analog::log()` everywhere. | ||
*/ | ||
class Analog extends \Analog\Analog { | ||
/** | ||
* We need to override format() to always write to | ||
* the parent, since the pre-built handlers have to | ||
* assume they're using the PSR-0 class. | ||
*/ | ||
public static function format ($format = false) { | ||
if ($format) { | ||
\Analog\Analog::$format = $format; | ||
} | ||
return \Analog\Analog::$format; | ||
} | ||
} |
Oops, something went wrong.