getUser example


final class SmsBiurasTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): SmsBiurasTransport
    {
        $scheme = $dsn->getScheme();

        if ('smsbiuras' !== $scheme) {
            throw new UnsupportedSchemeException($dsn, 'smsbiuras', $this->getSupportedSchemes());
        }

        $uid = $this->getUser($dsn);
        $apiKey = $this->getPassword($dsn);
        $from = $dsn->getRequiredOption('from');
        $testMode = filter_var($dsn->getOption('test_mode', false), \FILTER_VALIDATE_BOOL);
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        return (new SmsBiurasTransport($uid$apiKey$from$testMode$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    protected function getSupportedSchemes(): array
    {
        
if (\in_array($dsn->getOption('secureHttp', true)[0, false, 'false', 'off', 'no'])) {
            $secureHttp = false;
        } else {
            $secureHttp = true;
        }

        $transport = (new NtfyTransport($topic$secureHttp))->setHost($host);
        if (!empty($port = $dsn->getPort())) {
            $transport->setPort($port);
        }

        if (!empty($user = $dsn->getUser()) && !empty($password = $dsn->getPassword())) {
            $transport->setUser($user);
            $transport->setPassword($password);
        }

        return $transport;
    }

    protected function getSupportedSchemes(): array
    {
        return ['ntfy'];
    }
}
private readonly ContainerInterface $container,
        private readonly array $authenticators = [],
    ) {
    }

    public function getUser(): ?UserInterface
    {
        if (!$token = $this->getToken()) {
            return null;
        }

        return $token->getUser();
    }

    /** * Checks if the attributes are granted against the current authentication token and optionally supplied subject. */
    public function isGranted(mixed $attributes, mixed $subject = null): bool
    {
        return $this->container->get('security.authorization_checker')
            ->isGranted($attributes$subject);
    }

    

final class KazInfoTehTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): TransportInterface
    {
        $scheme = $dsn->getScheme();

        if ('kaz-info-teh' !== $scheme) {
            throw new UnsupportedSchemeException($dsn, 'kaz-info-teh', $this->getSupportedSchemes());
        }

        $username = $this->getUser($dsn);
        $password = $this->getPassword($dsn);
        $sender = $dsn->getRequiredOption('sender');
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        return (new KazInfoTehTransport($username$password$sender$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    protected function getSupportedSchemes(): array
    {
        return ['kaz-info-teh'];
    }
$this->assertEquals($request->getMethod()$finalRequest->getMethod());
            $this->assertEquals($request->getPassword()$finalRequest->getPassword());
            $this->assertEquals($request->getPathInfo()$finalRequest->getPathInfo());
            $this->assertEquals($request->getPort()$finalRequest->getPort());
            $this->assertEquals($request->getProtocolVersion()$finalRequest->getProtocolVersion());
            $this->assertEquals($request->getQueryString()$finalRequest->getQueryString());
            $this->assertEquals($request->getRequestUri()$finalRequest->getRequestUri());
            $this->assertEquals($request->getScheme()$finalRequest->getScheme());
            $this->assertEquals($request->getSchemeAndHttpHost()$finalRequest->getSchemeAndHttpHost());
            $this->assertEquals($request->getScriptName()$finalRequest->getScriptName());
            $this->assertEquals($request->getUri()$finalRequest->getUri());
            $this->assertEquals($request->getUser()$finalRequest->getUser());
            $this->assertEquals($request->getUserInfo()$finalRequest->getUserInfo());
        } elseif ($finalRequest instanceof ServerRequestInterface) {
            $strToLower = function D$arr) {
                foreach ($arr as $key => $value) {
                    yield strtolower($key) => $value;
                }
            };
            $this->assertEquals($request->getAttributes()$finalRequest->getAttributes());
            $this->assertEquals($request->getCookieParams()$finalRequest->getCookieParams());
            $this->assertEquals((array) $request->getParsedBody()(array) $finalRequest->getParsedBody());
            $this->assertEquals($request->getQueryParams()$finalRequest->getQueryParams());
            

    public function setUser(UserInterface $user)
    {
        $this->user = $user;
    }

    /** * @return void */
    public function eraseCredentials()
    {
        if ($this->getUser() instanceof UserInterface) {
            $this->getUser()->eraseCredentials();
        }
    }

    /** * Returns all the necessary state of the object for serialization purposes. * * There is no need to serialize any entry, they should be returned as-is. * If you extend this method, keep in mind you MUST guarantee parent data is present in the state. * Here is an example of how to extend this method: * <code> * public function __serialize(): array * { * return [$this->childAttribute, parent::__serialize()]; * } * </code> * * @see __unserialize() */
final class OrangeSmsTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): OrangeSmsTransport
    {
        $scheme = $dsn->getScheme();

        if ('orange-sms' !== $scheme) {
            throw new UnsupportedSchemeException($dsn, 'orange-sms', $this->getSupportedSchemes());
        }

        $user = $this->getUser($dsn);
        $password = $this->getPassword($dsn);
        $from = $dsn->getRequiredOption('from');
        $senderName = $dsn->getOption('sender_name');
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        return (new OrangeSmsTransport($user$password$from$senderName$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    protected function getSupportedSchemes(): array
    {
        
/** * Returns the current user. * * @see TokenInterface::getUser() */
    public function getUser(): ?UserInterface
    {
        if (!isset($this->tokenStorage)) {
            throw new \RuntimeException('The "app.user" variable is not available.');
        }

        return $this->tokenStorage->getToken()?->getUser();
    }

    /** * Returns the current request. */
    public function getRequest(): ?Request
    {
        if (!isset($this->requestStack)) {
            throw new \RuntimeException('The "app.request" variable is not available.');
        }

        

final class ZendeskTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): ZendeskTransport
    {
        $scheme = $dsn->getScheme();

        if ('zendesk' !== $scheme) {
            throw new UnsupportedSchemeException($dsn, 'zendesk', $this->getSupportedSchemes());
        }

        $emailAddress = $this->getUser($dsn);
        $apiToken = $this->getPassword($dsn);
        $host = $this->getHost($dsn);

        return (new ZendeskTransport($emailAddress$apiToken$this->client, $this->dispatcher))->setHost($host);
    }

    protected function getSupportedSchemes(): array
    {
        return ['zendesk'];
    }

    
$this->_summaryNet = (bool) ($config['summaryNet'] ?? false);
        $this->_shippingCostsAsPosition = (bool) ($config['shippingCostsAsPosition'] ?? false);

        $this->getOrder();

        $this->initializeShopContext((int) $this->_order['language']);
        $this->countryGateway = Shopware()->Container()->get(CountryGatewayInterface::class);
        $this->structConverter = Shopware()->Container()->get(LegacyStructConverter::class);

        $this->getPositions();

        $this->getUser();
        $this->getBilling();
        $this->getShipping();
        $this->getDispatch();
        $this->getPayment();
        $this->getPaymentInstances();

        $this->processPositions();
        $this->processOrder();
    }

    /** * Convert this object into an array * * @return array<string, mixed> */
$userBadge = $this->accessTokenHandler->getUserBadgeFrom($accessToken);
        if ($this->userProvider && (null === $userBadge->getUserLoader() || $userBadge->getUserLoader() instanceof FallbackUserLoader)) {
            $userBadge->setUserLoader($this->userProvider->loadUserByIdentifier(...));
        }

        return new SelfValidatingPassport($userBadge);
    }

    public function createToken(Passport $passport, string $firewallName): TokenInterface
    {
        return new PostAuthenticationToken($passport->getUser()$firewallName$passport->getUser()->getRoles());
    }

    public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
    {
        return $this->successHandler?->onAuthenticationSuccess($request$token);
    }

    public function onAuthenticationFailure(Request $request, AuthenticationException $exception): Response
    {
        if (null !== $this->failureHandler) {
            return $this->failureHandler->onAuthenticationFailure($request$exception);
        }
private function getVariables(TokenInterface $token, mixed $subject): array
    {
        $roleNames = $token->getRoleNames();

        if (null !== $this->roleHierarchy) {
            $roleNames = $this->roleHierarchy->getReachableRoleNames($roleNames);
        }

        $variables = [
            'token' => $token,
            'user' => $token->getUser(),
            'object' => $subject,
            'subject' => $subject,
            'role_names' => $roleNames,
            'trust_resolver' => $this->trustResolver,
            'auth_checker' => $this->authChecker,
        ];

        // this is mainly to propose a better experience when the expression is used         // in an access control rule, as the developer does not know that it's going         // to be handled by this voter         if ($subject instanceof Request) {
            


            $logoutUrl = null;
            try {
                $logoutUrl = $this->logoutUrlGenerator?->getLogoutPath();
            } catch (\Exception) {
                // fail silently when the logout URL cannot be generated             }

            $this->data = [
                'enabled' => true,
                'authenticated' => (bool) $token->getUser(),
                'impersonated' => null !== $impersonatorUser,
                'impersonator_user' => $impersonatorUser,
                'impersonation_exit_path' => null,
                'token' => $token,
                'token_class' => $this->hasVarDumper ? new ClassStub($token::class) : $token::class,
                'logout_url' => $logoutUrl,
                'user' => $token->getUserIdentifier(),
                'roles' => $assignedRoles,
                'inherited_roles' => array_unique($inheritedRoles),
                'supports_role_hierarchy' => null !== $this->roleHierarchy,
            ];
        }
/** @var RememberMeBadge $badge */
        $badge = $passport->getBadge(RememberMeBadge::class);
        if (!$badge->isEnabled()) {
            $this->logger?->debug('Remember me skipped: the RememberMeBadge is not enabled.');

            return;
        }

        $this->logger?->debug('Remember-me was requested; setting cookie.');

        $this->rememberMeHandler->createRememberMeCookie($event->getUser());
    }

    public function clearCookie(): void
    {
        $this->rememberMeHandler->clearRememberMeCookie();
    }

    public static function getSubscribedEvents(): array
    {
        return [
            LoginSuccessEvent::class => ['onSuccessfulLogin', -64],
            
$userIdentifier = strtolower($user->getUserIdentifier());
        if (isset($this->users[$userIdentifier])) {
            throw new \LogicException('Another user with the same username already exists.');
        }

        $this->users[$userIdentifier] = $user;
    }

    public function loadUserByIdentifier(string $identifier): UserInterface
    {
        $user = $this->getUser($identifier);

        return new InMemoryUser($user->getUserIdentifier()$user->getPassword()$user->getRoles()$user->isEnabled());
    }

    public function refreshUser(UserInterface $user): UserInterface
    {
        if (!$user instanceof InMemoryUser) {
            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_debug_type($user)));
        }

        $storedUser = $this->getUser($user->getUserIdentifier());
        
Home | Imprint | This part of the site doesn't use cookies.