slender/module-loader

简单、解耦的应用模块

0.0.1 2014-12-13 14:16 UTC

This package is not auto-updated.

Last update: 2024-09-24 01:37:07 UTC


README

Packagist.org Package Latest Stable Version License

Build Status Coverage Status

为解耦应用组件提供简单的模块加载

安装

通过composer安装

composer require slender/module-loader

用法

<?php
    
use \Slender\ModuleLoader\ModuleLoader;
use \Slender\ModuleLoader\ModuleInterface;


$app = new \Slim\App();

/**
 * An example module class
 */
class MyModule implements ModuleInterface
{
	public function invokeModule( \Slim\App $slim )
	{
		$slim->get('/foo',function(){
			/* ... */
		});
	}
}

// Create the module loader instance
$moduleManager = new SimpleModuleLoader();

// Try to load the module
$moduleManager->loadModule('\Acme\Example\MyModule', $slim);

模块定位器

模块定位器负责将模块标识符字符串转换为可调用的对象,该对象可以调用以加载模块。模块定位器必须实现 Slender\ModuleLoader\ModuleLocatorInterface

ModuleManager 包含两个默认定位器,在默认使用 SimpleModuleLoader 时会被加载。

Slender 模块定位器

Slender\ModuleLoader\Locator\SlenderModuleLocator 此定位器将使用模块标识符作为完全限定类名,并尝试加载实现 Slender\ModuleLoader\ModuleInterface 的类。

可调用类定位器

Slender\ModuleLoader\Locator\InvokableClassModuleLocator 此定位器将使用模块标识符作为完全限定类名,并尝试加载该类,然后调用它。