Skip to content

Commit

Permalink
Moved Loader class
Browse files Browse the repository at this point in the history
Removed Loader class from core package and 
moved it to the root of the library.
Updated examples with the new loader.
  • Loading branch information
Mattijs Hoitink committed Oct 31, 2010
1 parent 19fdd66 commit 220870b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 119 deletions.
4 changes: 2 additions & 2 deletions examples/command_sequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
set_include_path(realpath(__DIR__ . '/../lib') . PATH_SEPARATOR . get_include_path());

// Register the Steel autoloader
require 'steel/core/Loader.php';
\steel\core\Loader::registerAutoload();
require 'steel/Loader.php';
\steel\Loader::registerAutoload();

// Create a new sequence
$sequence = new \steel\command\Sequence();
Expand Down
54 changes: 0 additions & 54 deletions examples/routing.php

This file was deleted.

51 changes: 51 additions & 0 deletions lib/steel/Loader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Loader.php
*
* @package Steel
* @copyright Copyright (c) 2010 Mattijs Hoitink <mattijs@monkeyandmachine.com>
* @license New BSD License - http://github.com/mattijs/Steel/raw/master/LICENSE
*/

namespace steel\core;

/**
* Loader for Steel classes.
*
* @todo add class cache
* @package Steel
* @author Mattijs Hoitink <mattijs@monkeyandmachine.com>
*/
class Loader
{

/**
* Autoloader implementation based on the example from
* the PHP standards group.
* @see http://groups.google.com/group/php-standards/web/psr-0-final-proposal
* @param string $className
*/
public static function autoload($className)
{
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strripos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';

require $fileName;
}

/**
* Register this class with the autoloading stack.
*/
public static function registerAutoload()
{
spl_autoload_register(array('self', 'autoload'));
}

}
63 changes: 0 additions & 63 deletions lib/steel/core/Loader.php

This file was deleted.

0 comments on commit 220870b

Please sign in to comment.