diff --git a/framework/core/src/Event/AbstractConfigureGambits.php b/framework/core/src/Event/AbstractConfigureGambits.php index 824e052e2..fd228c490 100644 --- a/framework/core/src/Event/AbstractConfigureGambits.php +++ b/framework/core/src/Event/AbstractConfigureGambits.php @@ -17,7 +17,7 @@ abstract class AbstractConfigureGambits /** * @var GambitManager */ - protected $gambits; + public $gambits; /** * @param GambitManager $gambits diff --git a/framework/core/src/Event/ConfigureApiController.php b/framework/core/src/Event/ConfigureApiController.php index 0a2a2a4d5..511fa225e 100644 --- a/framework/core/src/Event/ConfigureApiController.php +++ b/framework/core/src/Event/ConfigureApiController.php @@ -27,6 +27,15 @@ class ConfigureApiController $this->controller = $controller; } + /** + * @param string $controller + * @return bool + */ + public function isController($controller) + { + return $this->controller instanceof $controller; + } + /** * Set the serializer that will serialize data for the endpoint. * @@ -40,11 +49,11 @@ class ConfigureApiController /** * Include the given relationship by default. * - * @param string $name + * @param string|array $name */ public function addInclude($name) { - $this->controller->include[] = $name; + $this->controller->include = array_merge($this->controller->include, (array) $name); } /** diff --git a/framework/core/src/Event/ConfigureClientView.php b/framework/core/src/Event/ConfigureClientView.php index cb2a0d613..d492a7de4 100644 --- a/framework/core/src/Event/ConfigureClientView.php +++ b/framework/core/src/Event/ConfigureClientView.php @@ -64,9 +64,9 @@ class ConfigureClientView $this->view->addBootstrapper($bootstrapper); } - public function addTranslations(array $keys) + public function addTranslations($keys) { - foreach ($keys as $key) { + foreach ((array) $keys as $key) { $this->keys[] = $key; } } diff --git a/framework/core/src/Event/GetApiRelationship.php b/framework/core/src/Event/GetApiRelationship.php index 3453907c8..323cf0e63 100644 --- a/framework/core/src/Event/GetApiRelationship.php +++ b/framework/core/src/Event/GetApiRelationship.php @@ -44,4 +44,14 @@ class GetApiRelationship $this->serializer = $serializer; $this->relationship = $relationship; } + + /** + * @param string $serializer + * @param string $relationship + * @return bool + */ + public function isRelationship($serializer, $relationship) + { + return $this->serializer instanceof $serializer && $this->relationship === $relationship; + } } diff --git a/framework/core/src/Event/GetModelRelationship.php b/framework/core/src/Event/GetModelRelationship.php index 6d62c907c..f48cb55ad 100644 --- a/framework/core/src/Event/GetModelRelationship.php +++ b/framework/core/src/Event/GetModelRelationship.php @@ -37,4 +37,14 @@ class GetModelRelationship $this->model = $model; $this->relationship = $relationship; } + + /** + * @param string $model + * @param string $relationship + * @return bool + */ + public function isRelationship($model, $relationship) + { + return $this->model instanceof $model && $this->relationship === $relationship; + } } diff --git a/framework/core/src/Event/PrepareApiAttributes.php b/framework/core/src/Event/PrepareApiAttributes.php index 28d0a8aee..ef45499c1 100644 --- a/framework/core/src/Event/PrepareApiAttributes.php +++ b/framework/core/src/Event/PrepareApiAttributes.php @@ -41,6 +41,11 @@ class PrepareApiAttributes */ public $attributes; + /** + * @var \Flarum\Core\User + */ + public $actor; + /** * @param AbstractSerializer $serializer The class doing the serializing. * @param object|array $model The model being serialized. @@ -51,5 +56,15 @@ class PrepareApiAttributes $this->serializer = $serializer; $this->model = $model; $this->attributes = &$attributes; + $this->actor = $serializer->getActor(); + } + + /** + * @param string $serializer + * @return bool + */ + public function isSerializer($serializer) + { + return $this->serializer instanceof $serializer; } } diff --git a/framework/core/src/Event/PrepareApiData.php b/framework/core/src/Event/PrepareApiData.php index 7dbfb1fe7..26d9b6d84 100644 --- a/framework/core/src/Event/PrepareApiData.php +++ b/framework/core/src/Event/PrepareApiData.php @@ -37,9 +37,15 @@ class PrepareApiData public $document; /** - * @param AbstractSerializeController $endpoint + * @var \Flarum\Core\User + */ + public $actor; + + /** + * @param AbstractSerializeController $controller * @param mixed $data * @param ServerRequestInterface $request + * @param Document $document */ public function __construct( AbstractSerializeController $controller, @@ -51,5 +57,15 @@ class PrepareApiData $this->data = &$data; $this->request = $request; $this->document = $document; + $this->actor = $request->getAttribute('actor'); + } + + /** + * @param string $controller + * @return bool + */ + public function isController($controller) + { + return $this->controller instanceof $controller; } }