Skip to content

Implement ResourceAdapter abstract methods #23

@miscampbell

Description

@miscampbell

Hi

Can I propose we remove the abstract methods that are declared on the ResourceAdapter.php class and implement them to return an Exception instead?

My reason for this is to fix the issue when I wished to extend the ResourceAdapter and have requirement for the majority of the methods that are already flagged as abstract.

Let me know your thoughts. Please see example of the type of class declaration I wish to avoid:

class RevokeTokenResourceAdapter extends ResourceAdapter
{
    public function post($payload, $params, WebRequest $request)
    {
        $token = $this->extractAuthorizationToken($request);

        try {
            $apiToken = ApiToken::findFirst(new Equals('Token', $token));
            $apiToken->Expires = new RhubarbDateTime('-10 seconds');
            $apiToken->save();
        } catch (RecordNotFoundException $ex) {
        }

        $response = new \stdClass();
        $response->status = true;

        return $response;
    }

    private function extractAuthorizationToken(WebRequest $request)
    {
        $token = '';
        if (!$request->header("Authorization")) {
            Log::debug("Authorization header missing. If using fcgi be sure to instruct Apache to include this header", "RESTAPI");
            return $token;
        }

        $authString = trim($request->header("Authorization"));

        if (stripos($authString, "token") !== 0 && stripos($authString, "bearer") !== 0) {
            return $token;
        }

        if (!preg_match("/(token|bearer)(=|\s+)\"?([[:alnum:]]+)\"?/i", $authString, $match)) {
            return $token;
        }

        $token = $match[3];

        return $token;
    }

    protected function countItems($rangeStart, $rangeEnd, $params, ?WebRequest $request)
    {

    }

    protected function getItems($rangeStart, $rangeEnd, $params, ?WebRequest $request)
    {

    }

    public function putResource($resource)
    {

    }

    public function makeResourceByIdentifier($id)
    {

    }

    public function makeResourceFromData($data)
    {

    }
}

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions