在使用Lumen进行开发的时候。如果你使用:./artisan的时候报错:Cannot declare class Event, because the name is already in use。检查一下LOG发现是:
XML/HTML代码
- [2016-12-07 15:27:37] lumen.ERROR: ErrorException: Cannot declare class Event, because the name is already in use in /home/web/vendor/laravel/lumen-framework/src/Application.php:661
- Stack trace:
- #0 [internal function]: Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}(2, 'Cannot declare ...', '/Volumes/docume...', 661, Array)
- #1 /home/web/vendor/laravel/lumen-framework/src/Application.php(661): class_alias('Illuminate\\Supp...', 'Event')
- #2 /home/web/vendor/laravel/lumen-framework/src/Application.php(631): Laravel\Lumen\Application->withAliases(Array)
- #3 /home/web/vendor/laravel/lumen-framework/src/Application.php(766): Laravel\Lumen\Application->withFacades(true)
- #4 /home/web/vendor/laravel/lumen-framework/src/Console/Kernel.php(54): Laravel\Lumen\Application->prepareForConsoleCommand(true)
- #5 [internal function]: Laravel\Lumen\Console\Kernel->__construct(Object(Laravel\Lumen\Application))
- #6 /home/web/vendor/illuminate/container/Container.php(794): ReflectionClass->newInstanceArgs(Array)
- #7 /home/web/vendor/illuminate/container/Container.php(644): Illuminate\Container\Container->build('App\\Console\\Ker...', Array)
- #8 /home/web/vendor/laravel/lumen-framework/src/Application.php(211): Illuminate\Container\Container->make('App\\Console\\Ker...', Array)
- #9 /home/web/vendor/illuminate/container/Container.php(231): Laravel\Lumen\Application->make('App\\Console\\Ker...', Array)
- #10 /home/web/vendor/illuminate/container/Container.php(746): Illuminate\Container\Container->Illuminate\Container\{closure}(Object(Laravel\Lumen\Application), Array)
- #11 /home/web/vendor/illuminate/container/Container.php(644): Illuminate\Container\Container->build(Object(Closure), Array)
- #12 /home/web/vendor/laravel/lumen-framework/src/Application.php(211): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
- #13 /home/web/artisan(32): Laravel\Lumen\Application->make('Illuminate\\Cont...')
- #14 {main}
看了一下,Application.php的第661行对应的方法,我靠。
PHP代码
- /**
- * Register the aliases for the application.
- *
- * @param array $userAliases
- * @return void
- */
- public function withAliases($userAliases = [])
- {
- $defaults = [
- 'Illuminate\Support\Facades\Auth' => 'Auth',
- 'Illuminate\Support\Facades\Cache' => 'Cache',
- 'Illuminate\Support\Facades\DB' => 'DB',
- 'Illuminate\Support\Facades\Event' => 'Events',
- 'Illuminate\Support\Facades\Gate' => 'Gate',
- 'Illuminate\Support\Facades\Log' => 'Log',
- 'Illuminate\Support\Facades\Queue' => 'Queue',
- 'Illuminate\Support\Facades\Schema' => 'Schema',
- 'Illuminate\Support\Facades\URL' => 'URL',
- 'Illuminate\Support\Facades\Validator' => 'Validator',
- ];
- if (! static::$aliasesRegistered) {
- static::$aliasesRegistered = true;
- $merged = array_merge($defaults, $userAliases);
- foreach ($merged as $original => $alias) {
- class_alias($original, $alias);
- }
- }
- }
。。。。。怎么可以这样写呢?也不担心代码会不会冲突。就直接这样了??怪不得很多代码识别不了。更痛苦的是,前段时间为了测试命令行下的多线程,加载了:brew install php70-event,直接就冲突了。
不得已,brew remove php70-event。反正这个我也几乎用不到。哎~
所幸,搞定