merophp/bundle-manager

0.1-beta 2022-02-03 14:41 UTC

This package is auto-updated.

Last update: 2024-09-29 06:14:38 UTC


README

merophp框架的包管理器。

安装

通过composer

composer require merophp/bundle-manager

基本用法

require_once 'vendor/autoload.php';

use Merophp\BundleManager\BundleManager;

use Merophp\BundleManager\Collection\BundleCollection;
use Merophp\BundleManager\Provider\BundleProvider;
use Merophp\BundleManager\Bundle;

$collection = new BundleCollection();
$collection->addMultiple([
    new Bundle('MyOrganization\\MyBundlename'),
    new Bundle('MyOrganization\\MyBundlename2', ['myconfigKey'=>'myConfigValue']),
]);

$provider = new BundleProvider($collection);
$bundleManager = new BundleManager($provider);

$bundleManager->startRegisteredBundles();

包引导

一个包必须有一个实现Merophp\BundleManager\BundleBootstrapper\BundleBootstrapperInterface接口的引导类。引导类的名称由包标识符作为命名空间前缀和Bootstrapping/Bootstrapper组成。例如,上面的完全合格引导类名称是MyOrganization\MyBundlename\Bootstrapping\Bootstrapper


namespace MyOrganization\MyBundlename\Bootstrapping;

use Merophp\BundleManager\BundleBootstrapperInterface;

class Bootstrapper implements BundleBootstrapperInterface
{
    public function setConfiguration(array $configuration = [])
    {}

    public function setup()
    {}

    public function tearDown()
    {}
}

包引导器有两个生命周期方法 'setup' 和 'tearDown',这些方法由包管理器调用。'setup' 在包启动时被调用,而 'tearDown' 在PHP执行结束时被调用。