<commit_before><?php

namespace OAuth2;

use OutOfBoundsException;
use OAuth2\Storage\SessionInterface;
use OAuth2\Storage\SessionScopeInterface;

class ResourceServer
{
    protected $accessToken = null;

    protected $sessionId = null;

    protected $ownerType = null;

    protected $ownerId = null;

    protected $sessionScopes = array();

    protected $storages = array();

    protected $request = null;

    protected $tokenKey = 'oauth_token';

    /**
     * Sets up the Resource
     *
     * @param  SessionInterface  The Session Storage Object
     * @param  SessionScopeInterface  The Session Scope Storage Object
     */
    public function __construct(SessionInterface $session, SessionScopeInterface $session_scope)
    {
        $this->storages['session'] = $session;
        $this->storages['session_scope'] = $session_scope;
    }

    /**
     * Sets the Request Object
     *
     * @param  RequestInterface The Request Object
     */
    public function setRequest(RequestInterface $request)
    {
        $this->request = $request;
    }

    /**
     * Gets the Request object.  It will create one from the globals if one is not set.
     *
     * @return  RequestInterface
     */
    public function getRequest()
    {
        if ($this->request === null) {
            $this->request = Request::buildFromGlobals();
        }

        return $this->request;
    }

    /**
     * Gets the Owner ID.
     *
     * @return  int
     */
    public function getOwnerId()
    {
        return $this->ownerId;
    }

    /**
     * Gets the Owner Type.
     *
     * @return  string
     */
    public function getOwnerType()
    {
        return $this->ownerId;
    }

    /**
     * Gets the Access Token.
     *
     * @return  string
     */
    public function getAccessToken()
    {
        return $this->accessToken;
    }

    /**
     * Checks if the Access Token is valid or not.
     *
     * @return bool
     */
    public function isValid()
    {
        $access_token = $this->determineAccessToken();

        $result = $this->storages['session']->validateAccessToken($access_token);

        if ( ! $result) {
            return false;
        }

        $this->accessToken = $access_token;
        $this->sessionId = $result['id'];
        $this->ownerType = $result['owner_type'];
        $this->ownerId = $result['owner_id'];

        $this->sessionScopes = $this->storages['session_scope']->getScopes($this->sessionId);

        return true;
    }

    /**
     * Checks if the current session has the given scope(s).
     *
     * @param   array
     */
    public function hasScope($scopes)
    {
        if (is_string($scopes)) {
            if (in_array($scopes, $this->sessionScopes)) {
                return true;
            }
            return false;
        } elseif (is_array($scopes)) {
            foreach ($scopes as $scope) {<commit_msg>Various bug fixes<commit_after><?php

namespace OAuth2;

use OutOfBoundsException;
use OAuth2\Storage\SessionInterface;
use OAuth2\Storage\SessionScopeInterface;
use OAuth2\Util\RequestInterface;

class ResourceServer
{
    protected $accessToken = null;

    protected $sessionId = null;

    protected $ownerType = null;

    protected $ownerId = null;

    protected $sessionScopes = array();

    protected $storages = array();

    protected $request = null;

    protected $tokenKey = 'oauth_token';

    /**
     * Sets up the Resource
     *
     * @param  SessionInterface  The Session Storage Object
     * @param  SessionScopeInterface  The Session Scope Storage Object
     */
    public function __construct(SessionInterface $session)
    {
        $this->storages['session'] = $session;
    }

    /**
     * Sets the Request Object
     *
     * @param  RequestInterface The Request Object
     */
    public function setRequest(RequestInterface $request)
    {
        $this->request = $request;
    }

    /**
     * Gets the Request object.  It will create one from the globals if one is not set.
     *
     * @return  RequestInterface
     */
    public function getRequest()
    {
        if ($this->request === null) {
            // @codeCoverageIgnoreStart
            $this->request = Request::buildFromGlobals();
        }
        // @codeCoverageIgnoreEnd

        return $this->request;
    }

    public function getTokenKey()
    {
        return $this->tokenKey;
    }

    public function setTokenKey($key)
    {
        $this->tokenKey = $key;
    }

    /**
     * Gets the Owner ID.
     *
     * @return  int
     */
    public function getOwnerId()
    {
        return $this->ownerId;
    }

    /**
     * Gets the Owner Type.
     *
     * @return  string
     */
    public function getOwnerType()
    {
        return $this->ownerType;
    }

    /**
     * Gets the Access Token.
     *
     * @return  string
     */
    public function getAccessToken()
    {
        return $this->accessToken;
    }

    /**
     * Checks if the Access Token is valid or not.
     *
     * @return bool
     */
    public function isValid()
    {
        $access_token = $this->determineAccessToken();

        $result = $this->storages['session']->validateAccessToken($access_token);

        if ( ! $result) {
            return false;
        }

        $this->accessToken = $access_token;
        $this->sessionId = $result['id'];
        $this->ownerType = $result['owner_type'];
        $this->ownerId = $result['owner_id'];

        $this->sessionScopes = $this->storages['session']->getScopes($this->sessionId);

        return true;
    }

    /**
     * Checks if the current session has the given scope(s).
     *
     * @param   array
     */
    public function hasScope($scopes)
    {
        if (is_string($scopes)) {
            if (in_array($scopes, $this->sessionScopes)) {
                return true;
            }
            return false;
        } elseif (is_array($scopes)) {
            foreach ($scopes as $scope) {
{'fraction_non_alphanumeric': 0.11697670521199934, 'fraction_numerical': 0.0011731188201776438, 'mean_word_length': 2.014141414141414, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4866435', 'n_tokens_mistral': 1753, 'n_tokens_neox': 1702, 'n_words': 414}