Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Zend Loader Laravel Package

zendframework/zend-loader

Autoloading and class loading utilities for Zend Framework applications. Provides standard and optimized autoloaders (including PSR-0/PSR-4 style support), plugin class loading, and tools to resolve and map class names to files for legacy or modular codebases.

View on GitHub
Deep Wiki
Context7

The SplAutoloader Interface

While any valid PHP callback may be registered with spl_autoload_register(), the autoloaders zend-loader provides offer more flexibility by being stateful and allowing configuration. To provide a common interface for such autoloaders, zend-loader provides the SplAutoloader interface.

Objects implementing this interface provide a standard mechanism for configuration, a method that may be invoked to attempt to load a class, and a method for registering with the SPL autoloading mechanism.

Quick Start

To create your own autoloading mechanism, create a class implementing the SplAutoloader interface (you may review the methods defined in the methods section). As an example, consider the following autoloader, which will look for a class file named after the class within a list of registered directories.

namespace Custom;

use InvalidArgumentException;
use Traversable;
use Zend\Loader\SplAutoloader;

class ModifiedIncludePathAutoloader implements SplAutoloader
{
    protected $paths = array();

    public function __construct($options = null)
    {
        if (null !== $options) {
            $this->setOptions($options);
        }
    }

    public function setOptions($options)
    {
        if (! is_array($options) && ! $options instanceof Traversable) {
            throw new InvalidArgumentException();
        }

        foreach ($options as $path) {
            if (! in_array($path, $this->paths)) {
                $this->paths[] = $path;
            }
        }
    }

    public function autoload($classname)
    {
        $filename = $classname . '.php';
        foreach ($this->paths as $path) {
            $test = sprintf('%s/%s', $path, $filename);
            if (file_exists($test)) {
                return include($test);
            }
        }
        return false;
    }

    public function register()
    {
        spl_autoload_register([$this, 'autoload']);
    }
}

To use this ModifiedIncludePathAutoloader from the previous example:

$options = [
   '/path/one',
   '/path/two',
];
$autoloader = new Custom\ModifiedIncludePathAutoloader($options);
$autoloader->register();

Configuration Options

This component defines no configuration options, as it is an interface.

Available Methods

__construct

__construct($options = null) : void

Autoloader constructors should optionally receive configuration. Typically, if received, these will be passed to the setOptions() method to process.

setOptions

setOptions(array|Traversable $options) : void

Used to configure the autoloader. Typically, it should expect either an array or a Traversable object, though validation of the options is left to implementation.

autoload

autoload(string $class) : false|string

This method should be used to resolve a class name to the file defining it. When a positive match is found, return the class name; otherwise, return a boolean false.

register

register() : void

Should be used to register the autoloader instance with spl_autoload_register(). Invariably, the method should look like the following:

public function register()
{
    spl_autoload_register([$this, 'autoload']);
}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport