当前位置: 首页>>代码示例>>PHP>>正文


PHP Injector::prepare方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:zvax,项目名称:stepping,代码行数:21,代码来源:InjectionParams.php

示例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);
 }
开发者ID:cspray,项目名称:labrador-http,代码行数:8,代码来源:Services.php

示例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');
         });
     });
 }
开发者ID:shadowhand,项目名称:radiotide,代码行数:9,代码来源:PlatesSessionConfiguration.php

示例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);
     });
 }
开发者ID:equip,项目名称:framework,代码行数:13,代码来源:EnvConfiguration.php

示例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);
     });
 }
开发者ID:shadowhand,项目名称:radiotide,代码行数:10,代码来源:MiddlewareConfiguration.php

示例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);
     });
 }
开发者ID:shadowhand,项目名称:radiotide,代码行数:12,代码来源:RoutingConfiguration.php

示例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;
}
开发者ID:danack,项目名称:githubartaxservice,代码行数:52,代码来源:testBootstrap.php

示例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']);
 }
开发者ID:JasonBusse,项目名称:rest_scheduler,代码行数:9,代码来源:WhoopsConfiguration.php

示例9: apply

 public function apply(Injector $injector)
 {
     $injector->prepare(FormatterResponder::class, [$this, 'prepareResponder']);
 }
开发者ID:elevenone,项目名称:spark-project-foundation,代码行数:4,代码来源:bootstrap.0.7.php

示例10: apply

 public function apply(Injector $injector)
 {
     $injector->prepare(FormattedResponder::class, function (FormattedResponder $responder) {
         return $responder->withFormatters([PlatesFormatter::class => 1.0]);
     });
 }
开发者ID:mikegreiling,项目名称:spark,代码行数:6,代码来源:PlatesResponderConfiguration.php

示例11: apply

 public function apply(Injector $injector)
 {
     $injector->prepare(FormattedResponder::class, function (FormattedResponder $responder) {
         return $responder->withValue(PlatesFormatter::class, 1.0);
     });
 }
开发者ID:JasonBusse,项目名称:rest_scheduler,代码行数:6,代码来源:PlatesResponderConfiguration.php

示例12: apply

 public function apply(Injector $injector)
 {
     $injector->prepare(ChainedResponder::class, function (ChainedResponder $responder) {
         return $responder->withAddedResponder(RedirectResponder::class);
     });
 }
开发者ID:shadowhand,项目名称:radiotide,代码行数:6,代码来源:ResponderConfiguration.php

示例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);
 }
开发者ID:barthelemy-ehui,项目名称:auryn,代码行数:11,代码来源:InjectorTest.php

示例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")) {
开发者ID:kelunik,项目名称:chat-main,代码行数:31,代码来源:aerys.php

示例15: apply

 public function apply(Injector $injector)
 {
     $injector->define(Engine::class, [':directory' => __DIR__ . '/../../templates']);
     $injector->prepare(Engine::class, [$this, 'prepareTemplates']);
 }
开发者ID:graphis,项目名称:cookcountycommunityfund,代码行数:5,代码来源:PlatesConfiguration.php


注:本文中的Auryn\Injector::prepare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。