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


PHP Container::instance方法代码示例

本文整理汇总了PHP中Illuminate\Contracts\Container\Container::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::instance方法的具体用法?PHP Container::instance怎么用?PHP Container::instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Contracts\Container\Container的用法示例。


在下文中一共展示了Container::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setupContainer

 /**
  * Setup the IoC container instance.
  *
  * @param  \Illuminate\Contracts\Container\Container  $container
  * @return void
  */
 protected function setupContainer(Container $container)
 {
     $this->container = $container;
     if (!$this->container->bound('config')) {
         $this->container->instance('config', new Fluent());
     }
 }
开发者ID:Vinelab,项目名称:neoeloquent-support,代码行数:13,代码来源:CapsuleManagerTrait.php

示例2: createVersionFactory

 /**
  * Create the VersionFactory for the Version
  *
  * @return \LaraPackage\Api\Contracts\Factory\VersionFactory
  * @internal param $version
  *
  */
 protected function createVersionFactory()
 {
     $version = $this->requestParser->version();
     $factory = $this->apiVersion->factory($version);
     $instance = $this->app->make($factory);
     $this->app->instance(\LaraPackage\Api\Contracts\Factory\VersionFactory::class, $instance);
     return $instance;
 }
开发者ID:larapackage,项目名称:api,代码行数:15,代码来源:Factory.php

示例3: __invoke

 /**
  * {@inheritdoc}
  */
 public function __invoke(Request $request, Response $response, callable $out = null)
 {
     if (($token = array_get($request->getCookieParams(), 'flarum_remember')) && ($accessToken = AccessToken::valid($token))) {
         $this->app->instance('flarum.actor', $user = $accessToken->user);
         $user->updateLastSeen()->save();
     }
     return $out ? $out($request, $response) : $response;
 }
开发者ID:huytd,项目名称:core,代码行数:11,代码来源:LoginWithCookie.php

示例4: __invoke

 /**
  * {@inheritdoc}
  */
 public function __invoke(Request $request, Response $response, callable $out = null)
 {
     $header = $request->getHeaderLine('authorization');
     if (starts_with($header, $this->prefix) && ($token = substr($header, strlen($this->prefix))) && ($accessToken = AccessToken::valid($token))) {
         $this->app->instance('flarum.actor', $user = $accessToken->user);
         $user->updateLastSeen()->save();
     }
     return $out ? $out($request, $response) : $response;
 }
开发者ID:huytd,项目名称:core,代码行数:12,代码来源:LoginWithHeader.php

示例5: __invoke

 /**
  * {@inheritdoc}
  */
 public function __invoke(Request $request, Response $response, callable $out = null)
 {
     if (($token = array_get($request->getCookieParams(), 'flarum_remember')) && ($accessToken = AccessToken::valid($token)) && $accessToken->user->isAdmin()) {
         $this->app->instance('flarum.actor', $accessToken->user);
     } else {
         die('Access Denied');
     }
     return $out ? $out($request, $response) : $response;
 }
开发者ID:huytd,项目名称:core,代码行数:12,代码来源:LoginWithCookieAndCheckAdmin.php

示例6: dispatch

 /**
  * Dispatch a request.
  *
  * @param \Illuminate\Http\Request $request
  * @param string                   $version
  *
  * @return mixed
  */
 public function dispatch(Request $request, $version)
 {
     if (!isset($this->routes[$version])) {
         throw new UnknownVersionException();
     }
     $this->router->setRoutes($this->routes[$version]);
     // Because the above call will reset the routes defined on the applications
     // UrlGenerator we will simply rebind the routes to the application
     // container which will trigger the rebinding event.
     $this->container->instance('routes', $this->applicationRoutes);
     return $this->router->dispatch($request);
 }
开发者ID:sharenjoy,项目名称:api,代码行数:20,代码来源:Laravel.php

示例7: logIn

 /**
  * Set the application's actor instance according to the request token.
  *
  * @param Request $request
  * @return bool
  */
 protected function logIn(Request $request)
 {
     if ($token = $this->getToken($request)) {
         if (!$token->isValid()) {
             // TODO: https://github.com/flarum/core/issues/253
         } elseif ($token->user) {
             $this->app->instance('flarum.actor', $user = $token->user);
             $user->updateLastSeen()->save();
             return true;
         }
     }
     return false;
 }
开发者ID:redstarxz,项目名称:flarumone,代码行数:19,代码来源:LoginWithCookie.php

示例8: sendRequestThroughRouter

 /**
  * Send the request through the Dingo router.
  *
  * @param \Dingo\Api\Http\Request $request
  *
  * @return \Dingo\Api\Http\Response
  */
 protected function sendRequestThroughRouter(HttpRequest $request)
 {
     $this->app->instance('request', $request);
     return (new Pipeline($this->app))->send($request)->through($this->middleware)->then(function ($request) {
         return $this->router->dispatch($request);
     });
 }
开发者ID:ben-challis,项目名称:api-1,代码行数:14,代码来源:Request.php

示例9: versionFactoryExpectations

 /**
  * @param App                                               $app
  * @param \LaraPackage\Api\Contracts\Request\Parser         $requestParser
  * @param \LaraPackage\Api\Contracts\Factory\VersionFactory $versionFactory
  */
 protected function versionFactoryExpectations(App $app, \LaraPackage\Api\Contracts\Request\Parser $requestParser, \LaraPackage\Api\Contracts\Factory\VersionFactory $versionFactory, ApiVersion $apiVersion)
 {
     $requestParser->version()->shouldBeCalled()->willReturn($this->version);
     $apiVersion->factory($this->version)->shouldBeCalled()->willReturn(VersionFactory::class);
     $app->instance(\LaraPackage\Api\Contracts\Factory\VersionFactory::class, $versionFactory)->shouldBeCalled();
     $app->make(VersionFactory::class)->shouldBeCalledTimes(1)->willReturn($versionFactory);
 }
开发者ID:larapackage,项目名称:api,代码行数:12,代码来源:FactorySpec.php

示例10: bindContext

 /**
  * Bind the given security context to the Request and Container.
  *
  * @param string  $context
  * @param Request $request
  */
 public function bindContext($context, Request $request)
 {
     $security = $this->getSecurity($context);
     $this->container->instance(SecurityApi::class, $security);
     $this->container->bind(UrlGeneratorContract::class, function () use($security) {
         return $security->url();
     });
     $this->container->bind([UrlGenerator::class => 'url'], function (Container $container) use($security) {
         /** @var PermissionAwareUrlGeneratorExtension $url */
         $url = $container->make(PermissionAwareUrlGeneratorExtension::class);
         $url->setUrlGenerator($security->url());
         return $url;
     });
     $request->setUserResolver(function () use($security) {
         return $security->getUser();
     });
 }
开发者ID:digbang,项目名称:security,代码行数:23,代码来源:SecurityContext.php

示例11: __invoke

 /**
  * {@inheritdoc}
  */
 public function __invoke(Request $request, Response $response, callable $out = null)
 {
     $header = $request->getHeaderLine('authorization');
     $parts = explode(';', $header);
     if (isset($parts[0]) && starts_with($parts[0], $this->prefix)) {
         $token = substr($parts[0], strlen($this->prefix));
         if ($accessToken = AccessToken::valid($token)) {
             $this->app->instance('flarum.actor', $user = $accessToken->user);
             $user->updateLastSeen()->save();
         } elseif (isset($parts[1]) && ($apiKey = ApiKey::valid($token))) {
             $userParts = explode('=', trim($parts[1]));
             if (isset($userParts[0]) && $userParts[0] === 'userId') {
                 $this->app->instance('flarum.actor', $user = User::find($userParts[1]));
             }
         }
     }
     return $out ? $out($request, $response) : $response;
 }
开发者ID:helisz,项目名称:chrishe.bbs,代码行数:21,代码来源:LoginWithHeader.php

示例12: storeConfiguration

 protected function storeConfiguration()
 {
     $dbConfig = $this->dataSource->getDatabaseConfiguration();
     $config = ['debug' => true, 'database' => ['driver' => $dbConfig['driver'], 'host' => $dbConfig['host'], 'database' => $dbConfig['database'], 'username' => $dbConfig['username'], 'password' => $dbConfig['password'], 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => $dbConfig['prefix'], 'strict' => false], 'url' => $this->dataSource->getBaseUrl(), 'paths' => ['api' => 'api', 'admin' => 'admin']];
     $this->info('Testing config');
     $this->container->instance('flarum.config', $config);
     $this->container->make('flarum.db');
     $this->info('Writing config');
     file_put_contents($this->getConfigFile(), '<?php return ' . var_export($config, true) . ';');
 }
开发者ID:huytd,项目名称:core,代码行数:10,代码来源:InstallCommand.php

示例13: handle

 /**
  * Start JSON API support.
  *
  * This middleware:
  * - Loads the configuration for the named API that this request is being routed to.
  * - Registers the API in the service container.
  * - Triggers client/server content negotiation as per the JSON API spec.
  *
  * @param Request $request
  * @param Closure $next
  * @param $namespace
  *      the API namespace, as per your JSON API configuration.
  * @return mixed
  */
 public function handle($request, Closure $next, $namespace)
 {
     /** @var ApiFactory $factory */
     $factory = $this->container->make(ApiFactoryInterface::class);
     /** @var ServerRequestInterface $request */
     $serverRequest = $this->container->make(ServerRequestInterface::class);
     /** @var RequestFactoryInterface $requestFactory */
     $requestFactory = $this->container->make(RequestFactoryInterface::class);
     /** Build and register the API */
     $api = $factory->createApi($namespace, $request->getSchemeAndHttpHost());
     $this->container->instance(ApiInterface::class, $api);
     /** Build and register the JSON API request */
     $jsonApiRequest = $requestFactory->build($api, $serverRequest);
     $this->container->instance(RequestInterface::class, $jsonApiRequest);
     /** Override the current page resolution */
     AbstractPaginator::currentPageResolver(function () {
         /** @var PaginatorInterface $paginator */
         $paginator = $this->container->make(PaginatorInterface::class);
         return $paginator->getCurrentPage();
     });
     return $next($request);
 }
开发者ID:cloudcreativity,项目名称:laravel-json-api,代码行数:36,代码来源:BootJsonApi.php

示例14: register

 /**
  * Register an addon.
  *
  * @param $path
  * @param $enabled
  * @param $installed
  */
 public function register($path, array $enabled, array $installed)
 {
     if (!is_dir($path)) {
         return;
     }
     $vendor = strtolower(basename(dirname($path)));
     $slug = strtolower(substr(basename($path), 0, strpos(basename($path), '-')));
     $type = strtolower(substr(basename($path), strpos(basename($path), '-') + 1));
     $class = studly_case($vendor) . '\\' . studly_case($slug) . studly_case($type) . '\\' . studly_case($slug) . studly_case($type);
     /* @var Addon|Module|Extension|Twig_ExtensionInterface $addon */
     $addon = app($class)->setPath($path)->setType($type)->setSlug($slug)->setVendor($vendor);
     // If the addon supports states - set the state now.
     if ($addon->getType() === 'module' || $addon->getType() === 'extension') {
         $addon->setInstalled(in_array($addon->getNamespace(), $installed));
         $addon->setEnabled(in_array($addon->getNamespace(), $enabled));
     }
     // Bind to the service container.
     $this->container->alias($addon->getNamespace(), $alias = get_class($addon));
     $this->container->instance($alias, $addon);
     // Load package configuration.
     $this->configurator->addNamespace($addon->getNamespace(), $addon->getPath('resources/config'));
     // Load system overrides.
     $this->configurator->addNamespaceOverrides($addon->getNamespace(), base_path('resources/addons/' . $addon->getVendor() . '/' . $addon->getSlug() . '-' . $addon->getType()));
     // Load application overrides.
     $this->configurator->addNamespaceOverrides($addon->getNamespace(), $this->application->getResourcesPath('addons/' . $addon->getVendor() . '/' . $addon->getSlug() . '-' . $addon->getType() . '/config'));
     // Continue loading things.
     $this->provider->register($addon);
     // Add the view / translation namespaces.
     $this->views->addNamespace($addon->getNamespace(), $addon->getPath('resources/views'));
     $this->translator->addNamespace($addon->getNamespace(), $addon->getPath('resources/lang'));
     /*
      * If the addon is a plugin then
      * load it into Twig when appropriate.
      */
     if ($addon->getType() === 'plugin') {
         $this->events->listen('Anomaly\\Streams\\Platform\\View\\Event\\RegisteringTwigPlugins', function (RegisteringTwigPlugins $event) use($addon) {
             $twig = $event->getTwig();
             $twig->addExtension($addon);
         });
     }
     $this->collection->put($addon->getNamespace(), $addon);
     $this->events->fire(new AddonWasRegistered($addon));
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:50,代码来源:AddonIntegrator.php

示例15: getCorsAnalysis

 /**
  * This method saves analysis result in Illuminate Container for
  * using it in other parts of the application (e.g. in exception handler).
  *
  * @param Request $request
  *
  * @return AnalysisResultInterface
  */
 protected function getCorsAnalysis(Request $request)
 {
     $analysis = $this->analyzer->analyze($this->getRequestAdapter($request));
     $this->container->instance(AnalysisResultInterface::class, $analysis);
     return $analysis;
 }
开发者ID:neomerx,项目名称:cors-illuminate,代码行数:14,代码来源:CorsMiddleware.php


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