Please provide your PHP and Swoole version. (php -v and php --ri swoole)
PHP: 7.2.8
Swoole: 4.0.4
Please provide your Laravel/Lumen version.
Laravel 5.6.35
Which release version of this package are you using?
Laravel Swoole: 2.4.1
What did you do? If possible, provide a recipe for reproducing the error.
Created an custom UserProvider for authentification.
declare(strict_types=1);
namespace App\Auth;
use App\Repository\User\UserRepositoryInterface;
use Illuminate\Auth\EloquentUserProvider as ServiceProvider;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
/**
* Class EloquentCachedUserProvider
* @package App\Auth
*
* Created to cache users for authentication
* Caching is supported only for OAuth authentication now
*/
class EloquentCachedUserProvider extends ServiceProvider
{
/**
* @var UserRepositoryInterface
*/
protected $userRepository;
/**
* EloquentCachedUserProvider constructor.
* @param HasherContract $hasher
* @param string $model model class name
* @param UserRepositoryInterface $userRepository
*/
public function __construct(HasherContract $hasher, string $model, UserRepositoryInterface $userRepository)
{
$this->userRepository = $userRepository;
parent::__construct($hasher, $model);
}
/**
* Retrieve a user by their unique identifier.
*
* @param mixed $identifier
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function retrieveById($identifier): ?\Illuminate\Contracts\Auth\Authenticatable
{
return $this->userRepository->get($identifier);
}
}
Registered that user provider in AuthServiceProvider:
/**
* Register any authentication / authorization services.
*/
public function register(): void
{
$this->app->singleton(EloquentCachedUserProvider::class, function (ApplicationContract $app) {
/* @var \Illuminate\Auth\AuthManager $authManager */
$authManager = $app['auth'];
/* @var \Illuminate\Config\Repository $config */
$config = $app['config'];
/* @var \Illuminate\Contracts\Hashing\Hasher $hasher */
$hasher = $app['hash'];
/* @var UserRepositoryInterface $userRepository */
$userRepository = $app->get(UserRepositoryInterface::class);
$authUserProvider = $authManager->getDefaultUserProvider() ?? 'users';
$authUserProviderConfig = $config->get("auth.providers.{$authUserProvider}");
return new EloquentCachedUserProvider(
$hasher,
$authUserProviderConfig['model'],
$userRepository
);
});
}
What did you expect to see?
UserProvider should be resolved only once.
What did you see instead?
It doesn't work without including AuthServiceProvder to "providers" section and UserProvider is resolved everytime.
So, i've tried to register UserProvider inside the Application class, but this didn't bring the desired result.
I've read past issues with a similar question, but all I've seen is that the feature is not yet implemented. Is there any clean workaround to this? Maybe overriding something to patch pre-resolved instances list?
Hi @codercms ,
Indeed, this feature is not implemented yet. Recently I'm working on refactoring this project and coroutine feature. This will be supported in the next release version.
@albertcht thanks! I'm really looking forward to release of that feature.
Good luck!
Hi @codercms ,
This feature has been implemented in release v2.5.0. Now you can customize it in pre_resolved in swoole_http.php. You can go check it.
Most helpful comment
Hi @codercms ,
Indeed, this feature is not implemented yet. Recently I'm working on refactoring this project and coroutine feature. This will be supported in the next release version.