src/MvcRouteListener.php
/**
     * Trigger the authentication event
     *
     * @param MvcEvent $mvcEvent
     * @return null|Response
     */
Trigger the authentication event
@param MvcEvent $mvcEvent
@return null|Response
Trigger the authentication event @param MvcEvent $mvcEvent @return null|Response
public function authentication(MvcEvent $mvcEvent)
    {
        if (! $mvcEvent->getRequest() instanceof HttpRequest
            || $mvcEvent->getRequest()->isOptions()
        ) {
            return;
        }
        $mvcAuthEvent = $this->mvcAuthEvent;
        $mvcAuthEvent->setName($mvcAuthEvent::EVENT_AUTHENTICATION);
        $responses    = $this->events->triggerEventUntil(function ($r) {
            return ($r instanceof Identity\IdentityInterface
                || $r instanceof Result
                || $r instanceof Response
            );
        }, $mvcAuthEvent);
        $result  = $responses->last();
        $storage = $this->authentication->getStorage();
        if ($result instanceof Response) {
            return $result;
        }
        if ($result instanceof Identity\IdentityInterface) {
            $storage->write($result);
        }
        if ($result instanceof Result
            && $result->isValid()
        ) {
            $mvcAuthEvent->setAuthenticationResult($result);
            $mvcAuthEvent->setIdentity(new Identity\AuthenticatedIdentity($result->getIdentity()));
            return;
        }
        $identity = $this->authentication->getIdentity();
        if ($identity === null && ! $mvcAuthEvent->hasAuthenticationResult()) {
            $mvcAuthEvent->setIdentity(new Identity\GuestIdentity());
            return;
        }
        if ($mvcAuthEvent->hasAuthenticationResult()
            && $mvcAuthEvent->getAuthenticationResult()->isValid()
        ) {
            $mvcAuthEvent->setIdentity(
                new Identity\AuthenticatedIdentity(
                    $mvcAuthEvent->getAuthenticationResult()->getIdentity()
                )
            );
        }
        if ($identity instanceof Identity\IdentityInterface) {
            $mvcAuthEvent->setIdentity($identity);
            return;
        }
        if ($identity !== null) {
            $mvcAuthEvent->setIdentity(new Identity\AuthenticatedIdentity($identity));
            return;
        }
    }
public function authentication ( MvcEvent $ mvcEvent ) { if ( ! $ mvcEvent -> getRequest ( ) instanceof HttpRequest || $ mvcEvent -> getRequest ( ) -> isOptions ( ) ) { return ; } $ mvcAuthEvent = $ this -> mvcAuthEvent ; $ mvcAuthEvent -> setName ( $ mvcAuthEvent :: EVENT_AUTHENTICATION ) ; $ responses = $ this -> events -> triggerEventUntil ( function ( $ r ) { return ( $ r instanceof Identity \ IdentityInterface || $ r instanceof Result || $ r instanceof Response ) ; } , $ mvcAuthEvent ) ; $ result = $ responses -> last ( ) ; $ storage = $ this -> authentication -> getStorage ( ) ; if ( $ result instanceof Response ) { return $ result ; } if ( $ result instanceof Identity \ IdentityInterface ) { $ storage -> write ( $ result ) ; } if ( $ result instanceof Result && $ result -> isValid ( ) ) { $ mvcAuthEvent -> setAuthenticationResult ( $ result ) ; $ mvcAuthEvent -> setIdentity ( new Identity \ AuthenticatedIdentity ( $ result -> getIdentity ( ) ) ) ; return ; } $ identity = $ this -> authentication -> getIdentity ( ) ; if ( $ identity === null && ! $ mvcAuthEvent -> hasAuthenticationResult ( ) ) { $ mvcAuthEvent -> setIdentity ( new Identity \ GuestIdentity ( ) ) ; return ; } if ( $ mvcAuthEvent -> hasAuthenticationResult ( ) && $ mvcAuthEvent -> getAuthenticationResult ( ) -> isValid ( ) ) { $ mvcAuthEvent -> setIdentity ( new Identity \ AuthenticatedIdentity ( $ mvcAuthEvent -> getAuthenticationResult ( ) -> getIdentity ( ) ) ) ; } if ( $ identity instanceof Identity \ IdentityInterface ) { $ mvcAuthEvent -> setIdentity ( $ identity ) ; return ; } if ( $ identity !== null ) { $ mvcAuthEvent -> setIdentity ( new Identity \ AuthenticatedIdentity ( $ identity ) ) ; return ; } }
Trigger the authentication event
 @param MvcEvent $mvcEvent
 @return null|Response
Trigger the authentication event @param MvcEvent $mvcEvent @return null|Response
// If we have a response, return immediately // Determine if the listener returned an identity // If we have a Result, we create an AuthenticatedIdentity from it // if there is no Authentication identity or result, safe to assume we have a guest // identity found in authentication; we can assume we're authenticated