minime / quantum
该包已被废弃,不再维护。未建议替代包。
Quantum 是一种独特的容器,用于管理数据结构的并行状态。
0.0.1
2013-12-06 16:41 UTC
Requires
- php: >=5.4.0
This package is auto-updated.
Last update: 2022-02-01 12:29:05 UTC
README
Quantum 是一种独特的容器,用于管理数据结构的并行状态。给它一个可调用的工厂,开始展开。
安装
终端爱好者: composer require minime/quantum:~0.0
🎱
用法
<?php // Quantum Object looks more expressive when aliased use Minime\Quantum\Object as Container; // Quantum needs a callable to produce new states, so let's create one $Container = (new Container(function(){ return new SomeFancyContainer(); })) // this is the default environment ->mount('default')->interact(function($container){ $container->shared('Database', new Database( [ 'driver' => 'postgre', 'host' => 'localhost' ] )); /*...*/ }) // this will be our test/cli environment ->extend('default', 'test')->interact(function($container){ $container->get('Database')->config( [ 'database' => 'app_unit_test', 'user' => 'foo', 'password' => 'bar' ] ); }) // this will be our development environment ->extend('default', 'development')->interact(function($container){ $container->get('Database')->config( [ 'database' => 'app_development', 'user' => 'bar', 'password' => 'baz' ] ); }) // production! ->extend('default', 'production')->interact(function($container){ $container->get('Database')->config( [ 'host' => 'my.production.ip', 'database' => 'app', 'user' => 'app', 'password' => 'P@sW04d' ] ); });
在状态之间切换
<?php // get test container $TestContainer = $Container->mount('test')->expose(); // get development container $DevelopmentContainer = $Container->mount('development')->expose(); // get production container $ProductionContainer = $Container->mount('production')->expose();
同时交互所有状态
<?php $Container->each(function($container){ // routine });
版权
版权(c)2013 Márcio Almada。按照MIT风格的许可条款分发。有关详细信息,请参阅LICENSE。