mirror of
https://github.com/flarum/framework.git
synced 2025-02-07 16:23:02 +08:00
Remove deprecated API events
This commit is contained in:
parent
2ee8358dbb
commit
1ae7dbe464
|
@ -110,10 +110,8 @@ class ApiServiceProvider extends AbstractServiceProvider
|
|||
$this->setNotificationSerializers();
|
||||
|
||||
AbstractSerializeController::setContainer($this->app);
|
||||
AbstractSerializeController::setEventDispatcher($events = $this->app->make('events'));
|
||||
|
||||
AbstractSerializer::setContainer($this->app);
|
||||
AbstractSerializer::setEventDispatcher($events);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,11 +9,8 @@
|
|||
|
||||
namespace Flarum\Api\Controller;
|
||||
|
||||
use Flarum\Api\Event\WillGetData;
|
||||
use Flarum\Api\Event\WillSerializeData;
|
||||
use Flarum\Api\JsonApiResponse;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
|
@ -77,11 +74,6 @@ abstract class AbstractSerializeController implements RequestHandlerInterface
|
|||
*/
|
||||
protected static $container;
|
||||
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected static $events;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
@ -107,11 +99,6 @@ abstract class AbstractSerializeController implements RequestHandlerInterface
|
|||
}
|
||||
}
|
||||
|
||||
// Deprected in beta 15, removed in beta 16
|
||||
static::$events->dispatch(
|
||||
new WillGetData($this)
|
||||
);
|
||||
|
||||
$data = $this->data($request, $document);
|
||||
|
||||
foreach (array_reverse(array_merge([static::class], class_parents($this))) as $class) {
|
||||
|
@ -122,11 +109,6 @@ abstract class AbstractSerializeController implements RequestHandlerInterface
|
|||
}
|
||||
}
|
||||
|
||||
// Deprecated in beta 15, removed in beta 16
|
||||
static::$events->dispatch(
|
||||
new WillSerializeData($this, $data, $request, $document)
|
||||
);
|
||||
|
||||
$serializer = static::$container->make($this->serializer);
|
||||
$serializer->setRequest($request);
|
||||
|
||||
|
@ -325,22 +307,6 @@ abstract class AbstractSerializeController implements RequestHandlerInterface
|
|||
$this->sort = $sort;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Dispatcher
|
||||
*/
|
||||
public static function getEventDispatcher()
|
||||
{
|
||||
return static::$events;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public static function setEventDispatcher(Dispatcher $events)
|
||||
{
|
||||
static::$events = $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Container
|
||||
*/
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Api\Event;
|
||||
|
||||
use DateTime;
|
||||
use Flarum\Api\Serializer\AbstractSerializer;
|
||||
|
||||
/**
|
||||
* Prepare API attributes.
|
||||
*
|
||||
* This event is fired when a serializer is constructing an array of resource
|
||||
* attributes for API output.
|
||||
*
|
||||
* @deprecated in beta 15, removed in beta 16
|
||||
*/
|
||||
class Serializing
|
||||
{
|
||||
/**
|
||||
* The class doing the serializing.
|
||||
*
|
||||
* @var AbstractSerializer
|
||||
*/
|
||||
public $serializer;
|
||||
|
||||
/**
|
||||
* The model being serialized.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $model;
|
||||
|
||||
/**
|
||||
* The serialized attributes of the resource.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $attributes;
|
||||
|
||||
/**
|
||||
* @var \Flarum\User\User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
/**
|
||||
* @param AbstractSerializer $serializer The class doing the serializing.
|
||||
* @param object|array $model The model being serialized.
|
||||
* @param array $attributes The serialized attributes of the resource.
|
||||
*/
|
||||
public function __construct(AbstractSerializer $serializer, $model, array &$attributes)
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime|null $date
|
||||
* @return string|null
|
||||
*/
|
||||
public function formatDate(DateTime $date = null)
|
||||
{
|
||||
if ($date) {
|
||||
return $date->format(DateTime::RFC3339);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,141 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Api\Event;
|
||||
|
||||
use Flarum\Api\Controller\AbstractSerializeController;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
/**
|
||||
* @deprecated in beta 15, removed in beta 16
|
||||
*/
|
||||
class WillGetData
|
||||
{
|
||||
/**
|
||||
* @var AbstractSerializeController
|
||||
*/
|
||||
public $controller;
|
||||
|
||||
/**
|
||||
* @param AbstractSerializeController $controller
|
||||
*/
|
||||
public function __construct(AbstractSerializeController $controller)
|
||||
{
|
||||
$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.
|
||||
*
|
||||
* @param string $serializer
|
||||
*/
|
||||
public function setSerializer($serializer)
|
||||
{
|
||||
$this->controller->serializer = $serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the given relationship by default.
|
||||
*
|
||||
* @param string|array $name
|
||||
*/
|
||||
public function addInclude($name)
|
||||
{
|
||||
$this->controller->include = array_merge($this->controller->include, (array) $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't include the given relationship by default.
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function removeInclude($name)
|
||||
{
|
||||
Arr::forget($this->controller->include, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the given relationship available for inclusion.
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function addOptionalInclude($name)
|
||||
{
|
||||
$this->controller->optionalInclude[] = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't allow the given relationship to be included.
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function removeOptionalInclude($name)
|
||||
{
|
||||
Arr::forget($this->controller->optionalInclude, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default number of results.
|
||||
*
|
||||
* @param int $limit
|
||||
*/
|
||||
public function setLimit($limit)
|
||||
{
|
||||
$this->controller->limit = $limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum number of results.
|
||||
*
|
||||
* @param int $max
|
||||
*/
|
||||
public function setMaxLimit($max)
|
||||
{
|
||||
$this->controller->maxLimit = $max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow sorting results by the given field.
|
||||
*
|
||||
* @param string $field
|
||||
*/
|
||||
public function addSortField($field)
|
||||
{
|
||||
$this->controller->sortFields[] = $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disallow sorting results by the given field.
|
||||
*
|
||||
* @param string $field
|
||||
*/
|
||||
public function removeSortField($field)
|
||||
{
|
||||
Arr::forget($this->controller->sortFields, $field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default sort order for the results.
|
||||
*
|
||||
* @param array $sort
|
||||
*/
|
||||
public function setSort(array $sort)
|
||||
{
|
||||
$this->controller->sort = $sort;
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Api\Event;
|
||||
|
||||
use Flarum\Api\Controller\AbstractSerializeController;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
/**
|
||||
* @deprecated in beta 15, removed in beta 16
|
||||
*/
|
||||
class WillSerializeData
|
||||
{
|
||||
/**
|
||||
* @var AbstractSerializeController
|
||||
*/
|
||||
public $controller;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* @var ServerRequestInterface
|
||||
*/
|
||||
public $request;
|
||||
|
||||
/**
|
||||
* @var Document
|
||||
*/
|
||||
public $document;
|
||||
|
||||
/**
|
||||
* @var \Flarum\User\User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
/**
|
||||
* @param AbstractSerializeController $controller
|
||||
* @param mixed $data
|
||||
* @param ServerRequestInterface $request
|
||||
* @param Document $document
|
||||
*/
|
||||
public function __construct(
|
||||
AbstractSerializeController $controller,
|
||||
&$data,
|
||||
ServerRequestInterface $request,
|
||||
Document $document
|
||||
) {
|
||||
$this->controller = $controller;
|
||||
$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;
|
||||
}
|
||||
}
|
|
@ -11,11 +11,8 @@ namespace Flarum\Api\Serializer;
|
|||
|
||||
use Closure;
|
||||
use DateTime;
|
||||
use Flarum\Api\Event\Serializing;
|
||||
use Flarum\Event\GetApiRelationship;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Support\Arr;
|
||||
use InvalidArgumentException;
|
||||
use LogicException;
|
||||
|
@ -38,11 +35,6 @@ abstract class AbstractSerializer extends BaseAbstractSerializer
|
|||
*/
|
||||
protected $actor;
|
||||
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected static $dispatcher;
|
||||
|
||||
/**
|
||||
* @var Container
|
||||
*/
|
||||
|
@ -105,11 +97,6 @@ abstract class AbstractSerializer extends BaseAbstractSerializer
|
|||
}
|
||||
}
|
||||
|
||||
// Deprecated in beta 15, removed in beta 16
|
||||
static::$dispatcher->dispatch(
|
||||
new Serializing($this, $model, $attributes)
|
||||
);
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
|
@ -153,27 +140,21 @@ abstract class AbstractSerializer extends BaseAbstractSerializer
|
|||
*/
|
||||
protected function getCustomRelationship($model, $name)
|
||||
{
|
||||
// Deprecated in beta 15, removed in beta 16
|
||||
$relationship = static::$dispatcher->until(
|
||||
new GetApiRelationship($this, $name, $model)
|
||||
);
|
||||
|
||||
foreach (array_merge([static::class], class_parents($this)) as $class) {
|
||||
$callback = Arr::get(static::$customRelations, "$class.$name");
|
||||
|
||||
if (is_callable($callback)) {
|
||||
$relationship = $callback($this, $model);
|
||||
break;
|
||||
|
||||
if (isset($relationship) && ! ($relationship instanceof Relationship)) {
|
||||
throw new LogicException(
|
||||
'GetApiRelationship handler must return an instance of '.Relationship::class
|
||||
);
|
||||
}
|
||||
|
||||
return $relationship;
|
||||
}
|
||||
}
|
||||
|
||||
if ($relationship && ! ($relationship instanceof Relationship)) {
|
||||
throw new LogicException(
|
||||
'GetApiRelationship handler must return an instance of '.Relationship::class
|
||||
);
|
||||
}
|
||||
|
||||
return $relationship;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -282,22 +263,6 @@ abstract class AbstractSerializer extends BaseAbstractSerializer
|
|||
return $serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Dispatcher
|
||||
*/
|
||||
public static function getEventDispatcher()
|
||||
{
|
||||
return static::$dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Dispatcher $dispatcher
|
||||
*/
|
||||
public static function setEventDispatcher(Dispatcher $dispatcher)
|
||||
{
|
||||
static::$dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Container
|
||||
*/
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Event;
|
||||
|
||||
use Flarum\Api\Serializer\AbstractSerializer;
|
||||
|
||||
/**
|
||||
* Get an API serializer relationship.
|
||||
*
|
||||
* This event is fired when a relationship is to be included on an API document.
|
||||
* If a handler wishes to fulfil the given relationship, then it should return
|
||||
* an instance of `Tobscure\JsonApi\Relationship`.
|
||||
*
|
||||
* @see AbstractSerializer::hasOne()
|
||||
* @see AbstractSerializer::hasMany()
|
||||
* @see https://github.com/tobscure/json-api
|
||||
*
|
||||
* @deprecated in beta 15, removed in beta 16
|
||||
*/
|
||||
class GetApiRelationship
|
||||
{
|
||||
/**
|
||||
* @var AbstractSerializer
|
||||
*/
|
||||
public $serializer;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $relationship;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
public $model;
|
||||
|
||||
/**
|
||||
* @param AbstractSerializer $serializer
|
||||
* @param string $relationship
|
||||
* @param mixed $model
|
||||
*/
|
||||
public function __construct(AbstractSerializer $serializer, $relationship, $model)
|
||||
{
|
||||
$this->serializer = $serializer;
|
||||
$this->relationship = $relationship;
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $serializer
|
||||
* @param string $relationship
|
||||
* @return bool
|
||||
*/
|
||||
public function isRelationship($serializer, $relationship)
|
||||
{
|
||||
return $this->serializer instanceof $serializer && $this->relationship === $relationship;
|
||||
}
|
||||
}
|
|
@ -10,10 +10,8 @@
|
|||
namespace Flarum\Tests\integration\api\discussions;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Event\ScopeModelVisibility;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class ShowTest extends TestCase
|
||||
|
|
Loading…
Reference in New Issue
Block a user