本文整理汇总了PHP中Auryn\Injector类的典型用法代码示例。如果您正苦于以下问题:PHP Injector类的具体用法?PHP Injector怎么用?PHP Injector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Injector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: apply
/**
* @inheritDoc
*/
public function apply(Injector $injector)
{
$injector->alias(RequestInterface::class, ServerRequest::class);
$injector->alias(ResponseInterface::class, Response::class);
$injector->alias(ServerRequestInterface::class, ServerRequest::class);
$injector->delegate(ServerRequest::class, [ServerRequestFactory::class, 'fromGlobals']);
}
示例2: __invoke
public function __invoke(Injector $injector)
{
$injector->share($injector);
foreach ($this->classes as $class) {
$injector->execute($class);
}
}
示例3: apply
/**
* @inheritDoc
*/
public function apply(Injector $injector)
{
foreach ($this as $class) {
$configuration = $injector->make($class);
$configuration->apply($injector);
}
}
示例4: initialize
/**
* Creates all service hook handlers.
*/
private function initialize()
{
$injector = new Injector();
$namespace = __NAMESPACE__ . "\\Service\\";
$basePath = __DIR__ . "/../vendor/kelunik/chat-services/res/schema/";
$transform = function ($match) {
return strtoupper($match[1]);
};
try {
foreach ($this->config["services"] as $name => $enabled) {
if (!$enabled) {
continue;
}
$service = $injector->make($namespace . preg_replace_callback("~-([a-z])~", $transform, ucfirst($name)));
$found = false;
foreach (scandir($basePath . $name) as $file) {
if ($file === "." || $file === "..") {
continue;
}
$found = true;
$uri = realpath($basePath . $name . "/" . $file);
$schema = $this->retriever->retrieve("file://" . $uri);
$this->schemas[$name][strtok($file, ".")] = $schema;
}
if (!$found) {
throw new RuntimeException("every service must have at least one event schema");
}
$this->services[$name] = $service;
}
} catch (InjectorException $e) {
throw new RuntimeException("couldn't create all services", 0, $e);
}
}
示例5: testStageRunning
public function testStageRunning()
{
$functionsCalled = [];
$tiersByStage = new ExecutableListByTier();
$fn2 = function () use(&$functionsCalled) {
$functionsCalled[2] = true;
};
$fn0 = function () use(&$functionsCalled, $tiersByStage, $fn2) {
$functionsCalled[0] = true;
$tiersByStage->addExecutableToTier(4, $fn2);
};
$fn1 = function () use(&$functionsCalled) {
$functionsCalled[1] = true;
};
$tiersByStage->addExecutableToTier(2, $fn0);
$tiersByStage->addExecutableToTier(2, $fn1);
$injector = new Injector();
foreach ($tiersByStage as $appStage => $executablesForTier) {
foreach ($executablesForTier as $executable) {
$injector->execute($executable->getCallable());
}
}
$this->assertArrayHasKey(0, $functionsCalled);
$this->assertArrayHasKey(1, $functionsCalled);
$this->assertArrayHasKey(2, $functionsCalled);
}
示例6: apply
/**
* @inheritDoc
*/
public function apply(Injector $injector)
{
$injector->alias('Psr\\Http\\Message\\RequestInterface', 'Zend\\Diactoros\\ServerRequest');
$injector->alias('Psr\\Http\\Message\\ResponseInterface', 'Zend\\Diactoros\\Response');
$injector->alias('Psr\\Http\\Message\\ServerRequestInterface', 'Zend\\Diactoros\\ServerRequest');
$injector->delegate('Zend\\Diactoros\\ServerRequest', 'Zend\\Diactoros\\ServerRequestFactory::fromGlobals');
}
示例7: apply
/**
*
* {@inheritDoc}
*
* @see \Spark\Configuration\ConfigurationInterface::apply()
*/
public function apply(Injector $injector)
{
$injector->alias(ExtractorInterface::class, HeaderExtractor::class);
$injector->define(HeaderExtractor::class, [':header' => 'token']);
$injector->alias(\Spark\Auth\Credentials\ExtractorInterface::class, BodyExtractor::class);
$injector->alias(AdapterInterface::class, AuthAdapter::class);
}
示例8: apply
/**
* @inheritDoc
*/
public function apply(Injector $injector)
{
$injector->define(RelayBuilder::class, ['resolver' => 'Spark\\Resolver\\ResolverInterface']);
$injector->delegate('Relay\\Relay', function (RelayBuilder $builder, Middleware $queue) {
return $builder->newInstance($queue);
});
}
示例9: setMedoo
function setMedoo()
{
$injector = new Injector();
$injector->share('medoo');
$injector->define('medoo', [':options' => $this->databaseconfig]);
$this->medoodb = $injector->make('medoo');
}
示例10: testApply
/**
* @param string $class
* @dataProvider dataMapping
*/
public function testApply($class)
{
$injector = new Injector();
$configuration = $injector->make(AuraCliConfiguration::class);
$configuration->apply($injector);
$instance = $injector->make($class);
$this->assertInstanceOf($class, $instance);
}
示例11: testApply
public function testApply()
{
$injector = new Injector();
$configuration = $injector->make(PredisConfiguration::class);
$configuration->apply($injector);
$instance = $injector->make(Client::class);
$this->assertInstanceOf(Client::class, $instance);
}
示例12: apply
/**
* @inheritDoc
*/
public function apply(Injector $injector)
{
$injector->define(RelayBuilder::class, ['resolver' => ResolverInterface::class]);
$factory = function (RelayBuilder $builder, MiddlewareSet $queue) {
return $builder->newInstance($queue);
};
$injector->delegate(Relay::class, $factory);
}
示例13: makeClient
public function makeClient(Injector $injector)
{
if (empty($this->env['chamber_api_secret'])) {
throw new \DomainException('Bad API configuration');
}
$handler = $injector->execute([$this, 'makeStack']);
return new Client(compact('handler'));
}
示例14: apply
/**
* Applies a configuration set to a dependency injector.
*
* @param Injector $injector
*/
public function apply(Injector $injector)
{
// Create a new Manager instance.
$manager = new Manager(new ArrayDriver());
// Managers can do everything
$manager->role('manager')->allow('all');
// $manager->role('employee')->allow('guest', 'read');
$injector->share($manager);
}
示例15: apply
public function apply(Injector $injector)
{
$injector->prepare(Engine::class, function (Engine $engine) use($injector) {
$session = $injector->make(Session::class);
$engine->registerFunction('is_logged_in', function () use($session) {
return $session->has('rdio.token') && $session->has('tidal.session');
});
});
}