shopbase/globalizer

用于全局化类别的库

1.0.0.0 2019-01-13 22:10 UTC

This package is auto-updated.

Last update: 2024-09-10 01:11:39 UTC


README

此库用于全局化类实例。

用法

为了初始化、获取、重置和删除全局化器,包括几个函数。

\Shopbase\Globalizer\Globalizer::init(); // initialize the globalizer and add a gobal instance
\Shopbase\Globalizer\Globalizer::get(); // get the global instance
\Shopbase\Globalizer\Globalizer::reset(); // reset the global instance
\Shopbase\Globalizer\Globalizer::delete(); // delete the global instance

为了处理存储在全局化器中的类的实例,包括以下函数

setClass(string $class) // Set new global instance of an class
getClass(string $class) // get global instance of an class
removeClass(string $class) // remove global instance of an class
syncWithGlobal() // sync global instances

示例

class Foo
{
    protected $bar = 'FooBar';
    
    public function getBar() : string
    {
        return $this->bar;
    }
}

\Shopbase\Globalizer\Globalizer::init()->setClass('Foo');

echo \Shopbase\Globalizer\Globalizer::get()->getClass('Foo');

// Result will be: 'FooBar';

Donate