Skip to content
Snippets Groups Projects
Select Git revision
  • master
  • release-1.1.0
  • laminas_migration
  • laminas_migration_bs5
  • 1.1.0
  • 4.0.0
  • 2.0.0
  • 1.0.1
  • 1.0.0
  • 0.2
  • 0.1
11 results

AdapterChain.php

Blame
  • Forked from lib / unicaen / authentification
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    AdapterChain.php 2.44 KiB
    <?php
    
    namespace UnicaenAuthentification\Authentication\Adapter;
    
    use Zend\Stdlib\RequestInterface as Request;
    use Zend\Stdlib\ResponseInterface as Response;
    use ZfcUser\Exception;
    
    class AdapterChain extends \ZfcUser\Authentication\Adapter\AdapterChain
    {
        /**
         * prepareForAuthentication
         *
         * @param  Request $request
         * @return Response|bool
         * @throws Exception\AuthenticationEventException
         */
        public function prepareForAuthentication(Request $request)
        {
            $e = $this->getEvent();
            $e->setRequest($request);
    
            $this->getEventManager()->trigger('authenticate.pre', $e);
    
            $result = $this->getEventManager()->triggerUntil(function ($result) {
                return $result === true || $result instanceof Response;
            }, 'authenticate', $e);
    
            if ($result->stopped()) {
                $last = $result->last();
                if ($last === true || $last instanceof Response) {
                    return $last;
                }
    //            throw new Exception\AuthenticationEventException(
    //                sprintf(
    //                    'Auth event was stopped without a response. Got "%s" instead',
    //                    is_object($result->last()) ? get_class($result->last()) : gettype($result->last())
    //                )
    //            );
            }
    
            if ($e->getIdentity()) {
                $this->getEventManager()->trigger('authenticate.success', $e);
                return true;
            }
    
            $this->getEventManager()->trigger('authenticate.fail', $e);
    
            return false;
        }
    
        /**
         * logoutAdapters
         *
         * @return Response|null
         */
        public function logoutAdapters(): ?Response
        {
            //Adapters might need to perform additional cleanup after logout
            $responseCollection = $this->getEventManager()->triggerUntil(function ($test) {
                return ($test instanceof Response);
            }, 'logout', $this->getEvent());
    
            if ($responseCollection->stopped()) {
                if ($responseCollection->last() instanceof Response) {
                    return $responseCollection->last();
                }
    
                throw new Exception\AuthenticationEventException(
                    sprintf(