Merge pull request #2557 from flarum/as/remove-deprecated

Remove deprecated PHP events, bootstrap.php fallback
This commit is contained in:
Alexander Skvortsov 2021-01-23 16:52:38 -05:00 committed by GitHub
commit e42df50d31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 38 additions and 1268 deletions

View File

@ -13,7 +13,6 @@ use Flarum\Api\Controller\AbstractSerializeController;
use Flarum\Api\Serializer\AbstractSerializer;
use Flarum\Api\Serializer\BasicDiscussionSerializer;
use Flarum\Api\Serializer\NotificationSerializer;
use Flarum\Event\ConfigureNotificationTypes;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\ErrorHandling\JsonApiFormatter;
use Flarum\Foundation\ErrorHandling\Registry;
@ -111,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);
}
/**
@ -122,14 +119,8 @@ class ApiServiceProvider extends AbstractServiceProvider
*/
protected function setNotificationSerializers()
{
$blueprints = [];
$serializers = $this->app->make('flarum.api.notification_serializers');
// Deprecated in beta 15, remove in beta 16
$this->app->make('events')->dispatch(
new ConfigureNotificationTypes($blueprints, $serializers)
);
foreach ($serializers as $type => $serializer) {
NotificationSerializer::setSubjectSerializer($type, $serializer);
}

View File

@ -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
*/

View File

@ -12,7 +12,6 @@ namespace Flarum\Api\Controller;
use Flarum\Api\Serializer\DiscussionSerializer;
use Flarum\Discussion\Command\ReadDiscussion;
use Flarum\Discussion\Command\StartDiscussion;
use Flarum\Post\Floodgate;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
@ -41,19 +40,12 @@ class CreateDiscussionController extends AbstractCreateController
*/
protected $bus;
/**
* @var Floodgate
*/
protected $floodgate;
/**
* @param Dispatcher $bus
* @param Floodgate $floodgate
*/
public function __construct(Dispatcher $bus, Floodgate $floodgate)
public function __construct(Dispatcher $bus)
{
$this->bus = $bus;
$this->floodgate = $floodgate;
}
/**
@ -64,13 +56,6 @@ class CreateDiscussionController extends AbstractCreateController
$actor = $request->getAttribute('actor');
$ipAddress = Arr::get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1');
/**
* @deprecated, remove in beta 15.
*/
if (! $request->getAttribute('bypassFloodgate')) {
$this->floodgate->assertNotFlooding($actor);
}
$discussion = $this->bus->dispatch(
new StartDiscussion($actor, Arr::get($request->getParsedBody(), 'data', []), $ipAddress)
);

View File

@ -12,7 +12,6 @@ namespace Flarum\Api\Controller;
use Flarum\Api\Serializer\PostSerializer;
use Flarum\Discussion\Command\ReadDiscussion;
use Flarum\Post\Command\PostReply;
use Flarum\Post\Floodgate;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
@ -40,19 +39,12 @@ class CreatePostController extends AbstractCreateController
*/
protected $bus;
/**
* @var \Flarum\Post\Floodgate
*/
protected $floodgate;
/**
* @param Dispatcher $bus
* @param \Flarum\Post\Floodgate $floodgate
*/
public function __construct(Dispatcher $bus, Floodgate $floodgate)
public function __construct(Dispatcher $bus)
{
$this->bus = $bus;
$this->floodgate = $floodgate;
}
/**
@ -65,13 +57,6 @@ class CreatePostController extends AbstractCreateController
$discussionId = Arr::get($data, 'relationships.discussion.data.id');
$ipAddress = Arr::get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1');
/**
* @deprecated, remove in beta 15.
*/
if (! $request->getAttribute('bypassFloodgate')) {
$this->floodgate->assertNotFlooding($actor);
}
$post = $this->bus->dispatch(
new PostReply($discussionId, $actor, $data, $ipAddress)
);

View File

@ -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);
}
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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
*/

View File

@ -9,7 +9,6 @@
namespace Flarum\Database;
use Flarum\Event\ScopeModelVisibility;
use Flarum\User\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;
@ -41,11 +40,6 @@ trait ScopeVisibilityTrait
*/
public function scopeWhereVisibleTo(Builder $query, User $actor, string $ability = 'view')
{
/**
* @deprecated beta 15, remove beta 15
*/
static::$dispatcher->dispatch(new ScopeModelVisibility($query, $actor, $ability));
foreach (array_reverse(array_merge([static::class], class_parents($this))) as $class) {
foreach (Arr::get(static::$visibilityScopers, "$class.*", []) as $listener) {
$listener($actor, $query, $ability);

View File

@ -1,58 +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\Notification\Blueprint\BlueprintInterface;
use InvalidArgumentException;
use ReflectionClass;
/**
* @deprecated in beta 15, removed in beta 16
*/
class ConfigureNotificationTypes
{
/**
* @var array
*/
private $blueprints;
/**
* @var array
*/
private $serializers;
/**
* @param array $blueprints
* @param array $serializers
*/
public function __construct(array &$blueprints, array &$serializers = [])
{
$this->blueprints = &$blueprints;
$this->serializers = &$serializers;
}
/**
* @param string $blueprint
* @param string $serializer
* @param array $enabledByDefault
*/
public function add($blueprint, $serializer, $enabledByDefault = [])
{
if (! (new ReflectionClass($blueprint))->implementsInterface(BlueprintInterface::class)) {
throw new InvalidArgumentException(
'Notification blueprint '.$blueprint.' must implement '.BlueprintInterface::class
);
}
$this->blueprints[$blueprint] = $enabledByDefault;
$this->serializers[$blueprint::getType()] = $serializer;
}
}

View File

@ -1,28 +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;
/**
* @deprecated in beta 15, remove in beta 16. Use the Post extender instead.
*/
class ConfigurePostTypes
{
private $models;
public function __construct(array &$models)
{
$this->models = &$models;
}
public function add($class)
{
$this->models[] = $class;
}
}

View File

@ -1,23 +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\User\User;
/**
* @deprecated beta 15, removed beta 16
*/
class ConfigureUserPreferences
{
public function add($key, callable $transformer = null, $default = null)
{
User::addPreference($key, $transformer, $default);
}
}

View File

@ -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;
}
}

View File

@ -1,45 +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\User\User;
/**
* @deprecated beta 15, remove beta 16
*/
class GetPermission
{
/**
* @var User
*/
public $actor;
/**
* @var string
*/
public $ability;
/**
* @var mixed
*/
public $model;
/**
* @param User $actor
* @param string $ability
* @param mixed $model
*/
public function __construct(User $actor, $ability, $model)
{
$this->actor = $actor;
$this->ability = $ability;
$this->model = $model;
}
}

View File

@ -1,49 +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\User\User;
use Illuminate\Database\Eloquent\Builder;
/**
* The `ScopeModelVisibility` event allows constraints to be applied in a query
* to fetch a model, effectively scoping that model's visibility to the user.
*
* @deprecated beta 15, remove beta 16
*/
class ScopeModelVisibility
{
/**
* @var Builder
*/
public $query;
/**
* @var User
*/
public $actor;
/**
* @var string
*/
public $ability;
/**
* @param Builder $query
* @param User $actor
* @param string $ability
*/
public function __construct(Builder $query, User $actor, $ability)
{
$this->query = $query;
$this->actor = $actor;
$this->ability = $ability;
}
}

View File

@ -28,18 +28,6 @@ class Csrf implements ExtenderInterface
return $this;
}
/**
* Exempt a path from csrf checks. Wildcards are supported.
*
* @deprecated beta 15, remove beta 16. Exempt routes should be used instead.
*/
public function exemptPath(string $path)
{
$this->csrfExemptRoutes[] = $path;
return $this;
}
public function extend(Container $container, Extension $extension = null)
{
$container->extend('flarum.http.csrfExemptPaths', function ($existingExemptPaths) {

View File

@ -334,15 +334,6 @@ class Extension implements Arrayable
return $filename;
}
// To give extension authors some time to migrate to the new extension
// format, we will also fallback to the old bootstrap.php name. Consider
// this feature deprecated.
$deprecatedFilename = "{$this->path}/bootstrap.php";
if (file_exists($deprecatedFilename)) {
return $deprecatedFilename;
}
return null;
}

View File

@ -1,31 +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\Formatter\Event;
use s9e\TextFormatter\Configurator;
/**
* @deprecated beta 15, removed beta 16. Use the Formatter extender instead.
*/
class Configuring
{
/**
* @var Configurator
*/
public $configurator;
/**
* @param Configurator $configurator
*/
public function __construct(Configurator $configurator)
{
$this->configurator = $configurator;
}
}

View File

@ -1,45 +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\Formatter\Event;
use s9e\TextFormatter\Parser;
/**
* @deprecated beta 15, removed beta 16. Use the Formatter extender instead.
*/
class Parsing
{
/**
* @var Parser
*/
public $parser;
/**
* @var mixed
*/
public $context;
/**
* @var string
*/
public $text;
/**
* @param Parser $parser
* @param mixed $context
* @param string $text
*/
public function __construct(Parser $parser, $context, &$text)
{
$this->parser = $parser;
$this->context = $context;
$this->text = &$text;
}
}

View File

@ -1,53 +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\Formatter\Event;
use Psr\Http\Message\ServerRequestInterface;
use s9e\TextFormatter\Renderer;
/**
* @deprecated beta 15, removed beta 16. Use the Formatter extender instead.
*/
class Rendering
{
/**
* @var Renderer
*/
public $renderer;
/**
* @var mixed
*/
public $context;
/**
* @var string
*/
public $xml;
/**
* @var ServerRequestInterface
*/
public $request;
/**
* @param Renderer $renderer
* @param mixed $context
* @param string $xml
* @param ServerRequestInterface|null $request
*/
public function __construct(Renderer $renderer, $context, &$xml, ServerRequestInterface $request = null)
{
$this->renderer = $renderer;
$this->context = $context;
$this->xml = &$xml;
$this->request = $request;
}
}

View File

@ -9,11 +9,7 @@
namespace Flarum\Formatter;
use Flarum\Formatter\Event\Configuring;
use Flarum\Formatter\Event\Parsing;
use Flarum\Formatter\Event\Rendering;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Contracts\Events\Dispatcher;
use Psr\Http\Message\ServerRequestInterface;
use s9e\TextFormatter\Configurator;
use s9e\TextFormatter\Unparser;
@ -31,11 +27,6 @@ class Formatter
*/
protected $cache;
/**
* @var Dispatcher
*/
protected $events;
/**
* @var string
*/
@ -43,13 +34,11 @@ class Formatter
/**
* @param Repository $cache
* @param Dispatcher $events
* @param string $cacheDir
*/
public function __construct(Repository $cache, Dispatcher $events, $cacheDir)
public function __construct(Repository $cache, $cacheDir)
{
$this->cache = $cache;
$this->events = $events;
$this->cacheDir = $cacheDir;
}
@ -79,9 +68,6 @@ class Formatter
{
$parser = $this->getParser($context);
// Deprecated in beta 15, remove in beta 16
$this->events->dispatch(new Parsing($parser, $context, $text));
foreach ($this->parsingCallbacks as $callback) {
$text = $callback($parser, $context, $text);
}
@ -101,9 +87,6 @@ class Formatter
{
$renderer = $this->getRenderer();
// Deprecated in beta 15, remove in beta 16
$this->events->dispatch(new Rendering($renderer, $context, $xml, $request));
foreach ($this->renderingCallbacks as $callback) {
$xml = $callback($renderer, $context, $xml, $request);
}
@ -153,9 +136,6 @@ class Formatter
$configurator->Autolink;
$configurator->tags->onDuplicate('replace');
// Deprecated in beta 15, remove in beta 16
$this->events->dispatch(new Configuring($configurator));
foreach ($this->configurationCallbacks as $callback) {
$callback($configurator);
}

View File

@ -24,7 +24,6 @@ class FormatterServiceProvider extends AbstractServiceProvider
$this->app->singleton('flarum.formatter', function (Container $container) {
return new Formatter(
new Repository($container->make('cache.filestore')),
$container->make('events'),
$this->app[Paths::class]->storage.'/formatter'
);
});

View File

@ -9,8 +9,6 @@
namespace Flarum\Foundation;
use Flarum\Foundation\Event\Validating;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\Arr;
use Illuminate\Validation\Factory;
use Illuminate\Validation\ValidationException;
@ -38,11 +36,6 @@ abstract class AbstractValidator
*/
protected $validator;
/**
* @var Dispatcher
*/
protected $events;
/**
* @var TranslatorInterface
*/
@ -50,13 +43,11 @@ abstract class AbstractValidator
/**
* @param Factory $validator
* @param Dispatcher $events
* @param TranslatorInterface $translator
*/
public function __construct(Factory $validator, Dispatcher $events, TranslatorInterface $translator)
public function __construct(Factory $validator, TranslatorInterface $translator)
{
$this->validator = $validator;
$this->events = $events;
$this->translator = $translator;
}
@ -102,13 +93,6 @@ abstract class AbstractValidator
$validator = $this->validator->make($attributes, $rules, $this->getMessages());
/**
* @deprecated in beta 15, removed in beta 16.
*/
$this->events->dispatch(
new Validating($this, $validator)
);
foreach ($this->configuration as $callable) {
$callable($this, $validator);
}

View File

@ -1,42 +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\Foundation\Event;
use Flarum\Foundation\AbstractValidator;
use Illuminate\Validation\Validator;
/**
* @deprecated in Beta 15, remove in beta 16. Use the Validator extender instead.
* The `Validating` event is called when a validator instance for a
* model is being built. This event can be used to add custom rules/extensions
* to the validator for when validation takes place.
*/
class Validating
{
/**
* @var \Flarum\Foundation\AbstractValidator
*/
public $type;
/**
* @var Validator
*/
public $validator;
/**
* @param AbstractValidator $type
* @param Validator $validator
*/
public function __construct(AbstractValidator $type, Validator $validator)
{
$this->type = $type;
$this->validator = $validator;
}
}

View File

@ -26,12 +26,8 @@ class CheckCsrfToken implements Middleware
public function process(Request $request, Handler $handler): Response
{
$path = $request->getAttribute('originalUri')->getPath();
foreach ($this->exemptRoutes as $exemptRoute) {
/**
* @deprecated path match should be removed in beta 16, only route name match should be supported.
*/
if ($exemptRoute === $request->getAttribute('routeName') || fnmatch($exemptRoute, $path)) {
if ($exemptRoute === $request->getAttribute('routeName')) {
return $handler->handle($request);
}
}

View File

@ -1,42 +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\Notification\Event;
use Flarum\Notification\Blueprint\BlueprintInterface;
/**
* @deprecated in beta 15, removed in beta 16
*/
class Sending
{
/**
* The blueprint for the notification.
*
* @var BlueprintInterface
*/
public $blueprint;
/**
* The users that the notification will be sent to.
*
* @var array|int[]
*/
public $users;
/**
* @param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint
* @param \Flarum\User\User[] $users
*/
public function __construct(BlueprintInterface $blueprint, array &$users)
{
$this->blueprint = $blueprint;
$this->users = &$users;
}
}

View File

@ -9,7 +9,6 @@
namespace Flarum\Notification;
use Flarum\Event\ConfigureNotificationTypes;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Notification\Blueprint\DiscussionRenamedBlueprint;
@ -60,11 +59,6 @@ class NotificationServiceProvider extends AbstractServiceProvider
{
$blueprints = $this->app->make('flarum.notification.blueprints');
// Deprecated in beta 15, remove in beta 16
$this->app->make('events')->dispatch(
new ConfigureNotificationTypes($blueprints)
);
foreach ($blueprints as $blueprint => $driversEnabledByDefault) {
$this->addType($blueprint, $driversEnabledByDefault);
}

View File

@ -11,7 +11,6 @@ namespace Flarum\Notification;
use Flarum\Notification\Blueprint\BlueprintInterface;
use Flarum\Notification\Driver\NotificationDriverInterface;
use Flarum\Notification\Event\Sending;
use Flarum\User\User;
/**
@ -110,11 +109,6 @@ class NotificationSyncer
foreach (static::getNotificationDrivers() as $driverName => $driver) {
$driver->send($blueprint, $newRecipients);
}
if (count($newRecipients)) {
// Deprecated in beta 15, removed in beta 16
event(new Sending($blueprint, $newRecipients));
}
}
/**

View File

@ -1,31 +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\Post\Event;
use Flarum\User\User;
/**
* @deprecated beta 15, remove beta 16
*/
class CheckingForFlooding
{
/**
* @var User
*/
public $actor;
/**
* @param User|null $actor
*/
public function __construct(User $actor = null)
{
$this->actor = $actor;
}
}

View File

@ -1,60 +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\Post;
use DateTime;
use Flarum\Post\Event\CheckingForFlooding;
use Flarum\Post\Exception\FloodingException;
use Flarum\User\User;
use Illuminate\Contracts\Events\Dispatcher;
/**
* @deprecated beta 14, removed beta 15 in favor of Floodgate middleware
*/
class Floodgate
{
/**
* @var Dispatcher
*/
protected $events;
public function __construct(Dispatcher $events)
{
$this->events = $events;
}
/**
* @param User $actor
* @throws FloodingException
*/
public function assertNotFlooding(User $actor)
{
if ($actor->can('postWithoutThrottle')) {
return;
}
if ($this->isFlooding($actor)) {
throw new FloodingException;
}
}
/**
* @param User $actor
* @return bool
*/
public function isFlooding(User $actor): bool
{
$isFlooding = $this->events->until(
new CheckingForFlooding($actor)
);
return $isFlooding ?? Post::where('user_id', $actor->id)->where('created_at', '>=', new DateTime('-10 seconds'))->exists();
}
}

View File

@ -10,7 +10,6 @@
namespace Flarum\Post;
use DateTime;
use Flarum\Event\ConfigurePostTypes;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Post\Access\ScopePostVisibility;
@ -61,11 +60,6 @@ class PostServiceProvider extends AbstractServiceProvider
DiscussionRenamedPost::class
];
// Deprecated in beta 15, remove in beta 16.
$this->app->make('events')->dispatch(
new ConfigurePostTypes($models)
);
foreach ($models as $model) {
Post::setModel($model::$type, $model);
}

View File

@ -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\User;
use Flarum\Event\GetPermission;
use Flarum\Event\ScopeModelVisibility;
use Illuminate\Contracts\Events\Dispatcher;
abstract class AbstractPolicy
{
/**
* @var string
*/
protected $model;
/**
* @param Dispatcher $events
*/
public function subscribe(Dispatcher $events)
{
$events->listen(GetPermission::class, [$this, 'getPermission']);
$events->listen(ScopeModelVisibility::class, [$this, 'scopeModelVisibility']);
}
/**
* @param GetPermission $event
* @return bool|void
*/
public function getPermission(GetPermission $event)
{
if (! $event->model instanceof $this->model && $event->model !== $this->model) {
return;
}
if (method_exists($this, $event->ability)) {
$result = call_user_func_array([$this, $event->ability], [$event->actor, $event->model]);
if (! is_null($result)) {
return $result;
}
}
if (method_exists($this, 'can')) {
return call_user_func_array([$this, 'can'], [$event->actor, $event->ability, $event->model]);
}
}
/**
* @param ScopeModelVisibility $event
* @deprecated beta 15, remove beta 16
*/
public function scopeModelVisibility(ScopeModelVisibility $event)
{
if ($event->query->getModel() instanceof $this->model) {
if (substr($event->ability, 0, 4) === 'view') {
$method = 'find'.substr($event->ability, 4);
if (method_exists($this, $method)) {
call_user_func_array([$this, $method], [$event->actor, $event->query]);
}
} elseif (method_exists($this, 'findWithPermission')) {
call_user_func_array([$this, 'findWithPermission'], [$event->actor, $event->query, $event->ability]);
}
}
}
}

View File

@ -10,10 +10,8 @@
namespace Flarum\User\Access;
use Flarum\Database\AbstractModel;
use Flarum\Event\GetPermission;
use Flarum\User\User;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\Arr;
class Gate
@ -30,11 +28,6 @@ class Gate
*/
protected $container;
/**
* @var Dispatcher
*/
protected $events;
/**
* @var array
*/
@ -46,12 +39,12 @@ class Gate
protected $policies;
/**
* @param Dispatcher $events
* @param Container $container
* @param array $policyClasses
*/
public function __construct(Container $container, Dispatcher $events, array $policyClasses)
public function __construct(Container $container, array $policyClasses)
{
$this->container = $container;
$this->events = $events;
$this->policyClasses = $policyClasses;
}
@ -88,20 +81,6 @@ class Gate
}
}
// START OLD DEPRECATED SYSTEM
// Fire an event so that core and extension modelPolicies can hook into
// this permission query and explicitly grant or deny the
// permission.
$allowed = $this->events->until(
new GetPermission($actor, $ability, $model)
);
if (! is_null($allowed)) {
return $allowed;
}
// END OLD DEPRECATED SYSTEM
// If no policy covered this permission query, we will only grant
// the permission if the actor's groups have it. Otherwise, we will
// not allow the user to perform this action.

View File

@ -14,7 +14,6 @@ use DomainException;
use Flarum\Database\AbstractModel;
use Flarum\Database\ScopeVisibilityTrait;
use Flarum\Discussion\Discussion;
use Flarum\Event\ConfigureUserPreferences;
use Flarum\Foundation\EventGeneratorTrait;
use Flarum\Group\Group;
use Flarum\Group\Permission;
@ -142,13 +141,6 @@ class User extends AbstractModel
Notification::whereSubject($user)->delete();
});
/**
* @deprecated beta 15, remove beta 16
*/
static::$dispatcher->dispatch(
new ConfigureUserPreferences
);
}
/**
@ -803,20 +795,6 @@ class User extends AbstractModel
static::$hasher = $hasher;
}
/**
* @deprecated beta 15, remove beta 16. Use `registerPreference` instead.
*
* Register a preference with a transformer and a default value.
*
* @param string $key
* @param callable $transformer
* @param mixed $default
*/
public static function addPreference($key, callable $transformer = null, $default = null)
{
return static::registerPreference($key, $transformer, $default);
}
/**
* Register a preference with a transformer and a default value.
*

View File

@ -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
@ -118,29 +116,6 @@ class ShowTest extends TestCase
$this->assertEquals(2, Arr::get($json, 'data.relationships.posts.data.0.id'));
}
/**
* @test
*/
public function when_allowed_guests_can_see_hidden_posts()
{
/** @var Dispatcher $events */
$events = $this->app()->getContainer()->make(Dispatcher::class);
$events->listen(ScopeModelVisibility::class, function (ScopeModelVisibility $event) {
if ($event->ability === 'hidePosts') {
$event->query->whereRaw('1=1');
}
});
$response = $this->send(
$this->request('GET', '/api/discussions/4')
);
$json = json_decode($response->getBody()->getContents(), true);
$this->assertEquals(2, Arr::get($json, 'data.relationships.posts.data.0.id'));
}
/**
* @test
*/

View File

@ -41,38 +41,8 @@ class CsrfTest extends TestCase
/**
* @test
* @deprecated
*/
public function create_user_post_doesnt_need_csrf_token_if_whitelisted()
{
$this->extend(
(new Extend\Csrf)
->exemptPath('/api/users')
);
$response = $this->send(
$this->request('POST', '/api/users', [
'json' => [
'data' => [
'attributes' => $this->testUser
]
],
])
);
$this->assertEquals(201, $response->getStatusCode());
$user = User::where('username', $this->testUser['username'])->firstOrFail();
$this->assertEquals(0, $user->is_email_confirmed);
$this->assertEquals($this->testUser['username'], $user->username);
$this->assertEquals($this->testUser['email'], $user->email);
}
/**
* @test
*/
public function create_user_post_doesnt_need_csrf_token_if_whitelisted_via_routename()
{
$this->extend(
(new Extend\Csrf)
@ -97,22 +67,4 @@ class CsrfTest extends TestCase
$this->assertEquals($this->testUser['username'], $user->username);
$this->assertEquals($this->testUser['email'], $user->email);
}
/**
* @test
* @deprecated
*/
public function csrf_matches_wildcards_properly()
{
$this->extend(
(new Extend\Csrf)
->exemptPath('/api/fake/*/up')
);
$response = $this->send(
$this->request('POST', '/api/fake/route/i/made/up')
);
$this->assertEquals(404, $response->getStatusCode());
}
}

View File

@ -18,6 +18,7 @@ use Flarum\Tests\integration\RetrievesAuthorizedUsers;
use Flarum\Tests\integration\TestCase;
use Flarum\User\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;
class ModelVisibilityTest extends TestCase
{
@ -46,6 +47,27 @@ class ModelVisibilityTest extends TestCase
]);
}
/**
* @test
*/
public function when_allowed_guests_can_see_hidden_posts()
{
$this->extend(
(new Extend\ModelVisibility(CommentPost::class))
->scope(function (User $user, Builder $query) {
$query->whereRaw('1=1');
}, 'hidePosts')
);
$response = $this->send(
$this->request('GET', '/api/discussions/2')
);
$json = json_decode($response->getBody()->getContents(), true);
$this->assertEquals(1, Arr::get($json, 'data.relationships.posts.data.0.id'));
}
/**
* @test
*/