Closed ideepblue closed 3 months ago
@ideepblue by default, Winter CMS does not auto-discover Laravel packages, to allow plugins to control whether Laravel packages are loaded or not depending on whether the plugin is installed or not.
You can enable package autodiscovery by changing the loadDiscoveredPackages
value in config/app.php
to true
. Alternatively, if you know that you want this package to be always enabled for your project, you can add its ServiceProvider
class into the providers
array in the same file.
@bennothommo I have already enabled the loadDiscoveredPackages
to true
. I can confirm this package's ServiceProvider has been called when booting up the Winter CMS. That's why I have attached a screenshot showing the driver has been bind into the container protected variable $bindings
.
Please have a look at the screenshot below.
The error only happens when the Laravel package tries to resolve its driver via $this->app->makeWith('<driver-key-name>', $parameters)
.
@ideepblue My apologies - you are right. We will look into this a bit further.
Thanks @bennothommo , let me know if you need more information from me.
This issue will be closed and archived in 3 days, as there has been no activity in the last 60 days. If this issue is still relevant or you would like to see it actioned, please respond and we will re-open this issue. If this issue is critical to your business, consider joining the Premium Support Program where a Service Level Agreement is offered.
My temporary solution, binding the driver to the Winter\Storm\Foundation\Maker
:
use ElfSundae\Laravel\Hashid\Base62Driver;
use ElfSundae\Laravel\Hashid\Base62IntegerDriver;
use ElfSundae\Laravel\Hashid\HashidsDriver;
use ElfSundae\Laravel\Hashid\HashidsIntegerDriver;
use ElfSundae\Laravel\Hashid\HashidsHexDriver;
use ElfSundae\Laravel\Hashid\HashidsStringDriver;
use ElfSundae\Laravel\Hashid\OptimusDriver;
use Winter\Storm\Foundation\Maker;
class Plugin extends PluginBase
{
public function boot()
{
// hashid
$this->solveHashidDriverIssue();
}
private function solveHashidDriverIssue()
{
/** @var Maker $maker */
$drivers = [
Base62Driver::class,
Base62IntegerDriver::class,
HashidsDriver::class,
HashidsHexDriver::class,
HashidsIntegerDriver::class,
HashidsStringDriver::class,
OptimusDriver::class,
];
// Ref: https://github.com/wintercms/winter/issues/249
$maker = $this->app->make(Maker::class);
foreach ($drivers as $concrete) {
$abstract = 'hashid.driver.'
. Str::snake(preg_replace('#Driver$#', '', class_basename($concrete)));
$closure = function ($container, $parameters = []) use ($abstract, $concrete) {
return new $concrete(array_get($parameters, 'config', []));
};
$maker->bind($abstract, $closure);
}
}
}
This issue will be closed and archived in 3 days, as there has been no activity in the last 60 days. If this issue is still relevant or you would like to see it actioned, please respond and we will re-open this issue. If this issue is critical to your business, consider joining the Premium Support Program where a Service Level Agreement is offered.
This issue will be closed and archived in 3 days, as there has been no activity in the last 60 days. If this issue is still relevant or you would like to see it actioned, please respond and we will re-open this issue. If this issue is critical to your business, consider joining the Premium Support Program where a Service Level Agreement is offered.
This issue will be closed and archived in 3 days, as there has been no activity in the last 60 days. If this issue is still relevant or you would like to see it actioned, please respond and we will re-open this issue. If this issue is critical to your business, consider joining the Premium Support Program where a Service Level Agreement is offered.
This issue will be closed and archived in 3 days, as there has been no activity in the last 60 days. If this issue is still relevant or you would like to see it actioned, please respond and we will re-open this issue. If this issue is critical to your business, consider joining the Premium Support Program where a Service Level Agreement is offered.
This issue will be closed and archived in 3 days, as there has been no activity in this issue for the last 6 months. If this issue is still relevant or you would like to see it actioned, please respond within 3 days. If this issue is critical for your business, please reach out to us at wintercms@luketowers.ca.
This issue will be closed and archived in 3 days, as there has been no activity in this issue for the last 6 months. If this issue is still relevant or you would like to see it actioned, please respond within 3 days. If this issue is critical for your business, please reach out to us at wintercms@luketowers.ca.
This issue will be closed and archived in 3 days, as there has been no activity in this issue for the last 6 months. If this issue is still relevant or you would like to see it actioned, please respond within 3 days. If this issue is critical for your business, please reach out to us at wintercms@luketowers.ca.
This issue will be closed and archived in 3 days, as there has been no activity in this issue for the last 6 months. If this issue is still relevant or you would like to see it actioned, please respond within 3 days. If this issue is critical for your business, please reach out to us at wintercms@luketowers.ca.
Description:
I installed a package
elfsundae/laravel-hashid
viacomposer require elfsundae/laravel-hashid
. And publish the config file viaphp artisan vendor:publish --tag=hashid
. I still use the default config file.However, when I use tinker to test this hashid package, I got an error:
I have checked the source code of
elfsundae/laravel-hashid
. In its service provider, it binds the driver into the\Winter\Storm\Foundation\Application::$bindings
. The binding key ishashid.driver.hashids_integer
(See the screenshot below).Driver binding in
\ElfSundae\Laravel\Hashid\HashidServiceProvider::registerServices
When
hashid()
invoked, the package will resolve driver binding via\ElfSundae\Laravel\Hashid\HashidManager::resolveBinding
:It finally reaches
\Winter\Storm\Foundation\Application::make
:Because the driver is binding into the
Winter\Storm\Foundation\Application
, notWinter\Storm\Foundation\Maker
.Then, the actual \Winter\Storm\Foundation\Maker::build function reaches
$reflector = new ReflectionClass('');
, exception throwed.Steps To Reproduce:
composer require elfsundae/laravel-hashid
php artisan vendor:publish --tag=hashid
php artisan tinker
then typehashid()