Skip to content

Instantiate message via late static binding #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Message implements \ArrayAccess, \IteratorAggregate
/**
* Creates a Message object from the raw POST data
*
* @return Message
* @return static
* @throws \RuntimeException If the POST data is absent, or not a valid JSON document
*/
public static function fromRawPostData()
Expand All @@ -41,25 +41,25 @@ public static function fromRawPostData()
}

// Read the raw POST data and JSON-decode it into a message.
return self::fromJsonString(file_get_contents('php://input'));
return static::fromJsonString(file_get_contents('php://input'));
}

/**
* Creates a Message object from a PSR-7 Request or ServerRequest object.
*
* @param RequestInterface $request
* @return Message
* @return static
*/
public static function fromPsrRequest(RequestInterface $request)
{
return self::fromJsonString($request->getBody());
return static::fromJsonString($request->getBody());
}

/**
* Creates a Message object from a JSON-decodable string.
*
* @param string $requestBody
* @return Message
* @return static
*/
public static function fromJsonString($requestBody)
{
Expand All @@ -68,7 +68,7 @@ public static function fromJsonString($requestBody)
throw new \RuntimeException('Invalid POST data.');
}

return new Message($data);
return new static($data);
}

/**
Expand Down