Skip to content

Commit

Permalink
Merge pull request #27915 from xuanquynh/getNamespace_is_independent
Browse files Browse the repository at this point in the history
[5.8] getNamespace is independent
  • Loading branch information
taylorotwell authored Mar 18, 2019
2 parents 4de008b + 9b5b6d5 commit c2410f0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -1174,11 +1174,11 @@ public function getNamespace()
return $this->namespace;
}

$composer = json_decode(file_get_contents(base_path('composer.json')), true);
$composer = json_decode(file_get_contents($this->basePath('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)) {
if (realpath($this->path()) === realpath($this->basePath($pathChoice))) {
return $this->namespace = $namespace;
}
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Foundation/FoundationApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,15 @@ public function testBootedCallbacks()

$this->assertEquals(4, $counter);
}

public function testGetNamespace()
{
$app1 = new Application(realpath(__DIR__.'/fixtures/laravel1'));
$app2 = new Application(realpath(__DIR__.'/fixtures/laravel2'));

$this->assertSame('Laravel\\One\\', $app1->getNamespace());
$this->assertSame('Laravel\\Two\\', $app2->getNamespace());
}
}

class ApplicationBasicServiceProviderStub extends ServiceProvider
Expand Down
7 changes: 7 additions & 0 deletions tests/Foundation/fixtures/laravel1/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"autoload": {
"psr-4": {
"Laravel\\One\\": "app/"
}
}
}
7 changes: 7 additions & 0 deletions tests/Foundation/fixtures/laravel2/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"autoload": {
"psr-4": {
"Laravel\\Two\\": "app/"
}
}
}

0 comments on commit c2410f0

Please sign in to comment.