public function __construct($name = null) { if ($name) { $this->name = $name; } $this->setContextHandler(new \Owl\Context\Redis(['token' => 'job:' . $this->getName(), 'service' => \Owl\Service\Container::getInstance()->get('redis'), 'ttl' => 7 * 86400])); }
function __bootstrap() { static $boot = false; if ($boot) { return true; } $boot = true; // 加载配置文件 \Owl\Config::merge(require ROOT_DIR . '/config/main.php'); // 初始化外部服务容器 \Owl\Service\Container::getInstance()->setServices(\Owl\Config::get('services')); }
<?php if (!file_exists(__DIR__ . '/../vendor')) { die('run "composer install" first' . PHP_EOL); } defined('TEST') or define('TEST', true); define('TEST_DIR', __DIR__); require __DIR__ . '/../vendor/autoload.php'; \Owl\Service\Container::getInstance()->setServices(['mock.storage' => ['class' => '\\Tests\\Mock\\DataMapper\\Service']]);
/** * 获得存储服务连接实例 * * @return Owl\Service * @throws \RuntimeException Data class没有配置存储服务 */ public function getService() { $service = $this->getOption('service'); return \Owl\Service\Container::getInstance()->get($service); }