Skip to content

Commit

Permalink
Cleaning up the foundation application.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Dec 19, 2016
1 parent 3df97c8 commit 3385fdc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
17 changes: 4 additions & 13 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,20 +559,13 @@ public function register($provider, $options = [], $force = false)
// application instance automatically for the developer. This is simply
// a more convenient way of specifying your service provider classes.
if (is_string($provider)) {
$provider = $this->resolveProviderClass($provider);
$provider = $this->resolveProvider($provider);
}

if (method_exists($provider, 'register')) {
$provider->register();
}

// Once we have registered the service we will iterate through the options
// and set each of them on the application so they will be available on
// the actual loading of the service objects and for developer usage.
foreach ($options as $key => $value) {
$this[$key] = $value;
}

$this->markAsRegistered($provider);

// If the application has already booted, we will call this boot method on
Expand Down Expand Up @@ -606,7 +599,7 @@ public function getProvider($provider)
* @param string $provider
* @return \Illuminate\Support\ServiceProvider
*/
public function resolveProviderClass($provider)
public function resolveProvider($provider)
{
return new $provider($this);
}
Expand All @@ -619,11 +612,9 @@ public function resolveProviderClass($provider)
*/
protected function markAsRegistered($provider)
{
$this['events']->fire($class = get_class($provider), [$provider]);

This comment has been minimized.

Copy link
@neyaoz

neyaoz Jan 1, 2017

Contributor

What is the reason for this deletion? It is useful to observe for a provider registration to manipulate it when we need. Actually, we are able to do it via App@booting, maybe this is why. Right?


$this->serviceProviders[] = $provider;

$this->loadedProviders[$class] = true;
$this->loadedProviders[get_class($provider)] = true;
}

/**
Expand Down Expand Up @@ -1051,7 +1042,7 @@ public function setLocale($locale)

$this['translator']->setLocale($locale);

$this['events']->fire('locale.changed', [$locale]);
$this['events']->fire(new Events\LocaleUpdated($locale));
}

/**
Expand Down
24 changes: 24 additions & 0 deletions src/Illuminate/Foundation/Events/LocaleUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Illuminate\Foundation\Events;

class LocaleUpdated
{
/**
* The new locale.
*
* @var string
*/
public $locale;

/**
* Create a new event instance.
*
* @param string $locale
* @return void
*/
public function __construct($locale)
{
$this->locale = $locale;
}
}
2 changes: 1 addition & 1 deletion tests/Foundation/FoundationApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testSetLocaleSetsLocaleAndFiresLocaleChangedEvent()
$app['translator'] = $trans = m::mock('StdClass');
$trans->shouldReceive('setLocale')->once()->with('foo');
$app['events'] = $events = m::mock('StdClass');
$events->shouldReceive('fire')->once()->with('locale.changed', ['foo']);
$events->shouldReceive('fire')->once()->with(m::type('Illuminate\Foundation\Events\LocaleUpdated'));

$app->setLocale('foo');
}
Expand Down
8 changes: 2 additions & 6 deletions tests/Foundation/FoundationProviderRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ public function testServicesAreRegisteredWhenManifestIsNotRecompiled()
$repo->shouldReceive('loadManifest')->once()->andReturn(['eager' => ['foo'], 'deferred' => ['deferred'], 'providers' => ['providers'], 'when' => []]);
$repo->shouldReceive('shouldRecompile')->once()->andReturn(false);
$provider = m::mock('Illuminate\Support\ServiceProvider');
$repo->shouldReceive('createProvider')->once()->with('foo')->andReturn($provider);

$app->shouldReceive('register')->once()->with($provider);
$app->shouldReceive('register')->once()->with('foo');
$app->shouldReceive('runningInConsole')->andReturn(false);
$app->shouldReceive('addDeferredServices')->once()->with(['deferred']);

Expand Down Expand Up @@ -48,10 +47,7 @@ public function testManifestIsProperlyRecompiled()
return $manifest;
});

// bar mock should be registered with the application since it's eager
$repo->shouldReceive('createProvider')->once()->with('bar')->andReturn($barMock);

$app->shouldReceive('register')->once()->with($barMock);
$app->shouldReceive('register')->once()->with('bar');
$app->shouldReceive('runningInConsole')->andReturn(false);
$app->shouldReceive('addDeferredServices')->once()->with(['foo.provides1' => 'foo', 'foo.provides2' => 'foo']);

Expand Down

0 comments on commit 3385fdc

Please sign in to comment.