本文整理汇总了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);
}
示例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);
}
示例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} ?>";
});
}
示例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;
}
示例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));
}
}
示例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;
}
示例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();
}
示例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;
}
示例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());
}
示例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;
}
示例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
}
示例12: setupApplication
private function setupApplication()
{
$app = new Application();
$app->setBasePath(sys_get_temp_dir());
$app->instance('config', new Repository());
return $app;
}
示例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);
}
示例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;
}
示例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;
}