/** * 各个对象初始化 * * @access public static * @return void */ public static function init($ini) { self::setAutoLoad(); /** * @配置文件 */ \Myfox\Lib\Config::register('default', $ini); $config = \Myfox\Lib\Config::instance('default'); /** * @数据库 */ foreach ((array) $config->get('mysql') as $name => $file) { \Myfox\Lib\Mysql::register($name, $file); } /** * @日志对象 */ foreach ((array) $config->get('log') as $name => $url) { \Myfox\Lib\Factory::registerLog($name, $url); } /** * @告警提醒 */ \Myfox\Lib\Alert::init(__DIR__ . '/../etc/alert.ini'); }
public function test_should_get_object_works_fine() { $object = Factory::getObject('Myfox\\Test\\Factory\\Test', 'hello'); $this->assertEquals('hello', $object->a); $this->assertEquals('default', $object->b); $object->b = 'world'; $this->assertEquals($object, Factory::getObject('Myfox\\Test\\Factory\\Test', 'hello')); }
public function test_should_factory_get_log_works_fine() { $log = Factory::getLog('Iamnotexist'); $this->assertTrue($log instanceof \Myfox\Lib\Blackhole); Factory::registerLog('unittest', sprintf('log://debug.notice.warning.error/%s/tmp/test.log?buffer=0', __DIR__)); $log = Factory::getLog('UnittEst '); $this->assertTrue($log instanceof \Myfox\Lib\Log); }
/** * 构造函数 * * @access public * @return void */ public function __construct($option) { $this->option = (array) $option + $this->option; $this->cleanup(); $this->log = \Myfox\Lib\Factory::getLog('daemon'); }