本文整理汇总了PHP中Auryn\Injector::prepare方法的典型用法代码示例。如果您正苦于以下问题:PHP Injector::prepare方法的具体用法?PHP Injector::prepare怎么用?PHP Injector::prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Auryn\Injector
的用法示例。
在下文中一共展示了Injector::prepare方法的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: registerExceptionHandlerServices
private function registerExceptionHandlerServices(Injector $injector)
{
$injector->share(Run::class);
$injector->prepare(Run::class, function (Run $run) {
$run->pushHandler(new PrettyPageHandler());
});
$injector->share(ExceptionHandlingPlugin::class);
}
示例3: 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');
});
});
}
示例4: apply
/**
* @inheritDoc
*/
public function apply(Injector $injector)
{
$injector->define(Loader::class, [':filepaths' => $this->envfile]);
$injector->share(Env::class);
$injector->prepare(Env::class, function (Env $env, Injector $injector) {
$loader = $injector->make(Loader::class);
$values = $loader->parse()->toArray();
return $env->withValues($values);
});
}
示例5: apply
public function apply(Injector $injector)
{
$injector->alias(Collection::class, DefaultCollection::class);
$injector->prepare(Collection::class, function (Collection $collection) {
$middleware = $collection->getArrayCopy();
// Do session checking before routing
array_splice($middleware, array_search(RouteHandler::class, $middleware), 0, CheckSessionMiddleware::class);
$collection->exchangeArray($middleware);
});
}
示例6: apply
public function apply(Injector $injector)
{
$injector->prepare(Router::class, function (Router $router) {
$router->get('/', Choose::class);
$router->post('/import', Import::class);
$router->get('/login', Login::class);
$router->get('/login/rdio', LoginRdio::class);
$router->get('/login/tidal', LoginTidal::class);
$router->post('/login/tidal', LoginTidal::class);
$router->get('/logout', Logout::class);
});
}
示例7: 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;
}
示例8: apply
/**
* @inheritDoc
*/
public function apply(Injector $injector)
{
$injector->prepare(Whoops::class, [$this, 'prepareWhoops']);
$injector->prepare(JsonResponseHandler::class, [$this, 'prepareJsonHandler']);
$injector->prepare(PlainTextHandler::class, [$this, 'preparePlainTextHandler']);
}
示例9: apply
public function apply(Injector $injector)
{
$injector->prepare(FormatterResponder::class, [$this, 'prepareResponder']);
}
示例10: apply
public function apply(Injector $injector)
{
$injector->prepare(FormattedResponder::class, function (FormattedResponder $responder) {
return $responder->withFormatters([PlatesFormatter::class => 1.0]);
});
}
示例11: apply
public function apply(Injector $injector)
{
$injector->prepare(FormattedResponder::class, function (FormattedResponder $responder) {
return $responder->withValue(PlatesFormatter::class, 1.0);
});
}
示例12: apply
public function apply(Injector $injector)
{
$injector->prepare(ChainedResponder::class, function (ChainedResponder $responder) {
return $responder->withAddedResponder(RedirectResponder::class);
});
}
示例13: testPrepareCallableReplacesObjectWithReturnValueOfSameClassType
public function testPrepareCallableReplacesObjectWithReturnValueOfSameClassType()
{
$injector = new Injector();
$expected = new SomeImplementation();
// <-- implements SomeInterface
$injector->prepare("Auryn\\Test\\SomeImplementation", function ($impl) use($expected) {
return $expected;
});
$actual = $injector->make("Auryn\\Test\\SomeImplementation");
$this->assertSame($expected, $actual);
}
示例14: Injector
use Kelunik\Chat\Chat;
use Kelunik\ChatMain\SecurityMiddleware;
use Kelunik\Template\TemplateService;
use function Aerys\root;
use function Aerys\router;
use function Aerys\session;
use function Amp\reactor;
$injector = new Injector();
$injector->alias("Kelunik\\Chat\\Storage\\MessageStorage", "Kelunik\\Chat\\Storage\\MysqlMessageStorage");
$injector->alias("Kelunik\\Chat\\Storage\\PingStorage", "Kelunik\\Chat\\Storage\\MysqlPingStorage");
$injector->alias("Kelunik\\Chat\\Storage\\RoomStorage", "Kelunik\\Chat\\Storage\\MysqlRoomStorage");
$injector->alias("Kelunik\\Chat\\Storage\\UserStorage", "Kelunik\\Chat\\Storage\\MysqlUserStorage");
$injector->alias("Kelunik\\Chat\\Events\\EventSub", "Kelunik\\Chat\\Events\\RedisEventSub");
$injector->alias("Kelunik\\Chat\\Search\\Messages\\MessageSearch", "Kelunik\\Chat\\Search\\Messages\\ElasticSearch");
$injector->prepare("Kelunik\\Template\\TemplateService", function (TemplateService $service) {
$service->setBaseDirectory(__DIR__ . "/../res/html");
});
$injector->define("Kelunik\\Chat\\Search\\Messages\\ElasticSearch", [":host" => config("elastic.host"), ":port" => config("elastic.port")]);
$injector->share($injector);
$injector->share("Kelunik\\Template\\TemplateService");
$injector->share(new Redis(config("redis.protocol") . "://" . config("redis.host") . ":" . config("redis.port")));
$injector->share(new SubscribeClient(config("redis.protocol") . "://" . config("redis.host") . ":" . config("redis.port")));
$injector->share(new MySQL(sprintf("host=%s;user=%s;pass=%s;db=%s", config("database.host"), config("database.user"), config("database.pass"), config("database.name"))));
$auth = $injector->make("Kelunik\\ChatMain\\Auth");
/** @var TemplateService $templateService */
$templateService = $injector->make("Kelunik\\Template\\TemplateService");
/** @var Chat $chat */
$chat = $injector->make("Kelunik\\Chat\\Chat");
$router = router()->get("", function (Request $req, Response $resp) use($templateService) {
$session = (yield (new Session($req))->read());
if (!$session->get("login")) {
示例15: apply
public function apply(Injector $injector)
{
$injector->define(Engine::class, [':directory' => __DIR__ . '/../../templates']);
$injector->prepare(Engine::class, [$this, 'prepareTemplates']);
}