Overview

Namespaces

  • PHP
  • PHPassLib
    • Application
    • Exception
    • Hash
    • Test
      • Application
      • Hash

Classes

  • Loader
  • Utilities

Interfaces

  • Exception
  • Hash
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * PHP Password Library
 4:  *
 5:  * @package PHPassLib\Loaders
 6:  * @author Ryan Chouinard <rchouinard@gmail.com>
 7:  * @copyright Copyright (c) 2012, Ryan Chouinard
 8:  * @license MIT License - http://www.opensource.org/licenses/mit-license.php
 9:  * @version 3.0.0-dev
10:  */
11: 
12: namespace PHPassLib;
13: 
14: /**
15:  * Class Loader
16:  *
17:  * This class provides methods for loading library resources conforming to
18:  * PSR-0 standards. Only classes in the PHPassLib namespace will be loaded by
19:  * Loader::load().
20:  *
21:  * @package PHPassLib\Loaders
22:  * @author Ryan Chouinard <rchouinard@gmail.com>
23:  * @copyright Copyright (c) 2012, Ryan Chouinard
24:  * @license MIT License - http://www.opensource.org/licenses/mit-license.php
25:  */
26: class Loader
27: {
28: 
29:     /**
30:      * Load a library class.
31:      *
32:      * Performs checks to make sure only local library classes are loaded, and
33:      * the class file exists within the library path.
34:      *
35:      * @param string $class The fully qualified class name to load.
36:      * @return void
37:      */
38:     public static function load($class)
39:     {
40:         if (substr($class, 0, 9) !== 'PHPassLib') {
41:             return;
42:         }
43: 
44:         $libraryRoot = dirname(__DIR__);
45:         $file = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
46:         $file = $libraryRoot . DIRECTORY_SEPARATOR . $file;
47:         if (substr($file, 0, strlen($libraryRoot)) == $libraryRoot) {
48:             if (is_readable($file)) {
49:                 include $file;
50:             }
51:         }
52:     }
53: 
54:     /**
55:      * Register an autoloader for the library.
56:      *
57:      * @return boolean Returns true on success, false on failure.
58:      */
59:     public static function registerAutoloader()
60:     {
61:         return spl_autoload_register(array ('PHPassLib\\Loader', 'load'));
62:     }
63: 
64: }
65: 
PHP Password Library API documentation generated by ApiGen 2.8.0