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


PHP Application::singleton方法代码示例

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


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

示例1: initialize

 /**
  * Initialize the Laravel framework.
  * @param SymfonyRequest $request
  */
 private function initialize($request = null)
 {
     // Store a reference to the database object
     // so the database connection can be reused during tests
     $this->oldDb = null;
     if ($this->app['db'] && $this->app['db']->connection()) {
         $this->oldDb = $this->app['db'];
     }
     // The module can login a user with the $I->amLoggedAs() method,
     // but this is not persisted between requests. Store a reference
     // to the logged in user to simulate this.
     $loggedInUser = null;
     if ($this->app['auth'] && $this->app['auth']->check()) {
         $loggedInUser = $this->app['auth']->user();
     }
     // Load the application object
     $this->app = $this->kernel = $this->loadApplication();
     // Set the request instance for the application
     if (is_null($request)) {
         $appConfig = (require $this->module->config['project_dir'] . 'config/app.php');
         $request = SymfonyRequest::create($appConfig['url']);
     }
     $this->app->instance('request', Request::createFromBase($request));
     $this->app->instance('middleware.disable', $this->module->config['disable_middleware']);
     // Reset the old database after the DatabaseServiceProvider ran.
     // This way other service providers that rely on the $app['db'] entry
     // have the correct instance available.
     if ($this->oldDb) {
         $this->app['events']->listen('Illuminate\\Database\\DatabaseServiceProvider', function () {
             $this->app->singleton('db', function () {
                 return $this->oldDb;
             });
         });
     }
     $this->app->make('Illuminate\\Contracts\\Http\\Kernel')->bootstrap();
     // If events should be disabled mock the event dispatcher instance
     if ($this->module->config['disable_events']) {
         $this->mockEventDispatcher();
     }
     // Setup an event listener to listen for all events that are triggered
     $this->setupEventListener();
     // If there was a user logged in restore this user.
     // Also reload the user object from the user provider to prevent stale user data.
     if ($loggedInUser) {
         $refreshed = $this->app['auth']->getProvider()->retrieveById($loggedInUser->getAuthIdentifier());
         $this->app['auth']->setUser($refreshed ?: $loggedInUser);
     }
     $this->module->setApplication($this->app);
 }
开发者ID:vladislavl-hyuna,项目名称:crmapp,代码行数:53,代码来源:Laravel5.php

示例2: dataLoader

 /**
  * Magic method implementation for all the services
  *
  * @param string $name            
  * @param mixed $arguments            
  * @throws Exception
  * @return RentalsUnitedCaching\Services\Processable
  */
 public function dataLoader($name = null, $arguments = null)
 {
     $name = $name ? $name : 'base';
     $name = 'Jasekz\\RentalsUnitedCaching\\DataLoaders\\' . ucfirst($name);
     try {
         if (!isset($this->app[$name])) {
             // bind for if not already done so
             $this->app->singleton($name, function () use($name, $arguments) {
                 return new $name($arguments);
             });
         }
         return $this->app[$name];
     } catch (Exception $e) {
         throw $e;
     }
 }
开发者ID:jasekz,项目名称:rentals-united-caching,代码行数:24,代码来源:RentalsUnitedCaching.php

示例3: handle

 /**
  * Handle the command.
  *
  * @param Repository  $config
  * @param Application $application
  */
 public function handle(Repository $config, Application $application)
 {
     // First trigger to resolve.
     $application->make('translator');
     /*
      * Change the lang loader so we can
      * add a few more necessary override
      * paths to the API.
      */
     $application->singleton('translation.loader', function ($application) {
         return new Loader($application['files'], $application['path.lang']);
     });
     /*
      * Re-bind the translator so we can use
      * the new loader defined above.
      */
     $application->singleton('translator', function ($application) {
         $loader = $application->make('translation.loader');
         // When registering the translator component, we'll need to set the default
         // locale as well as the fallback locale. So, we'll grab the application
         // configuration so we can easily get both of these values from there.
         $locale = $application['config']['app.locale'];
         $trans = new Translator($loader, $locale);
         $trans->setFallback($application['config']['app.fallback_locale']);
         return $trans;
     });
     /*
      * Set the locale if LOCALE is defined.
      *
      * LOCALE is defined first thing in our
      * HTTP Kernel. Respect it!
      */
     if (defined('LOCALE')) {
         $application->setLocale(LOCALE);
         $config->set('app.locale', LOCALE);
     }
     // Set our locale namespace.
     $application->make('translator')->addNamespace('streams', realpath(__DIR__ . '/../../../resources/lang'));
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:45,代码来源:ConfigureTranslator.php

示例4: initialize

 /**
  * Initialize the Laravel framework.
  *
  * @param SymfonyRequest $request
  */
 private function initialize($request = null)
 {
     // Store a reference to the database object
     // so the database connection can be reused during tests
     $this->oldDb = null;
     if (isset($this->app['db']) && $this->app['db']->connection()) {
         $this->oldDb = $this->app['db'];
     }
     $this->app = $this->kernel = $this->loadApplication();
     // Set the request instance for the application,
     if (is_null($request)) {
         $appConfig = (require $this->module->config['project_dir'] . 'config/app.php');
         $request = SymfonyRequest::create($appConfig['url']);
     }
     $this->app->instance('request', Request::createFromBase($request));
     // Reset the old database after the DatabaseServiceProvider ran.
     // This way other service providers that rely on the $app['db'] entry
     // have the correct instance available.
     if ($this->oldDb) {
         $this->app['events']->listen('Illuminate\\Database\\DatabaseServiceProvider', function () {
             $this->app->singleton('db', function () {
                 return $this->oldDb;
             });
         });
     }
     $this->app->make('Illuminate\\Contracts\\Http\\Kernel')->bootstrap();
     // Record all triggered events by adding a wildcard event listener
     $this->app['events']->listen('*', function () {
         $this->triggeredEvents[] = $this->normalizeEvent($this->app['events']->firing());
     });
     // Replace the Laravel exception handler with our decorated exception handler,
     // so exceptions can be intercepted for the disable_exception_handling functionality.
     $decorator = new ExceptionHandlerDecorator($this->app['Illuminate\\Contracts\\Debug\\ExceptionHandler']);
     $decorator->exceptionHandlingDisabled($this->exceptionHandlingDisabled);
     $this->app->instance('Illuminate\\Contracts\\Debug\\ExceptionHandler', $decorator);
     if ($this->module->config['disable_middleware'] || $this->middlewareDisabled) {
         $this->app->instance('middleware.disable', true);
     }
     if ($this->module->config['disable_events'] || $this->eventsDisabled) {
         $this->mockEventDispatcher();
     }
     if ($this->module->config['disable_model_events'] || $this->modelEventsDisabled) {
         Model::unsetEventDispatcher();
     }
     $this->applyBindings();
     $this->applyContextualBindings();
     $this->applyInstances();
     $this->module->setApplication($this->app);
 }
开发者ID:solutionDrive,项目名称:Codeception,代码行数:54,代码来源:Laravel5.php

示例5: singleton

 /**
  * Register a shared binding in the container.
  *
  * @param string|array $abstract
  * @param \Closure|string|null $concrete
  * @return void 
  * @static 
  */
 public static function singleton($abstract, $concrete = null)
 {
     //Method inherited from \Illuminate\Container\Container
     \Illuminate\Foundation\Application::singleton($abstract, $concrete);
 }
开发者ID:satriashp,项目名称:tour,代码行数:13,代码来源:_ide_helper.php

示例6: resolveApplicationExceptionHandler

 /**
  * Resolve application HTTP exception handler.
  *
  * @param  \Illuminate\Foundation\Application  $app
  *
  * @return void
  */
 protected function resolveApplicationExceptionHandler($app)
 {
     $app->singleton('Illuminate\\Contracts\\Debug\\ExceptionHandler', 'AcExceptionsHandler');
 }
开发者ID:efficiently,项目名称:authority-controller,代码行数:11,代码来源:AcTestCase.php

示例7: Application

<?php

use Illuminate\Foundation\Application;
// create the application
$app = new Application(realpath(__DIR__ . "/../"));
// bind important interfaces
$app->singleton(Illuminate\Contracts\Http\Kernel::class, App\Http\Kernel::class);
$app->singleton(Illuminate\Contracts\Console\Kernel::class, App\Console\Kernel::class);
$app->singleton(Illuminate\Contracts\Debug\ExceptionHandler::class, App\Exceptions\Handler::class);
// return the application
return $app;
开发者ID:kevinsimard,项目名称:laravel-app,代码行数:11,代码来源:app.php

示例8: singleton

 /**
  * Register a shared binding in the container.
  *
  * @param  string|array          $abstract
  * @param  \Closure|string|null  $concrete
  */
 protected function singleton($abstract, $concrete = null)
 {
     $this->app->singleton($abstract, $concrete);
 }
开发者ID:dprabhath,项目名称:SEP_WE_016,代码行数:10,代码来源:ServiceProvider.php

示例9: resolveApplicationConsoleKernel

 /**
  * Resolve application Console Kernel implementation.
  *
  * @param  \Illuminate\Foundation\Application  $app
  * @return void
  */
 protected function resolveApplicationConsoleKernel($app)
 {
     $app->singleton('Illuminate\\Contracts\\Console\\Kernel', 'Nuwave\\Lighthouse\\Tests\\Support\\Console\\Kernel');
 }
开发者ID:nuwave,项目名称:lighthouse,代码行数:10,代码来源:SchemaGeneratorTest.php

示例10: bootstrapPattern

 /**
  * @param string                 $basePath The application base path
  * @param ProvidesCapsulePattern $pattern  The capsule pattern
  *
  * @return \Illuminate\Foundation\Application
  */
 protected function bootstrapPattern($basePath, $pattern)
 {
     //  Get the app's autoloader
     /** @noinspection PhpIncludeInspection */
     require Disk::path([$basePath, 'vendor', 'autoload.php']);
     //  Create the application
     $_app = new Application($basePath);
     $_app->useEnvironmentPath($basePath);
     foreach ($pattern as $_abstract => $_concrete) {
         $_app->singleton($_abstract, $_concrete);
     }
     //  Set up logging
     $_app->configureMonologUsing(function (Logger $monolog) {
         $_logFile = Disk::path([env('DFE_CAPSULE_LOG_PATH', storage_path('logs')), $this->instanceId . '.log']);
         $_handler = new StreamHandler($_logFile);
         $_handler->setFormatter(new LineFormatter(null, null, true, true));
         $monolog->pushHandler($_handler);
     });
     $this->basePath = $basePath;
     return $this->app = $_app;
 }
开发者ID:dreamfactorysoftware,项目名称:dfe-capsule,代码行数:27,代码来源:Capsule.php

示例11:

 function it_should_register_core_contract(Application $app)
 {
     $app->offsetGet(Argument::type('string'))->shouldBeCalled();
     $app->singleton('Atlas\\CoreContract', 'Atlas\\Core')->shouldBeCalled();
     $this->register();
 }
开发者ID:AtlasCM,项目名称:Core,代码行数:6,代码来源:CoreServiceProviderSpec.php


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