首页 文章

Laravel 4 facade类不在外观根类上调用函数

提问于
浏览
0

我通过artisan workbench命令在laravel 4中设置了一个包 . 我创建了一个facade类,然后按照this tutorial提出以下服务提供者,facade和root类:

SRC / Spoolphiz / Infusionsoft / InfusionsoftServiceProvider.php:

namespace Spoolphiz\Infusionsoft;
use Illuminate\Support\ServiceProvider;

class InfusionsoftServiceProvider extends ServiceProvider {

    protected $defer = false;

    /**
     * Bootstrap the application events.
     *
     * @return void
     */
    public function boot()
    {
        $this->package('spoolphiz/infusionsoft');
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {   
        // Register 'infusionsoft' instance container to our Infusionsoft object
        $this->app['infusionsoft'] = $this->app->share(function($app)
        {
            return new Spoolphiz\Infusionsoft\Infusionsoft;
        });
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return array();
    }

}

SRC / Spoolphiz / Infusionsoft /墙面/ Facade.php:

namespace Spoolphiz\Infusionsoft\Facades;

use Illuminate\Support\Facades\Facade;

class Infusionsoft extends Facade {

    /**
     * Get the registered name of the component.
     *
     * @return string
     */
    protected static function getFacadeAccessor() { return 'infusionsoft'; }

}

最后,我在src / Spoolphiz / Infusionsoft / Infusionsoft.php中设置了要连接到外观的底层类:

namespace Spoolphiz\Infusionsoft;

//use Spoolphiz\Infusionsoft\iSDK;
/*
This is hackish and a un-laravel way to handle the requirement of \iSDK but unfortunately the xmlrpc3.0 lib doesn't want to correctly encode values when run with a namespace. Will try to resolve this later.
*/
require_once(__DIR__.'/isdk.php');

class Infusionsoft extends \iSDK {

    protected $_app;

    /**
    * Init the sdk
    * 
    */
    public function __construct( $connectionName )
    {           
        $this->_app = parent::cfgCon($connectionName);
    }

    public function test()
    {
        dd('works');
    }
}

我在app / config / config.php中设置了Infusionsoft的服务提供者和外观别名 . 当我尝试针对Spoolphiz \ Infusionsoft \ Facade \ Infusionsoft的实例运行属于扩展iSDK类的方法时,我得到未定义的方法错误,如下所示:

调用未定义的方法Spoolphiz \ Infusionsoft \ Facades \ Infusionsoft :: loadCon()

为什么是这样?外观的重点是能够根据其根类调用方法......

1 回答

  • 3

    看起来我是傻瓜 . 我正在laravel工作台上开发这个软件包 . 完成后我将其提交给packagist并在同一个laravel应用程序中设置它的要求 . 将软件包安装在供应商目录和工作台中会导致某种冲突 .

    获得的经验教训:确保您的工作台和应用程序的供应商目录中没有相同的软件包 .

相关问题