From 639f85d2a4ca08e7b9a2e002bb0d572a53a15a84 Mon Sep 17 00:00:00 2001 From: "N.Ilya" Date: Fri, 5 Jun 2015 20:11:02 +0000 Subject: [PATCH] Fix app namespace determination --- src/Illuminate/Foundation/Application.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index 8edf6c0cb844..b677b5916f3f 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -3,6 +3,7 @@ namespace Illuminate\Foundation; use Closure; +use RuntimeException; use Illuminate\Http\Request; use Illuminate\Container\Container; use Illuminate\Filesystem\Filesystem; @@ -1054,6 +1055,8 @@ protected function getKernel() * Get the application namespace. * * @return string + * + * @ throws \RuntimeException */ public function getNamespace() { @@ -1061,8 +1064,16 @@ public function getNamespace() return $this->namespace; } - $this->namespace = strtok(get_class($this->getKernel()), '\\').'\\'; + $composer = json_decode(file_get_contents(base_path().'/composer.json'), true); + + foreach ((array) data_get($composer, 'autoload.psr-4') as $namespace => $path) { + foreach ((array) $path as $pathChoice) { + if (realpath(app_path()) == realpath(base_path().'/'.$pathChoice)) { + return $this->namespace = $namespace; + } + } + } - return $this->namespace; + throw new RuntimeException('Unable to detect application namespace.'); } }