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