mirror of
https://github.com/flarum/core.git
synced 2025-07-19 07:41:22 +02:00
@@ -1,9 +1,9 @@
|
|||||||
language: php
|
language: php
|
||||||
|
|
||||||
php:
|
php:
|
||||||
- 5.6
|
|
||||||
- 7.0
|
- 7.0
|
||||||
- 7.1
|
- 7.1
|
||||||
|
- 7.2
|
||||||
- hhvm
|
- hhvm
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
|
@@ -20,24 +20,24 @@
|
|||||||
"docs": "http://flarum.org/docs"
|
"docs": "http://flarum.org/docs"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.6.0",
|
"php": ">=7.0",
|
||||||
"dflydev/fig-cookies": "^1.0.2",
|
"dflydev/fig-cookies": "^1.0.2",
|
||||||
"doctrine/dbal": "^2.5",
|
"doctrine/dbal": "^2.5",
|
||||||
"components/font-awesome": "^4.6",
|
"components/font-awesome": "^4.6",
|
||||||
"franzl/whoops-middleware": "^0.4.0",
|
"franzl/whoops-middleware": "^0.4.0",
|
||||||
"illuminate/bus": "5.1.*",
|
"illuminate/bus": "5.5.*",
|
||||||
"illuminate/cache": "5.1.*",
|
"illuminate/cache": "5.5.*",
|
||||||
"illuminate/config": "5.1.*",
|
"illuminate/config": "5.5.*",
|
||||||
"illuminate/container": "5.1.*",
|
"illuminate/container": "5.5.*",
|
||||||
"illuminate/contracts": "5.1.*",
|
"illuminate/contracts": "5.5.*",
|
||||||
"illuminate/database": "^5.1.31",
|
"illuminate/database": "5.5.*",
|
||||||
"illuminate/events": "5.1.*",
|
"illuminate/events": "5.5.*",
|
||||||
"illuminate/filesystem": "5.1.*",
|
"illuminate/filesystem": "5.5.*",
|
||||||
"illuminate/hashing": "5.1.*",
|
"illuminate/hashing": "5.5.*",
|
||||||
"illuminate/mail": "5.1.*",
|
"illuminate/mail": "5.5.*",
|
||||||
"illuminate/support": "5.1.*",
|
"illuminate/support": "5.5.*",
|
||||||
"illuminate/validation": "5.1.*",
|
"illuminate/validation": "5.5.*",
|
||||||
"illuminate/view": "5.1.*",
|
"illuminate/view": "5.5.*",
|
||||||
"intervention/image": "^2.3.0",
|
"intervention/image": "^2.3.0",
|
||||||
"league/flysystem": "^1.0.11",
|
"league/flysystem": "^1.0.11",
|
||||||
"league/oauth2-client": "~1.0",
|
"league/oauth2-client": "~1.0",
|
||||||
@@ -46,11 +46,11 @@
|
|||||||
"nikic/fast-route": "^0.6",
|
"nikic/fast-route": "^0.6",
|
||||||
"oyejorge/less.php": "~1.5",
|
"oyejorge/less.php": "~1.5",
|
||||||
"psr/http-message": "^1.0",
|
"psr/http-message": "^1.0",
|
||||||
"symfony/config": "^2.7",
|
"symfony/config": "^3.3",
|
||||||
"symfony/console": "^2.7",
|
"symfony/console": "^3.3",
|
||||||
"symfony/http-foundation": "^2.7",
|
"symfony/http-foundation": "^3.3",
|
||||||
"symfony/translation": "^2.7",
|
"symfony/translation": "^3.3",
|
||||||
"symfony/yaml": "^2.7",
|
"symfony/yaml": "^3.3",
|
||||||
"s9e/text-formatter": "^0.8.1",
|
"s9e/text-formatter": "^0.8.1",
|
||||||
"tobscure/json-api": "^0.3.0",
|
"tobscure/json-api": "^0.3.0",
|
||||||
"zendframework/zend-diactoros": "^1.6",
|
"zendframework/zend-diactoros": "^1.6",
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"mockery/mockery": "^0.9.4",
|
"mockery/mockery": "^0.9.4",
|
||||||
"phpunit/phpunit": "^4.8"
|
"phpunit/phpunit": "^6.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
@@ -20,7 +20,7 @@ return [
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Store slugs for existing discussions
|
// Store slugs for existing discussions
|
||||||
$schema->getConnection()->table('discussions')->chunk(100, function ($discussions) use ($schema) {
|
$schema->getConnection()->table('discussions')->chunkById(100, function ($discussions) use ($schema) {
|
||||||
foreach ($discussions as $discussion) {
|
foreach ($discussions as $discussion) {
|
||||||
$schema->getConnection()->table('discussions')->where('id', $discussion->id)->update([
|
$schema->getConnection()->table('discussions')->where('id', $discussion->id)->update([
|
||||||
'slug' => Str::slug($discussion->title)
|
'slug' => Str::slug($discussion->title)
|
||||||
|
@@ -11,13 +11,23 @@
|
|||||||
|
|
||||||
namespace Flarum\Admin;
|
namespace Flarum\Admin;
|
||||||
|
|
||||||
use Flarum\Core\Listener\CheckCustomLessFormat;
|
use Flarum\Admin\Middleware\RequireAdministrateAbility;
|
||||||
use Flarum\Event\ExtensionWasDisabled;
|
use Flarum\Event\ConfigureMiddleware;
|
||||||
use Flarum\Event\ExtensionWasEnabled;
|
use Flarum\Extension\Event\Disabled;
|
||||||
use Flarum\Event\SettingWasSet;
|
use Flarum\Extension\Event\Enabled;
|
||||||
use Flarum\Foundation\AbstractServiceProvider;
|
use Flarum\Foundation\AbstractServiceProvider;
|
||||||
use Flarum\Http\Handler\RouteHandlerFactory;
|
use Flarum\Http\Middleware\AuthenticateWithSession;
|
||||||
|
use Flarum\Http\Middleware\DispatchRoute;
|
||||||
|
use Flarum\Http\Middleware\HandleErrors;
|
||||||
|
use Flarum\Http\Middleware\ParseJsonBody;
|
||||||
|
use Flarum\Http\Middleware\RememberFromCookie;
|
||||||
|
use Flarum\Http\Middleware\SetLocale;
|
||||||
|
use Flarum\Http\Middleware\StartSession;
|
||||||
use Flarum\Http\RouteCollection;
|
use Flarum\Http\RouteCollection;
|
||||||
|
use Flarum\Http\RouteHandlerFactory;
|
||||||
|
use Flarum\Http\UrlGenerator;
|
||||||
|
use Flarum\Settings\Event\Saved;
|
||||||
|
use Zend\Stratigility\MiddlewarePipe;
|
||||||
|
|
||||||
class AdminServiceProvider extends AbstractServiceProvider
|
class AdminServiceProvider extends AbstractServiceProvider
|
||||||
{
|
{
|
||||||
@@ -26,13 +36,35 @@ class AdminServiceProvider extends AbstractServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
$this->app->singleton(UrlGenerator::class, function () {
|
$this->app->extend(UrlGenerator::class, function (UrlGenerator $url) {
|
||||||
return new UrlGenerator($this->app, $this->app->make('flarum.admin.routes'));
|
return $url->addCollection('admin', $this->app->make('flarum.admin.routes'), 'admin');
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->app->singleton('flarum.admin.routes', function () {
|
$this->app->singleton('flarum.admin.routes', function () {
|
||||||
return new RouteCollection;
|
return new RouteCollection;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$this->app->singleton('flarum.admin.middleware', function ($app) {
|
||||||
|
$pipe = new MiddlewarePipe;
|
||||||
|
$pipe->raiseThrowables();
|
||||||
|
|
||||||
|
// All requests should first be piped through our global error handler
|
||||||
|
$debugMode = ! $app->isUpToDate() || $app->inDebugMode();
|
||||||
|
$pipe->pipe($app->make(HandleErrors::class, ['debug' => $debugMode]));
|
||||||
|
|
||||||
|
$pipe->pipe($app->make(ParseJsonBody::class));
|
||||||
|
$pipe->pipe($app->make(StartSession::class));
|
||||||
|
$pipe->pipe($app->make(RememberFromCookie::class));
|
||||||
|
$pipe->pipe($app->make(AuthenticateWithSession::class));
|
||||||
|
$pipe->pipe($app->make(SetLocale::class));
|
||||||
|
$pipe->pipe($app->make(RequireAdministrateAbility::class));
|
||||||
|
|
||||||
|
event(new ConfigureMiddleware($pipe, 'admin'));
|
||||||
|
|
||||||
|
$pipe->pipe($app->make(DispatchRoute::class, ['routes' => $app->make('flarum.admin.routes')]));
|
||||||
|
|
||||||
|
return $pipe;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,18 +90,15 @@ class AdminServiceProvider extends AbstractServiceProvider
|
|||||||
*/
|
*/
|
||||||
protected function populateRoutes(RouteCollection $routes)
|
protected function populateRoutes(RouteCollection $routes)
|
||||||
{
|
{
|
||||||
$route = $this->app->make(RouteHandlerFactory::class);
|
$factory = $this->app->make(RouteHandlerFactory::class);
|
||||||
|
|
||||||
$routes->get(
|
$callback = include __DIR__.'/routes.php';
|
||||||
'/',
|
$callback($routes, $factory);
|
||||||
'index',
|
|
||||||
$route->toController(Controller\WebAppController::class)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function flushWebAppAssetsWhenThemeChanged()
|
protected function flushWebAppAssetsWhenThemeChanged()
|
||||||
{
|
{
|
||||||
$this->app->make('events')->listen(SettingWasSet::class, function (SettingWasSet $event) {
|
$this->app->make('events')->listen(Saved::class, function (Saved $event) {
|
||||||
if (preg_match('/^theme_|^custom_less$/i', $event->key)) {
|
if (preg_match('/^theme_|^custom_less$/i', $event->key)) {
|
||||||
$this->getWebAppAssets()->flushCss();
|
$this->getWebAppAssets()->flushCss();
|
||||||
}
|
}
|
||||||
@@ -80,8 +109,8 @@ class AdminServiceProvider extends AbstractServiceProvider
|
|||||||
{
|
{
|
||||||
$events = $this->app->make('events');
|
$events = $this->app->make('events');
|
||||||
|
|
||||||
$events->listen(ExtensionWasEnabled::class, [$this, 'flushWebAppAssets']);
|
$events->listen(Enabled::class, [$this, 'flushWebAppAssets']);
|
||||||
$events->listen(ExtensionWasDisabled::class, [$this, 'flushWebAppAssets']);
|
$events->listen(Disabled::class, [$this, 'flushWebAppAssets']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function flushWebAppAssets()
|
public function flushWebAppAssets()
|
||||||
@@ -90,11 +119,11 @@ class AdminServiceProvider extends AbstractServiceProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Flarum\Http\WebApp\WebAppAssets
|
* @return \Flarum\Frontend\FrontendAssets
|
||||||
*/
|
*/
|
||||||
protected function getWebAppAssets()
|
protected function getWebAppAssets()
|
||||||
{
|
{
|
||||||
return $this->app->make(WebApp::class)->getAssets();
|
return $this->app->make(Frontend::class)->getAssets();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function checkCustomLessFormat()
|
protected function checkCustomLessFormat()
|
||||||
|
@@ -9,10 +9,10 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core\Listener;
|
namespace Flarum\Admin;
|
||||||
|
|
||||||
use Flarum\Core\Exception\ValidationException;
|
use Flarum\Foundation\ValidationException;
|
||||||
use Flarum\Event\PrepareSerializedSetting;
|
use Flarum\Settings\Event\Serializing;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
use Less_Exception_Parser;
|
use Less_Exception_Parser;
|
||||||
use Less_Parser;
|
use Less_Parser;
|
||||||
@@ -21,10 +21,10 @@ class CheckCustomLessFormat
|
|||||||
{
|
{
|
||||||
public function subscribe(Dispatcher $events)
|
public function subscribe(Dispatcher $events)
|
||||||
{
|
{
|
||||||
$events->listen(PrepareSerializedSetting::class, [$this, 'check']);
|
$events->listen(Serializing::class, [$this, 'check']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function check(PrepareSerializedSetting $event)
|
public function check(Serializing $event)
|
||||||
{
|
{
|
||||||
if ($event->key === 'custom_less') {
|
if ($event->key === 'custom_less') {
|
||||||
$parser = new Less_Parser();
|
$parser = new Less_Parser();
|
@@ -11,17 +11,17 @@
|
|||||||
|
|
||||||
namespace Flarum\Admin\Controller;
|
namespace Flarum\Admin\Controller;
|
||||||
|
|
||||||
use Flarum\Admin\WebApp;
|
use Flarum\Admin\Frontend;
|
||||||
use Flarum\Core\Permission;
|
|
||||||
use Flarum\Event\PrepareUnserializedSettings;
|
|
||||||
use Flarum\Extension\ExtensionManager;
|
use Flarum\Extension\ExtensionManager;
|
||||||
use Flarum\Http\Controller\AbstractWebAppController;
|
use Flarum\Frontend\AbstractFrontendController;
|
||||||
|
use Flarum\Group\Permission;
|
||||||
|
use Flarum\Settings\Event\Deserializing;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
use Illuminate\Database\ConnectionInterface;
|
use Illuminate\Database\ConnectionInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class WebAppController extends AbstractWebAppController
|
class FrontendController extends AbstractFrontendController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var SettingsRepositoryInterface
|
* @var SettingsRepositoryInterface
|
||||||
@@ -34,13 +34,18 @@ class WebAppController extends AbstractWebAppController
|
|||||||
protected $extensions;
|
protected $extensions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param WebApp $webApp
|
* @var ConnectionInterface
|
||||||
|
*/
|
||||||
|
protected $db;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Frontend $webApp
|
||||||
* @param Dispatcher $events
|
* @param Dispatcher $events
|
||||||
* @param SettingsRepositoryInterface $settings
|
* @param SettingsRepositoryInterface $settings
|
||||||
* @param ExtensionManager $extensions
|
* @param ExtensionManager $extensions
|
||||||
* @param ConnectionInterface $db
|
* @param ConnectionInterface $db
|
||||||
*/
|
*/
|
||||||
public function __construct(WebApp $webApp, Dispatcher $events, SettingsRepositoryInterface $settings, ExtensionManager $extensions, ConnectionInterface $db)
|
public function __construct(Frontend $webApp, Dispatcher $events, SettingsRepositoryInterface $settings, ExtensionManager $extensions, ConnectionInterface $db)
|
||||||
{
|
{
|
||||||
$this->webApp = $webApp;
|
$this->webApp = $webApp;
|
||||||
$this->events = $events;
|
$this->events = $events;
|
||||||
@@ -59,7 +64,7 @@ class WebAppController extends AbstractWebAppController
|
|||||||
$settings = $this->settings->all();
|
$settings = $this->settings->all();
|
||||||
|
|
||||||
$this->events->fire(
|
$this->events->fire(
|
||||||
new PrepareUnserializedSettings($settings)
|
new Deserializing($settings)
|
||||||
);
|
);
|
||||||
|
|
||||||
$view->setVariable('settings', $settings);
|
$view->setVariable('settings', $settings);
|
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
namespace Flarum\Admin;
|
namespace Flarum\Admin;
|
||||||
|
|
||||||
use Flarum\Http\WebApp\AbstractWebApp;
|
use Flarum\Frontend\AbstractFrontend;
|
||||||
|
|
||||||
class WebApp extends AbstractWebApp
|
class Frontend extends AbstractFrontend
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace Flarum\Admin\Middleware;
|
namespace Flarum\Admin\Middleware;
|
||||||
|
|
||||||
use Flarum\Core\Access\AssertPermissionTrait;
|
use Flarum\User\AssertPermissionTrait;
|
||||||
use Psr\Http\Message\ResponseInterface as Response;
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
use Zend\Stratigility\MiddlewareInterface;
|
use Zend\Stratigility\MiddlewareInterface;
|
||||||
|
@@ -1,54 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Flarum.
|
|
||||||
*
|
|
||||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Flarum\Admin;
|
|
||||||
|
|
||||||
use Flarum\Event\ConfigureMiddleware;
|
|
||||||
use Flarum\Foundation\Application;
|
|
||||||
use Flarum\Http\AbstractServer;
|
|
||||||
use Zend\Stratigility\MiddlewarePipe;
|
|
||||||
|
|
||||||
class Server extends AbstractServer
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function getMiddleware(Application $app)
|
|
||||||
{
|
|
||||||
$pipe = new MiddlewarePipe;
|
|
||||||
$pipe->raiseThrowables();
|
|
||||||
|
|
||||||
if ($app->isInstalled()) {
|
|
||||||
$path = parse_url($app->url('admin'), PHP_URL_PATH);
|
|
||||||
|
|
||||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\HandleErrors', ['debug' => $app->inDebugMode() || ! $app->isUpToDate()]));
|
|
||||||
|
|
||||||
if ($app->isUpToDate()) {
|
|
||||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\ParseJsonBody'));
|
|
||||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\StartSession'));
|
|
||||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\RememberFromCookie'));
|
|
||||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\AuthenticateWithSession'));
|
|
||||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\SetLocale'));
|
|
||||||
$pipe->pipe($path, $app->make('Flarum\Admin\Middleware\RequireAdministrateAbility'));
|
|
||||||
|
|
||||||
event(new ConfigureMiddleware($pipe, $path, $this));
|
|
||||||
|
|
||||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.admin.routes')]));
|
|
||||||
} else {
|
|
||||||
$app->register('Flarum\Update\UpdateServiceProvider');
|
|
||||||
|
|
||||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.update.routes')]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $pipe;
|
|
||||||
}
|
|
||||||
}
|
|
22
framework/core/src/Admin/routes.php
Normal file
22
framework/core/src/Admin/routes.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Flarum\Admin\Controller;
|
||||||
|
use Flarum\Http\RouteCollection;
|
||||||
|
use Flarum\Http\RouteHandlerFactory;
|
||||||
|
|
||||||
|
return function (RouteCollection $map, RouteHandlerFactory $route) {
|
||||||
|
$map->get(
|
||||||
|
'/',
|
||||||
|
'index',
|
||||||
|
$route->toController(Controller\FrontendController::class)
|
||||||
|
);
|
||||||
|
};
|
@@ -37,10 +37,8 @@ class ApiKey extends AbstractModel
|
|||||||
*/
|
*/
|
||||||
public static function generate()
|
public static function generate()
|
||||||
{
|
{
|
||||||
$key = new static;
|
return new static([
|
||||||
|
'id' => str_random(40)
|
||||||
$key->id = str_random(40);
|
]);
|
||||||
|
|
||||||
return $key;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,16 +12,29 @@
|
|||||||
namespace Flarum\Api;
|
namespace Flarum\Api;
|
||||||
|
|
||||||
use Flarum\Api\Controller\AbstractSerializeController;
|
use Flarum\Api\Controller\AbstractSerializeController;
|
||||||
|
use Flarum\Api\Middleware\FakeHttpMethods;
|
||||||
|
use Flarum\Api\Middleware\HandleErrors;
|
||||||
use Flarum\Api\Serializer\AbstractSerializer;
|
use Flarum\Api\Serializer\AbstractSerializer;
|
||||||
|
use Flarum\Api\Serializer\BasicDiscussionSerializer;
|
||||||
use Flarum\Api\Serializer\NotificationSerializer;
|
use Flarum\Api\Serializer\NotificationSerializer;
|
||||||
use Flarum\Event\ConfigureApiRoutes;
|
use Flarum\Event\ConfigureApiRoutes;
|
||||||
|
use Flarum\Event\ConfigureMiddleware;
|
||||||
use Flarum\Event\ConfigureNotificationTypes;
|
use Flarum\Event\ConfigureNotificationTypes;
|
||||||
use Flarum\Foundation\AbstractServiceProvider;
|
use Flarum\Foundation\AbstractServiceProvider;
|
||||||
use Flarum\Http\Handler\RouteHandlerFactory;
|
use Flarum\Http\Middleware\AuthenticateWithHeader;
|
||||||
|
use Flarum\Http\Middleware\AuthenticateWithSession;
|
||||||
|
use Flarum\Http\Middleware\DispatchRoute;
|
||||||
|
use Flarum\Http\Middleware\ParseJsonBody;
|
||||||
|
use Flarum\Http\Middleware\RememberFromCookie;
|
||||||
|
use Flarum\Http\Middleware\SetLocale;
|
||||||
|
use Flarum\Http\Middleware\StartSession;
|
||||||
use Flarum\Http\RouteCollection;
|
use Flarum\Http\RouteCollection;
|
||||||
|
use Flarum\Http\RouteHandlerFactory;
|
||||||
|
use Flarum\Http\UrlGenerator;
|
||||||
use Tobscure\JsonApi\ErrorHandler;
|
use Tobscure\JsonApi\ErrorHandler;
|
||||||
use Tobscure\JsonApi\Exception\Handler\FallbackExceptionHandler;
|
use Tobscure\JsonApi\Exception\Handler\FallbackExceptionHandler;
|
||||||
use Tobscure\JsonApi\Exception\Handler\InvalidParameterExceptionHandler;
|
use Tobscure\JsonApi\Exception\Handler\InvalidParameterExceptionHandler;
|
||||||
|
use Zend\Stratigility\MiddlewarePipe;
|
||||||
|
|
||||||
class ApiServiceProvider extends AbstractServiceProvider
|
class ApiServiceProvider extends AbstractServiceProvider
|
||||||
{
|
{
|
||||||
@@ -30,27 +43,48 @@ class ApiServiceProvider extends AbstractServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
$this->app->singleton(UrlGenerator::class, function () {
|
$this->app->extend(UrlGenerator::class, function (UrlGenerator $url) {
|
||||||
return new UrlGenerator($this->app, $this->app->make('flarum.api.routes'));
|
return $url->addCollection('api', $this->app->make('flarum.api.routes'), 'api');
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->app->singleton('flarum.api.routes', function () {
|
$this->app->singleton('flarum.api.routes', function () {
|
||||||
return new RouteCollection;
|
return new RouteCollection;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$this->app->singleton('flarum.api.middleware', function ($app) {
|
||||||
|
$pipe = new MiddlewarePipe;
|
||||||
|
$pipe->raiseThrowables();
|
||||||
|
|
||||||
|
$pipe->pipe($app->make(HandleErrors::class));
|
||||||
|
|
||||||
|
$pipe->pipe($app->make(ParseJsonBody::class));
|
||||||
|
$pipe->pipe($app->make(FakeHttpMethods::class));
|
||||||
|
$pipe->pipe($app->make(StartSession::class));
|
||||||
|
$pipe->pipe($app->make(RememberFromCookie::class));
|
||||||
|
$pipe->pipe($app->make(AuthenticateWithSession::class));
|
||||||
|
$pipe->pipe($app->make(AuthenticateWithHeader::class));
|
||||||
|
$pipe->pipe($app->make(SetLocale::class));
|
||||||
|
|
||||||
|
event(new ConfigureMiddleware($pipe, 'api'));
|
||||||
|
|
||||||
|
$pipe->pipe($app->make(DispatchRoute::class, ['routes' => $app->make('flarum.api.routes')]));
|
||||||
|
|
||||||
|
return $pipe;
|
||||||
|
});
|
||||||
|
|
||||||
$this->app->singleton(ErrorHandler::class, function () {
|
$this->app->singleton(ErrorHandler::class, function () {
|
||||||
$handler = new ErrorHandler;
|
$handler = new ErrorHandler;
|
||||||
|
|
||||||
$handler->registerHandler(new Handler\FloodingExceptionHandler);
|
$handler->registerHandler(new ExceptionHandler\FloodingExceptionHandler);
|
||||||
$handler->registerHandler(new Handler\IlluminateValidationExceptionHandler);
|
$handler->registerHandler(new ExceptionHandler\IlluminateValidationExceptionHandler);
|
||||||
$handler->registerHandler(new Handler\InvalidAccessTokenExceptionHandler);
|
$handler->registerHandler(new ExceptionHandler\InvalidAccessTokenExceptionHandler);
|
||||||
$handler->registerHandler(new Handler\InvalidConfirmationTokenExceptionHandler);
|
$handler->registerHandler(new ExceptionHandler\InvalidConfirmationTokenExceptionHandler);
|
||||||
$handler->registerHandler(new Handler\MethodNotAllowedExceptionHandler);
|
$handler->registerHandler(new ExceptionHandler\MethodNotAllowedExceptionHandler);
|
||||||
$handler->registerHandler(new Handler\ModelNotFoundExceptionHandler);
|
$handler->registerHandler(new ExceptionHandler\ModelNotFoundExceptionHandler);
|
||||||
$handler->registerHandler(new Handler\PermissionDeniedExceptionHandler);
|
$handler->registerHandler(new ExceptionHandler\PermissionDeniedExceptionHandler);
|
||||||
$handler->registerHandler(new Handler\RouteNotFoundExceptionHandler);
|
$handler->registerHandler(new ExceptionHandler\RouteNotFoundExceptionHandler);
|
||||||
$handler->registerHandler(new Handler\TokenMismatchExceptionHandler);
|
$handler->registerHandler(new ExceptionHandler\TokenMismatchExceptionHandler);
|
||||||
$handler->registerHandler(new Handler\ValidationExceptionHandler);
|
$handler->registerHandler(new ExceptionHandler\ValidationExceptionHandler);
|
||||||
$handler->registerHandler(new InvalidParameterExceptionHandler);
|
$handler->registerHandler(new InvalidParameterExceptionHandler);
|
||||||
$handler->registerHandler(new FallbackExceptionHandler($this->app->inDebugMode()));
|
$handler->registerHandler(new FallbackExceptionHandler($this->app->inDebugMode()));
|
||||||
|
|
||||||
@@ -81,7 +115,7 @@ class ApiServiceProvider extends AbstractServiceProvider
|
|||||||
{
|
{
|
||||||
$blueprints = [];
|
$blueprints = [];
|
||||||
$serializers = [
|
$serializers = [
|
||||||
'discussionRenamed' => 'Flarum\Api\Serializer\DiscussionBasicSerializer'
|
'discussionRenamed' => BasicDiscussionSerializer::class
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->app->make('events')->fire(
|
$this->app->make('events')->fire(
|
||||||
@@ -100,298 +134,13 @@ class ApiServiceProvider extends AbstractServiceProvider
|
|||||||
*/
|
*/
|
||||||
protected function populateRoutes(RouteCollection $routes)
|
protected function populateRoutes(RouteCollection $routes)
|
||||||
{
|
{
|
||||||
$route = $this->app->make(RouteHandlerFactory::class);
|
$factory = $this->app->make(RouteHandlerFactory::class);
|
||||||
|
|
||||||
// Get forum information
|
$callback = include __DIR__.'/routes.php';
|
||||||
$routes->get(
|
$callback($routes, $factory);
|
||||||
'/forum',
|
|
||||||
'forum.show',
|
|
||||||
$route->toController(Controller\ShowForumController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Retrieve authentication token
|
|
||||||
$routes->post(
|
|
||||||
'/token',
|
|
||||||
'token',
|
|
||||||
$route->toController(Controller\TokenController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Send forgot password email
|
|
||||||
$routes->post(
|
|
||||||
'/forgot',
|
|
||||||
'forgot',
|
|
||||||
$route->toController(Controller\ForgotPasswordController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Users
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
// List users
|
|
||||||
$routes->get(
|
|
||||||
'/users',
|
|
||||||
'users.index',
|
|
||||||
$route->toController(Controller\ListUsersController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Register a user
|
|
||||||
$routes->post(
|
|
||||||
'/users',
|
|
||||||
'users.create',
|
|
||||||
$route->toController(Controller\CreateUserController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Get a single user
|
|
||||||
$routes->get(
|
|
||||||
'/users/{id}',
|
|
||||||
'users.show',
|
|
||||||
$route->toController(Controller\ShowUserController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Edit a user
|
|
||||||
$routes->patch(
|
|
||||||
'/users/{id}',
|
|
||||||
'users.update',
|
|
||||||
$route->toController(Controller\UpdateUserController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Delete a user
|
|
||||||
$routes->delete(
|
|
||||||
'/users/{id}',
|
|
||||||
'users.delete',
|
|
||||||
$route->toController(Controller\DeleteUserController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Upload avatar
|
|
||||||
$routes->post(
|
|
||||||
'/users/{id}/avatar',
|
|
||||||
'users.avatar.upload',
|
|
||||||
$route->toController(Controller\UploadAvatarController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Remove avatar
|
|
||||||
$routes->delete(
|
|
||||||
'/users/{id}/avatar',
|
|
||||||
'users.avatar.delete',
|
|
||||||
$route->toController(Controller\DeleteAvatarController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// send confirmation email
|
|
||||||
$routes->post(
|
|
||||||
'/users/{id}/send-confirmation',
|
|
||||||
'users.confirmation.send',
|
|
||||||
$route->toController(Controller\SendConfirmationEmailController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Notifications
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
// List notifications for the current user
|
|
||||||
$routes->get(
|
|
||||||
'/notifications',
|
|
||||||
'notifications.index',
|
|
||||||
$route->toController(Controller\ListNotificationsController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Mark all notifications as read
|
|
||||||
$routes->post(
|
|
||||||
'/notifications/read',
|
|
||||||
'notifications.readAll',
|
|
||||||
$route->toController(Controller\ReadAllNotificationsController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Mark a single notification as read
|
|
||||||
$routes->patch(
|
|
||||||
'/notifications/{id}',
|
|
||||||
'notifications.update',
|
|
||||||
$route->toController(Controller\UpdateNotificationController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Discussions
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
// List discussions
|
|
||||||
$routes->get(
|
|
||||||
'/discussions',
|
|
||||||
'discussions.index',
|
|
||||||
$route->toController(Controller\ListDiscussionsController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Create a discussion
|
|
||||||
$routes->post(
|
|
||||||
'/discussions',
|
|
||||||
'discussions.create',
|
|
||||||
$route->toController(Controller\CreateDiscussionController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Show a single discussion
|
|
||||||
$routes->get(
|
|
||||||
'/discussions/{id}',
|
|
||||||
'discussions.show',
|
|
||||||
$route->toController(Controller\ShowDiscussionController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Edit a discussion
|
|
||||||
$routes->patch(
|
|
||||||
'/discussions/{id}',
|
|
||||||
'discussions.update',
|
|
||||||
$route->toController(Controller\UpdateDiscussionController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Delete a discussion
|
|
||||||
$routes->delete(
|
|
||||||
'/discussions/{id}',
|
|
||||||
'discussions.delete',
|
|
||||||
$route->toController(Controller\DeleteDiscussionController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Posts
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
// List posts, usually for a discussion
|
|
||||||
$routes->get(
|
|
||||||
'/posts',
|
|
||||||
'posts.index',
|
|
||||||
$route->toController(Controller\ListPostsController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Create a post
|
|
||||||
$routes->post(
|
|
||||||
'/posts',
|
|
||||||
'posts.create',
|
|
||||||
$route->toController(Controller\CreatePostController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Show a single or multiple posts by ID
|
|
||||||
$routes->get(
|
|
||||||
'/posts/{id}',
|
|
||||||
'posts.show',
|
|
||||||
$route->toController(Controller\ShowPostController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Edit a post
|
|
||||||
$routes->patch(
|
|
||||||
'/posts/{id}',
|
|
||||||
'posts.update',
|
|
||||||
$route->toController(Controller\UpdatePostController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Delete a post
|
|
||||||
$routes->delete(
|
|
||||||
'/posts/{id}',
|
|
||||||
'posts.delete',
|
|
||||||
$route->toController(Controller\DeletePostController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Groups
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
// List groups
|
|
||||||
$routes->get(
|
|
||||||
'/groups',
|
|
||||||
'groups.index',
|
|
||||||
$route->toController(Controller\ListGroupsController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Create a group
|
|
||||||
$routes->post(
|
|
||||||
'/groups',
|
|
||||||
'groups.create',
|
|
||||||
$route->toController(Controller\CreateGroupController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Edit a group
|
|
||||||
$routes->patch(
|
|
||||||
'/groups/{id}',
|
|
||||||
'groups.update',
|
|
||||||
$route->toController(Controller\UpdateGroupController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Delete a group
|
|
||||||
$routes->delete(
|
|
||||||
'/groups/{id}',
|
|
||||||
'groups.delete',
|
|
||||||
$route->toController(Controller\DeleteGroupController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Administration
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Toggle an extension
|
|
||||||
$routes->patch(
|
|
||||||
'/extensions/{name}',
|
|
||||||
'extensions.update',
|
|
||||||
$route->toController(Controller\UpdateExtensionController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Uninstall an extension
|
|
||||||
$routes->delete(
|
|
||||||
'/extensions/{name}',
|
|
||||||
'extensions.delete',
|
|
||||||
$route->toController(Controller\UninstallExtensionController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Update settings
|
|
||||||
$routes->post(
|
|
||||||
'/settings',
|
|
||||||
'settings',
|
|
||||||
$route->toController(Controller\SetSettingsController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Update a permission
|
|
||||||
$routes->post(
|
|
||||||
'/permission',
|
|
||||||
'permission',
|
|
||||||
$route->toController(Controller\SetPermissionController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Upload a logo
|
|
||||||
$routes->post(
|
|
||||||
'/logo',
|
|
||||||
'logo',
|
|
||||||
$route->toController(Controller\UploadLogoController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Remove the logo
|
|
||||||
$routes->delete(
|
|
||||||
'/logo',
|
|
||||||
'logo.delete',
|
|
||||||
$route->toController(Controller\DeleteLogoController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Upload a favicon
|
|
||||||
$routes->post(
|
|
||||||
'/favicon',
|
|
||||||
'favicon',
|
|
||||||
$route->toController(Controller\UploadFaviconController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Remove the favicon
|
|
||||||
$routes->delete(
|
|
||||||
'/favicon',
|
|
||||||
'favicon.delete',
|
|
||||||
$route->toController(Controller\DeleteFaviconController::class)
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->app->make('events')->fire(
|
$this->app->make('events')->fire(
|
||||||
new ConfigureApiRoutes($routes, $route)
|
new ConfigureApiRoutes($routes, $factory)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,9 +12,9 @@
|
|||||||
namespace Flarum\Api;
|
namespace Flarum\Api;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Core\User;
|
|
||||||
use Flarum\Foundation\Application;
|
use Flarum\Foundation\Application;
|
||||||
use Flarum\Http\Controller\ControllerInterface;
|
use Flarum\Http\Controller\ControllerInterface;
|
||||||
|
use Flarum\User\User;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Zend\Diactoros\ServerRequestFactory;
|
use Zend\Diactoros\ServerRequestFactory;
|
||||||
|
|
||||||
|
@@ -13,7 +13,7 @@ namespace Flarum\Api\Controller;
|
|||||||
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
abstract class AbstractCreateController extends AbstractResourceController
|
abstract class AbstractCreateController extends AbstractShowController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
@@ -14,7 +14,7 @@ namespace Flarum\Api\Controller;
|
|||||||
use Tobscure\JsonApi\Collection;
|
use Tobscure\JsonApi\Collection;
|
||||||
use Tobscure\JsonApi\SerializerInterface;
|
use Tobscure\JsonApi\SerializerInterface;
|
||||||
|
|
||||||
abstract class AbstractCollectionController extends AbstractSerializeController
|
abstract class AbstractListController extends AbstractSerializeController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
|
use Flarum\Api\Event\WillGetData;
|
||||||
|
use Flarum\Api\Event\WillSerializeData;
|
||||||
use Flarum\Api\JsonApiResponse;
|
use Flarum\Api\JsonApiResponse;
|
||||||
use Flarum\Event\ConfigureApiController;
|
|
||||||
use Flarum\Event\PrepareApiData;
|
|
||||||
use Flarum\Http\Controller\ControllerInterface;
|
use Flarum\Http\Controller\ControllerInterface;
|
||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
@@ -91,13 +91,13 @@ abstract class AbstractSerializeController implements ControllerInterface
|
|||||||
$document = new Document;
|
$document = new Document;
|
||||||
|
|
||||||
static::$events->fire(
|
static::$events->fire(
|
||||||
new ConfigureApiController($this)
|
new WillGetData($this)
|
||||||
);
|
);
|
||||||
|
|
||||||
$data = $this->data($request, $document);
|
$data = $this->data($request, $document);
|
||||||
|
|
||||||
static::$events->fire(
|
static::$events->fire(
|
||||||
new PrepareApiData($this, $data, $request, $document)
|
new WillSerializeData($this, $data, $request, $document)
|
||||||
);
|
);
|
||||||
|
|
||||||
$serializer = static::$container->make($this->serializer);
|
$serializer = static::$container->make($this->serializer);
|
||||||
|
@@ -14,7 +14,7 @@ namespace Flarum\Api\Controller;
|
|||||||
use Tobscure\JsonApi\Resource;
|
use Tobscure\JsonApi\Resource;
|
||||||
use Tobscure\JsonApi\SerializerInterface;
|
use Tobscure\JsonApi\SerializerInterface;
|
||||||
|
|
||||||
abstract class AbstractResourceController extends AbstractSerializeController
|
abstract class AbstractShowController extends AbstractSerializeController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Command\ReadDiscussion;
|
use Flarum\Discussion\Command\ReadDiscussion;
|
||||||
use Flarum\Core\Command\StartDiscussion;
|
use Flarum\Discussion\Command\StartDiscussion;
|
||||||
use Flarum\Core\Post\Floodgate;
|
use Flarum\Post\Floodgate;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Command\CreateGroup;
|
use Flarum\Group\Command\CreateGroup;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Command\PostReply;
|
use Flarum\Discussion\Command\ReadDiscussion;
|
||||||
use Flarum\Core\Command\ReadDiscussion;
|
use Flarum\Post\Command\PostReply;
|
||||||
use Flarum\Core\Post\Floodgate;
|
use Flarum\Post\Floodgate;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
@@ -41,13 +41,13 @@ class CreatePostController extends AbstractCreateController
|
|||||||
protected $bus;
|
protected $bus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Floodgate
|
* @var \Flarum\Post\Floodgate
|
||||||
*/
|
*/
|
||||||
protected $floodgate;
|
protected $floodgate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Dispatcher $bus
|
* @param Dispatcher $bus
|
||||||
* @param Floodgate $floodgate
|
* @param \Flarum\Post\Floodgate $floodgate
|
||||||
*/
|
*/
|
||||||
public function __construct(Dispatcher $bus, Floodgate $floodgate)
|
public function __construct(Dispatcher $bus, Floodgate $floodgate)
|
||||||
{
|
{
|
||||||
@@ -83,7 +83,7 @@ class CreatePostController extends AbstractCreateController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$discussion = $post->discussion;
|
$discussion = $post->discussion;
|
||||||
$discussion->posts = $discussion->postsVisibleTo($actor)->orderBy('time')->lists('id');
|
$discussion->posts = $discussion->postsVisibleTo($actor)->orderBy('time')->pluck('id');
|
||||||
|
|
||||||
return $post;
|
return $post;
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Command\RegisterUser;
|
use Flarum\User\Command\RegisterUser;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
@@ -11,12 +11,12 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Command\DeleteAvatar;
|
use Flarum\User\Command\DeleteAvatar;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
class DeleteAvatarController extends AbstractResourceController
|
class DeleteAvatarController extends AbstractShowController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Command\DeleteDiscussion;
|
use Flarum\Discussion\Command\DeleteDiscussion;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
|
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Access\AssertPermissionTrait;
|
|
||||||
use Flarum\Foundation\Application;
|
use Flarum\Foundation\Application;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
|
use Flarum\User\AssertPermissionTrait;
|
||||||
use League\Flysystem\Adapter\Local;
|
use League\Flysystem\Adapter\Local;
|
||||||
use League\Flysystem\Filesystem;
|
use League\Flysystem\Filesystem;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Command\DeleteGroup;
|
use Flarum\Group\Command\DeleteGroup;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
|
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Access\AssertPermissionTrait;
|
|
||||||
use Flarum\Foundation\Application;
|
use Flarum\Foundation\Application;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
|
use Flarum\User\AssertPermissionTrait;
|
||||||
use League\Flysystem\Adapter\Local;
|
use League\Flysystem\Adapter\Local;
|
||||||
use League\Flysystem\Filesystem;
|
use League\Flysystem\Filesystem;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Command\DeletePost;
|
use Flarum\Post\Command\DeletePost;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Command\DeleteUser;
|
use Flarum\User\Command\DeleteUser;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
|
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Command\RequestPasswordReset;
|
|
||||||
use Flarum\Core\Repository\UserRepository;
|
|
||||||
use Flarum\Http\Controller\ControllerInterface;
|
use Flarum\Http\Controller\ControllerInterface;
|
||||||
|
use Flarum\User\Command\RequestPasswordReset;
|
||||||
|
use Flarum\User\UserRepository;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Zend\Diactoros\Response\EmptyResponse;
|
use Zend\Diactoros\Response\EmptyResponse;
|
||||||
@@ -21,7 +21,7 @@ use Zend\Diactoros\Response\EmptyResponse;
|
|||||||
class ForgotPasswordController implements ControllerInterface
|
class ForgotPasswordController implements ControllerInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Flarum\Core\Repository\UserRepository
|
* @var \Flarum\User\UserRepository
|
||||||
*/
|
*/
|
||||||
protected $users;
|
protected $users;
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ class ForgotPasswordController implements ControllerInterface
|
|||||||
protected $bus;
|
protected $bus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Flarum\Core\Repository\UserRepository $users
|
* @param \Flarum\User\UserRepository $users
|
||||||
* @param Dispatcher $bus
|
* @param Dispatcher $bus
|
||||||
*/
|
*/
|
||||||
public function __construct(UserRepository $users, Dispatcher $bus)
|
public function __construct(UserRepository $users, Dispatcher $bus)
|
||||||
|
@@ -11,13 +11,13 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Api\UrlGenerator;
|
use Flarum\Discussion\Search\DiscussionSearcher;
|
||||||
use Flarum\Core\Search\Discussion\DiscussionSearcher;
|
use Flarum\Http\UrlGenerator;
|
||||||
use Flarum\Core\Search\SearchCriteria;
|
use Flarum\Search\SearchCriteria;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
class ListDiscussionsController extends AbstractCollectionController
|
class ListDiscussionsController extends AbstractListController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -86,7 +86,7 @@ class ListDiscussionsController extends AbstractCollectionController
|
|||||||
$results = $this->searcher->search($criteria, $limit, $offset, $load);
|
$results = $this->searcher->search($criteria, $limit, $offset, $load);
|
||||||
|
|
||||||
$document->addPaginationLinks(
|
$document->addPaginationLinks(
|
||||||
$this->url->toRoute('discussions.index'),
|
$this->url->to('api')->route('discussions.index'),
|
||||||
$request->getQueryParams(),
|
$request->getQueryParams(),
|
||||||
$offset,
|
$offset,
|
||||||
$limit,
|
$limit,
|
||||||
|
@@ -11,11 +11,11 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Group;
|
use Flarum\Group\Group;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
class ListGroupsController extends AbstractCollectionController
|
class ListGroupsController extends AbstractListController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
@@ -11,14 +11,14 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Api\UrlGenerator;
|
use Flarum\Discussion\Discussion;
|
||||||
use Flarum\Core\Discussion;
|
use Flarum\Http\UrlGenerator;
|
||||||
use Flarum\Core\Exception\PermissionDeniedException;
|
use Flarum\Notification\NotificationRepository;
|
||||||
use Flarum\Core\Repository\NotificationRepository;
|
use Flarum\User\Exception\PermissionDeniedException;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
class ListNotificationsController extends AbstractCollectionController
|
class ListNotificationsController extends AbstractListController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -92,7 +92,7 @@ class ListNotificationsController extends AbstractCollectionController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$document->addPaginationLinks(
|
$document->addPaginationLinks(
|
||||||
$this->url->toRoute('notifications.index'),
|
$this->url->to('api')->route('notifications.index'),
|
||||||
$request->getQueryParams(),
|
$request->getQueryParams(),
|
||||||
$offset,
|
$offset,
|
||||||
$limit,
|
$limit,
|
||||||
@@ -111,7 +111,7 @@ class ListNotificationsController extends AbstractCollectionController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Flarum\Core\Notification[] $notifications
|
* @param \Flarum\Notification\Notification[] $notifications
|
||||||
*/
|
*/
|
||||||
private function loadSubjectDiscussions(array $notifications)
|
private function loadSubjectDiscussions(array $notifications)
|
||||||
{
|
{
|
||||||
|
@@ -11,14 +11,14 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Repository\PostRepository;
|
|
||||||
use Flarum\Event\ConfigurePostsQuery;
|
use Flarum\Event\ConfigurePostsQuery;
|
||||||
|
use Flarum\Post\PostRepository;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
use Tobscure\JsonApi\Exception\InvalidParameterException;
|
use Tobscure\JsonApi\Exception\InvalidParameterException;
|
||||||
|
|
||||||
class ListPostsController extends AbstractCollectionController
|
class ListPostsController extends AbstractListController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -42,12 +42,12 @@ class ListPostsController extends AbstractCollectionController
|
|||||||
public $sortFields = ['time'];
|
public $sortFields = ['time'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Flarum\Core\Repository\PostRepository
|
* @var \Flarum\Post\PostRepository
|
||||||
*/
|
*/
|
||||||
protected $posts;
|
protected $posts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Flarum\Core\Repository\PostRepository $posts
|
* @param \Flarum\Post\PostRepository $posts
|
||||||
*/
|
*/
|
||||||
public function __construct(PostRepository $posts)
|
public function __construct(PostRepository $posts)
|
||||||
{
|
{
|
||||||
@@ -122,7 +122,7 @@ class ListPostsController extends AbstractCollectionController
|
|||||||
$query->orderBy($field, $order);
|
$query->orderBy($field, $order);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query->lists('id')->all();
|
return $query->pluck('id')->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -11,14 +11,14 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Api\UrlGenerator;
|
use Flarum\Http\UrlGenerator;
|
||||||
use Flarum\Core\Exception\PermissionDeniedException;
|
use Flarum\Search\SearchCriteria;
|
||||||
use Flarum\Core\Search\SearchCriteria;
|
use Flarum\User\Exception\PermissionDeniedException;
|
||||||
use Flarum\Core\Search\User\UserSearcher;
|
use Flarum\User\Search\UserSearcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
class ListUsersController extends AbstractCollectionController
|
class ListUsersController extends AbstractListController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -84,7 +84,7 @@ class ListUsersController extends AbstractCollectionController
|
|||||||
$results = $this->searcher->search($criteria, $limit, $offset, $load);
|
$results = $this->searcher->search($criteria, $limit, $offset, $load);
|
||||||
|
|
||||||
$document->addPaginationLinks(
|
$document->addPaginationLinks(
|
||||||
$this->url->toRoute('users.index'),
|
$this->url->to('api')->route('users.index'),
|
||||||
$request->getQueryParams(),
|
$request->getQueryParams(),
|
||||||
$offset,
|
$offset,
|
||||||
$limit,
|
$limit,
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Command\ReadAllNotifications;
|
use Flarum\Notification\Command\ReadAllNotifications;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
|
@@ -11,12 +11,12 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Access\AssertPermissionTrait;
|
|
||||||
use Flarum\Core\EmailToken;
|
|
||||||
use Flarum\Core\Exception\PermissionDeniedException;
|
|
||||||
use Flarum\Forum\UrlGenerator;
|
|
||||||
use Flarum\Http\Controller\ControllerInterface;
|
use Flarum\Http\Controller\ControllerInterface;
|
||||||
|
use Flarum\Http\UrlGenerator;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
|
use Flarum\User\AssertPermissionTrait;
|
||||||
|
use Flarum\User\EmailToken;
|
||||||
|
use Flarum\User\Exception\PermissionDeniedException;
|
||||||
use Illuminate\Contracts\Mail\Mailer;
|
use Illuminate\Contracts\Mail\Mailer;
|
||||||
use Illuminate\Mail\Message;
|
use Illuminate\Mail\Message;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
@@ -80,7 +80,7 @@ class SendConfirmationEmailController implements ControllerInterface
|
|||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'{username}' => $actor->username,
|
'{username}' => $actor->username,
|
||||||
'{url}' => $this->url->toRoute('confirmEmail', ['token' => $token->id]),
|
'{url}' => $this->url->to('forum')->route('confirmEmail', ['token' => $token->id]),
|
||||||
'{forum}' => $this->settings->get('forum_title')
|
'{forum}' => $this->settings->get('forum_title')
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Access\AssertPermissionTrait;
|
use Flarum\Group\Permission;
|
||||||
use Flarum\Core\Permission;
|
|
||||||
use Flarum\Http\Controller\ControllerInterface;
|
use Flarum\Http\Controller\ControllerInterface;
|
||||||
|
use Flarum\User\AssertPermissionTrait;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Zend\Diactoros\Response\EmptyResponse;
|
use Zend\Diactoros\Response\EmptyResponse;
|
||||||
|
|
||||||
|
@@ -11,11 +11,11 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Access\AssertPermissionTrait;
|
|
||||||
use Flarum\Event\PrepareSerializedSetting;
|
|
||||||
use Flarum\Event\SettingWasSet;
|
|
||||||
use Flarum\Http\Controller\ControllerInterface;
|
use Flarum\Http\Controller\ControllerInterface;
|
||||||
|
use Flarum\Settings\Event\Saved;
|
||||||
|
use Flarum\Settings\Event\Serializing;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
|
use Flarum\User\AssertPermissionTrait;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Zend\Diactoros\Response\EmptyResponse;
|
use Zend\Diactoros\Response\EmptyResponse;
|
||||||
@@ -53,11 +53,11 @@ class SetSettingsController implements ControllerInterface
|
|||||||
$settings = $request->getParsedBody();
|
$settings = $request->getParsedBody();
|
||||||
|
|
||||||
foreach ($settings as $k => $v) {
|
foreach ($settings as $k => $v) {
|
||||||
$this->dispatcher->fire(new PrepareSerializedSetting($k, $v));
|
$this->dispatcher->fire(new Serializing($k, $v));
|
||||||
|
|
||||||
$this->settings->set($k, $v);
|
$this->settings->set($k, $v);
|
||||||
|
|
||||||
$this->dispatcher->fire(new SettingWasSet($k, $v));
|
$this->dispatcher->fire(new Saved($k, $v));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new EmptyResponse(204);
|
return new EmptyResponse(204);
|
||||||
|
@@ -11,17 +11,17 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Discussion;
|
use Flarum\Discussion\Discussion;
|
||||||
use Flarum\Core\Repository\DiscussionRepository;
|
use Flarum\Discussion\DiscussionRepository;
|
||||||
use Flarum\Core\Repository\PostRepository;
|
use Flarum\Post\PostRepository;
|
||||||
use Flarum\Core\User;
|
use Flarum\User\User;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
class ShowDiscussionController extends AbstractResourceController
|
class ShowDiscussionController extends AbstractShowController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var DiscussionRepository
|
* @var \Flarum\Discussion\DiscussionRepository
|
||||||
*/
|
*/
|
||||||
protected $discussions;
|
protected $discussions;
|
||||||
|
|
||||||
@@ -58,8 +58,8 @@ class ShowDiscussionController extends AbstractResourceController
|
|||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Flarum\Core\Repository\DiscussionRepository $discussions
|
* @param \Flarum\Discussion\DiscussionRepository $discussions
|
||||||
* @param \Flarum\Core\Repository\PostRepository $posts
|
* @param \Flarum\Post\PostRepository $posts
|
||||||
*/
|
*/
|
||||||
public function __construct(DiscussionRepository $discussions, PostRepository $posts)
|
public function __construct(DiscussionRepository $discussions, PostRepository $posts)
|
||||||
{
|
{
|
||||||
@@ -117,7 +117,7 @@ class ShowDiscussionController extends AbstractResourceController
|
|||||||
*/
|
*/
|
||||||
private function loadPostIds(Discussion $discussion, User $actor)
|
private function loadPostIds(Discussion $discussion, User $actor)
|
||||||
{
|
{
|
||||||
return $discussion->postsVisibleTo($actor)->orderBy('time')->lists('id')->all();
|
return $discussion->postsVisibleTo($actor)->orderBy('time')->pluck('id')->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -11,11 +11,11 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Group;
|
use Flarum\Group\Group;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
class ShowForumController extends AbstractResourceController
|
class ShowForumController extends AbstractShowController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
@@ -11,11 +11,11 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Repository\PostRepository;
|
use Flarum\Post\PostRepository;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
class ShowPostController extends AbstractResourceController
|
class ShowPostController extends AbstractShowController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -34,12 +34,12 @@ class ShowPostController extends AbstractResourceController
|
|||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Flarum\Core\Repository\PostRepository
|
* @var \Flarum\Post\PostRepository
|
||||||
*/
|
*/
|
||||||
protected $posts;
|
protected $posts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param PostRepository $posts
|
* @param \Flarum\Post\PostRepository $posts
|
||||||
*/
|
*/
|
||||||
public function __construct(PostRepository $posts)
|
public function __construct(PostRepository $posts)
|
||||||
{
|
{
|
||||||
|
@@ -11,11 +11,11 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Repository\UserRepository;
|
use Flarum\User\UserRepository;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
class ShowUserController extends AbstractResourceController
|
class ShowUserController extends AbstractShowController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -28,12 +28,12 @@ class ShowUserController extends AbstractResourceController
|
|||||||
public $include = ['groups'];
|
public $include = ['groups'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var UserRepository
|
* @var \Flarum\User\UserRepository
|
||||||
*/
|
*/
|
||||||
protected $users;
|
protected $users;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param UserRepository $users
|
* @param \Flarum\User\UserRepository $users
|
||||||
*/
|
*/
|
||||||
public function __construct(UserRepository $users)
|
public function __construct(UserRepository $users)
|
||||||
{
|
{
|
||||||
|
@@ -11,10 +11,10 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Exception\PermissionDeniedException;
|
|
||||||
use Flarum\Core\Repository\UserRepository;
|
|
||||||
use Flarum\Http\AccessToken;
|
use Flarum\Http\AccessToken;
|
||||||
use Flarum\Http\Controller\ControllerInterface;
|
use Flarum\Http\Controller\ControllerInterface;
|
||||||
|
use Flarum\User\Exception\PermissionDeniedException;
|
||||||
|
use Flarum\User\UserRepository;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher;
|
||||||
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
|
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
@@ -23,7 +23,7 @@ use Zend\Diactoros\Response\JsonResponse;
|
|||||||
class TokenController implements ControllerInterface
|
class TokenController implements ControllerInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var UserRepository
|
* @var \Flarum\User\UserRepository
|
||||||
*/
|
*/
|
||||||
protected $users;
|
protected $users;
|
||||||
|
|
||||||
|
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Access\AssertPermissionTrait;
|
|
||||||
use Flarum\Extension\ExtensionManager;
|
use Flarum\Extension\ExtensionManager;
|
||||||
|
use Flarum\User\AssertPermissionTrait;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class UninstallExtensionController extends AbstractDeleteController
|
class UninstallExtensionController extends AbstractDeleteController
|
||||||
|
@@ -11,14 +11,14 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Command\EditDiscussion;
|
use Flarum\Discussion\Command\EditDiscussion;
|
||||||
use Flarum\Core\Command\ReadDiscussion;
|
use Flarum\Discussion\Command\ReadDiscussion;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
class UpdateDiscussionController extends AbstractResourceController
|
class UpdateDiscussionController extends AbstractShowController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -63,7 +63,7 @@ class UpdateDiscussionController extends AbstractResourceController
|
|||||||
|
|
||||||
if ($posts = $discussion->getModifiedPosts()) {
|
if ($posts = $discussion->getModifiedPosts()) {
|
||||||
$posts = (new Collection($posts))->load('discussion', 'user');
|
$posts = (new Collection($posts))->load('discussion', 'user');
|
||||||
$discussionPosts = $discussion->postsVisibleTo($actor)->orderBy('time')->lists('id')->all();
|
$discussionPosts = $discussion->postsVisibleTo($actor)->orderBy('time')->pluck('id')->all();
|
||||||
|
|
||||||
foreach ($discussionPosts as &$id) {
|
foreach ($discussionPosts as &$id) {
|
||||||
foreach ($posts as $post) {
|
foreach ($posts as $post) {
|
||||||
|
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Access\AssertPermissionTrait;
|
|
||||||
use Flarum\Extension\ExtensionManager;
|
use Flarum\Extension\ExtensionManager;
|
||||||
use Flarum\Http\Controller\ControllerInterface;
|
use Flarum\Http\Controller\ControllerInterface;
|
||||||
|
use Flarum\User\AssertPermissionTrait;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class UpdateExtensionController implements ControllerInterface
|
class UpdateExtensionController implements ControllerInterface
|
||||||
|
@@ -11,12 +11,12 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Command\EditGroup;
|
use Flarum\Group\Command\EditGroup;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
class UpdateGroupController extends AbstractResourceController
|
class UpdateGroupController extends AbstractShowController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
@@ -11,12 +11,12 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Command\ReadNotification;
|
use Flarum\Notification\Command\ReadNotification;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
class UpdateNotificationController extends AbstractResourceController
|
class UpdateNotificationController extends AbstractShowController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
@@ -11,12 +11,12 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Command\EditPost;
|
use Flarum\Post\Command\EditPost;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
class UpdatePostController extends AbstractResourceController
|
class UpdatePostController extends AbstractShowController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
@@ -11,13 +11,13 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Command\EditUser;
|
use Flarum\User\Command\EditUser;
|
||||||
use Flarum\Core\Exception\PermissionDeniedException;
|
use Flarum\User\Exception\PermissionDeniedException;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
class UpdateUserController extends AbstractResourceController
|
class UpdateUserController extends AbstractShowController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
@@ -11,12 +11,12 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Command\UploadAvatar;
|
use Flarum\User\Command\UploadAvatar;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
class UploadAvatarController extends AbstractResourceController
|
class UploadAvatarController extends AbstractShowController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Access\AssertPermissionTrait;
|
|
||||||
use Flarum\Foundation\Application;
|
use Flarum\Foundation\Application;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
|
use Flarum\User\AssertPermissionTrait;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Intervention\Image\ImageManager;
|
use Intervention\Image\ImageManager;
|
||||||
use League\Flysystem\Adapter\Local;
|
use League\Flysystem\Adapter\Local;
|
||||||
@@ -80,7 +80,7 @@ class UploadFaviconController extends ShowForumController
|
|||||||
$mount->delete($file);
|
$mount->delete($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
$uploadName = 'favicon-'.Str::lower(Str::quickRandom(8)).'.'.$extension;
|
$uploadName = 'favicon-'.Str::lower(Str::random(8)).'.'.$extension;
|
||||||
|
|
||||||
$mount->move('source://'.pathinfo($tmpFile, PATHINFO_BASENAME), "target://$uploadName");
|
$mount->move('source://'.pathinfo($tmpFile, PATHINFO_BASENAME), "target://$uploadName");
|
||||||
|
|
||||||
|
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Controller;
|
namespace Flarum\Api\Controller;
|
||||||
|
|
||||||
use Flarum\Core\Access\AssertPermissionTrait;
|
|
||||||
use Flarum\Foundation\Application;
|
use Flarum\Foundation\Application;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
|
use Flarum\User\AssertPermissionTrait;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Intervention\Image\ImageManager;
|
use Intervention\Image\ImageManager;
|
||||||
use League\Flysystem\Adapter\Local;
|
use League\Flysystem\Adapter\Local;
|
||||||
@@ -73,7 +73,7 @@ class UploadLogoController extends ShowForumController
|
|||||||
$mount->delete($file);
|
$mount->delete($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
$uploadName = 'logo-'.Str::lower(Str::quickRandom(8)).'.png';
|
$uploadName = 'logo-'.Str::lower(Str::random(8)).'.png';
|
||||||
|
|
||||||
$mount->move('source://'.pathinfo($tmpFile, PATHINFO_BASENAME), "target://$uploadName");
|
$mount->move('source://'.pathinfo($tmpFile, PATHINFO_BASENAME), "target://$uploadName");
|
||||||
|
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Event;
|
namespace Flarum\Api\Event;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Flarum\Api\Serializer\AbstractSerializer;
|
use Flarum\Api\Serializer\AbstractSerializer;
|
||||||
@@ -17,10 +17,10 @@ use Flarum\Api\Serializer\AbstractSerializer;
|
|||||||
/**
|
/**
|
||||||
* Prepare API attributes.
|
* Prepare API attributes.
|
||||||
*
|
*
|
||||||
* This event is fired when a serialize is constructing an array of resource
|
* This event is fired when a serializer is constructing an array of resource
|
||||||
* attributes for API output.
|
* attributes for API output.
|
||||||
*/
|
*/
|
||||||
class PrepareApiAttributes
|
class Serializing
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The class doing the serializing.
|
* The class doing the serializing.
|
||||||
@@ -44,7 +44,7 @@ class PrepareApiAttributes
|
|||||||
public $attributes;
|
public $attributes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Flarum\Core\User
|
* @var \Flarum\User\User
|
||||||
*/
|
*/
|
||||||
public $actor;
|
public $actor;
|
||||||
|
|
@@ -9,11 +9,11 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Event;
|
namespace Flarum\Api\Event;
|
||||||
|
|
||||||
use Flarum\Api\Controller\AbstractSerializeController;
|
use Flarum\Api\Controller\AbstractSerializeController;
|
||||||
|
|
||||||
class ConfigureApiController
|
class WillGetData
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var AbstractSerializeController
|
* @var AbstractSerializeController
|
@@ -9,13 +9,13 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Event;
|
namespace Flarum\Api\Event;
|
||||||
|
|
||||||
use Flarum\Api\Controller\AbstractSerializeController;
|
use Flarum\Api\Controller\AbstractSerializeController;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
class PrepareApiData
|
class WillSerializeData
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var AbstractSerializeController
|
* @var AbstractSerializeController
|
||||||
@@ -38,7 +38,7 @@ class PrepareApiData
|
|||||||
public $document;
|
public $document;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Flarum\Core\User
|
* @var \Flarum\User\User
|
||||||
*/
|
*/
|
||||||
public $actor;
|
public $actor;
|
||||||
|
|
@@ -9,10 +9,10 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Handler;
|
namespace Flarum\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Core\Exception\FloodingException;
|
use Flarum\Post\Exception\FloodingException;
|
||||||
use Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface;
|
use Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface;
|
||||||
use Tobscure\JsonApi\Exception\Handler\ResponseBag;
|
use Tobscure\JsonApi\Exception\Handler\ResponseBag;
|
||||||
|
|
@@ -9,10 +9,10 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Handler;
|
namespace Flarum\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Contracts\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
use Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface;
|
use Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface;
|
||||||
use Tobscure\JsonApi\Exception\Handler\ResponseBag;
|
use Tobscure\JsonApi\Exception\Handler\ResponseBag;
|
||||||
|
|
||||||
@@ -32,7 +32,8 @@ class IlluminateValidationExceptionHandler implements ExceptionHandlerInterface
|
|||||||
public function handle(Exception $e)
|
public function handle(Exception $e)
|
||||||
{
|
{
|
||||||
$status = 422;
|
$status = 422;
|
||||||
$errors = $this->formatErrors($e->errors()->toArray());
|
|
||||||
|
$errors = $this->formatErrors($e->errors());
|
||||||
|
|
||||||
return new ResponseBag($status, $errors);
|
return new ResponseBag($status, $errors);
|
||||||
}
|
}
|
@@ -9,7 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Handler;
|
namespace Flarum\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Api\Exception\InvalidAccessTokenException;
|
use Flarum\Api\Exception\InvalidAccessTokenException;
|
@@ -9,10 +9,10 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Handler;
|
namespace Flarum\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Core\Exception\InvalidConfirmationTokenException;
|
use Flarum\User\Exception\InvalidConfirmationTokenException;
|
||||||
use Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface;
|
use Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface;
|
||||||
use Tobscure\JsonApi\Exception\Handler\ResponseBag;
|
use Tobscure\JsonApi\Exception\Handler\ResponseBag;
|
||||||
|
|
@@ -9,7 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Handler;
|
namespace Flarum\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Http\Exception\MethodNotAllowedException;
|
use Flarum\Http\Exception\MethodNotAllowedException;
|
@@ -9,7 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Handler;
|
namespace Flarum\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
@@ -9,10 +9,10 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Handler;
|
namespace Flarum\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Core\Exception\PermissionDeniedException;
|
use Flarum\User\Exception\PermissionDeniedException;
|
||||||
use Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface;
|
use Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface;
|
||||||
use Tobscure\JsonApi\Exception\Handler\ResponseBag;
|
use Tobscure\JsonApi\Exception\Handler\ResponseBag;
|
||||||
|
|
@@ -9,7 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Handler;
|
namespace Flarum\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Http\Exception\RouteNotFoundException;
|
use Flarum\Http\Exception\RouteNotFoundException;
|
@@ -9,7 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Handler;
|
namespace Flarum\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Http\Exception\TokenMismatchException;
|
use Flarum\Http\Exception\TokenMismatchException;
|
@@ -9,10 +9,10 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Handler;
|
namespace Flarum\Api\ExceptionHandler;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Core\Exception\ValidationException;
|
use Flarum\Foundation\ValidationException;
|
||||||
use Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface;
|
use Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface;
|
||||||
use Tobscure\JsonApi\Exception\Handler\ResponseBag;
|
use Tobscure\JsonApi\Exception\Handler\ResponseBag;
|
||||||
|
|
@@ -13,9 +13,9 @@ namespace Flarum\Api\Serializer;
|
|||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Flarum\Core\User;
|
use Flarum\Api\Event\Serializing;
|
||||||
use Flarum\Event\GetApiRelationship;
|
use Flarum\Event\GetApiRelationship;
|
||||||
use Flarum\Event\PrepareApiAttributes;
|
use Flarum\User\User;
|
||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
@@ -71,7 +71,7 @@ abstract class AbstractSerializer extends BaseAbstractSerializer
|
|||||||
$attributes = $this->getDefaultAttributes($model);
|
$attributes = $this->getDefaultAttributes($model);
|
||||||
|
|
||||||
static::$dispatcher->fire(
|
static::$dispatcher->fire(
|
||||||
new PrepareApiAttributes($this, $model, $attributes)
|
new Serializing($this, $model, $attributes)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $attributes;
|
return $attributes;
|
||||||
|
@@ -11,10 +11,10 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Serializer;
|
namespace Flarum\Api\Serializer;
|
||||||
|
|
||||||
use Flarum\Core\Discussion;
|
use Flarum\Discussion\Discussion;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
|
||||||
class DiscussionBasicSerializer extends AbstractSerializer
|
class BasicDiscussionSerializer extends AbstractSerializer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -46,7 +46,7 @@ class DiscussionBasicSerializer extends AbstractSerializer
|
|||||||
*/
|
*/
|
||||||
protected function startUser($discussion)
|
protected function startUser($discussion)
|
||||||
{
|
{
|
||||||
return $this->hasOne($discussion, 'Flarum\Api\Serializer\UserBasicSerializer');
|
return $this->hasOne($discussion, BasicUserSerializer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,7 +54,7 @@ class DiscussionBasicSerializer extends AbstractSerializer
|
|||||||
*/
|
*/
|
||||||
protected function startPost($discussion)
|
protected function startPost($discussion)
|
||||||
{
|
{
|
||||||
return $this->hasOne($discussion, 'Flarum\Api\Serializer\PostBasicSerializer');
|
return $this->hasOne($discussion, BasicPostSerializer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,7 +62,7 @@ class DiscussionBasicSerializer extends AbstractSerializer
|
|||||||
*/
|
*/
|
||||||
protected function lastUser($discussion)
|
protected function lastUser($discussion)
|
||||||
{
|
{
|
||||||
return $this->hasOne($discussion, 'Flarum\Api\Serializer\UserBasicSerializer');
|
return $this->hasOne($discussion, BasicUserSerializer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,7 +70,7 @@ class DiscussionBasicSerializer extends AbstractSerializer
|
|||||||
*/
|
*/
|
||||||
protected function lastPost($discussion)
|
protected function lastPost($discussion)
|
||||||
{
|
{
|
||||||
return $this->hasOne($discussion, 'Flarum\Api\Serializer\PostBasicSerializer');
|
return $this->hasOne($discussion, BasicPostSerializer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,7 +78,7 @@ class DiscussionBasicSerializer extends AbstractSerializer
|
|||||||
*/
|
*/
|
||||||
protected function posts($discussion)
|
protected function posts($discussion)
|
||||||
{
|
{
|
||||||
return $this->hasMany($discussion, 'Flarum\Api\Serializer\PostSerializer');
|
return $this->hasMany($discussion, PostSerializer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,7 +86,7 @@ class DiscussionBasicSerializer extends AbstractSerializer
|
|||||||
*/
|
*/
|
||||||
protected function relevantPosts($discussion)
|
protected function relevantPosts($discussion)
|
||||||
{
|
{
|
||||||
return $this->hasMany($discussion, 'Flarum\Api\Serializer\PostBasicSerializer');
|
return $this->hasMany($discussion, BasicPostSerializer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,6 +94,6 @@ class DiscussionBasicSerializer extends AbstractSerializer
|
|||||||
*/
|
*/
|
||||||
protected function hideUser($discussion)
|
protected function hideUser($discussion)
|
||||||
{
|
{
|
||||||
return $this->hasOne($discussion, 'Flarum\Api\Serializer\UserBasicSerializer');
|
return $this->hasOne($discussion, BasicUserSerializer::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -11,11 +11,11 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Serializer;
|
namespace Flarum\Api\Serializer;
|
||||||
|
|
||||||
use Flarum\Core\Post;
|
use Flarum\Post\CommentPost;
|
||||||
use Flarum\Core\Post\CommentPost;
|
use Flarum\Post\Post;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
|
||||||
class PostBasicSerializer extends AbstractSerializer
|
class BasicPostSerializer extends AbstractSerializer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -25,7 +25,7 @@ class PostBasicSerializer extends AbstractSerializer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
* @param \Flarum\Core\Post $post
|
* @param \Flarum\Post\Post $post
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
protected function getDefaultAttributes($post)
|
protected function getDefaultAttributes($post)
|
||||||
@@ -57,7 +57,7 @@ class PostBasicSerializer extends AbstractSerializer
|
|||||||
*/
|
*/
|
||||||
protected function user($post)
|
protected function user($post)
|
||||||
{
|
{
|
||||||
return $this->hasOne($post, 'Flarum\Api\Serializer\UserBasicSerializer');
|
return $this->hasOne($post, BasicUserSerializer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,6 +65,6 @@ class PostBasicSerializer extends AbstractSerializer
|
|||||||
*/
|
*/
|
||||||
protected function discussion($post)
|
protected function discussion($post)
|
||||||
{
|
{
|
||||||
return $this->hasOne($post, 'Flarum\Api\Serializer\DiscussionBasicSerializer');
|
return $this->hasOne($post, BasicDiscussionSerializer::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -11,10 +11,10 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Serializer;
|
namespace Flarum\Api\Serializer;
|
||||||
|
|
||||||
use Flarum\Core\User;
|
use Flarum\User\User;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
|
||||||
class UserBasicSerializer extends AbstractSerializer
|
class BasicUserSerializer extends AbstractSerializer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -47,6 +47,6 @@ class UserBasicSerializer extends AbstractSerializer
|
|||||||
*/
|
*/
|
||||||
protected function groups($user)
|
protected function groups($user)
|
||||||
{
|
{
|
||||||
return $this->hasMany($user, 'Flarum\Api\Serializer\GroupSerializer');
|
return $this->hasMany($user, GroupSerializer::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -11,18 +11,18 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Serializer;
|
namespace Flarum\Api\Serializer;
|
||||||
|
|
||||||
use Flarum\Core\Access\Gate;
|
use Flarum\Discussion\Discussion;
|
||||||
use Flarum\Core\Discussion;
|
use Flarum\User\Gate;
|
||||||
|
|
||||||
class DiscussionSerializer extends DiscussionBasicSerializer
|
class DiscussionSerializer extends BasicDiscussionSerializer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Gate
|
* @var \Flarum\User\Gate
|
||||||
*/
|
*/
|
||||||
protected $gate;
|
protected $gate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Flarum\Core\Access\Gate $gate
|
* @param \Flarum\User\Gate $gate
|
||||||
*/
|
*/
|
||||||
public function __construct(Gate $gate)
|
public function __construct(Gate $gate)
|
||||||
{
|
{
|
||||||
|
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Serializer;
|
namespace Flarum\Api\Serializer;
|
||||||
|
|
||||||
use Flarum\Forum\UrlGenerator;
|
|
||||||
use Flarum\Foundation\Application;
|
use Flarum\Foundation\Application;
|
||||||
|
use Flarum\Http\UrlGenerator;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
|
|
||||||
class ForumSerializer extends AbstractSerializer
|
class ForumSerializer extends AbstractSerializer
|
||||||
@@ -97,7 +97,7 @@ class ForumSerializer extends AbstractSerializer
|
|||||||
*/
|
*/
|
||||||
protected function groups($model)
|
protected function groups($model)
|
||||||
{
|
{
|
||||||
return $this->hasMany($model, 'Flarum\Api\Serializer\GroupSerializer');
|
return $this->hasMany($model, GroupSerializer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -107,7 +107,7 @@ class ForumSerializer extends AbstractSerializer
|
|||||||
{
|
{
|
||||||
$logoPath = $this->settings->get('logo_path');
|
$logoPath = $this->settings->get('logo_path');
|
||||||
|
|
||||||
return $logoPath ? $this->url->toPath('assets/'.$logoPath) : null;
|
return $logoPath ? $this->url->to('forum')->path('assets/'.$logoPath) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,6 +117,6 @@ class ForumSerializer extends AbstractSerializer
|
|||||||
{
|
{
|
||||||
$faviconPath = $this->settings->get('favicon_path');
|
$faviconPath = $this->settings->get('favicon_path');
|
||||||
|
|
||||||
return $faviconPath ? $this->url->toPath('assets/'.$faviconPath) : null;
|
return $faviconPath ? $this->url->to('forum')->path('assets/'.$faviconPath) : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Serializer;
|
namespace Flarum\Api\Serializer;
|
||||||
|
|
||||||
use Flarum\Core\Group;
|
use Flarum\Group\Group;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Symfony\Component\Translation\TranslatorInterface;
|
use Symfony\Component\Translation\TranslatorInterface;
|
||||||
|
|
||||||
@@ -57,14 +57,6 @@ class GroupSerializer extends AbstractSerializer
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Tobscure\JsonApi\Relationship
|
|
||||||
*/
|
|
||||||
protected function permissions($group)
|
|
||||||
{
|
|
||||||
return $this->hasMany($group, 'Flarum\Api\Serializers\PermissionSerializer');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return string
|
* @return string
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Serializer;
|
namespace Flarum\Api\Serializer;
|
||||||
|
|
||||||
use Flarum\Core\Notification;
|
use Flarum\Notification\Notification;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
|
||||||
class NotificationSerializer extends AbstractSerializer
|
class NotificationSerializer extends AbstractSerializer
|
||||||
@@ -32,7 +32,7 @@ class NotificationSerializer extends AbstractSerializer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
* @param \Flarum\Core\Notification $notification
|
* @param \Flarum\Notification\Notification $notification
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
protected function getDefaultAttributes($notification)
|
protected function getDefaultAttributes($notification)
|
||||||
@@ -57,7 +57,7 @@ class NotificationSerializer extends AbstractSerializer
|
|||||||
*/
|
*/
|
||||||
protected function user($notification)
|
protected function user($notification)
|
||||||
{
|
{
|
||||||
return $this->hasOne($notification, 'Flarum\Api\Serializer\UserBasicSerializer');
|
return $this->hasOne($notification, BasicUserSerializer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,7 +65,7 @@ class NotificationSerializer extends AbstractSerializer
|
|||||||
*/
|
*/
|
||||||
protected function sender($notification)
|
protected function sender($notification)
|
||||||
{
|
{
|
||||||
return $this->hasOne($notification, 'Flarum\Api\Serializer\UserBasicSerializer');
|
return $this->hasOne($notification, BasicUserSerializer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -11,18 +11,18 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Serializer;
|
namespace Flarum\Api\Serializer;
|
||||||
|
|
||||||
use Flarum\Core\Access\Gate;
|
use Flarum\Post\CommentPost;
|
||||||
use Flarum\Core\Post\CommentPost;
|
use Flarum\User\Gate;
|
||||||
|
|
||||||
class PostSerializer extends PostBasicSerializer
|
class PostSerializer extends BasicPostSerializer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Flarum\Core\Access\Gate
|
* @var \Flarum\User\Gate
|
||||||
*/
|
*/
|
||||||
protected $gate;
|
protected $gate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Flarum\Core\Access\Gate $gate
|
* @param \Flarum\User\Gate $gate
|
||||||
*/
|
*/
|
||||||
public function __construct(Gate $gate)
|
public function __construct(Gate $gate)
|
||||||
{
|
{
|
||||||
@@ -77,7 +77,7 @@ class PostSerializer extends PostBasicSerializer
|
|||||||
*/
|
*/
|
||||||
protected function user($post)
|
protected function user($post)
|
||||||
{
|
{
|
||||||
return $this->hasOne($post, 'Flarum\Api\Serializer\UserSerializer');
|
return $this->hasOne($post, UserSerializer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,7 +85,7 @@ class PostSerializer extends PostBasicSerializer
|
|||||||
*/
|
*/
|
||||||
protected function discussion($post)
|
protected function discussion($post)
|
||||||
{
|
{
|
||||||
return $this->hasOne($post, 'Flarum\Api\Serializer\DiscussionBasicSerializer');
|
return $this->hasOne($post, BasicDiscussionSerializer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,7 +93,7 @@ class PostSerializer extends PostBasicSerializer
|
|||||||
*/
|
*/
|
||||||
protected function editUser($post)
|
protected function editUser($post)
|
||||||
{
|
{
|
||||||
return $this->hasOne($post, 'Flarum\Api\Serializer\UserBasicSerializer');
|
return $this->hasOne($post, BasicUserSerializer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,6 +101,6 @@ class PostSerializer extends PostBasicSerializer
|
|||||||
*/
|
*/
|
||||||
protected function hideUser($post)
|
protected function hideUser($post)
|
||||||
{
|
{
|
||||||
return $this->hasOne($post, 'Flarum\Api\Serializer\UserBasicSerializer');
|
return $this->hasOne($post, BasicUserSerializer::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,12 +11,12 @@
|
|||||||
|
|
||||||
namespace Flarum\Api\Serializer;
|
namespace Flarum\Api\Serializer;
|
||||||
|
|
||||||
use Flarum\Core\Access\Gate;
|
use Flarum\User\Gate;
|
||||||
|
|
||||||
class UserSerializer extends UserBasicSerializer
|
class UserSerializer extends BasicUserSerializer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Gate
|
* @var \Flarum\User\Gate
|
||||||
*/
|
*/
|
||||||
protected $gate;
|
protected $gate;
|
||||||
|
|
||||||
|
@@ -1,62 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Flarum.
|
|
||||||
*
|
|
||||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Flarum\Api;
|
|
||||||
|
|
||||||
use Flarum\Event\ConfigureMiddleware;
|
|
||||||
use Flarum\Foundation\Application;
|
|
||||||
use Flarum\Http\AbstractServer;
|
|
||||||
use Tobscure\JsonApi\Document;
|
|
||||||
use Zend\Stratigility\MiddlewarePipe;
|
|
||||||
|
|
||||||
class Server extends AbstractServer
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function getMiddleware(Application $app)
|
|
||||||
{
|
|
||||||
$pipe = new MiddlewarePipe;
|
|
||||||
$pipe->raiseThrowables();
|
|
||||||
|
|
||||||
$path = parse_url($app->url('api'), PHP_URL_PATH);
|
|
||||||
|
|
||||||
if ($app->isInstalled() && $app->isUpToDate()) {
|
|
||||||
$pipe->pipe($path, $app->make('Flarum\Api\Middleware\HandleErrors'));
|
|
||||||
|
|
||||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\ParseJsonBody'));
|
|
||||||
$pipe->pipe($path, $app->make('Flarum\Api\Middleware\FakeHttpMethods'));
|
|
||||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\StartSession'));
|
|
||||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\RememberFromCookie'));
|
|
||||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\AuthenticateWithSession'));
|
|
||||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\AuthenticateWithHeader'));
|
|
||||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\SetLocale'));
|
|
||||||
|
|
||||||
event(new ConfigureMiddleware($pipe, $path, $this));
|
|
||||||
|
|
||||||
$pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.api.routes')]));
|
|
||||||
} else {
|
|
||||||
$pipe->pipe($path, function () {
|
|
||||||
$document = new Document;
|
|
||||||
$document->setErrors([
|
|
||||||
[
|
|
||||||
'code' => 503,
|
|
||||||
'title' => 'Service Unavailable'
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
|
|
||||||
return new JsonApiResponse($document, 503);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return $pipe;
|
|
||||||
}
|
|
||||||
}
|
|
304
framework/core/src/Api/routes.php
Normal file
304
framework/core/src/Api/routes.php
Normal file
@@ -0,0 +1,304 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Flarum\Api\Controller;
|
||||||
|
use Flarum\Http\RouteCollection;
|
||||||
|
use Flarum\Http\RouteHandlerFactory;
|
||||||
|
|
||||||
|
return function (RouteCollection $map, RouteHandlerFactory $route) {
|
||||||
|
// Get forum information
|
||||||
|
$map->get(
|
||||||
|
'/forum',
|
||||||
|
'forum.show',
|
||||||
|
$route->toController(Controller\ShowForumController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Retrieve authentication token
|
||||||
|
$map->post(
|
||||||
|
'/token',
|
||||||
|
'token',
|
||||||
|
$route->toController(Controller\TokenController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Send forgot password email
|
||||||
|
$map->post(
|
||||||
|
'/forgot',
|
||||||
|
'forgot',
|
||||||
|
$route->toController(Controller\ForgotPasswordController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Users
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
// List users
|
||||||
|
$map->get(
|
||||||
|
'/users',
|
||||||
|
'users.index',
|
||||||
|
$route->toController(Controller\ListUsersController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Register a user
|
||||||
|
$map->post(
|
||||||
|
'/users',
|
||||||
|
'users.create',
|
||||||
|
$route->toController(Controller\CreateUserController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Get a single user
|
||||||
|
$map->get(
|
||||||
|
'/users/{id}',
|
||||||
|
'users.show',
|
||||||
|
$route->toController(Controller\ShowUserController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Edit a user
|
||||||
|
$map->patch(
|
||||||
|
'/users/{id}',
|
||||||
|
'users.update',
|
||||||
|
$route->toController(Controller\UpdateUserController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Delete a user
|
||||||
|
$map->delete(
|
||||||
|
'/users/{id}',
|
||||||
|
'users.delete',
|
||||||
|
$route->toController(Controller\DeleteUserController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Upload avatar
|
||||||
|
$map->post(
|
||||||
|
'/users/{id}/avatar',
|
||||||
|
'users.avatar.upload',
|
||||||
|
$route->toController(Controller\UploadAvatarController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Remove avatar
|
||||||
|
$map->delete(
|
||||||
|
'/users/{id}/avatar',
|
||||||
|
'users.avatar.delete',
|
||||||
|
$route->toController(Controller\DeleteAvatarController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// send confirmation email
|
||||||
|
$map->post(
|
||||||
|
'/users/{id}/send-confirmation',
|
||||||
|
'users.confirmation.send',
|
||||||
|
$route->toController(Controller\SendConfirmationEmailController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Notifications
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
// List notifications for the current user
|
||||||
|
$map->get(
|
||||||
|
'/notifications',
|
||||||
|
'notifications.index',
|
||||||
|
$route->toController(Controller\ListNotificationsController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Mark all notifications as read
|
||||||
|
$map->post(
|
||||||
|
'/notifications/read',
|
||||||
|
'notifications.readAll',
|
||||||
|
$route->toController(Controller\ReadAllNotificationsController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Mark a single notification as read
|
||||||
|
$map->patch(
|
||||||
|
'/notifications/{id}',
|
||||||
|
'notifications.update',
|
||||||
|
$route->toController(Controller\UpdateNotificationController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Discussions
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
// List discussions
|
||||||
|
$map->get(
|
||||||
|
'/discussions',
|
||||||
|
'discussions.index',
|
||||||
|
$route->toController(Controller\ListDiscussionsController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create a discussion
|
||||||
|
$map->post(
|
||||||
|
'/discussions',
|
||||||
|
'discussions.create',
|
||||||
|
$route->toController(Controller\CreateDiscussionController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Show a single discussion
|
||||||
|
$map->get(
|
||||||
|
'/discussions/{id}',
|
||||||
|
'discussions.show',
|
||||||
|
$route->toController(Controller\ShowDiscussionController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Edit a discussion
|
||||||
|
$map->patch(
|
||||||
|
'/discussions/{id}',
|
||||||
|
'discussions.update',
|
||||||
|
$route->toController(Controller\UpdateDiscussionController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Delete a discussion
|
||||||
|
$map->delete(
|
||||||
|
'/discussions/{id}',
|
||||||
|
'discussions.delete',
|
||||||
|
$route->toController(Controller\DeleteDiscussionController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Posts
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
// List posts, usually for a discussion
|
||||||
|
$map->get(
|
||||||
|
'/posts',
|
||||||
|
'posts.index',
|
||||||
|
$route->toController(Controller\ListPostsController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create a post
|
||||||
|
$map->post(
|
||||||
|
'/posts',
|
||||||
|
'posts.create',
|
||||||
|
$route->toController(Controller\CreatePostController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Show a single or multiple posts by ID
|
||||||
|
$map->get(
|
||||||
|
'/posts/{id}',
|
||||||
|
'posts.show',
|
||||||
|
$route->toController(Controller\ShowPostController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Edit a post
|
||||||
|
$map->patch(
|
||||||
|
'/posts/{id}',
|
||||||
|
'posts.update',
|
||||||
|
$route->toController(Controller\UpdatePostController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Delete a post
|
||||||
|
$map->delete(
|
||||||
|
'/posts/{id}',
|
||||||
|
'posts.delete',
|
||||||
|
$route->toController(Controller\DeletePostController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Groups
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
// List groups
|
||||||
|
$map->get(
|
||||||
|
'/groups',
|
||||||
|
'groups.index',
|
||||||
|
$route->toController(Controller\ListGroupsController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create a group
|
||||||
|
$map->post(
|
||||||
|
'/groups',
|
||||||
|
'groups.create',
|
||||||
|
$route->toController(Controller\CreateGroupController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Edit a group
|
||||||
|
$map->patch(
|
||||||
|
'/groups/{id}',
|
||||||
|
'groups.update',
|
||||||
|
$route->toController(Controller\UpdateGroupController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Delete a group
|
||||||
|
$map->delete(
|
||||||
|
'/groups/{id}',
|
||||||
|
'groups.delete',
|
||||||
|
$route->toController(Controller\DeleteGroupController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Administration
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Toggle an extension
|
||||||
|
$map->patch(
|
||||||
|
'/extensions/{name}',
|
||||||
|
'extensions.update',
|
||||||
|
$route->toController(Controller\UpdateExtensionController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Uninstall an extension
|
||||||
|
$map->delete(
|
||||||
|
'/extensions/{name}',
|
||||||
|
'extensions.delete',
|
||||||
|
$route->toController(Controller\UninstallExtensionController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Update settings
|
||||||
|
$map->post(
|
||||||
|
'/settings',
|
||||||
|
'settings',
|
||||||
|
$route->toController(Controller\SetSettingsController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Update a permission
|
||||||
|
$map->post(
|
||||||
|
'/permission',
|
||||||
|
'permission',
|
||||||
|
$route->toController(Controller\SetPermissionController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Upload a logo
|
||||||
|
$map->post(
|
||||||
|
'/logo',
|
||||||
|
'logo',
|
||||||
|
$route->toController(Controller\UploadLogoController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Remove the logo
|
||||||
|
$map->delete(
|
||||||
|
'/logo',
|
||||||
|
'logo.delete',
|
||||||
|
$route->toController(Controller\DeleteLogoController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Upload a favicon
|
||||||
|
$map->post(
|
||||||
|
'/favicon',
|
||||||
|
'favicon',
|
||||||
|
$route->toController(Controller\UploadFaviconController::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Remove the favicon
|
||||||
|
$map->delete(
|
||||||
|
'/favicon',
|
||||||
|
'favicon.delete',
|
||||||
|
$route->toController(Controller\DeleteFaviconController::class)
|
||||||
|
);
|
||||||
|
};
|
28
framework/core/src/Bus/BusServiceProvider.php
Normal file
28
framework/core/src/Bus/BusServiceProvider.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Flarum\Bus;
|
||||||
|
|
||||||
|
use Flarum\Foundation\AbstractServiceProvider;
|
||||||
|
use Illuminate\Contracts\Bus\Dispatcher as BusContract;
|
||||||
|
use Illuminate\Contracts\Queue\Factory as QueueFactoryContract;
|
||||||
|
|
||||||
|
class BusServiceProvider extends AbstractServiceProvider
|
||||||
|
{
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
$this->app->bind(BusContract::class, function ($app) {
|
||||||
|
return new Dispatcher($app, function ($connection = null) use ($app) {
|
||||||
|
return $app[QueueFactoryContract::class]->connection($connection);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
28
framework/core/src/Bus/Dispatcher.php
Normal file
28
framework/core/src/Bus/Dispatcher.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Flarum\Bus;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Dispatcher as BaseDispatcher;
|
||||||
|
|
||||||
|
class Dispatcher extends BaseDispatcher
|
||||||
|
{
|
||||||
|
public function getCommandHandler($command)
|
||||||
|
{
|
||||||
|
$handler = get_class($command).'Handler';
|
||||||
|
|
||||||
|
if (class_exists($handler)) {
|
||||||
|
return $this->container->make($handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::getCommandHandler($command);
|
||||||
|
}
|
||||||
|
}
|
@@ -9,7 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Console\Command;
|
namespace Flarum\Console;
|
||||||
|
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
@@ -11,16 +11,32 @@
|
|||||||
|
|
||||||
namespace Flarum\Console;
|
namespace Flarum\Console;
|
||||||
|
|
||||||
use Flarum\Console\Command\GenerateMigrationCommand;
|
use Flarum\Database\Console\GenerateMigrationCommand;
|
||||||
use Flarum\Debug\Console\CacheClearCommand;
|
use Flarum\Database\Console\MigrateCommand;
|
||||||
use Flarum\Debug\Console\InfoCommand;
|
use Flarum\Foundation\Application;
|
||||||
use Flarum\Foundation\AbstractServer;
|
use Flarum\Foundation\Console\CacheClearCommand;
|
||||||
|
use Flarum\Foundation\Console\InfoCommand;
|
||||||
|
use Flarum\Foundation\Site;
|
||||||
use Flarum\Install\Console\InstallCommand;
|
use Flarum\Install\Console\InstallCommand;
|
||||||
use Flarum\Update\Console\MigrateCommand;
|
use Flarum\Install\InstallServiceProvider;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application as ConsoleApplication;
|
||||||
|
|
||||||
class Server extends AbstractServer
|
class Server
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param Site $site
|
||||||
|
* @return Server
|
||||||
|
*/
|
||||||
|
public static function fromSite(Site $site)
|
||||||
|
{
|
||||||
|
return new static($site->boot());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __construct(Application $app)
|
||||||
|
{
|
||||||
|
$this->app = $app;
|
||||||
|
}
|
||||||
|
|
||||||
public function listen()
|
public function listen()
|
||||||
{
|
{
|
||||||
$console = $this->getConsoleApplication();
|
$console = $this->getConsoleApplication();
|
||||||
@@ -29,14 +45,13 @@ class Server extends AbstractServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Application
|
* @return ConsoleApplication
|
||||||
*/
|
*/
|
||||||
protected function getConsoleApplication()
|
protected function getConsoleApplication()
|
||||||
{
|
{
|
||||||
$app = $this->getApp();
|
$console = new ConsoleApplication('Flarum', $this->app->version());
|
||||||
$console = new Application('Flarum', $app->version());
|
|
||||||
|
|
||||||
$app->register('Flarum\Install\InstallServiceProvider');
|
$this->app->register(InstallServiceProvider::class);
|
||||||
|
|
||||||
$commands = [
|
$commands = [
|
||||||
InstallCommand::class,
|
InstallCommand::class,
|
||||||
@@ -44,7 +59,7 @@ class Server extends AbstractServer
|
|||||||
GenerateMigrationCommand::class,
|
GenerateMigrationCommand::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($app->isInstalled()) {
|
if ($this->app->isInstalled()) {
|
||||||
$commands = array_merge($commands, [
|
$commands = array_merge($commands, [
|
||||||
InfoCommand::class,
|
InfoCommand::class,
|
||||||
CacheClearCommand::class
|
CacheClearCommand::class
|
||||||
@@ -52,9 +67,9 @@ class Server extends AbstractServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($commands as $command) {
|
foreach ($commands as $command) {
|
||||||
$console->add($app->make(
|
$console->add($this->app->make(
|
||||||
$command,
|
$command,
|
||||||
['config' => $app->isInstalled() ? $app->make('flarum.config') : []]
|
['config' => $this->app->isInstalled() ? $this->app->make('flarum.config') : []]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,78 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Flarum.
|
|
||||||
*
|
|
||||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Flarum\Core\Post;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Database\Eloquent\ScopeInterface;
|
|
||||||
|
|
||||||
class RegisteredTypesScope implements ScopeInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The index at which we added a where clause.
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $whereIndex;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The index at which we added where bindings.
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $bindingIndex;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The number of where bindings we added.
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $bindingCount;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply the scope to a given Eloquent query builder.
|
|
||||||
*
|
|
||||||
* @param Builder $builder
|
|
||||||
* @param Model $post
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function apply(Builder $builder, Model $post)
|
|
||||||
{
|
|
||||||
$query = $builder->getQuery();
|
|
||||||
|
|
||||||
$this->whereIndex = count($query->wheres ?: []);
|
|
||||||
$this->bindingIndex = count($query->getRawBindings()['where']);
|
|
||||||
|
|
||||||
$types = array_keys($post::getModels());
|
|
||||||
$this->bindingCount = count($types);
|
|
||||||
$query->whereIn('type', $types);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the scope from the given Eloquent query builder.
|
|
||||||
*
|
|
||||||
* @param Builder $builder
|
|
||||||
* @param Model $post
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function remove(Builder $builder, Model $post)
|
|
||||||
{
|
|
||||||
$query = $builder->getQuery();
|
|
||||||
|
|
||||||
unset($query->wheres[$this->whereIndex]);
|
|
||||||
$query->wheres = array_values($query->wheres);
|
|
||||||
|
|
||||||
$whereBindings = $query->getRawBindings()['where'];
|
|
||||||
array_splice($whereBindings, $this->bindingIndex, $this->bindingCount);
|
|
||||||
$query->setBindings(array_values($whereBindings));
|
|
||||||
}
|
|
||||||
}
|
|
@@ -9,8 +9,9 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Console\Command;
|
namespace Flarum\Database\Console;
|
||||||
|
|
||||||
|
use Flarum\Console\AbstractCommand;
|
||||||
use Flarum\Database\MigrationCreator;
|
use Flarum\Database\MigrationCreator;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
@@ -9,9 +9,9 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Update\Console;
|
namespace Flarum\Database\Console;
|
||||||
|
|
||||||
use Flarum\Console\Command\AbstractCommand;
|
use Flarum\Console\AbstractCommand;
|
||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
|
|
||||||
class MigrateCommand extends AbstractCommand
|
class MigrateCommand extends AbstractCommand
|
@@ -58,7 +58,8 @@ class DatabaseMigrationRepository implements MigrationRepositoryInterface
|
|||||||
return $this->table()
|
return $this->table()
|
||||||
->where('extension', $extension)
|
->where('extension', $extension)
|
||||||
->orderBy('migration', 'asc')
|
->orderBy('migration', 'asc')
|
||||||
->lists('migration');
|
->pluck('migration')
|
||||||
|
->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -12,10 +12,8 @@
|
|||||||
namespace Flarum\Database;
|
namespace Flarum\Database;
|
||||||
|
|
||||||
use Flarum\Foundation\AbstractServiceProvider;
|
use Flarum\Foundation\AbstractServiceProvider;
|
||||||
use Flarum\Foundation\Application;
|
|
||||||
use Illuminate\Database\ConnectionResolver;
|
use Illuminate\Database\ConnectionResolver;
|
||||||
use Illuminate\Database\Connectors\ConnectionFactory;
|
use Illuminate\Database\Connectors\ConnectionFactory;
|
||||||
use PDO;
|
|
||||||
|
|
||||||
class DatabaseServiceProvider extends AbstractServiceProvider
|
class DatabaseServiceProvider extends AbstractServiceProvider
|
||||||
{
|
{
|
||||||
@@ -29,7 +27,6 @@ class DatabaseServiceProvider extends AbstractServiceProvider
|
|||||||
|
|
||||||
$connection = $factory->make($this->app->config('database'));
|
$connection = $factory->make($this->app->config('database'));
|
||||||
$connection->setEventDispatcher($this->app->make('Illuminate\Contracts\Events\Dispatcher'));
|
$connection->setEventDispatcher($this->app->make('Illuminate\Contracts\Events\Dispatcher'));
|
||||||
$connection->setFetchMode(PDO::FETCH_CLASS);
|
|
||||||
|
|
||||||
return $connection;
|
return $connection;
|
||||||
});
|
});
|
||||||
@@ -46,14 +43,6 @@ class DatabaseServiceProvider extends AbstractServiceProvider
|
|||||||
});
|
});
|
||||||
|
|
||||||
$this->app->alias('Illuminate\Database\ConnectionResolverInterface', 'db');
|
$this->app->alias('Illuminate\Database\ConnectionResolverInterface', 'db');
|
||||||
|
|
||||||
$this->app->singleton('Flarum\Database\MigrationRepositoryInterface', function ($app) {
|
|
||||||
return new DatabaseMigrationRepository($app['db'], 'migrations');
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->app->bind(MigrationCreator::class, function (Application $app) {
|
|
||||||
return new MigrationCreator($app->make('Illuminate\Filesystem\Filesystem'), $app->basePath());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
32
framework/core/src/Database/MigrationServiceProvider.php
Normal file
32
framework/core/src/Database/MigrationServiceProvider.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Flarum\Database;
|
||||||
|
|
||||||
|
use Flarum\Foundation\AbstractServiceProvider;
|
||||||
|
use Flarum\Foundation\Application;
|
||||||
|
|
||||||
|
class MigrationServiceProvider extends AbstractServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
$this->app->singleton('Flarum\Database\MigrationRepositoryInterface', function ($app) {
|
||||||
|
return new DatabaseMigrationRepository($app['db'], 'migrations');
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->app->bind(MigrationCreator::class, function (Application $app) {
|
||||||
|
return new MigrationCreator($app->make('Illuminate\Filesystem\Filesystem'), $app->basePath());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@@ -299,7 +299,7 @@ class Migrator
|
|||||||
/**
|
/**
|
||||||
* Get the migration repository instance.
|
* Get the migration repository instance.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Database\Migrations\MigrationRepositoryInterface
|
* @return MigrationRepositoryInterface
|
||||||
*/
|
*/
|
||||||
public function getRepository()
|
public function getRepository()
|
||||||
{
|
{
|
||||||
|
@@ -9,10 +9,10 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core\Support;
|
namespace Flarum\Database;
|
||||||
|
|
||||||
use Flarum\Core\User;
|
|
||||||
use Flarum\Event\ScopeModelVisibility;
|
use Flarum\Event\ScopeModelVisibility;
|
||||||
|
use Flarum\User\User;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
trait ScopeVisibilityTrait
|
trait ScopeVisibilityTrait
|
@@ -9,9 +9,9 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core\Command;
|
namespace Flarum\Discussion\Command;
|
||||||
|
|
||||||
use Flarum\Core\User;
|
use Flarum\User\User;
|
||||||
|
|
||||||
class DeleteDiscussion
|
class DeleteDiscussion
|
||||||
{
|
{
|
@@ -9,13 +9,13 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core\Command;
|
namespace Flarum\Discussion\Command;
|
||||||
|
|
||||||
use Flarum\Core\Access\AssertPermissionTrait;
|
use Flarum\Discussion\DiscussionRepository;
|
||||||
use Flarum\Core\Exception\PermissionDeniedException;
|
use Flarum\Discussion\Event\Deleting;
|
||||||
use Flarum\Core\Repository\DiscussionRepository;
|
use Flarum\Foundation\DispatchEventsTrait;
|
||||||
use Flarum\Core\Support\DispatchEventsTrait;
|
use Flarum\User\AssertPermissionTrait;
|
||||||
use Flarum\Event\DiscussionWillBeDeleted;
|
use Flarum\User\Exception\PermissionDeniedException;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
|
|
||||||
class DeleteDiscussionHandler
|
class DeleteDiscussionHandler
|
||||||
@@ -24,7 +24,7 @@ class DeleteDiscussionHandler
|
|||||||
use AssertPermissionTrait;
|
use AssertPermissionTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var DiscussionRepository
|
* @var \Flarum\Discussion\DiscussionRepository
|
||||||
*/
|
*/
|
||||||
protected $discussions;
|
protected $discussions;
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ class DeleteDiscussionHandler
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param DeleteDiscussion $command
|
* @param DeleteDiscussion $command
|
||||||
* @return \Flarum\Core\Discussion
|
* @return \Flarum\Discussion\Discussion
|
||||||
* @throws PermissionDeniedException
|
* @throws PermissionDeniedException
|
||||||
*/
|
*/
|
||||||
public function handle(DeleteDiscussion $command)
|
public function handle(DeleteDiscussion $command)
|
||||||
@@ -52,7 +52,7 @@ class DeleteDiscussionHandler
|
|||||||
$this->assertCan($actor, 'delete', $discussion);
|
$this->assertCan($actor, 'delete', $discussion);
|
||||||
|
|
||||||
$this->events->fire(
|
$this->events->fire(
|
||||||
new DiscussionWillBeDeleted($discussion, $actor, $command->data)
|
new Deleting($discussion, $actor, $command->data)
|
||||||
);
|
);
|
||||||
|
|
||||||
$discussion->delete();
|
$discussion->delete();
|
@@ -9,9 +9,9 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core\Command;
|
namespace Flarum\Discussion\Command;
|
||||||
|
|
||||||
use Flarum\Core\User;
|
use Flarum\User\User;
|
||||||
|
|
||||||
class EditDiscussion
|
class EditDiscussion
|
||||||
{
|
{
|
||||||
@@ -25,7 +25,7 @@ class EditDiscussion
|
|||||||
/**
|
/**
|
||||||
* The user performing the action.
|
* The user performing the action.
|
||||||
*
|
*
|
||||||
* @var \Flarum\Core\User
|
* @var \Flarum\User\User
|
||||||
*/
|
*/
|
||||||
public $actor;
|
public $actor;
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ class EditDiscussion
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $discussionId The ID of the discussion to edit.
|
* @param int $discussionId The ID of the discussion to edit.
|
||||||
* @param \Flarum\Core\User $actor The user performing the action.
|
* @param \Flarum\User\User $actor The user performing the action.
|
||||||
* @param array $data The attributes to update on the discussion.
|
* @param array $data The attributes to update on the discussion.
|
||||||
*/
|
*/
|
||||||
public function __construct($discussionId, User $actor, array $data)
|
public function __construct($discussionId, User $actor, array $data)
|
@@ -9,14 +9,13 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core\Command;
|
namespace Flarum\Discussion\Command;
|
||||||
|
|
||||||
use Flarum\Core\Access\AssertPermissionTrait;
|
use Flarum\Discussion\DiscussionRepository;
|
||||||
use Flarum\Core\Exception\PermissionDeniedException;
|
use Flarum\Discussion\DiscussionValidator;
|
||||||
use Flarum\Core\Repository\DiscussionRepository;
|
use Flarum\Discussion\Event\Saving;
|
||||||
use Flarum\Core\Support\DispatchEventsTrait;
|
use Flarum\Foundation\DispatchEventsTrait;
|
||||||
use Flarum\Core\Validator\DiscussionValidator;
|
use Flarum\User\AssertPermissionTrait;
|
||||||
use Flarum\Event\DiscussionWillBeSaved;
|
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
|
|
||||||
class EditDiscussionHandler
|
class EditDiscussionHandler
|
||||||
@@ -48,8 +47,8 @@ class EditDiscussionHandler
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param EditDiscussion $command
|
* @param EditDiscussion $command
|
||||||
* @return \Flarum\Core\Discussion
|
* @return \Flarum\Discussion\Discussion
|
||||||
* @throws PermissionDeniedException
|
* @throws \Flarum\User\Exception\PermissionDeniedException
|
||||||
*/
|
*/
|
||||||
public function handle(EditDiscussion $command)
|
public function handle(EditDiscussion $command)
|
||||||
{
|
{
|
||||||
@@ -76,7 +75,7 @@ class EditDiscussionHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->events->fire(
|
$this->events->fire(
|
||||||
new DiscussionWillBeSaved($discussion, $actor, $data)
|
new Saving($discussion, $actor, $data)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->validator->assertValid($discussion->getDirty());
|
$this->validator->assertValid($discussion->getDirty());
|
@@ -9,9 +9,9 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core\Command;
|
namespace Flarum\Discussion\Command;
|
||||||
|
|
||||||
use Flarum\Core\User;
|
use Flarum\User\User;
|
||||||
|
|
||||||
class ReadDiscussion
|
class ReadDiscussion
|
||||||
{
|
{
|
@@ -9,12 +9,12 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core\Command;
|
namespace Flarum\Discussion\Command;
|
||||||
|
|
||||||
use Flarum\Core\Access\AssertPermissionTrait;
|
use Flarum\Discussion\DiscussionRepository;
|
||||||
use Flarum\Core\Repository\DiscussionRepository;
|
use Flarum\Discussion\Event\UserDataSaving;
|
||||||
use Flarum\Core\Support\DispatchEventsTrait;
|
use Flarum\Foundation\DispatchEventsTrait;
|
||||||
use Flarum\Event\DiscussionStateWillBeSaved;
|
use Flarum\User\AssertPermissionTrait;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
|
|
||||||
class ReadDiscussionHandler
|
class ReadDiscussionHandler
|
||||||
@@ -39,8 +39,8 @@ class ReadDiscussionHandler
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ReadDiscussion $command
|
* @param ReadDiscussion $command
|
||||||
* @return \Flarum\Core\DiscussionState
|
* @return \Flarum\Discussion\UserState
|
||||||
* @throws \Flarum\Core\Exception\PermissionDeniedException
|
* @throws \Flarum\User\Exception\PermissionDeniedException
|
||||||
*/
|
*/
|
||||||
public function handle(ReadDiscussion $command)
|
public function handle(ReadDiscussion $command)
|
||||||
{
|
{
|
||||||
@@ -54,7 +54,7 @@ class ReadDiscussionHandler
|
|||||||
$state->read($command->readNumber);
|
$state->read($command->readNumber);
|
||||||
|
|
||||||
$this->events->fire(
|
$this->events->fire(
|
||||||
new DiscussionStateWillBeSaved($state)
|
new UserDataSaving($state)
|
||||||
);
|
);
|
||||||
|
|
||||||
$state->save();
|
$state->save();
|
@@ -9,9 +9,9 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core\Command;
|
namespace Flarum\Discussion\Command;
|
||||||
|
|
||||||
use Flarum\Core\User;
|
use Flarum\User\User;
|
||||||
|
|
||||||
class StartDiscussion
|
class StartDiscussion
|
||||||
{
|
{
|
@@ -9,14 +9,15 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core\Command;
|
namespace Flarum\Discussion\Command;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Core\Access\AssertPermissionTrait;
|
use Flarum\Discussion\Discussion;
|
||||||
use Flarum\Core\Discussion;
|
use Flarum\Discussion\DiscussionValidator;
|
||||||
use Flarum\Core\Support\DispatchEventsTrait;
|
use Flarum\Discussion\Event\Saving;
|
||||||
use Flarum\Core\Validator\DiscussionValidator;
|
use Flarum\Foundation\DispatchEventsTrait;
|
||||||
use Flarum\Event\DiscussionWillBeSaved;
|
use Flarum\Post\Command\PostReply;
|
||||||
|
use Flarum\User\AssertPermissionTrait;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher;
|
||||||
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
|
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
|
||||||
|
|
||||||
@@ -31,14 +32,14 @@ class StartDiscussionHandler
|
|||||||
protected $bus;
|
protected $bus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var DiscussionValidator
|
* @var \Flarum\Discussion\DiscussionValidator
|
||||||
*/
|
*/
|
||||||
protected $validator;
|
protected $validator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param EventDispatcher $events
|
* @param EventDispatcher $events
|
||||||
* @param BusDispatcher $bus
|
* @param BusDispatcher $bus
|
||||||
* @param DiscussionValidator $validator
|
* @param \Flarum\Discussion\DiscussionValidator $validator
|
||||||
*/
|
*/
|
||||||
public function __construct(EventDispatcher $events, BusDispatcher $bus, DiscussionValidator $validator)
|
public function __construct(EventDispatcher $events, BusDispatcher $bus, DiscussionValidator $validator)
|
||||||
{
|
{
|
||||||
@@ -70,7 +71,7 @@ class StartDiscussionHandler
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->events->fire(
|
$this->events->fire(
|
||||||
new DiscussionWillBeSaved($discussion, $actor, $data)
|
new Saving($discussion, $actor, $data)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->validator->assertValid($discussion->getAttributes());
|
$this->validator->assertValid($discussion->getAttributes());
|
@@ -9,19 +9,22 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core;
|
namespace Flarum\Discussion;
|
||||||
|
|
||||||
use Flarum\Core\Post\MergeableInterface;
|
|
||||||
use Flarum\Core\Support\EventGeneratorTrait;
|
|
||||||
use Flarum\Core\Support\ScopeVisibilityTrait;
|
|
||||||
use Flarum\Database\AbstractModel;
|
use Flarum\Database\AbstractModel;
|
||||||
use Flarum\Event\DiscussionWasDeleted;
|
use Flarum\Database\ScopeVisibilityTrait;
|
||||||
use Flarum\Event\DiscussionWasHidden;
|
use Flarum\Discussion\Event\Deleted;
|
||||||
use Flarum\Event\DiscussionWasRenamed;
|
use Flarum\Discussion\Event\Hidden;
|
||||||
use Flarum\Event\DiscussionWasRestored;
|
use Flarum\Discussion\Event\Renamed;
|
||||||
use Flarum\Event\DiscussionWasStarted;
|
use Flarum\Discussion\Event\Restored;
|
||||||
use Flarum\Event\PostWasDeleted;
|
use Flarum\Discussion\Event\Started;
|
||||||
use Flarum\Event\ScopePostVisibility;
|
use Flarum\Event\ScopePostVisibility;
|
||||||
|
use Flarum\Foundation\EventGeneratorTrait;
|
||||||
|
use Flarum\Post\Event\Deleted as PostDeleted;
|
||||||
|
use Flarum\Post\MergeableInterface;
|
||||||
|
use Flarum\Post\Post;
|
||||||
|
use Flarum\User\Guest;
|
||||||
|
use Flarum\User\User;
|
||||||
use Flarum\Util\Str;
|
use Flarum\Util\Str;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,7 +43,7 @@ use Flarum\Util\Str;
|
|||||||
* @property int|null $last_post_number
|
* @property int|null $last_post_number
|
||||||
* @property \Carbon\Carbon|null $hide_time
|
* @property \Carbon\Carbon|null $hide_time
|
||||||
* @property int|null $hide_user_id
|
* @property int|null $hide_user_id
|
||||||
* @property DiscussionState|null $state
|
* @property UserState|null $state
|
||||||
* @property \Illuminate\Database\Eloquent\Collection $posts
|
* @property \Illuminate\Database\Eloquent\Collection $posts
|
||||||
* @property \Illuminate\Database\Eloquent\Collection $comments
|
* @property \Illuminate\Database\Eloquent\Collection $comments
|
||||||
* @property \Illuminate\Database\Eloquent\Collection $participants
|
* @property \Illuminate\Database\Eloquent\Collection $participants
|
||||||
@@ -99,7 +102,7 @@ class Discussion extends AbstractModel
|
|||||||
parent::boot();
|
parent::boot();
|
||||||
|
|
||||||
static::deleted(function ($discussion) {
|
static::deleted(function ($discussion) {
|
||||||
$discussion->raise(new DiscussionWasDeleted($discussion));
|
$discussion->raise(new Deleted($discussion));
|
||||||
|
|
||||||
// Delete all of the posts in the discussion. Before we delete them
|
// Delete all of the posts in the discussion. Before we delete them
|
||||||
// in a big batch query, we will loop through them and raise a
|
// in a big batch query, we will loop through them and raise a
|
||||||
@@ -107,7 +110,7 @@ class Discussion extends AbstractModel
|
|||||||
$posts = $discussion->posts()->allTypes();
|
$posts = $discussion->posts()->allTypes();
|
||||||
|
|
||||||
foreach ($posts->get() as $post) {
|
foreach ($posts->get() as $post) {
|
||||||
$discussion->raise(new PostWasDeleted($post));
|
$discussion->raise(new PostDeleted($post));
|
||||||
}
|
}
|
||||||
|
|
||||||
$posts->delete();
|
$posts->delete();
|
||||||
@@ -135,7 +138,7 @@ class Discussion extends AbstractModel
|
|||||||
|
|
||||||
$discussion->setRelation('startUser', $user);
|
$discussion->setRelation('startUser', $user);
|
||||||
|
|
||||||
$discussion->raise(new DiscussionWasStarted($discussion));
|
$discussion->raise(new Started($discussion));
|
||||||
|
|
||||||
return $discussion;
|
return $discussion;
|
||||||
}
|
}
|
||||||
@@ -152,7 +155,7 @@ class Discussion extends AbstractModel
|
|||||||
$oldTitle = $this->title;
|
$oldTitle = $this->title;
|
||||||
$this->title = $title;
|
$this->title = $title;
|
||||||
|
|
||||||
$this->raise(new DiscussionWasRenamed($this, $oldTitle));
|
$this->raise(new Renamed($this, $oldTitle));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@@ -170,7 +173,7 @@ class Discussion extends AbstractModel
|
|||||||
$this->hide_time = time();
|
$this->hide_time = time();
|
||||||
$this->hide_user_id = $actor ? $actor->id : null;
|
$this->hide_user_id = $actor ? $actor->id : null;
|
||||||
|
|
||||||
$this->raise(new DiscussionWasHidden($this));
|
$this->raise(new Hidden($this));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@@ -187,7 +190,7 @@ class Discussion extends AbstractModel
|
|||||||
$this->hide_time = null;
|
$this->hide_time = null;
|
||||||
$this->hide_user_id = null;
|
$this->hide_user_id = null;
|
||||||
|
|
||||||
$this->raise(new DiscussionWasRestored($this));
|
$this->raise(new Restored($this));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@@ -270,7 +273,7 @@ class Discussion extends AbstractModel
|
|||||||
* DiscussionRenamedPost, and delete if the title has been reverted
|
* DiscussionRenamedPost, and delete if the title has been reverted
|
||||||
* completely.)
|
* completely.)
|
||||||
*
|
*
|
||||||
* @param MergeableInterface $post The post to save.
|
* @param \Flarum\Post\MergeableInterface $post The post to save.
|
||||||
* @return Post The resulting post. It may or may not be the same post as
|
* @return Post The resulting post. It may or may not be the same post as
|
||||||
* was originally intended to be saved. It also may not exist, if the
|
* was originally intended to be saved. It also may not exist, if the
|
||||||
* merge logic resulted in deletion.
|
* merge logic resulted in deletion.
|
||||||
@@ -301,7 +304,7 @@ class Discussion extends AbstractModel
|
|||||||
*/
|
*/
|
||||||
public function posts()
|
public function posts()
|
||||||
{
|
{
|
||||||
return $this->hasMany('Flarum\Core\Post');
|
return $this->hasMany('Flarum\Post\Post');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -353,7 +356,7 @@ class Discussion extends AbstractModel
|
|||||||
*/
|
*/
|
||||||
public function startPost()
|
public function startPost()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('Flarum\Core\Post', 'start_post_id');
|
return $this->belongsTo('Flarum\Post\Post', 'start_post_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -363,7 +366,7 @@ class Discussion extends AbstractModel
|
|||||||
*/
|
*/
|
||||||
public function startUser()
|
public function startUser()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('Flarum\Core\User', 'start_user_id');
|
return $this->belongsTo('Flarum\User\User', 'start_user_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -373,7 +376,7 @@ class Discussion extends AbstractModel
|
|||||||
*/
|
*/
|
||||||
public function lastPost()
|
public function lastPost()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('Flarum\Core\Post', 'last_post_id');
|
return $this->belongsTo('Flarum\Post\Post', 'last_post_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -383,7 +386,7 @@ class Discussion extends AbstractModel
|
|||||||
*/
|
*/
|
||||||
public function lastUser()
|
public function lastUser()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('Flarum\Core\User', 'last_user_id');
|
return $this->belongsTo('Flarum\User\User', 'last_user_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -393,7 +396,7 @@ class Discussion extends AbstractModel
|
|||||||
*/
|
*/
|
||||||
public function readers()
|
public function readers()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany('Flarum\Core\User', 'users_discussions');
|
return $this->belongsToMany('Flarum\User\User', 'users_discussions');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -412,7 +415,7 @@ class Discussion extends AbstractModel
|
|||||||
{
|
{
|
||||||
$user = $user ?: static::$stateUser;
|
$user = $user ?: static::$stateUser;
|
||||||
|
|
||||||
return $this->hasOne('Flarum\Core\DiscussionState')->where('user_id', $user ? $user->id : null);
|
return $this->hasOne('Flarum\Discussion\UserState')->where('user_id', $user ? $user->id : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -420,14 +423,14 @@ class Discussion extends AbstractModel
|
|||||||
* exist.
|
* exist.
|
||||||
*
|
*
|
||||||
* @param User $user
|
* @param User $user
|
||||||
* @return \Flarum\Core\DiscussionState
|
* @return \Flarum\Discussion\UserState
|
||||||
*/
|
*/
|
||||||
public function stateFor(User $user)
|
public function stateFor(User $user)
|
||||||
{
|
{
|
||||||
$state = $this->state($user)->first();
|
$state = $this->state($user)->first();
|
||||||
|
|
||||||
if (! $state) {
|
if (! $state) {
|
||||||
$state = new DiscussionState;
|
$state = new UserState;
|
||||||
$state->discussion_id = $this->id;
|
$state->discussion_id = $this->id;
|
||||||
$state->user_id = $user->id;
|
$state->user_id = $user->id;
|
||||||
}
|
}
|
@@ -9,13 +9,13 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Flarum\Core\Listener;
|
namespace Flarum\Discussion;
|
||||||
|
|
||||||
use Flarum\Core\Post;
|
use Flarum\Post\Event\Deleted;
|
||||||
use Flarum\Event\PostWasDeleted;
|
use Flarum\Post\Event\Hidden;
|
||||||
use Flarum\Event\PostWasHidden;
|
use Flarum\Post\Event\Posted;
|
||||||
use Flarum\Event\PostWasPosted;
|
use Flarum\Post\Event\Restored;
|
||||||
use Flarum\Event\PostWasRestored;
|
use Flarum\Post\Post;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
|
|
||||||
class DiscussionMetadataUpdater
|
class DiscussionMetadataUpdater
|
||||||
@@ -25,16 +25,16 @@ class DiscussionMetadataUpdater
|
|||||||
*/
|
*/
|
||||||
public function subscribe(Dispatcher $events)
|
public function subscribe(Dispatcher $events)
|
||||||
{
|
{
|
||||||
$events->listen(PostWasPosted::class, [$this, 'whenPostWasPosted']);
|
$events->listen(Posted::class, [$this, 'whenPostWasPosted']);
|
||||||
$events->listen(PostWasDeleted::class, [$this, 'whenPostWasDeleted']);
|
$events->listen(Deleted::class, [$this, 'whenPostWasDeleted']);
|
||||||
$events->listen(PostWasHidden::class, [$this, 'whenPostWasHidden']);
|
$events->listen(Hidden::class, [$this, 'whenPostWasHidden']);
|
||||||
$events->listen(PostWasRestored::class, [$this, 'whenPostWasRestored']);
|
$events->listen(Restored::class, [$this, 'whenPostWasRestored']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param PostWasPosted $event
|
* @param Posted $event
|
||||||
*/
|
*/
|
||||||
public function whenPostWasPosted(PostWasPosted $event)
|
public function whenPostWasPosted(Posted $event)
|
||||||
{
|
{
|
||||||
$discussion = $event->post->discussion;
|
$discussion = $event->post->discussion;
|
||||||
|
|
||||||
@@ -47,9 +47,9 @@ class DiscussionMetadataUpdater
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Flarum\Event\PostWasDeleted $event
|
* @param \Flarum\Post\Event\Deleted $event
|
||||||
*/
|
*/
|
||||||
public function whenPostWasDeleted(PostWasDeleted $event)
|
public function whenPostWasDeleted(Deleted $event)
|
||||||
{
|
{
|
||||||
$this->removePost($event->post);
|
$this->removePost($event->post);
|
||||||
|
|
||||||
@@ -61,17 +61,17 @@ class DiscussionMetadataUpdater
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param PostWasHidden $event
|
* @param \Flarum\Post\Event\Hidden $event
|
||||||
*/
|
*/
|
||||||
public function whenPostWasHidden(PostWasHidden $event)
|
public function whenPostWasHidden(Hidden $event)
|
||||||
{
|
{
|
||||||
$this->removePost($event->post);
|
$this->removePost($event->post);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param PostWasRestored $event
|
* @param Restored $event
|
||||||
*/
|
*/
|
||||||
public function whenPostWasRestored(PostWasRestored $event)
|
public function whenPostWasRestored(Restored $event)
|
||||||
{
|
{
|
||||||
$discussion = $event->post->discussion;
|
$discussion = $event->post->discussion;
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user