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


PHP Application::instance方法代码示例

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


在下文中一共展示了Application::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
     $oldDb = null;
     if ($this->app['db'] && $this->app['db']->connection()) {
         $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']);
     // Bootstrap the application
     $this->app->make('Illuminate\\Contracts\\Http\\Kernel')->bootstrap();
     // Restore the old database object if available
     if ($oldDb) {
         $this->app['db'] = $oldDb;
         Model::setConnectionResolver($this->app['db']);
     }
     // 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:Dossar,项目名称:boltbse,代码行数:43,代码来源:Laravel5.php

示例2: initialize

 /**
  * Initialize the Laravel framework.
  */
 private function initialize()
 {
     // Store a reference to the database object
     // so the database connection can be reused during tests
     $oldDb = null;
     if ($this->app['db'] && $this->app['db']->connection()) {
         $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();
     }
     $this->app = $this->kernel = $this->loadApplication();
     $this->app->make('Illuminate\\Contracts\\Http\\Kernel')->bootstrap();
     // Set the base url for the Request object
     $url = $this->app['config']->get('app.url', 'http://localhost');
     $this->app->instance('request', Request::createFromBase(SymfonyRequest::create($url)));
     if ($oldDb) {
         $this->app['db'] = $oldDb;
         Model::setConnectionResolver($this->app['db']);
     }
     // 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:corcre,项目名称:elabftw,代码行数:35,代码来源:Laravel5.php

示例3: register

 public function register()
 {
     $this->app->instance(__CLASS__, $this);
     $this->app->alias(__CLASS__, $this->containerName);
     $this->blade->directive('include_layout', function ($expr) {
         return "<?php echo app('{$this->containerName}')->renderLayout{$expr} ?>";
     });
 }
开发者ID:windqyoung,项目名称:utils,代码行数:8,代码来源:BladeExtension.php

示例4: createFreshMockInstance

 /**
  * Create a fresh mock instance for the given class.
  *
  * @param  string  $name
  * @return \Mockery\Expectation
  */
 protected static function createFreshMockInstance($name)
 {
     static::$resolvedInstance[$name] = $mock = static::createMockByName($name);
     if (isset(static::$app)) {
         static::$app->instance($name, $mock);
     }
     return $mock;
 }
开发者ID:hramose,项目名称:Sistema-Control-de-Almacen,代码行数:14,代码来源:Facade.php

示例5: bootstrap

 /**
  * Bootstrap the given application.
  *
  * @param  \Illuminate\Contracts\Foundation\Application $app
  * @return void
  */
 public function bootstrap(Application $app)
 {
     $this->app = $app;
     $this->app->setBasePath($this->basePath);
     $this->app->instance('path', $this->getPath());
     foreach (['config', 'database', 'lang', 'public', 'storage'] as $path) {
         $this->app->instance('path.' . $path, $this->getPath($path));
     }
 }
开发者ID:caffeinated,项目名称:beverage,代码行数:15,代码来源:CustomApplicationPaths.php

示例6: setupApplication

 /**
  * Setup application.
  *
  * @return Application
  */
 protected function setupApplication()
 {
     // Create the application such that the config is loaded
     $app = new Application();
     $app->instance('path', 'foobar');
     $app->instance('files', new Filesystem());
     $app->instance('config', new Repository($app->getConfigLoader(), 'foobar'));
     return $app;
 }
开发者ID:elevencodes,项目名称:instagram-laravel,代码行数:14,代码来源:InstagramTestCase.php

示例7: createApplication

 /**
  * Create an barebones Laravel application.
  */
 protected function createApplication()
 {
     $this->app = new Application(__DIR__ . '/../../..');
     $this->app->instance('config', new Repository([]));
     $this->app['config']->set('session.driver', 'array');
     $this->app['config']->set('database', ['fetch' => PDO::FETCH_CLASS, 'default' => 'sqlite', 'connections' => ['sqlite' => ['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '']], 'migrations' => 'migrations']);
     $this->app['config']->set('app', ['providers' => [FilesystemServiceProvider::class, FoundationServiceProvider::class, PipelineServiceProvider::class, SessionServiceProvider::class, ViewServiceProvider::class, DatabaseServiceProvider::class, MigrationServiceProvider::class]]);
     $this->app->registerConfiguredProviders();
     $this->app->boot();
 }
开发者ID:sellerlabs,项目名称:illuminated,代码行数:13,代码来源:IlluminatedTestCase.php

示例8: createApplication

 public function createApplication()
 {
     $app = new Application(__DIR__ . '/../stub');
     $app->instance('path', '');
     $app->instance('path.base', '');
     $app->instance('path.storage', '');
     $app->instance('config', new Config());
     $app->loadEnvironmentFrom(__DIR__ . '/../examples/' . '.env');
     (new DetectEnvironment())->bootstrap($app);
     return $app;
 }
开发者ID:paolooo,项目名称:laravel-doctrine,代码行数:11,代码来源:TestCase.php

示例9: shouldReceive

 /**
  * Initiate a mock expectation on the facade.
  *
  * @param  dynamic
  * @return \Mockery\Expectation
  */
 public static function shouldReceive()
 {
     $name = static::getFacadeAccessor();
     if (static::isMock()) {
         $mock = static::$resolvedInstance[$name];
     } else {
         static::$resolvedInstance[$name] = $mock = \Mockery::mock(static::getMockableClass($name));
         static::$app->instance($name, $mock);
     }
     return call_user_func_array(array($mock, 'shouldReceive'), func_get_args());
 }
开发者ID:centaurustech,项目名称:sagip,代码行数:17,代码来源:Facade.php

示例10: setupApplication

 public function setupApplication($config = true)
 {
     $app = new Application();
     $app->instance('path', 'foobar');
     $app->instance('files', new Filesystem());
     $app->instance('config', new Repository($app->getConfigLoader(), 'foobar'));
     if ($config) {
         $app['config']->set('statsd', array('host' => "localhost", 'port' => 7890, 'namespace' => 'test_namespace'));
     }
     return $app;
 }
开发者ID:threesquared,项目名称:statsd,代码行数:11,代码来源:LaravelTestCase.php

示例11: __construct

 /**
  * Constructor.
  *
  * @param Application $app
  */
 public function __construct(Application $app)
 {
     $this->app = $app;
     $this->httpKernel = $this->app->make('Illuminate\\Contracts\\Http\\Kernel');
     $this->httpKernel->bootstrap();
     $this->app->boot();
     $url = $this->app->config->get('app.url', 'http://localhost');
     $this->app->instance('request', Request::createFromBase(SyfmonyRequest::create($url)));
     $components = parse_url($url);
     $host = isset($components['host']) ? $components['host'] : 'localhost';
     parent::__construct($this, ['HTTP_HOST' => $host]);
     $this->followRedirects(true);
     // Parent constructor sets this to false by default
 }
开发者ID:codeception,项目名称:base,代码行数:19,代码来源:Laravel5.php

示例12: setupApplication

 private function setupApplication()
 {
     $app = new Application();
     $app->setBasePath(sys_get_temp_dir());
     $app->instance('config', new Repository());
     return $app;
 }
开发者ID:rezzafr33,项目名称:apaiio-laravel,代码行数:7,代码来源:ApaiIOServiceProviderTest.php

示例13: setUp

 /**
  * Bootstrap the test environemnt:
  * - Create an application instance and register it within itself.
  * - Register the package service provider with the app.
  * - Set the APP facade.
  *
  * @return void
  */
 public function setUp()
 {
     $app = new Application();
     $app->instance('app', $app);
     $app->register('Ideil\\LaravelFileOre\\LaravelFileOreServiceProvider');
     Facade::setFacadeApplication($app);
 }
开发者ID:ideil,项目名称:laravel-fileore,代码行数:15,代码来源:TestCase.php

示例14: getApplication

 public function getApplication()
 {
     $app = new Application();
     $app->instance('path', __DIR__);
     $app['path.storage'] = __DIR__ . '/storage';
     // Monolog
     $log = m::mock('Illuminate\\Log\\Writer');
     $log->shouldReceive('getMonolog')->andReturn(m::mock('Monolog\\Logger'));
     $app['log'] = $log;
     // Config
     $config = new Repository(m::mock('Illuminate\\Config\\LoaderInterface'), 'production');
     $config->getLoader()->shouldReceive('addNamespace')->with('laravel-sentry', __DIR__);
     $config->getLoader()->shouldReceive('cascadePackage')->andReturnUsing(function ($env, $package, $group, $items) {
         return $items;
     });
     $config->getLoader()->shouldReceive('exists')->with('environments', 'laravel-sentry')->andReturn(false);
     $config->getLoader()->shouldReceive('exists')->with('dsn', 'laravel-sentry')->andReturn(false);
     $config->getLoader()->shouldReceive('exists')->with('level', 'laravel-sentry')->andReturn(false);
     $config->getLoader()->shouldReceive('load')->with('production', 'config', 'laravel-sentry')->andReturn(array('environments' => array('prod', 'production'), 'dsn' => '', 'level' => 'error'));
     $config->package('foo/laravel-sentry', __DIR__);
     $app['config'] = $config;
     // Env
     $app['env'] = 'production';
     return $app;
 }
开发者ID:rcrowe,项目名称:laravel-sentry,代码行数:25,代码来源:ProviderTest.php

示例15: getApplication

 protected function getApplication($customConfig = [])
 {
     $app = new Application();
     $app->instance('path', __DIR__);
     $app['env'] = 'production';
     $app['path.config'] = $this->root . '/config';
     // Filesystem
     $files = m::mock('Illuminate\\Filesystem\\Filesystem');
     $app['files'] = $files;
     // View
     // $finder = m::mock('Illuminate\View\ViewFinderInterface');
     // $finder->shouldReceive('addExtension');
     // $app['view'] = new Factory(
     // new EngineResolver(),
     // $finder,
     // m::mock('Illuminate\Events\Dispatcher')
     // );
     // $config_data = include $config_file;
     // Config
     $app['config'] = new Repository([]);
     $app->bind('\\Illuminate\\Config\\Repository', function () use($app) {
         return $app['config'];
     });
     return $app;
 }
开发者ID:tureki,项目名称:rrs,代码行数:25,代码来源:Base.php


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