tueena-lib/loader

一个小巧的php服务,用于配置自动加载器。

v1.0.5 2017-01-07 09:30 UTC

This package is not auto-updated.

Last update: 2024-09-28 19:52:54 UTC


README

一个为php 7应用程序配置自动加载器的小型服务。

特性

  • 测试驱动开发。代码覆盖率100%。
  • 提供了一种将目录分配给命名空间的方法。
  • 提供了一种注册闭包的方法,该闭包将被调用来加载类。

使用方法

<?php

// Create an instance of the Loader class.
$loader = new Loader;

// Define a directory, where classes of a namespace are found.
// Namespaces are defined without leading and trailing backslashes.
// Directories without trailing slashes.
$loader->addNamespaceDirectory('my\\namespace', '/path/to/my/class/files');

// Or define a closure as loader. This closure will be called with the
// class name as parameter and must return true if the class could be
// loaded and false otherwise.
$loader->addLoader(function ($className) {
	if (!$className === 'my\\special\\class')
		return false;
	include '/path/to/my/special/class.php';
	return true;
});

// Method calls can be chained.
$loader
  ->addNamespaceDirectory(/* ... */)
  ->addNamespaceDirectory(/* ... */)
  ->addLoader(/* ... */)
  ->addNamespaceDirectory(/* ... */);

// Loaders are called in the order of definition.
// The Loader class implements the ILoader interface.

许可协议

MIT

要求

php >= 7.0.0

安装

如果你使用Composer

composer require tueena-lib/loader

否则只需下载两个类和接口并使用它们。

联系方式

Bastian Fenske bastian.fenske@tueena.org