AppserverIo\Appserver\ServletEngine\StandardSessionManager::find PHP Method

find() public method

Tries to find a session for the given request. The session-ID will be searched in the cookie header of the request, and in the request query string. If both values are present, the value in the query string takes precedence. If no session id is found, a new one is created and assigned to the request.
public find ( string $id ) : AppserverIo\Psr\Servlet\Http\ServletSessionInterface | null
$id string The unique session ID to that has to be returned
return AppserverIo\Psr\Servlet\Http\ServletSessionInterface | null The requested session
    public function find($id)
    {
        // return immediately if the requested session ID is empty
        if (empty($id)) {
            return;
        }
        // declare the session variable
        $session = null;
        // query whether or not the session with the passed ID exists
        if ($this->getSessions()->exists($id)) {
            $session = $this->getSessions()->get($id);
        } else {
            // iterate over the session handlers and try to un-persist the session
            /** @var \AppserverIo\Appserver\ServletEngine\Session\SessionHandlerInterface $sessionHandler */
            foreach ($this->getSessionHandlers() as $sessionHandler) {
                try {
                    if ($session = $sessionHandler->load($id)) {
                        $this->attach($session);
                        break;
                    }
                } catch (\Exception $e) {
                    // log the exception if a system logger is available
                    if ($logger = $this->getLogger(LoggerUtils::SYSTEM)) {
                        $logger->error($e->__toString());
                    }
                }
            }
        }
        // if we found a session, we've to check if it can be resumed
        if ($session instanceof ServletSessionInterface) {
            if ($session->canBeResumed()) {
                $session->resume();
                return $session;
            }
        }
    }