Skip to content

Commit

Permalink
Rebind Illuminate\Foundation\Bootstrap\LoadConfiguration with `Orch…
Browse files Browse the repository at this point in the history
…estra\Testbench\Bootstrap\LoadConfiguration`. Alternative solution to #77

Signed-off-by: crynobone <crynobone@gmail.com>
  • Loading branch information
crynobone committed Feb 7, 2015
1 parent a209cad commit be2e93e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ title: Testbench Change Log
### v3.0.2@dev {#v3-0-2}

* Timezone should be more explicit, and shouldn't attempt to set `date_default_timezone_set()` when timezone is `NULL`.
* Rebind `Illuminate\Foundation\Bootstrap\LoadConfiguration` with `Orchestra\Testbench\Bootstrap\LoadConfiguration`.

### v3.0.1 {#v3-0-1}

Expand Down
60 changes: 60 additions & 0 deletions src/Bootstrap/LoadConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php namespace Orchestra\Testbench\Bootstrap;

use Illuminate\Config\Repository;
use Symfony\Component\Finder\Finder;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Config\Repository as RepositoryContract;

class LoadConfiguration
{

/**
* Bootstrap the given application.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @return void
*/
public function bootstrap(Application $app)
{
$items = [];

$app->instance('config', $config = new Repository($items));

$this->loadConfigurationFiles($app, $config);

date_default_timezone_set($config['app.timezone']);

mb_internal_encoding('UTF-8');
}

/**
* Load the configuration items from all of the files.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @param \Illuminate\Contracts\Config\Repository $config
* @return void
*/
protected function loadConfigurationFiles(Application $app, RepositoryContract $config)
{
foreach ($this->getConfigurationFiles($app) as $key => $path) {
$config->set($key, require $path);
}
}

/**
* Get all of the configuration files for the application.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @return array
*/
protected function getConfigurationFiles(Application $app)
{
$files = [];

foreach (Finder::create()->files()->name('*.php')->in($app->configPath()) as $file) {
$files[basename($file->getRealPath(), '.php')] = $file->getRealPath();
}

return $files;
}
}
6 changes: 5 additions & 1 deletion src/Traits/ApplicationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ public function createApplication()
*/
protected function resolveApplication()
{
return new Application($this->getBasePath());
$app = new Application($this->getBasePath());

$app->bind('Illuminate\Foundation\Bootstrap\LoadConfiguration', 'Orchestra\Testbench\Bootstrap\LoadConfiguration');

return $app;
}

/**
Expand Down

0 comments on commit be2e93e

Please sign in to comment.