1
0
mirror of https://github.com/flarum/core.git synced 2025-07-18 23:31:17 +02:00

Remove a bunch of deprecated events

Use extenders instead!

Refs #1891.
This commit is contained in:
Franz Liedke
2020-04-27 22:04:08 +02:00
parent 6416fbd5d3
commit 42146fbad6
13 changed files with 6 additions and 467 deletions

View File

@@ -13,7 +13,6 @@ use Flarum\Api\Controller\AbstractSerializeController;
use Flarum\Api\Serializer\AbstractSerializer; use Flarum\Api\Serializer\AbstractSerializer;
use Flarum\Api\Serializer\BasicDiscussionSerializer; use Flarum\Api\Serializer\BasicDiscussionSerializer;
use Flarum\Api\Serializer\NotificationSerializer; use Flarum\Api\Serializer\NotificationSerializer;
use Flarum\Event\ConfigureApiRoutes;
use Flarum\Event\ConfigureNotificationTypes; use Flarum\Event\ConfigureNotificationTypes;
use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Application; use Flarum\Foundation\Application;
@@ -120,9 +119,5 @@ class ApiServiceProvider extends AbstractServiceProvider
$callback = include __DIR__.'/routes.php'; $callback = include __DIR__.'/routes.php';
$callback($routes, $factory); $callback($routes, $factory);
$this->app->make('events')->dispatch(
new ConfigureApiRoutes($routes, $factory)
);
} }
} }

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\Console\Event;
use Illuminate\Console\Command;
use Illuminate\Contracts\Container\Container;
use Symfony\Component\Console\Application;
/**
* @deprecated
*/
class Configuring
{
/**
* @var Container
*/
public $app;
/**
* @var Application
*/
public $console;
/**
* @param Container $container
* @param Application $console
*/
public function __construct(Container $container, Application $console)
{
$this->app = $container;
$this->console = $console;
}
/**
* Add a console command to the flarum binary.
*
* @param Command|string $command
*/
public function addCommand($command)
{
if (is_string($command)) {
$command = $this->app->make($command);
}
if ($command instanceof Command) {
$command->setLaravel($this->app);
}
$this->console->add($command);
}
}

View File

@@ -9,12 +9,10 @@
namespace Flarum\Console; namespace Flarum\Console;
use Flarum\Console\Event\Configuring;
use Flarum\Foundation\ErrorHandling\Registry; use Flarum\Foundation\ErrorHandling\Registry;
use Flarum\Foundation\ErrorHandling\Reporter; use Flarum\Foundation\ErrorHandling\Reporter;
use Flarum\Foundation\SiteInterface; use Flarum\Foundation\SiteInterface;
use Illuminate\Contracts\Container\Container; use Illuminate\Container\Container;
use Illuminate\Contracts\Events\Dispatcher;
use Symfony\Component\Console\Application; use Symfony\Component\Console\Application;
use Symfony\Component\Console\ConsoleEvents; use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleErrorEvent; use Symfony\Component\Console\Event\ConsoleErrorEvent;
@@ -39,32 +37,20 @@ class Server
$console->add($command); $console->add($command);
} }
$this->extend($console); // deprecated $this->handleErrors($console);
exit($console->run()); exit($console->run());
} }
/** private function handleErrors(Application $console)
* @deprecated
*/
private function extend(Application $console)
{
$container = \Illuminate\Container\Container::getInstance();
$this->handleErrors($container, $console);
$events = $container->make(Dispatcher::class);
$events->dispatch(new Configuring($container, $console));
}
private function handleErrors(Container $container, Application $console)
{ {
$dispatcher = new EventDispatcher(); $dispatcher = new EventDispatcher();
$dispatcher->addListener(ConsoleEvents::ERROR, function (ConsoleErrorEvent $event) use ($container) { $dispatcher->addListener(ConsoleEvents::ERROR, function (ConsoleErrorEvent $event) {
$container = Container::getInstance();
/** @var Registry $registry */ /** @var Registry $registry */
$registry = $container->make(Registry::class); $registry = $container->make(Registry::class);
$error = $registry->handle($event->getError()); $error = $registry->handle($event->getError());
/** @var Reporter[] $reporters */ /** @var Reporter[] $reporters */

View File

@@ -9,9 +9,6 @@
namespace Flarum\Database; namespace Flarum\Database;
use Flarum\Event\ConfigureModelDates;
use Flarum\Event\ConfigureModelDefaultAttributes;
use Flarum\Event\GetModelRelationship;
use Illuminate\Database\Eloquent\Model as Eloquent; use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
@@ -84,11 +81,6 @@ abstract class AbstractModel extends Eloquent
$this->attributes = array_merge($this->attributes, Arr::get(static::$defaults, $class, [])); $this->attributes = array_merge($this->attributes, Arr::get(static::$defaults, $class, []));
} }
// Deprecated in beta 13, remove in beta 14.
static::$dispatcher->dispatch(
new ConfigureModelDefaultAttributes($this, $this->attributes)
);
$this->attributes = array_map(function ($item) { $this->attributes = array_map(function ($item) {
return is_callable($item) ? $item() : $item; return is_callable($item) ? $item() : $item;
}, $this->attributes); }, $this->attributes);
@@ -103,10 +95,6 @@ abstract class AbstractModel extends Eloquent
*/ */
public function getDates() public function getDates()
{ {
static::$dispatcher->dispatch(
new ConfigureModelDates($this, $this->dates)
);
$dates = $this->dates; $dates = $this->dates;
foreach (array_merge(array_reverse(class_parents($this)), [static::class]) as $class) { foreach (array_merge(array_reverse(class_parents($this)), [static::class]) as $class) {
@@ -157,11 +145,6 @@ abstract class AbstractModel extends Eloquent
return $relation($this); return $relation($this);
} }
} }
// Deprecated, remove in beta 14
return static::$dispatcher->until(
new GetModelRelationship($this, $name)
);
} }
/** /**

View File

@@ -1,90 +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\Http\RouteCollection;
use Flarum\Http\RouteHandlerFactory;
/**
* @deprecated Will be removed in Beta.14.
*/
abstract class AbstractConfigureRoutes
{
/**
* @var RouteCollection
*/
public $routes;
/**
* @var RouteHandlerFactory
*/
protected $route;
/**
* @param RouteCollection $routes
* @param \Flarum\Http\RouteHandlerFactory $route
*/
public function __construct(RouteCollection $routes, RouteHandlerFactory $route)
{
$this->routes = $routes;
$this->route = $route;
}
/**
* @param string $url
* @param string $name
* @param string $controller
*/
public function get($url, $name, $controller)
{
$this->route('get', $url, $name, $controller);
}
/**
* @param string $url
* @param string $name
* @param string $controller
*/
public function post($url, $name, $controller)
{
$this->route('post', $url, $name, $controller);
}
/**
* @param string $url
* @param string $name
* @param string $controller
*/
public function patch($url, $name, $controller)
{
$this->route('patch', $url, $name, $controller);
}
/**
* @param string $url
* @param string $name
* @param string $controller
*/
public function delete($url, $name, $controller)
{
$this->route('delete', $url, $name, $controller);
}
/**
* @param string $method
* @param string $url
* @param string $name
* @param string $controller
*/
protected function route($method, $url, $name, $controller)
{
$this->routes->$method($url, $name, $this->route->toController($controller));
}
}

View File

@@ -1,17 +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 Will be removed in Beta.14. Use Flarum\Extend\Routes instead.
*/
class ConfigureApiRoutes extends AbstractConfigureRoutes
{
}

View File

@@ -1,26 +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\Forum\Controller\FrontendController;
/**
* @deprecated Will be removed in Beta.14. Use Flarum\Extend\Routes or Flarum\Extend\Frontend instead.
*/
class ConfigureForumRoutes extends AbstractConfigureRoutes
{
/**
* {@inheritdoc}
*/
public function get($url, $name, $handler = FrontendController::class)
{
parent::get($url, $name, $handler);
}
}

View File

@@ -1,79 +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 DirectoryIterator;
use Flarum\Locale\LocaleManager;
use Illuminate\Support\Arr;
use RuntimeException;
/**
* @deprecated Will be removed in Beta.14. Use Flarum\Extend\LanguagePack instead.
*/
class ConfigureLocales
{
/**
* @var LocaleManager
*/
public $locales;
/**
* @param LocaleManager $locales
*/
public function __construct(LocaleManager $locales)
{
$this->locales = $locales;
}
/**
* Load language pack resources from the given directory.
*
* @param string $directory
*/
public function loadLanguagePackFrom($directory)
{
$name = $title = basename($directory);
if (file_exists($manifest = $directory.'/composer.json')) {
$json = json_decode(file_get_contents($manifest), true);
if (empty($json)) {
throw new RuntimeException("Error parsing composer.json in $name: ".json_last_error_msg());
}
$locale = Arr::get($json, 'extra.flarum-locale.code');
$title = Arr::get($json, 'extra.flarum-locale.title', $title);
}
if (! isset($locale)) {
throw new RuntimeException("Language pack $name must define \"extra.flarum-locale.code\" in composer.json.");
}
$this->locales->addLocale($locale, $title);
if (! is_dir($localeDir = $directory.'/locale')) {
throw new RuntimeException("Language pack $name must have a \"locale\" subdirectory.");
}
if (file_exists($file = $localeDir.'/config.js')) {
$this->locales->addJsFile($locale, $file);
}
if (file_exists($file = $localeDir.'/config.css')) {
$this->locales->addCssFile($locale, $file);
}
foreach (new DirectoryIterator($localeDir) as $file) {
if ($file->isFile() && in_array($file->getExtension(), ['yml', 'yaml'])) {
$this->locales->addTranslations($locale, $file->getPathname());
}
}
}
}

View File

@@ -1,50 +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\Database\AbstractModel;
/**
* @deprecated in beta 13, removed in beta 14
*
* The `ConfigureModelDates` event is called to retrieve a list of fields for a model
* that should be converted into date objects.
*/
class ConfigureModelDates
{
/**
* @var AbstractModel
*/
public $model;
/**
* @var array
*/
public $dates;
/**
* @param AbstractModel $model
* @param array $dates
*/
public function __construct(AbstractModel $model, array &$dates)
{
$this->model = $model;
$this->dates = &$dates;
}
/**
* @param string $model
* @return bool
*/
public function isModel($model)
{
return $this->model instanceof $model;
}
}

View File

@@ -1,47 +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\Database\AbstractModel;
/**
* @deprecated in beta 13, removed in beta 14
*/
class ConfigureModelDefaultAttributes
{
/**
* @var AbstractModel
*/
public $model;
/**
* @var array
*/
public $attributes;
/**
* @param AbstractModel $model
* @param array $attributes
*/
public function __construct(AbstractModel $model, array &$attributes)
{
$this->model = $model;
$this->attributes = &$attributes;
}
/**
* @param string $model
* @return bool
*/
public function isModel($model)
{
return $this->model instanceof $model;
}
}

View File

@@ -1,51 +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\Database\AbstractModel;
/**
* @deprecated beta 13, use the Model extender instead.
*
* The `GetModelRelationship` event is called to retrieve Relation object for a
* model. Listeners should return an Eloquent Relation object.
*/
class GetModelRelationship
{
/**
* @var AbstractModel
*/
public $model;
/**
* @var string
*/
public $relationship;
/**
* @param AbstractModel $model
* @param string $relationship
*/
public function __construct(AbstractModel $model, $relationship)
{
$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;
}
}

View File

@@ -9,7 +9,6 @@
namespace Flarum\Forum; namespace Flarum\Forum;
use Flarum\Event\ConfigureForumRoutes;
use Flarum\Extension\Event\Disabled; use Flarum\Extension\Event\Disabled;
use Flarum\Extension\Event\Enabled; use Flarum\Extension\Event\Enabled;
use Flarum\Formatter\Formatter; use Flarum\Formatter\Formatter;
@@ -186,10 +185,6 @@ class ForumServiceProvider extends AbstractServiceProvider
$callback = include __DIR__.'/routes.php'; $callback = include __DIR__.'/routes.php';
$callback($routes, $factory); $callback($routes, $factory);
$this->app->make('events')->dispatch(
new ConfigureForumRoutes($routes, $factory)
);
} }
/** /**

View File

@@ -42,8 +42,6 @@ class LocaleServiceProvider extends AbstractServiceProvider
$locales->addLocale($this->getDefaultLocale(), 'Default'); $locales->addLocale($this->getDefaultLocale(), 'Default');
event(new ConfigureLocales($locales));
return $locales; return $locales;
}); });