lithium\core\Libraries::load PHP Method

load() public static method

Loads the class definition specified by $class. Looks through the list of libraries defined in $_configurations, which are added through lithium\core\Libraries::add().
See also: lithium\core\Libraries::add()
See also: lithium\core\Libraries::path()
public static load ( string $class, boolean $require = false ) : void
$class string The fully-namespaced (where applicable) name of the class to load.
$require boolean Specifies whether the class must be loaded or considered an exception. Defaults to `false`.
return void
    public static function load($class, $require = false)
    {
        $path = isset(static::$_cachedPaths[$class]) ? static::$_cachedPaths[$class] : null;
        $path = $path ?: static::path($class);
        if ($path && (include $path)) {
            static::$_cachedPaths[$class] = $path;
            if (method_exists($class, '__init')) {
                $message = "Support for automatic initialization of static classes has been ";
                $message .= "removed. `{$class}::__init()` exists, please remove it to get rid ";
                $message .= "of this message. Static classes must now be initialized manually. ";
                $message .= "i.e. by creating an `init()` method and calling it at the end of ";
                $message .= "the file and outside of the class.";
                throw new RuntimeException($message);
            }
        } elseif ($require) {
            throw new RuntimeException("Failed to load class `{$class}` from path `{$path}`.");
        }
    }

Usage Example

Esempio n. 1
0
 /**
  * Tests the loading of libraries
  */
 public function testLibraryLoad()
 {
     $expected = 'Failed to load class `SomeInvalidLibrary` from path ``.';
     $this->assertException($expected, function () {
         Libraries::load('SomeInvalidLibrary', true);
     });
 }
All Usage Examples Of lithium\core\Libraries::load