АС
Size: a a a
АС
АС
АС
АС
АС
АС
АС
EG
$interfaceClass = $factory->getClassByUser($user);
SM
$this->app->bind(Email::class, function ($app) {
return $app['request']->user()->getEmail();
});
АС
$this->app->bind(Interface::class, function ($app) {
return new Class1($app['request']->user());
});
DE
$interfaceClass = $factory->getClassByUser($user);
АС
АС
DM
services:
App\MyService:
factory: ['@App\MyServiceFactory', createMyServiceFactory]
arguments: ['@security.context']
EG
services:
App\MyService:
factory: ['@App\MyServiceFactory', createMyServiceFactory]
arguments: ['@security.context']
DM
EG
// src/Service/ExampleService.phpв случае с Laravel это будет AuthManager, скорее всего
// ...
use Symfony\Component\Security\Core\Security;
class ExampleService
{
private $security;
public function __construct(Security $security)
{
// Avoid calling getUser() in the constructor: auth may not
// be complete yet. Instead, store the entire Security object.
$this->security = $security;
}
public function someMethod()
{
// returns User object or null if not authenticated
$user = $this->security->getUser();
}
}
EG