我正在尝试为我的应用程序构建一个软件包,并且有一些config
文件可供用户发布和修改配置(例如每个laravel
软件包)。
我最近注意到只有在用户发布配置文件时才加载配置文件。
这是我在GitHub上的软件包仓库:Laravel Adobe Connect Client
这是我的服务提供商:
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
官方package,但一无所获!
答案 0 :(得分:0)
我发现了问题。该问题在延迟加载提供者的抵抗下: 它应该返回外观绑定名称而不是类名称。
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return [
Client::class,
'sco-record',
'principal',
'permission',
'common-info',
'sco',
'adobe-connect'
];
}