本文整理汇总了PHP中Auryn\Injector::delegate方法的典型用法代码示例。如果您正苦于以下问题:PHP Injector::delegate方法的具体用法?PHP Injector::delegate怎么用?PHP Injector::delegate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Auryn\Injector
的用法示例。
在下文中一共展示了Injector::delegate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addToInjector
public function addToInjector(Injector $injector)
{
foreach ($this->shares as $share) {
$injector->share($share);
}
foreach ($this->aliases as $original => $alias) {
$injector->alias($original, $alias);
}
foreach ($this->definitions as $name => $args) {
$injector->define($name, $args);
}
foreach ($this->params as $param => $value) {
$injector->defineParam($param, $value);
}
foreach ($this->delegates as $param => $callable) {
$injector->delegate($param, $callable);
}
foreach ($this->prepares as $class => $callable) {
$injector->prepare($class, $callable);
}
}
示例2: setup
public function setup()
{
parent::setup();
// Create a JigConfig object
$jigConfig = new JigConfig(__DIR__ . "/../../fixtures/templates/", __DIR__ . "/../../var/generatedTemplates/", Jig::COMPILE_CHECK_MTIME);
$this->injector = new Injector();
$this->injector->alias('Jig\\Escaper', 'Jig\\Bridge\\ZendEscaperBridge');
$this->injector->delegate('FastRoute\\Dispatcher', 'TierTest\\JigBridge\\createDispatcher');
$this->injector->share('FastRoute\\Dispatcher');
$this->injector->share($jigConfig);
}
示例3: 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);
});
}
示例4: 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']);
}
示例5: 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');
}
示例6: 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);
}
示例7: apply
/**
* Applies a configuration set to a dependency injector.
*
* @param Injector $injector
*/
public function apply(Injector $injector)
{
foreach (self::$entityRepositoryMap as $entityName => $repoClassName) {
$injector->delegate($repoClassName, function () use($entityName, $injector) {
/** @var EntityManager $entityManager */
$entityManager = $injector->make(EntityManager::class);
return $entityManager->getRepository($entityName);
});
}
}
示例8: apply
/**
* Applies a configuration set to a dependency injector.
*
* @param Injector $injector
*/
public function apply(Injector $injector)
{
foreach (self::$commandHandlerMapping as $command => $handler) {
$injector->alias($command, $handler);
}
$injector->delegate(CommandBus::class, function () use($injector) {
$handlerMiddleware = new CommandHandlerMiddleware(new ClassNameExtractor(), new CallableLocator([$injector, 'make']), new HandleInflector());
$lockingMiddleware = new LockingMiddleware();
$transactionMiddleware = new TransactionMiddleware($injector->make(EntityManager::class));
return new CommandBus([$transactionMiddleware, $lockingMiddleware, $handlerMiddleware]);
});
}
示例9: createInjector
function createInjector()
{
$jigTemplatePath = new \Jig\JigTemplatePath(__DIR__ . "/fixtures/templates/");
$jigCompilePath = new \Jig\JigCompilePath(__DIR__ . "/var/generatedTemplates/");
// Create a JigConfig object
$jigConfig = new JigConfig($jigTemplatePath, $jigCompilePath, Jig::COMPILE_CHECK_MTIME);
$injector = new Injector();
$injector->alias('Jig\\Escaper', 'Jig\\Bridge\\ZendEscaperBridge');
$injector->delegate('FastRoute\\Dispatcher', 'TierTest\\JigBridge\\createDispatcher');
$injector->share('FastRoute\\Dispatcher');
$injector->share($jigConfig);
return $injector;
}
示例10: createProvider
/**
* @param array $implementations
* @param array $shareClasses
* @return Provider
*/
function createProvider($implementations = array(), $shareClasses = array())
{
$provider = new Injector();
$provider->define('GithubService\\GithubArtaxService\\GithubArtaxService', [':userAgent' => 'Danack_test']);
$provider->prepare('Amp\\Artax\\Client', 'prepareArtaxClient');
$standardImplementations = ['GithubService\\GithubService' => 'DebugGithub', 'Amp\\Artax\\AsyncClient' => 'Amp\\Artax\\AsyncClient', 'Amp\\Reactor' => 'Amp\\NativeReactor', 'ArtaxServiceBuilder\\ResponseCache' => 'ArtaxServiceBuilder\\ResponseCache\\NullResponseCache', 'PSR\\Cache' => 'PSR\\Cache\\APCCache', 'Amp\\Addr\\Cache' => 'Amp\\Addr\\MemoryCache'];
$standardShares = ['Amp\\Reactor' => 'Amp\\Reactor'];
$provider->delegate('Amp\\Artax\\Client', 'createClient');
foreach ($standardImplementations as $interface => $implementation) {
if (array_key_exists($interface, $implementations)) {
if (is_object($implementations[$interface]) == true) {
$provider->alias($interface, get_class($implementations[$interface]));
$provider->share($implementations[$interface]);
} else {
$provider->alias($interface, $implementations[$interface]);
}
unset($implementations[$interface]);
} else {
if (is_object($implementation)) {
$implementation = get_class($implementation);
}
$provider->alias($interface, $implementation);
}
}
foreach ($implementations as $class => $implementation) {
if (is_object($implementation) == true) {
$provider->alias($class, get_class($implementation));
$provider->share($implementation);
} else {
$provider->alias($class, $implementation);
}
}
foreach ($standardShares as $class => $share) {
if (array_key_exists($class, $shareClasses)) {
$provider->share($shareClasses[$class]);
unset($shareClasses[$class]);
} else {
$provider->share($share);
}
}
foreach ($shareClasses as $class => $share) {
$provider->share($share);
}
$provider->share($provider);
//YOLO
return $provider;
}
示例11: apply
public function apply(Injector $injector)
{
$injector->delegate(Stdio::class, [$this, 'getStdio']);
$injector->delegate(Context::class, [$this, 'getContext']);
}
示例12: apply
public function apply(Injector $injector)
{
$injector->delegate(Client::class, [$this, 'makeClient']);
}
示例13: apply
public function apply(Injector $injector)
{
$injector->delegate(Pheanstalk::class, [$this, 'getPheanstalk']);
}
示例14: function
$injector->alias(AdminStorage::class, $config['storage']['admin'] ?? FileAdminStorage::class);
$injector->alias(BanStorage::class, $config['storage']['ban'] ?? FileBanStorage::class);
$injector->alias(KeyValueStorage::class, $config['storage']['keyvalue'] ?? FileKeyValueStorage::class);
$injector->alias(KeyValueStorageFactory::class, ($config['storage']['keyvalue'] ?? FileKeyValueStorage::class) . 'Factory');
$injector->alias(PluginStorage::class, $config['storage']['plugin'] ?? FilePluginStorage::class);
$injector->alias(RoomStorage::class, $config['storage']['room'] ?? FileRoomStorage::class);
$injector->define(BitlyClient::class, [':accessToken' => $config['bitly']['accessToken']]);
$injector->define(TwitterApplicationCredentials::class, [':key' => $config['twitter']['consumerKey'], ':secret' => $config['twitter']['consumerSecret']]);
$injector->define(TranslationAPICredentials::class, [':clientId' => $config['ms-translate']['client-id'] ?? '', ':clientSecret' => $config['ms-translate']['client-secret'] ?? '']);
$injector->define(WebSocketEventDispatcher::class, [':devMode' => $config['dev-mode']['enable'] ?? false]);
$injector->delegate(Logger::class, function () use($config) {
$flags = array_map('trim', explode('|', $config['logging']['level'] ?? ''));
if (empty($flags[0])) {
$flags = LogLevel::ALL;
} else {
$flags = array_reduce($flags, function ($carry, $flag) {
return $carry | constant(LogLevel::class . "::{$flag}");
}, 0);
}
$logger = $config['logging']['handler'] ?? StdOutLogger::class;
return new $logger($flags, ...array_values($config['logging']['params'] ?? []));
});
$injector->delegate(CredentialManager::class, function () use($config) {
$manager = new CredentialManager();
$haveDefault = false;
foreach ($config['openids'] ?? [] as $domain => $details) {
if (!isset($details['username'], $details['password'])) {
throw new InvalidConfigurationException("OpenID domain '{$domain}' does not define username and password");
}
$details = new Credentials(new OpenIdEmailAddress($details['username']), new OpenIdPassword($details['password']));
if ($domain === 'default') {
$haveDefault = true;
示例15: addInjectionParams
function addInjectionParams(Injector $injector, Tier $tier)
{
$injectionParams = $tier->getInjectionParams();
if (!$injectionParams) {
return;
}
foreach ($injectionParams->getAliases() as $original => $alias) {
$injector->alias($original, $alias);
}
foreach ($injectionParams->getShares() as $share) {
$injector->share($share);
}
foreach ($injectionParams->getParams() as $paramName => $value) {
$injector->defineParam($paramName, $value);
}
foreach ($injectionParams->getDelegates() as $className => $callable) {
$injector->delegate($className, $callable);
}
}