-
-
Notifications
You must be signed in to change notification settings - Fork 826
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the Request available to the Formatter\Rendering event (#1721)
This is important because extensions may wish to render post content differently depending on Request factors such as the actor. For example, an attachments extension might wish to hide attachments from guests. This solution is a bit of a hack-job for now, but soon when we refactor the API layer to use tobscure/json-api-server, and also refactor the Formatter layer, it can be revised.
- Loading branch information
1 parent
9b68bbe
commit 0ab9fac
Showing
7 changed files
with
41 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
use Illuminate\Contracts\Events\Dispatcher; | ||
use InvalidArgumentException; | ||
use LogicException; | ||
use Psr\Http\Message\ServerRequestInterface as Request; | ||
use Tobscure\JsonApi\AbstractSerializer as BaseAbstractSerializer; | ||
use Tobscure\JsonApi\Collection; | ||
use Tobscure\JsonApi\Relationship; | ||
|
@@ -28,6 +29,11 @@ | |
|
||
abstract class AbstractSerializer extends BaseAbstractSerializer | ||
{ | ||
/** | ||
* @var Request | ||
*/ | ||
protected $request; | ||
|
||
/** | ||
* @var User | ||
*/ | ||
|
@@ -44,19 +50,28 @@ abstract class AbstractSerializer extends BaseAbstractSerializer | |
protected static $container; | ||
|
||
/** | ||
* @return User | ||
* @return Request | ||
*/ | ||
public function getActor() | ||
public function getRequest() | ||
{ | ||
return $this->actor; | ||
return $this->request; | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
*/ | ||
public function setRequest(Request $request) | ||
{ | ||
$this->request = $request; | ||
$this->actor = $request->getAttribute('actor'); | ||
} | ||
|
||
/** | ||
* @param User $actor | ||
* @return User | ||
*/ | ||
public function setActor(User $actor) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
luceos
Member
|
||
public function getActor() | ||
{ | ||
$this->actor = $actor; | ||
return $this->actor; | ||
} | ||
|
||
/** | ||
|
@@ -231,7 +246,7 @@ protected function resolveSerializerClass($class) | |
{ | ||
$serializer = static::$container->make($class); | ||
|
||
$serializer->setActor($this->actor); | ||
$serializer->setRequest($this->request); | ||
|
||
return $serializer; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It's reasonable to provide a public method to set actor
I don't think it's a good idea to remove a public method without a good reason, because it can crash extensions.