mirror of
https://github.com/flarum/framework.git
synced 2025-01-19 18:12:59 +08:00
Update various event APIs
This commit is contained in:
parent
6bf93ae9f7
commit
d12d8fa5dd
|
@ -17,7 +17,7 @@ abstract class AbstractConfigureGambits
|
|||
/**
|
||||
* @var GambitManager
|
||||
*/
|
||||
protected $gambits;
|
||||
public $gambits;
|
||||
|
||||
/**
|
||||
* @param GambitManager $gambits
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user