I ended up creating an automated way of indexing my class files and then creating a file called "load" in the root of the component directory.
Example of my logging component load file: (using PHP 5.3 + namespaces btw)
PHP Code:
<?php namespace Logical::Log;
function __load ( $class )
{
static $index;
if ( empty( $index ) ) {
$index = array(
'exception' => '/exception.php',
'ifilter' => '/ifilter.php',
'filter::message' => '/filter/message.php',
'filter::priority' => '/filter/priority.php',
'filter::surpress' => '/filter/surpress.php',
'iformatter' => '/iformetter.php',
'format::simple' => '/format/simple.php',
'format::xml' => '/format/xml.php',
'manager' => '/manager.php',
'writer' => '/writer.php',
'write::database' => '/write/database.php',
'write::mock' => '/write/mock.php',
'write::null' => '/write/null.php',
'write::stream' => '/write/stream.php'
);
return spl_autoload_register( __FUNCTION__, true );
}
if ( !empty( $class ) && stripos( $class, __NAMESPACE__ ) !== false ) {
$class = str_replace( __NAMESPACE__ . '::', '', strtolower( $class ) );
if ( isset( $index[ $class ] ) ) {
include __DIR__ . $index[ $class ];
}
}
}
__load( null );
Usage:
PHP Code:
<?php
#future usage will utilize PHAR
#require_once 'phar:///logical/log/load';
require_once 'logical/log/load';
use Logical::Log::Write::Mock as MockWriter;
use Logical::Log;
$log = new Log::Manager( new MockWriter );
$log( 'info', 'Test Message' );
Edit:
Just found out, that the namespace separator is being changed from "::" to "\"
Bookmarks