自己创建包的问题,按照步骤做的,找不到对应的类,求助!
按步骤做的,但是访问出错了
一、config/app.php 的代码
二、src\Liuxk\Battle\Battle.php 代码
三、src\Liuxk\Battle\BattleServiceProvider.php 代码
四、 Facades 下代码
五、路由文件
六、报错信息:
一、config/app.php 的代码
'Liuxk\Battle\BattleServiceProvider',
二、src\Liuxk\Battle\Battle.php 代码
<?php namespace Liuxk\Battle;
class Battle {
public static function hello(){
return "What's up Zagreb!";
}
}
三、src\Liuxk\Battle\BattleServiceProvider.php 代码
<?php namespace Liuxk\Battle;
use Illuminate\Support\ServiceProvider;
class BattleServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
$this->package('liuxk/battle');
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app['battle'] = $this->app->share(function($app){
return new Battle;
});
$this->app->booting(function(){
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Battle', 'Liuxk\Battle\Facades\Battle');
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array();
}
}
四、 Facades 下代码
<?php namespace Liuxk\Battle\Facades;
use Illuminate\Support\Facades\Facade;
class Battle extends Facade{
protected static function getFacadeAccessor(){
return 'battle!';
}
}
五、路由文件
Route::get('/', function()
{
return View::make('hello');
});
//Route::controller('home','HomeController');
Route::get('swoole', 'SwooleController@init');
Route::get('swoole/connect', 'SwooleController@connect');
Route::get('home/show', array('as' => 'home', 'uses' => 'HomeController@show'));
Route::get('/war', function(){
echo Battle::hello();
});
六、报错信息:
ReflectionException (-1)
Class battle! does not exist
return is_string($abstract) && strpos($abstract, '\\') !== 0;
}
public function build($concrete, $parameters = array())
{
if ($concrete instanceof Closure) {
return $concrete($this, $parameters);
}
$reflector = new ReflectionClass($concrete);
if (!$reflector->isInstantiable()) {
$message = "Target [{$concrete}] is not instantiable.";
1 个回复
00幽靈00 - 略知一二,不求甚解
赞同来自: 小楼 、sysatom
替换成
试试这样。