0

我已经通过 artisan workbench 命令在 laravel 4 中设置了一个包。我创建了一个外观类并按照本教程提出了以下服务提供者、外观和根类:

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/Facades/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()

为什么是这样?外观的全部意义在于能够针对其根类调用方法......

4

1 回答 1

3

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

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

于 2013-06-14T18:44:53.813 回答