Overview

Namespaces

  • None
  • Xmf
    • Database
    • Module
      • Helper
    • Template
  • Xoops
    • Auth
    • Core
      • Cache
      • Database
        • Logging
        • Schema
      • Exception
      • Handler
        • Scheme
      • Kernel
        • Dtype
        • Handlers
        • Model
      • Lists
      • Locale
        • Punic
      • Service
        • Contract
      • Session
      • Text
        • Sanitizer
          • Extensions
      • Theme
        • Plugins
    • Form
    • Html
    • Locale
    • Module
      • Helper
      • Plugin

Classes

  • Assets
  • ComposerUtility
  • Events
  • FilterInput
  • FixedGroups
  • HttpRequest
  • Logger
  • MediaUploader
  • MimeTypes
  • PreloadItem
  • Psr0ClassLoader
  • Psr4ClassLoader
  • Random
  • Registry
  • Request
  • Security
  • XoopsTpl
  • Yaml

Interfaces

  • AttributeInterface
  • Overview
  • Namespace
  • Class
  • Tree

Class Psr4ClassLoader

A Class Loader that implements the technical interoperability standards for PHP 5.3 namespaces and class names set forth in PSR-4. This general-purpose implementation includes the optional functionality of allowing multiple base directories for a single namespace prefix.

From the PHP Framework Interop Group

Examples

Given a foo-bar package of classes in the file system at the following paths ... /path/to/packages/foo-bar/ src/ Baz.php # Foo\Bar\Baz Qux/ Quux.php # Foo\Bar\Qux\Quux tests/ BazTest.php # Foo\Bar\BazTest Qux/ QuuxTest.php # Foo\Bar\Qux\QuuxTest

... add the path to the class files for the \Foo\Bar\ namespace prefix as follows:

Namespace: Xoops\Core
Package: Xoops
Category: Xoops\Core\Psr4ClassLoader
Copyright: 2013 PHP Framework Interop Group
Copyright: 2013-2014 XOOPS Project (http://xoops.org)
License: (see above)
Author: https://github.com/php-fig/fig-standards/
Author: Richard Griffith richard@geekwright.com
See: http://www.php-fig.org/
Link: https://github.com/php-fig/fig-standards/wiki/PSR-4-Example-Implementations
Code:

<?php // instantiate the loader $loader = new \Xoops\Core\Psr4ClassLoader;

 // register the autoloader
 $loader->register();

 // register the base directories for the namespace prefix
 $loader->addNamespace('Foo\Bar', '/path/to/packages/foo-bar/src');
 $loader->addNamespace('Foo\Bar', '/path/to/packages/foo-bar/tests');

Code:

<?php new \Foo\Bar\Qux\Quux;


Code:

<?php new \Foo\Bar\Qux\QuuxTest;


Endcode:

The following line would cause the autoloader to attempt to load the \Foo\Bar\Qux\Quux class from /path/to/packages/foo-bar/src/Qux/Quux.php:


Endcode:

The following line would cause the autoloader to attempt to load the \Foo\Bar\Qux\QuuxTest class from /path/to/packages/foo-bar/tests/Qux/QuuxTest.php:


Endcode
Located at oops_lib/Xoops/Core/Psr4ClassLoader.php
Methods summary
public static SplClassLoader
# addLoader( type $namespace, mixed $path )

addLoader sets all basic options and registers the autoloader

addLoader sets all basic options and registers the autoloader

Parameters

$namespace
namespace
$path

path(s) to the namespace's directories Can be string - only one directory or array of strings - multiple directories

Returns

SplClassLoader
public null
# register( )

Register loader with SPL autoloader stack.

Register loader with SPL autoloader stack.

Returns

null
public null
# addNamespace( string $prefix, string $base_dir, boolean $prepend = false )

Adds a base directory for a namespace prefix.

Adds a base directory for a namespace prefix.

Parameters

$prefix
The namespace prefix.
$base_dir
Base directory for class files in namespace.
$prepend

If true, prepend the base directory to the stack instead of appending it; this causes it to be searched first rather than last.

Returns

null
public string|false
# loadClass( string $class )

Loads the class file for a given class name.

Loads the class file for a given class name.

Parameters

$class
The fully-qualified class name.

Returns

string|false

The mapped file name on success, or boolean false on failure.

protected false|string
# loadMappedFile( string $prefix, string $relative_class )

Load the mapped file for a namespace prefix and relative class.

Load the mapped file for a namespace prefix and relative class.

Parameters

$prefix
The namespace prefix.
$relative_class
The relative class name.

Returns

false|string

Boolean false if no mapped file can be loaded, or the name of the mapped file that was loaded.

protected boolean
# requireFile( string $file )

If a file exists, require it from the file system.

If a file exists, require it from the file system.

Parameters

$file
The file to require.

Returns

boolean
True if the file exists, false if not.
Properties summary
protected array $prefixes

An associative array where the key is a namespace prefix and the value is an array of base directories for classes in that namespace.

An associative array where the key is a namespace prefix and the value is an array of base directories for classes in that namespace.

# array()
API documentation generated by ApiGen