首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Con图只在信任信息发布时才加载。

Con图只在信任信息发布时才加载。
EN

Stack Overflow用户
提问于 2019-09-12 07:20:39
回答 1查看 35关注 0票数 0

我正在为我的应用程序构建一个包,用户可以在那里发布和修改一些config文件(就像每个laravel包一样)。

我最近注意到,只在用户发布配置文件时才加载配置文件。

这是我在GitHub:Laravel客户端上的包回购

这是我的服务提供商

代码语言:javascript
复制
class AdobeConnectServiceProvider extends ServiceProvider implements DeferrableProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        $this->mergeConfigFrom(__DIR__ . "/config/adobeConnect.php", 'adobeConnect');
        $this->bindFacades();
    }

    /**
     * Bind Facades
     *
     * @return void
     */
    private function bindFacades()
    {
        $config = $this->getAdobeConfig();
        $entities = $config["entities"];

        $this->app->singleton(Client::class, function () {
            return $this->processClient();
        });

        $this->app->bind('sco', function () use ($entities) {
            return new $entities["sco"]();
        });
        $this->app->bind('sco-record', function () use ($entities) {
            return new $entities["sco-record"]();
        });
        $this->app->bind('principal', function () use ($entities) {
            return new $entities["principal"]();
        });
        $this->app->bind('permission', function () use ($entities) {
            return new $entities["permission"]();
        });
        $this->app->bind('common-info', function () use ($entities) {
            return new $entities["common-info"]();
        });
        $this->app->singleton('adobe-connect', function () {
            return App::make(Client::class);
        });

    }

    /**
     * get Adobe Connect Client Config
     *
     * @return array|null
     */
    private function getAdobeConfig()
    {
        return $this->app["config"]->get("adobeConnect");
    }

    /**
     * login adobe client in case of there is no session configured
     *
     * @return Client
     */
    private function processClient()
    {
        $config = $this->getAdobeConfig();

        $connection = new Connection($config["host"], $config["connection"]);
        $client = new Client($connection);

        if ($config["session-cache"]["enabled"]) {
            $this->loginClient($client);
        }

        return $client;
    }

    /**
     * Login Client Based information that introduced in environment/config file
     *
     * @param Client $client
     *
     * @return void
     */
    private function loginClient(Client $client)
    {
        $config = $this->getAdobeConfig();
        $driver = $this->getCacheDriver();

        $session = Cache::store($driver)->remember(
            $config['session-cache']['key'],
            $config['session-cache']['timeout'],
            function () use ($config, $client) {
                $client->login($config["user-name"], $config["password"]);
                return $client->getSession();
            });

        $client->setSession($session);
    }

    /**
     * get Preferred cache driver
     *
     * @return string|null
     */
    private function getCacheDriver()
    {
        $config = $this->app["config"]->get("adobeConnect");
        if ($driver = $config["session-cache"]["driver"]) {
            return $driver;
        }
        return $this->app["config"]->get("cache.default");
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        $this->publishes([
            __DIR__ . '/config/adobeConnect.php' => config_path('adobeConnect.php'),
        ], 'adobe-connect');
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return [
            SCORecord::class,
            Principal::class,
            Permission::class,
            CommonInfo::class,
            Client::class,
            SCO::class,
            'adobe-connect'
        ];
    }
}

我读过laravel's的官方套餐,什么也没找到!

EN

回答 1

Stack Overflow用户

发布于 2019-09-12 07:53:21

我发现了问题所在。这个问题在延迟加载提供程序下很难解决:它应该返回facade绑定名称,而不是类名。

代码语言:javascript
复制
    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return [
            Client::class,
            'sco-record',
            'principal',
            'permission',
            'common-info',
            'sco',
            'adobe-connect'
        ];
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57901610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档