Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/Illuminate/Console/AppNamespaceDetectorTrait.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
<?php namespace Illuminate\Console;

use Illuminate\Container\Container;

trait AppNamespaceDetectorTrait {

/**
* Get the application namespace from the Kernel object.
* Get the application namespace.
*
* @return string
*
* @throws \RuntimeException
*/
protected function getAppNamespace()
{
$kernelContract = app()->runningInConsole()
? 'Illuminate\Contracts\Console\Kernel'
: 'Illuminate\Contracts\Http\Kernel';

return strtok(get_class(app($kernelContract)), '\\').'\\';
return Container::getInstance()->getNamespace();
}

}
8 changes: 3 additions & 5 deletions src/Illuminate/Console/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

abstract class GeneratorCommand extends Command {

use AppNamespaceDetectorTrait;

/**
* The filesystem instance.
*
Expand Down Expand Up @@ -70,7 +68,7 @@ public function fire()
*/
protected function getPath($name)
{
$name = str_replace($this->getAppNamespace(), '', $name);
$name = str_replace($this->laravel->getNamespace(), '', $name);

return $this->laravel['path'].'/'.str_replace('\\', '/', $name).'.php';
}
Expand All @@ -83,7 +81,7 @@ protected function getPath($name)
*/
protected function parseName($name)
{
$rootNamespace = $this->getAppNamespace();
$rootNamespace = $this->laravel->getNamespace();

if (starts_with($name, $rootNamespace))
{
Expand Down Expand Up @@ -150,7 +148,7 @@ protected function replaceNamespace(&$stub, $name)
);

$stub = str_replace(
'DummyRootNamespace', $this->getAppNamespace(), $stub
'DummyRootNamespace', $this->laravel->getNamespace(), $stub
);

return $this;
Expand Down
35 changes: 35 additions & 0 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ class Application extends Container implements ApplicationContract, HttpKernelIn
*/
protected $environmentFile = '.env';

/**
* The application namespace.
*
* @var string
*/
protected $namespace = null;

/**
* Create a new Illuminate application instance.
*
Expand Down Expand Up @@ -937,4 +944,32 @@ public function flush()
$this->loadedProviders = [];
}

/**
* Get the used kernel object.
*
* @return \Illuminate\Contracts\Console\Kernel|\Illuminate\Contracts\Http\Kernel
*/
protected function getKernel()
{
$kernelContract = $this->runningInConsole()
? 'Illuminate\Contracts\Console\Kernel'
: 'Illuminate\Contracts\Http\Kernel';

return $this->make($kernelContract);
}

/**
* Get the application namespace.
*
* @return string
*/
public function getNamespace()
{
if ( ! is_null($this->namespace)) return $this->namespace;

$this->namespace = strtok(get_class($this->getKernel()), '\\').'\\';

return $this->namespace;
}

}
5 changes: 1 addition & 4 deletions src/Illuminate/Foundation/Console/AppNameCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
use Illuminate\Foundation\Composer;
use Symfony\Component\Finder\Finder;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Console\AppNamespaceDetectorTrait;
use Symfony\Component\Console\Input\InputArgument;

class AppNameCommand extends Command {

use AppNamespaceDetectorTrait;

/**
* The console command name.
*
Expand Down Expand Up @@ -68,7 +65,7 @@ public function __construct(Composer $composer, Filesystem $files)
*/
public function fire()
{
$this->currentRoot = trim($this->getAppNamespace(), '\\');
$this->currentRoot = trim($this->laravel->getNamespace(), '\\');

$this->setBootstrapNamespaces();

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Foundation/Console/HandlerEventCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ protected function buildClass($name)

$event = $this->option('event');

if ( ! starts_with($event, $this->getAppNamespace()))
if ( ! starts_with($event, $this->laravel->getNamespace()))
{
$event = $this->getAppNamespace().'Events\\'.$event;
$event = $this->laravel->getNamespace().'Events\\'.$event;
}

$stub = str_replace(
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Foundation/Console/ListenerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ protected function buildClass($name)

$event = $this->option('event');

if ( ! starts_with($event, $this->getAppNamespace()))
if ( ! starts_with($event, $this->laravel->getNamespace()))
{
$event = $this->getAppNamespace().'Events\\'.$event;
$event = $this->laravel->getNamespace().'Events\\'.$event;
}

$stub = str_replace(
Expand Down