diff --git a/framework/core/.travis.yml b/framework/core/.travis.yml index 2226ea1a2..b217e0233 100644 --- a/framework/core/.travis.yml +++ b/framework/core/.travis.yml @@ -1,9 +1,9 @@ language: php php: - - 5.6 - 7.0 - 7.1 + - 7.2 - hhvm matrix: diff --git a/framework/core/composer.json b/framework/core/composer.json index 5bfcb2a57..9737688b2 100644 --- a/framework/core/composer.json +++ b/framework/core/composer.json @@ -20,24 +20,24 @@ "docs": "http://flarum.org/docs" }, "require": { - "php": ">=5.6.0", + "php": ">=7.0", "dflydev/fig-cookies": "^1.0.2", "doctrine/dbal": "^2.5", "components/font-awesome": "^4.6", "franzl/whoops-middleware": "^0.4.0", - "illuminate/bus": "5.1.*", - "illuminate/cache": "5.1.*", - "illuminate/config": "5.1.*", - "illuminate/container": "5.1.*", - "illuminate/contracts": "5.1.*", - "illuminate/database": "^5.1.31", - "illuminate/events": "5.1.*", - "illuminate/filesystem": "5.1.*", - "illuminate/hashing": "5.1.*", - "illuminate/mail": "5.1.*", - "illuminate/support": "5.1.*", - "illuminate/validation": "5.1.*", - "illuminate/view": "5.1.*", + "illuminate/bus": "5.5.*", + "illuminate/cache": "5.5.*", + "illuminate/config": "5.5.*", + "illuminate/container": "5.5.*", + "illuminate/contracts": "5.5.*", + "illuminate/database": "5.5.*", + "illuminate/events": "5.5.*", + "illuminate/filesystem": "5.5.*", + "illuminate/hashing": "5.5.*", + "illuminate/mail": "5.5.*", + "illuminate/support": "5.5.*", + "illuminate/validation": "5.5.*", + "illuminate/view": "5.5.*", "intervention/image": "^2.3.0", "league/flysystem": "^1.0.11", "league/oauth2-client": "~1.0", @@ -46,11 +46,11 @@ "nikic/fast-route": "^0.6", "oyejorge/less.php": "~1.5", "psr/http-message": "^1.0", - "symfony/config": "^2.7", - "symfony/console": "^2.7", - "symfony/http-foundation": "^2.7", - "symfony/translation": "^2.7", - "symfony/yaml": "^2.7", + "symfony/config": "^3.3", + "symfony/console": "^3.3", + "symfony/http-foundation": "^3.3", + "symfony/translation": "^3.3", + "symfony/yaml": "^3.3", "s9e/text-formatter": "^0.8.1", "tobscure/json-api": "^0.3.0", "zendframework/zend-diactoros": "^1.6", @@ -58,7 +58,7 @@ }, "require-dev": { "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^4.8" + "phpunit/phpunit": "^6.0" }, "autoload": { "psr-4": { diff --git a/framework/core/migrations/2016_02_04_095452_add_slug_to_discussions.php b/framework/core/migrations/2016_02_04_095452_add_slug_to_discussions.php index 0a87cc059..54ec4e31c 100644 --- a/framework/core/migrations/2016_02_04_095452_add_slug_to_discussions.php +++ b/framework/core/migrations/2016_02_04_095452_add_slug_to_discussions.php @@ -20,7 +20,7 @@ return [ }); // 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) { $schema->getConnection()->table('discussions')->where('id', $discussion->id)->update([ 'slug' => Str::slug($discussion->title) diff --git a/framework/core/src/Admin/AdminServiceProvider.php b/framework/core/src/Admin/AdminServiceProvider.php index 2dfc9f53f..d0ca1975f 100644 --- a/framework/core/src/Admin/AdminServiceProvider.php +++ b/framework/core/src/Admin/AdminServiceProvider.php @@ -11,13 +11,23 @@ namespace Flarum\Admin; -use Flarum\Core\Listener\CheckCustomLessFormat; -use Flarum\Event\ExtensionWasDisabled; -use Flarum\Event\ExtensionWasEnabled; -use Flarum\Event\SettingWasSet; +use Flarum\Admin\Middleware\RequireAdministrateAbility; +use Flarum\Event\ConfigureMiddleware; +use Flarum\Extension\Event\Disabled; +use Flarum\Extension\Event\Enabled; 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\RouteHandlerFactory; +use Flarum\Http\UrlGenerator; +use Flarum\Settings\Event\Saved; +use Zend\Stratigility\MiddlewarePipe; class AdminServiceProvider extends AbstractServiceProvider { @@ -26,13 +36,35 @@ class AdminServiceProvider extends AbstractServiceProvider */ public function register() { - $this->app->singleton(UrlGenerator::class, function () { - return new UrlGenerator($this->app, $this->app->make('flarum.admin.routes')); + $this->app->extend(UrlGenerator::class, function (UrlGenerator $url) { + return $url->addCollection('admin', $this->app->make('flarum.admin.routes'), 'admin'); }); $this->app->singleton('flarum.admin.routes', function () { 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) { - $route = $this->app->make(RouteHandlerFactory::class); + $factory = $this->app->make(RouteHandlerFactory::class); - $routes->get( - '/', - 'index', - $route->toController(Controller\WebAppController::class) - ); + $callback = include __DIR__.'/routes.php'; + $callback($routes, $factory); } 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)) { $this->getWebAppAssets()->flushCss(); } @@ -80,8 +109,8 @@ class AdminServiceProvider extends AbstractServiceProvider { $events = $this->app->make('events'); - $events->listen(ExtensionWasEnabled::class, [$this, 'flushWebAppAssets']); - $events->listen(ExtensionWasDisabled::class, [$this, 'flushWebAppAssets']); + $events->listen(Enabled::class, [$this, 'flushWebAppAssets']); + $events->listen(Disabled::class, [$this, 'flushWebAppAssets']); } public function flushWebAppAssets() @@ -90,11 +119,11 @@ class AdminServiceProvider extends AbstractServiceProvider } /** - * @return \Flarum\Http\WebApp\WebAppAssets + * @return \Flarum\Frontend\FrontendAssets */ protected function getWebAppAssets() { - return $this->app->make(WebApp::class)->getAssets(); + return $this->app->make(Frontend::class)->getAssets(); } protected function checkCustomLessFormat() diff --git a/framework/core/src/Core/Listener/CheckCustomLessFormat.php b/framework/core/src/Admin/CheckCustomLessFormat.php similarity index 78% rename from framework/core/src/Core/Listener/CheckCustomLessFormat.php rename to framework/core/src/Admin/CheckCustomLessFormat.php index 324b62bae..a2644945f 100644 --- a/framework/core/src/Core/Listener/CheckCustomLessFormat.php +++ b/framework/core/src/Admin/CheckCustomLessFormat.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Listener; +namespace Flarum\Admin; -use Flarum\Core\Exception\ValidationException; -use Flarum\Event\PrepareSerializedSetting; +use Flarum\Foundation\ValidationException; +use Flarum\Settings\Event\Serializing; use Illuminate\Contracts\Events\Dispatcher; use Less_Exception_Parser; use Less_Parser; @@ -21,10 +21,10 @@ class CheckCustomLessFormat { 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') { $parser = new Less_Parser(); diff --git a/framework/core/src/Admin/Controller/WebAppController.php b/framework/core/src/Admin/Controller/FrontendController.php similarity index 76% rename from framework/core/src/Admin/Controller/WebAppController.php rename to framework/core/src/Admin/Controller/FrontendController.php index a3d5a8100..cac26120e 100644 --- a/framework/core/src/Admin/Controller/WebAppController.php +++ b/framework/core/src/Admin/Controller/FrontendController.php @@ -11,17 +11,17 @@ namespace Flarum\Admin\Controller; -use Flarum\Admin\WebApp; -use Flarum\Core\Permission; -use Flarum\Event\PrepareUnserializedSettings; +use Flarum\Admin\Frontend; 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 Illuminate\Contracts\Events\Dispatcher; use Illuminate\Database\ConnectionInterface; use Psr\Http\Message\ServerRequestInterface; -class WebAppController extends AbstractWebAppController +class FrontendController extends AbstractFrontendController { /** * @var SettingsRepositoryInterface @@ -34,13 +34,18 @@ class WebAppController extends AbstractWebAppController protected $extensions; /** - * @param WebApp $webApp + * @var ConnectionInterface + */ + protected $db; + + /** + * @param Frontend $webApp * @param Dispatcher $events * @param SettingsRepositoryInterface $settings * @param ExtensionManager $extensions * @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->events = $events; @@ -59,7 +64,7 @@ class WebAppController extends AbstractWebAppController $settings = $this->settings->all(); $this->events->fire( - new PrepareUnserializedSettings($settings) + new Deserializing($settings) ); $view->setVariable('settings', $settings); diff --git a/framework/core/src/Admin/WebApp.php b/framework/core/src/Admin/Frontend.php similarity index 82% rename from framework/core/src/Admin/WebApp.php rename to framework/core/src/Admin/Frontend.php index 5e130130d..b984e15e2 100644 --- a/framework/core/src/Admin/WebApp.php +++ b/framework/core/src/Admin/Frontend.php @@ -11,9 +11,9 @@ namespace Flarum\Admin; -use Flarum\Http\WebApp\AbstractWebApp; +use Flarum\Frontend\AbstractFrontend; -class WebApp extends AbstractWebApp +class Frontend extends AbstractFrontend { /** * {@inheritdoc} diff --git a/framework/core/src/Admin/Middleware/RequireAdministrateAbility.php b/framework/core/src/Admin/Middleware/RequireAdministrateAbility.php index b52ab4163..b970e4d2e 100644 --- a/framework/core/src/Admin/Middleware/RequireAdministrateAbility.php +++ b/framework/core/src/Admin/Middleware/RequireAdministrateAbility.php @@ -11,7 +11,7 @@ namespace Flarum\Admin\Middleware; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Zend\Stratigility\MiddlewareInterface; diff --git a/framework/core/src/Admin/Server.php b/framework/core/src/Admin/Server.php deleted file mode 100644 index 73002a1bb..000000000 --- a/framework/core/src/Admin/Server.php +++ /dev/null @@ -1,54 +0,0 @@ - - * - * 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; - } -} diff --git a/framework/core/src/Admin/routes.php b/framework/core/src/Admin/routes.php new file mode 100644 index 000000000..eac48ca4e --- /dev/null +++ b/framework/core/src/Admin/routes.php @@ -0,0 +1,22 @@ + + * + * 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) + ); +}; diff --git a/framework/core/src/Api/ApiKey.php b/framework/core/src/Api/ApiKey.php index e6415df2b..baae2c01e 100644 --- a/framework/core/src/Api/ApiKey.php +++ b/framework/core/src/Api/ApiKey.php @@ -37,10 +37,8 @@ class ApiKey extends AbstractModel */ public static function generate() { - $key = new static; - - $key->id = str_random(40); - - return $key; + return new static([ + 'id' => str_random(40) + ]); } } diff --git a/framework/core/src/Api/ApiServiceProvider.php b/framework/core/src/Api/ApiServiceProvider.php index 7aa246cd3..f0bdf6659 100644 --- a/framework/core/src/Api/ApiServiceProvider.php +++ b/framework/core/src/Api/ApiServiceProvider.php @@ -12,16 +12,29 @@ namespace Flarum\Api; use Flarum\Api\Controller\AbstractSerializeController; +use Flarum\Api\Middleware\FakeHttpMethods; +use Flarum\Api\Middleware\HandleErrors; use Flarum\Api\Serializer\AbstractSerializer; +use Flarum\Api\Serializer\BasicDiscussionSerializer; use Flarum\Api\Serializer\NotificationSerializer; use Flarum\Event\ConfigureApiRoutes; +use Flarum\Event\ConfigureMiddleware; use Flarum\Event\ConfigureNotificationTypes; 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\RouteHandlerFactory; +use Flarum\Http\UrlGenerator; use Tobscure\JsonApi\ErrorHandler; use Tobscure\JsonApi\Exception\Handler\FallbackExceptionHandler; use Tobscure\JsonApi\Exception\Handler\InvalidParameterExceptionHandler; +use Zend\Stratigility\MiddlewarePipe; class ApiServiceProvider extends AbstractServiceProvider { @@ -30,27 +43,48 @@ class ApiServiceProvider extends AbstractServiceProvider */ public function register() { - $this->app->singleton(UrlGenerator::class, function () { - return new UrlGenerator($this->app, $this->app->make('flarum.api.routes')); + $this->app->extend(UrlGenerator::class, function (UrlGenerator $url) { + return $url->addCollection('api', $this->app->make('flarum.api.routes'), 'api'); }); $this->app->singleton('flarum.api.routes', function () { 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 () { $handler = new ErrorHandler; - $handler->registerHandler(new Handler\FloodingExceptionHandler); - $handler->registerHandler(new Handler\IlluminateValidationExceptionHandler); - $handler->registerHandler(new Handler\InvalidAccessTokenExceptionHandler); - $handler->registerHandler(new Handler\InvalidConfirmationTokenExceptionHandler); - $handler->registerHandler(new Handler\MethodNotAllowedExceptionHandler); - $handler->registerHandler(new Handler\ModelNotFoundExceptionHandler); - $handler->registerHandler(new Handler\PermissionDeniedExceptionHandler); - $handler->registerHandler(new Handler\RouteNotFoundExceptionHandler); - $handler->registerHandler(new Handler\TokenMismatchExceptionHandler); - $handler->registerHandler(new Handler\ValidationExceptionHandler); + $handler->registerHandler(new ExceptionHandler\FloodingExceptionHandler); + $handler->registerHandler(new ExceptionHandler\IlluminateValidationExceptionHandler); + $handler->registerHandler(new ExceptionHandler\InvalidAccessTokenExceptionHandler); + $handler->registerHandler(new ExceptionHandler\InvalidConfirmationTokenExceptionHandler); + $handler->registerHandler(new ExceptionHandler\MethodNotAllowedExceptionHandler); + $handler->registerHandler(new ExceptionHandler\ModelNotFoundExceptionHandler); + $handler->registerHandler(new ExceptionHandler\PermissionDeniedExceptionHandler); + $handler->registerHandler(new ExceptionHandler\RouteNotFoundExceptionHandler); + $handler->registerHandler(new ExceptionHandler\TokenMismatchExceptionHandler); + $handler->registerHandler(new ExceptionHandler\ValidationExceptionHandler); $handler->registerHandler(new InvalidParameterExceptionHandler); $handler->registerHandler(new FallbackExceptionHandler($this->app->inDebugMode())); @@ -81,7 +115,7 @@ class ApiServiceProvider extends AbstractServiceProvider { $blueprints = []; $serializers = [ - 'discussionRenamed' => 'Flarum\Api\Serializer\DiscussionBasicSerializer' + 'discussionRenamed' => BasicDiscussionSerializer::class ]; $this->app->make('events')->fire( @@ -100,298 +134,13 @@ class ApiServiceProvider extends AbstractServiceProvider */ protected function populateRoutes(RouteCollection $routes) { - $route = $this->app->make(RouteHandlerFactory::class); + $factory = $this->app->make(RouteHandlerFactory::class); - // Get forum information - $routes->get( - '/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) - ); + $callback = include __DIR__.'/routes.php'; + $callback($routes, $factory); $this->app->make('events')->fire( - new ConfigureApiRoutes($routes, $route) + new ConfigureApiRoutes($routes, $factory) ); } } diff --git a/framework/core/src/Api/Client.php b/framework/core/src/Api/Client.php index b99be47e6..774f0dadc 100644 --- a/framework/core/src/Api/Client.php +++ b/framework/core/src/Api/Client.php @@ -12,9 +12,9 @@ namespace Flarum\Api; use Exception; -use Flarum\Core\User; use Flarum\Foundation\Application; use Flarum\Http\Controller\ControllerInterface; +use Flarum\User\User; use InvalidArgumentException; use Zend\Diactoros\ServerRequestFactory; diff --git a/framework/core/src/Api/Controller/AbstractCreateController.php b/framework/core/src/Api/Controller/AbstractCreateController.php index 939ead0ca..bb31ede70 100644 --- a/framework/core/src/Api/Controller/AbstractCreateController.php +++ b/framework/core/src/Api/Controller/AbstractCreateController.php @@ -13,7 +13,7 @@ namespace Flarum\Api\Controller; use Psr\Http\Message\ServerRequestInterface; -abstract class AbstractCreateController extends AbstractResourceController +abstract class AbstractCreateController extends AbstractShowController { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/AbstractCollectionController.php b/framework/core/src/Api/Controller/AbstractListController.php similarity index 86% rename from framework/core/src/Api/Controller/AbstractCollectionController.php rename to framework/core/src/Api/Controller/AbstractListController.php index aa6883967..f8525af34 100644 --- a/framework/core/src/Api/Controller/AbstractCollectionController.php +++ b/framework/core/src/Api/Controller/AbstractListController.php @@ -14,7 +14,7 @@ namespace Flarum\Api\Controller; use Tobscure\JsonApi\Collection; use Tobscure\JsonApi\SerializerInterface; -abstract class AbstractCollectionController extends AbstractSerializeController +abstract class AbstractListController extends AbstractSerializeController { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/AbstractSerializeController.php b/framework/core/src/Api/Controller/AbstractSerializeController.php index 5bcdfb274..a7ea98986 100644 --- a/framework/core/src/Api/Controller/AbstractSerializeController.php +++ b/framework/core/src/Api/Controller/AbstractSerializeController.php @@ -11,9 +11,9 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Event\WillGetData; +use Flarum\Api\Event\WillSerializeData; use Flarum\Api\JsonApiResponse; -use Flarum\Event\ConfigureApiController; -use Flarum\Event\PrepareApiData; use Flarum\Http\Controller\ControllerInterface; use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Events\Dispatcher; @@ -91,13 +91,13 @@ abstract class AbstractSerializeController implements ControllerInterface $document = new Document; static::$events->fire( - new ConfigureApiController($this) + new WillGetData($this) ); $data = $this->data($request, $document); static::$events->fire( - new PrepareApiData($this, $data, $request, $document) + new WillSerializeData($this, $data, $request, $document) ); $serializer = static::$container->make($this->serializer); diff --git a/framework/core/src/Api/Controller/AbstractResourceController.php b/framework/core/src/Api/Controller/AbstractShowController.php similarity index 86% rename from framework/core/src/Api/Controller/AbstractResourceController.php rename to framework/core/src/Api/Controller/AbstractShowController.php index 6c5dc96ca..309ee2b34 100644 --- a/framework/core/src/Api/Controller/AbstractResourceController.php +++ b/framework/core/src/Api/Controller/AbstractShowController.php @@ -14,7 +14,7 @@ namespace Flarum\Api\Controller; use Tobscure\JsonApi\Resource; use Tobscure\JsonApi\SerializerInterface; -abstract class AbstractResourceController extends AbstractSerializeController +abstract class AbstractShowController extends AbstractSerializeController { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/CreateDiscussionController.php b/framework/core/src/Api/Controller/CreateDiscussionController.php index 6c3c005e7..69f2afc15 100644 --- a/framework/core/src/Api/Controller/CreateDiscussionController.php +++ b/framework/core/src/Api/Controller/CreateDiscussionController.php @@ -11,9 +11,9 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\ReadDiscussion; -use Flarum\Core\Command\StartDiscussion; -use Flarum\Core\Post\Floodgate; +use Flarum\Discussion\Command\ReadDiscussion; +use Flarum\Discussion\Command\StartDiscussion; +use Flarum\Post\Floodgate; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; diff --git a/framework/core/src/Api/Controller/CreateGroupController.php b/framework/core/src/Api/Controller/CreateGroupController.php index 977ae9c62..9bf23052f 100644 --- a/framework/core/src/Api/Controller/CreateGroupController.php +++ b/framework/core/src/Api/Controller/CreateGroupController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\CreateGroup; +use Flarum\Group\Command\CreateGroup; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; diff --git a/framework/core/src/Api/Controller/CreatePostController.php b/framework/core/src/Api/Controller/CreatePostController.php index 16ba2a679..1d7e9f5c2 100644 --- a/framework/core/src/Api/Controller/CreatePostController.php +++ b/framework/core/src/Api/Controller/CreatePostController.php @@ -11,9 +11,9 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\PostReply; -use Flarum\Core\Command\ReadDiscussion; -use Flarum\Core\Post\Floodgate; +use Flarum\Discussion\Command\ReadDiscussion; +use Flarum\Post\Command\PostReply; +use Flarum\Post\Floodgate; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; @@ -41,13 +41,13 @@ class CreatePostController extends AbstractCreateController protected $bus; /** - * @var Floodgate + * @var \Flarum\Post\Floodgate */ protected $floodgate; /** * @param Dispatcher $bus - * @param Floodgate $floodgate + * @param \Flarum\Post\Floodgate $floodgate */ public function __construct(Dispatcher $bus, Floodgate $floodgate) { @@ -83,7 +83,7 @@ class CreatePostController extends AbstractCreateController } $discussion = $post->discussion; - $discussion->posts = $discussion->postsVisibleTo($actor)->orderBy('time')->lists('id'); + $discussion->posts = $discussion->postsVisibleTo($actor)->orderBy('time')->pluck('id'); return $post; } diff --git a/framework/core/src/Api/Controller/CreateUserController.php b/framework/core/src/Api/Controller/CreateUserController.php index 608cd039d..155f862ac 100644 --- a/framework/core/src/Api/Controller/CreateUserController.php +++ b/framework/core/src/Api/Controller/CreateUserController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\RegisterUser; +use Flarum\User\Command\RegisterUser; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; diff --git a/framework/core/src/Api/Controller/DeleteAvatarController.php b/framework/core/src/Api/Controller/DeleteAvatarController.php index b360b87e4..61ab87109 100644 --- a/framework/core/src/Api/Controller/DeleteAvatarController.php +++ b/framework/core/src/Api/Controller/DeleteAvatarController.php @@ -11,12 +11,12 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\DeleteAvatar; +use Flarum\User\Command\DeleteAvatar; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class DeleteAvatarController extends AbstractResourceController +class DeleteAvatarController extends AbstractShowController { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/DeleteDiscussionController.php b/framework/core/src/Api/Controller/DeleteDiscussionController.php index 793c34273..17c0206d6 100644 --- a/framework/core/src/Api/Controller/DeleteDiscussionController.php +++ b/framework/core/src/Api/Controller/DeleteDiscussionController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\DeleteDiscussion; +use Flarum\Discussion\Command\DeleteDiscussion; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; diff --git a/framework/core/src/Api/Controller/DeleteFaviconController.php b/framework/core/src/Api/Controller/DeleteFaviconController.php index 00c38bb50..887360942 100644 --- a/framework/core/src/Api/Controller/DeleteFaviconController.php +++ b/framework/core/src/Api/Controller/DeleteFaviconController.php @@ -11,9 +11,9 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Access\AssertPermissionTrait; use Flarum\Foundation\Application; use Flarum\Settings\SettingsRepositoryInterface; +use Flarum\User\AssertPermissionTrait; use League\Flysystem\Adapter\Local; use League\Flysystem\Filesystem; use Psr\Http\Message\ServerRequestInterface; diff --git a/framework/core/src/Api/Controller/DeleteGroupController.php b/framework/core/src/Api/Controller/DeleteGroupController.php index 051edea19..e4f1adb61 100644 --- a/framework/core/src/Api/Controller/DeleteGroupController.php +++ b/framework/core/src/Api/Controller/DeleteGroupController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\DeleteGroup; +use Flarum\Group\Command\DeleteGroup; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; diff --git a/framework/core/src/Api/Controller/DeleteLogoController.php b/framework/core/src/Api/Controller/DeleteLogoController.php index 4e4cc016a..50a76c658 100644 --- a/framework/core/src/Api/Controller/DeleteLogoController.php +++ b/framework/core/src/Api/Controller/DeleteLogoController.php @@ -11,9 +11,9 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Access\AssertPermissionTrait; use Flarum\Foundation\Application; use Flarum\Settings\SettingsRepositoryInterface; +use Flarum\User\AssertPermissionTrait; use League\Flysystem\Adapter\Local; use League\Flysystem\Filesystem; use Psr\Http\Message\ServerRequestInterface; diff --git a/framework/core/src/Api/Controller/DeletePostController.php b/framework/core/src/Api/Controller/DeletePostController.php index 1b3ea47e1..eb1bd812c 100644 --- a/framework/core/src/Api/Controller/DeletePostController.php +++ b/framework/core/src/Api/Controller/DeletePostController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\DeletePost; +use Flarum\Post\Command\DeletePost; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; diff --git a/framework/core/src/Api/Controller/DeleteUserController.php b/framework/core/src/Api/Controller/DeleteUserController.php index 6f3a7fb42..2d00d8897 100644 --- a/framework/core/src/Api/Controller/DeleteUserController.php +++ b/framework/core/src/Api/Controller/DeleteUserController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\DeleteUser; +use Flarum\User\Command\DeleteUser; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; diff --git a/framework/core/src/Api/Controller/ForgotPasswordController.php b/framework/core/src/Api/Controller/ForgotPasswordController.php index 72c7ee759..341f16d34 100644 --- a/framework/core/src/Api/Controller/ForgotPasswordController.php +++ b/framework/core/src/Api/Controller/ForgotPasswordController.php @@ -11,9 +11,9 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\RequestPasswordReset; -use Flarum\Core\Repository\UserRepository; use Flarum\Http\Controller\ControllerInterface; +use Flarum\User\Command\RequestPasswordReset; +use Flarum\User\UserRepository; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; use Zend\Diactoros\Response\EmptyResponse; @@ -21,7 +21,7 @@ use Zend\Diactoros\Response\EmptyResponse; class ForgotPasswordController implements ControllerInterface { /** - * @var \Flarum\Core\Repository\UserRepository + * @var \Flarum\User\UserRepository */ protected $users; @@ -31,7 +31,7 @@ class ForgotPasswordController implements ControllerInterface protected $bus; /** - * @param \Flarum\Core\Repository\UserRepository $users + * @param \Flarum\User\UserRepository $users * @param Dispatcher $bus */ public function __construct(UserRepository $users, Dispatcher $bus) diff --git a/framework/core/src/Api/Controller/ListDiscussionsController.php b/framework/core/src/Api/Controller/ListDiscussionsController.php index 04db95c3a..7a90bf540 100644 --- a/framework/core/src/Api/Controller/ListDiscussionsController.php +++ b/framework/core/src/Api/Controller/ListDiscussionsController.php @@ -11,13 +11,13 @@ namespace Flarum\Api\Controller; -use Flarum\Api\UrlGenerator; -use Flarum\Core\Search\Discussion\DiscussionSearcher; -use Flarum\Core\Search\SearchCriteria; +use Flarum\Discussion\Search\DiscussionSearcher; +use Flarum\Http\UrlGenerator; +use Flarum\Search\SearchCriteria; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class ListDiscussionsController extends AbstractCollectionController +class ListDiscussionsController extends AbstractListController { /** * {@inheritdoc} @@ -86,7 +86,7 @@ class ListDiscussionsController extends AbstractCollectionController $results = $this->searcher->search($criteria, $limit, $offset, $load); $document->addPaginationLinks( - $this->url->toRoute('discussions.index'), + $this->url->to('api')->route('discussions.index'), $request->getQueryParams(), $offset, $limit, diff --git a/framework/core/src/Api/Controller/ListGroupsController.php b/framework/core/src/Api/Controller/ListGroupsController.php index 01ac443e0..f02253810 100644 --- a/framework/core/src/Api/Controller/ListGroupsController.php +++ b/framework/core/src/Api/Controller/ListGroupsController.php @@ -11,11 +11,11 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Group; +use Flarum\Group\Group; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class ListGroupsController extends AbstractCollectionController +class ListGroupsController extends AbstractListController { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/ListNotificationsController.php b/framework/core/src/Api/Controller/ListNotificationsController.php index f53f3be60..f09dd7ca9 100644 --- a/framework/core/src/Api/Controller/ListNotificationsController.php +++ b/framework/core/src/Api/Controller/ListNotificationsController.php @@ -11,14 +11,14 @@ namespace Flarum\Api\Controller; -use Flarum\Api\UrlGenerator; -use Flarum\Core\Discussion; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\Repository\NotificationRepository; +use Flarum\Discussion\Discussion; +use Flarum\Http\UrlGenerator; +use Flarum\Notification\NotificationRepository; +use Flarum\User\Exception\PermissionDeniedException; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class ListNotificationsController extends AbstractCollectionController +class ListNotificationsController extends AbstractListController { /** * {@inheritdoc} @@ -92,7 +92,7 @@ class ListNotificationsController extends AbstractCollectionController } $document->addPaginationLinks( - $this->url->toRoute('notifications.index'), + $this->url->to('api')->route('notifications.index'), $request->getQueryParams(), $offset, $limit, @@ -111,7 +111,7 @@ class ListNotificationsController extends AbstractCollectionController } /** - * @param \Flarum\Core\Notification[] $notifications + * @param \Flarum\Notification\Notification[] $notifications */ private function loadSubjectDiscussions(array $notifications) { diff --git a/framework/core/src/Api/Controller/ListPostsController.php b/framework/core/src/Api/Controller/ListPostsController.php index e202acd36..5c732bc6f 100644 --- a/framework/core/src/Api/Controller/ListPostsController.php +++ b/framework/core/src/Api/Controller/ListPostsController.php @@ -11,14 +11,14 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Repository\PostRepository; use Flarum\Event\ConfigurePostsQuery; +use Flarum\Post\PostRepository; use Illuminate\Database\Eloquent\Builder; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; use Tobscure\JsonApi\Exception\InvalidParameterException; -class ListPostsController extends AbstractCollectionController +class ListPostsController extends AbstractListController { /** * {@inheritdoc} @@ -42,12 +42,12 @@ class ListPostsController extends AbstractCollectionController public $sortFields = ['time']; /** - * @var \Flarum\Core\Repository\PostRepository + * @var \Flarum\Post\PostRepository */ protected $posts; /** - * @param \Flarum\Core\Repository\PostRepository $posts + * @param \Flarum\Post\PostRepository $posts */ public function __construct(PostRepository $posts) { @@ -122,7 +122,7 @@ class ListPostsController extends AbstractCollectionController $query->orderBy($field, $order); } - return $query->lists('id')->all(); + return $query->pluck('id')->all(); } /** diff --git a/framework/core/src/Api/Controller/ListUsersController.php b/framework/core/src/Api/Controller/ListUsersController.php index 733f25e79..679230a98 100644 --- a/framework/core/src/Api/Controller/ListUsersController.php +++ b/framework/core/src/Api/Controller/ListUsersController.php @@ -11,14 +11,14 @@ namespace Flarum\Api\Controller; -use Flarum\Api\UrlGenerator; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\Search\SearchCriteria; -use Flarum\Core\Search\User\UserSearcher; +use Flarum\Http\UrlGenerator; +use Flarum\Search\SearchCriteria; +use Flarum\User\Exception\PermissionDeniedException; +use Flarum\User\Search\UserSearcher; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class ListUsersController extends AbstractCollectionController +class ListUsersController extends AbstractListController { /** * {@inheritdoc} @@ -84,7 +84,7 @@ class ListUsersController extends AbstractCollectionController $results = $this->searcher->search($criteria, $limit, $offset, $load); $document->addPaginationLinks( - $this->url->toRoute('users.index'), + $this->url->to('api')->route('users.index'), $request->getQueryParams(), $offset, $limit, diff --git a/framework/core/src/Api/Controller/ReadAllNotificationsController.php b/framework/core/src/Api/Controller/ReadAllNotificationsController.php index 231f743ff..c60230fa5 100644 --- a/framework/core/src/Api/Controller/ReadAllNotificationsController.php +++ b/framework/core/src/Api/Controller/ReadAllNotificationsController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\ReadAllNotifications; +use Flarum\Notification\Command\ReadAllNotifications; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; diff --git a/framework/core/src/Api/Controller/SendConfirmationEmailController.php b/framework/core/src/Api/Controller/SendConfirmationEmailController.php index 3f870f160..2935f0067 100644 --- a/framework/core/src/Api/Controller/SendConfirmationEmailController.php +++ b/framework/core/src/Api/Controller/SendConfirmationEmailController.php @@ -11,12 +11,12 @@ 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\UrlGenerator; use Flarum\Settings\SettingsRepositoryInterface; +use Flarum\User\AssertPermissionTrait; +use Flarum\User\EmailToken; +use Flarum\User\Exception\PermissionDeniedException; use Illuminate\Contracts\Mail\Mailer; use Illuminate\Mail\Message; use Psr\Http\Message\ServerRequestInterface; @@ -80,7 +80,7 @@ class SendConfirmationEmailController implements ControllerInterface $data = [ '{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') ]; diff --git a/framework/core/src/Api/Controller/SetPermissionController.php b/framework/core/src/Api/Controller/SetPermissionController.php index 8eff7ccd9..1171111b1 100644 --- a/framework/core/src/Api/Controller/SetPermissionController.php +++ b/framework/core/src/Api/Controller/SetPermissionController.php @@ -11,9 +11,9 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Permission; +use Flarum\Group\Permission; use Flarum\Http\Controller\ControllerInterface; +use Flarum\User\AssertPermissionTrait; use Psr\Http\Message\ServerRequestInterface; use Zend\Diactoros\Response\EmptyResponse; diff --git a/framework/core/src/Api/Controller/SetSettingsController.php b/framework/core/src/Api/Controller/SetSettingsController.php index d714ab165..f98d4645f 100644 --- a/framework/core/src/Api/Controller/SetSettingsController.php +++ b/framework/core/src/Api/Controller/SetSettingsController.php @@ -11,11 +11,11 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Event\PrepareSerializedSetting; -use Flarum\Event\SettingWasSet; use Flarum\Http\Controller\ControllerInterface; +use Flarum\Settings\Event\Saved; +use Flarum\Settings\Event\Serializing; use Flarum\Settings\SettingsRepositoryInterface; +use Flarum\User\AssertPermissionTrait; use Illuminate\Contracts\Events\Dispatcher; use Psr\Http\Message\ServerRequestInterface; use Zend\Diactoros\Response\EmptyResponse; @@ -53,11 +53,11 @@ class SetSettingsController implements ControllerInterface $settings = $request->getParsedBody(); 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->dispatcher->fire(new SettingWasSet($k, $v)); + $this->dispatcher->fire(new Saved($k, $v)); } return new EmptyResponse(204); diff --git a/framework/core/src/Api/Controller/ShowDiscussionController.php b/framework/core/src/Api/Controller/ShowDiscussionController.php index e99ec54b0..a2930c15e 100644 --- a/framework/core/src/Api/Controller/ShowDiscussionController.php +++ b/framework/core/src/Api/Controller/ShowDiscussionController.php @@ -11,17 +11,17 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Discussion; -use Flarum\Core\Repository\DiscussionRepository; -use Flarum\Core\Repository\PostRepository; -use Flarum\Core\User; +use Flarum\Discussion\Discussion; +use Flarum\Discussion\DiscussionRepository; +use Flarum\Post\PostRepository; +use Flarum\User\User; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class ShowDiscussionController extends AbstractResourceController +class ShowDiscussionController extends AbstractShowController { /** - * @var DiscussionRepository + * @var \Flarum\Discussion\DiscussionRepository */ protected $discussions; @@ -58,8 +58,8 @@ class ShowDiscussionController extends AbstractResourceController ]; /** - * @param \Flarum\Core\Repository\DiscussionRepository $discussions - * @param \Flarum\Core\Repository\PostRepository $posts + * @param \Flarum\Discussion\DiscussionRepository $discussions + * @param \Flarum\Post\PostRepository $posts */ public function __construct(DiscussionRepository $discussions, PostRepository $posts) { @@ -117,7 +117,7 @@ class ShowDiscussionController extends AbstractResourceController */ 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(); } /** diff --git a/framework/core/src/Api/Controller/ShowForumController.php b/framework/core/src/Api/Controller/ShowForumController.php index 5449df604..2dd3cd369 100644 --- a/framework/core/src/Api/Controller/ShowForumController.php +++ b/framework/core/src/Api/Controller/ShowForumController.php @@ -11,11 +11,11 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Group; +use Flarum\Group\Group; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class ShowForumController extends AbstractResourceController +class ShowForumController extends AbstractShowController { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/ShowPostController.php b/framework/core/src/Api/Controller/ShowPostController.php index 1ce1f367b..49a5f2dec 100644 --- a/framework/core/src/Api/Controller/ShowPostController.php +++ b/framework/core/src/Api/Controller/ShowPostController.php @@ -11,11 +11,11 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Repository\PostRepository; +use Flarum\Post\PostRepository; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class ShowPostController extends AbstractResourceController +class ShowPostController extends AbstractShowController { /** * {@inheritdoc} @@ -34,12 +34,12 @@ class ShowPostController extends AbstractResourceController ]; /** - * @var \Flarum\Core\Repository\PostRepository + * @var \Flarum\Post\PostRepository */ protected $posts; /** - * @param PostRepository $posts + * @param \Flarum\Post\PostRepository $posts */ public function __construct(PostRepository $posts) { diff --git a/framework/core/src/Api/Controller/ShowUserController.php b/framework/core/src/Api/Controller/ShowUserController.php index fd35b2867..f61d3a1b6 100644 --- a/framework/core/src/Api/Controller/ShowUserController.php +++ b/framework/core/src/Api/Controller/ShowUserController.php @@ -11,11 +11,11 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Repository\UserRepository; +use Flarum\User\UserRepository; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class ShowUserController extends AbstractResourceController +class ShowUserController extends AbstractShowController { /** * {@inheritdoc} @@ -28,12 +28,12 @@ class ShowUserController extends AbstractResourceController public $include = ['groups']; /** - * @var UserRepository + * @var \Flarum\User\UserRepository */ protected $users; /** - * @param UserRepository $users + * @param \Flarum\User\UserRepository $users */ public function __construct(UserRepository $users) { diff --git a/framework/core/src/Api/Controller/TokenController.php b/framework/core/src/Api/Controller/TokenController.php index e5f1c445c..e0f6f6464 100644 --- a/framework/core/src/Api/Controller/TokenController.php +++ b/framework/core/src/Api/Controller/TokenController.php @@ -11,10 +11,10 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\Repository\UserRepository; use Flarum\Http\AccessToken; use Flarum\Http\Controller\ControllerInterface; +use Flarum\User\Exception\PermissionDeniedException; +use Flarum\User\UserRepository; use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher; use Illuminate\Contracts\Events\Dispatcher as EventDispatcher; use Psr\Http\Message\ServerRequestInterface; @@ -23,7 +23,7 @@ use Zend\Diactoros\Response\JsonResponse; class TokenController implements ControllerInterface { /** - * @var UserRepository + * @var \Flarum\User\UserRepository */ protected $users; diff --git a/framework/core/src/Api/Controller/UninstallExtensionController.php b/framework/core/src/Api/Controller/UninstallExtensionController.php index 4b9b185fb..454ea6109 100644 --- a/framework/core/src/Api/Controller/UninstallExtensionController.php +++ b/framework/core/src/Api/Controller/UninstallExtensionController.php @@ -11,8 +11,8 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Access\AssertPermissionTrait; use Flarum\Extension\ExtensionManager; +use Flarum\User\AssertPermissionTrait; use Psr\Http\Message\ServerRequestInterface; class UninstallExtensionController extends AbstractDeleteController diff --git a/framework/core/src/Api/Controller/UpdateDiscussionController.php b/framework/core/src/Api/Controller/UpdateDiscussionController.php index fc7070be0..3fa1900f3 100644 --- a/framework/core/src/Api/Controller/UpdateDiscussionController.php +++ b/framework/core/src/Api/Controller/UpdateDiscussionController.php @@ -11,14 +11,14 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\EditDiscussion; -use Flarum\Core\Command\ReadDiscussion; +use Flarum\Discussion\Command\EditDiscussion; +use Flarum\Discussion\Command\ReadDiscussion; use Illuminate\Contracts\Bus\Dispatcher; use Illuminate\Database\Eloquent\Collection; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class UpdateDiscussionController extends AbstractResourceController +class UpdateDiscussionController extends AbstractShowController { /** * {@inheritdoc} @@ -63,7 +63,7 @@ class UpdateDiscussionController extends AbstractResourceController if ($posts = $discussion->getModifiedPosts()) { $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 ($posts as $post) { diff --git a/framework/core/src/Api/Controller/UpdateExtensionController.php b/framework/core/src/Api/Controller/UpdateExtensionController.php index f9d983769..156d81b85 100644 --- a/framework/core/src/Api/Controller/UpdateExtensionController.php +++ b/framework/core/src/Api/Controller/UpdateExtensionController.php @@ -11,9 +11,9 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Access\AssertPermissionTrait; use Flarum\Extension\ExtensionManager; use Flarum\Http\Controller\ControllerInterface; +use Flarum\User\AssertPermissionTrait; use Psr\Http\Message\ServerRequestInterface; class UpdateExtensionController implements ControllerInterface diff --git a/framework/core/src/Api/Controller/UpdateGroupController.php b/framework/core/src/Api/Controller/UpdateGroupController.php index 748d35231..c4bd8f5dd 100644 --- a/framework/core/src/Api/Controller/UpdateGroupController.php +++ b/framework/core/src/Api/Controller/UpdateGroupController.php @@ -11,12 +11,12 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\EditGroup; +use Flarum\Group\Command\EditGroup; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class UpdateGroupController extends AbstractResourceController +class UpdateGroupController extends AbstractShowController { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/UpdateNotificationController.php b/framework/core/src/Api/Controller/UpdateNotificationController.php index 46b015d8b..f459e0338 100644 --- a/framework/core/src/Api/Controller/UpdateNotificationController.php +++ b/framework/core/src/Api/Controller/UpdateNotificationController.php @@ -11,12 +11,12 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\ReadNotification; +use Flarum\Notification\Command\ReadNotification; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class UpdateNotificationController extends AbstractResourceController +class UpdateNotificationController extends AbstractShowController { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/UpdatePostController.php b/framework/core/src/Api/Controller/UpdatePostController.php index a1e135e0b..6f13e3371 100644 --- a/framework/core/src/Api/Controller/UpdatePostController.php +++ b/framework/core/src/Api/Controller/UpdatePostController.php @@ -11,12 +11,12 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\EditPost; +use Flarum\Post\Command\EditPost; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class UpdatePostController extends AbstractResourceController +class UpdatePostController extends AbstractShowController { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/UpdateUserController.php b/framework/core/src/Api/Controller/UpdateUserController.php index d11e07e68..42a57754a 100644 --- a/framework/core/src/Api/Controller/UpdateUserController.php +++ b/framework/core/src/Api/Controller/UpdateUserController.php @@ -11,13 +11,13 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\EditUser; -use Flarum\Core\Exception\PermissionDeniedException; +use Flarum\User\Command\EditUser; +use Flarum\User\Exception\PermissionDeniedException; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class UpdateUserController extends AbstractResourceController +class UpdateUserController extends AbstractShowController { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/UploadAvatarController.php b/framework/core/src/Api/Controller/UploadAvatarController.php index cd71f2b10..b2e23e33b 100644 --- a/framework/core/src/Api/Controller/UploadAvatarController.php +++ b/framework/core/src/Api/Controller/UploadAvatarController.php @@ -11,12 +11,12 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\UploadAvatar; +use Flarum\User\Command\UploadAvatar; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class UploadAvatarController extends AbstractResourceController +class UploadAvatarController extends AbstractShowController { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/UploadFaviconController.php b/framework/core/src/Api/Controller/UploadFaviconController.php index 1ccd5e088..769838108 100644 --- a/framework/core/src/Api/Controller/UploadFaviconController.php +++ b/framework/core/src/Api/Controller/UploadFaviconController.php @@ -11,9 +11,9 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Access\AssertPermissionTrait; use Flarum\Foundation\Application; use Flarum\Settings\SettingsRepositoryInterface; +use Flarum\User\AssertPermissionTrait; use Illuminate\Support\Str; use Intervention\Image\ImageManager; use League\Flysystem\Adapter\Local; @@ -80,7 +80,7 @@ class UploadFaviconController extends ShowForumController $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"); diff --git a/framework/core/src/Api/Controller/UploadLogoController.php b/framework/core/src/Api/Controller/UploadLogoController.php index ff49683f2..e2d5d23f7 100644 --- a/framework/core/src/Api/Controller/UploadLogoController.php +++ b/framework/core/src/Api/Controller/UploadLogoController.php @@ -11,9 +11,9 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Access\AssertPermissionTrait; use Flarum\Foundation\Application; use Flarum\Settings\SettingsRepositoryInterface; +use Flarum\User\AssertPermissionTrait; use Illuminate\Support\Str; use Intervention\Image\ImageManager; use League\Flysystem\Adapter\Local; @@ -73,7 +73,7 @@ class UploadLogoController extends ShowForumController $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"); diff --git a/framework/core/src/Event/PrepareApiAttributes.php b/framework/core/src/Api/Event/Serializing.php similarity index 91% rename from framework/core/src/Event/PrepareApiAttributes.php rename to framework/core/src/Api/Event/Serializing.php index 533bef507..d84c9c1fe 100644 --- a/framework/core/src/Event/PrepareApiAttributes.php +++ b/framework/core/src/Api/Event/Serializing.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Api\Event; use DateTime; use Flarum\Api\Serializer\AbstractSerializer; @@ -17,10 +17,10 @@ use Flarum\Api\Serializer\AbstractSerializer; /** * 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. */ -class PrepareApiAttributes +class Serializing { /** * The class doing the serializing. @@ -44,7 +44,7 @@ class PrepareApiAttributes public $attributes; /** - * @var \Flarum\Core\User + * @var \Flarum\User\User */ public $actor; diff --git a/framework/core/src/Event/ConfigureApiController.php b/framework/core/src/Api/Event/WillGetData.php similarity index 98% rename from framework/core/src/Event/ConfigureApiController.php rename to framework/core/src/Api/Event/WillGetData.php index 974944674..790c546b0 100644 --- a/framework/core/src/Event/ConfigureApiController.php +++ b/framework/core/src/Api/Event/WillGetData.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Api\Event; use Flarum\Api\Controller\AbstractSerializeController; -class ConfigureApiController +class WillGetData { /** * @var AbstractSerializeController diff --git a/framework/core/src/Event/PrepareApiData.php b/framework/core/src/Api/Event/WillSerializeData.php similarity index 94% rename from framework/core/src/Event/PrepareApiData.php rename to framework/core/src/Api/Event/WillSerializeData.php index c39f0894f..700bb9ee6 100644 --- a/framework/core/src/Event/PrepareApiData.php +++ b/framework/core/src/Api/Event/WillSerializeData.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Api\Event; use Flarum\Api\Controller\AbstractSerializeController; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class PrepareApiData +class WillSerializeData { /** * @var AbstractSerializeController @@ -38,7 +38,7 @@ class PrepareApiData public $document; /** - * @var \Flarum\Core\User + * @var \Flarum\User\User */ public $actor; diff --git a/framework/core/src/Api/Handler/FloodingExceptionHandler.php b/framework/core/src/Api/ExceptionHandler/FloodingExceptionHandler.php similarity index 90% rename from framework/core/src/Api/Handler/FloodingExceptionHandler.php rename to framework/core/src/Api/ExceptionHandler/FloodingExceptionHandler.php index f589baa0a..0a55870dc 100644 --- a/framework/core/src/Api/Handler/FloodingExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/FloodingExceptionHandler.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Flarum\Api\Handler; +namespace Flarum\Api\ExceptionHandler; use Exception; -use Flarum\Core\Exception\FloodingException; +use Flarum\Post\Exception\FloodingException; use Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface; use Tobscure\JsonApi\Exception\Handler\ResponseBag; diff --git a/framework/core/src/Api/Handler/IlluminateValidationExceptionHandler.php b/framework/core/src/Api/ExceptionHandler/IlluminateValidationExceptionHandler.php similarity index 89% rename from framework/core/src/Api/Handler/IlluminateValidationExceptionHandler.php rename to framework/core/src/Api/ExceptionHandler/IlluminateValidationExceptionHandler.php index 16ccb3eff..afc496c1d 100644 --- a/framework/core/src/Api/Handler/IlluminateValidationExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/IlluminateValidationExceptionHandler.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Flarum\Api\Handler; +namespace Flarum\Api\ExceptionHandler; use Exception; -use Illuminate\Contracts\Validation\ValidationException; +use Illuminate\Validation\ValidationException; use Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface; use Tobscure\JsonApi\Exception\Handler\ResponseBag; @@ -32,7 +32,8 @@ class IlluminateValidationExceptionHandler implements ExceptionHandlerInterface public function handle(Exception $e) { $status = 422; - $errors = $this->formatErrors($e->errors()->toArray()); + + $errors = $this->formatErrors($e->errors()); return new ResponseBag($status, $errors); } diff --git a/framework/core/src/Api/Handler/InvalidAccessTokenExceptionHandler.php b/framework/core/src/Api/ExceptionHandler/InvalidAccessTokenExceptionHandler.php similarity index 95% rename from framework/core/src/Api/Handler/InvalidAccessTokenExceptionHandler.php rename to framework/core/src/Api/ExceptionHandler/InvalidAccessTokenExceptionHandler.php index 4a8c4b5e5..c91964f17 100644 --- a/framework/core/src/Api/Handler/InvalidAccessTokenExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/InvalidAccessTokenExceptionHandler.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Api\Handler; +namespace Flarum\Api\ExceptionHandler; use Exception; use Flarum\Api\Exception\InvalidAccessTokenException; diff --git a/framework/core/src/Api/Handler/InvalidConfirmationTokenExceptionHandler.php b/framework/core/src/Api/ExceptionHandler/InvalidConfirmationTokenExceptionHandler.php similarity index 89% rename from framework/core/src/Api/Handler/InvalidConfirmationTokenExceptionHandler.php rename to framework/core/src/Api/ExceptionHandler/InvalidConfirmationTokenExceptionHandler.php index bce460c0d..541b620f7 100644 --- a/framework/core/src/Api/Handler/InvalidConfirmationTokenExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/InvalidConfirmationTokenExceptionHandler.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Flarum\Api\Handler; +namespace Flarum\Api\ExceptionHandler; use Exception; -use Flarum\Core\Exception\InvalidConfirmationTokenException; +use Flarum\User\Exception\InvalidConfirmationTokenException; use Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface; use Tobscure\JsonApi\Exception\Handler\ResponseBag; diff --git a/framework/core/src/Api/Handler/MethodNotAllowedExceptionHandler.php b/framework/core/src/Api/ExceptionHandler/MethodNotAllowedExceptionHandler.php similarity index 95% rename from framework/core/src/Api/Handler/MethodNotAllowedExceptionHandler.php rename to framework/core/src/Api/ExceptionHandler/MethodNotAllowedExceptionHandler.php index 04d16075a..729815e95 100644 --- a/framework/core/src/Api/Handler/MethodNotAllowedExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/MethodNotAllowedExceptionHandler.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Api\Handler; +namespace Flarum\Api\ExceptionHandler; use Exception; use Flarum\Http\Exception\MethodNotAllowedException; diff --git a/framework/core/src/Api/Handler/ModelNotFoundExceptionHandler.php b/framework/core/src/Api/ExceptionHandler/ModelNotFoundExceptionHandler.php similarity index 95% rename from framework/core/src/Api/Handler/ModelNotFoundExceptionHandler.php rename to framework/core/src/Api/ExceptionHandler/ModelNotFoundExceptionHandler.php index fe8b24fce..e921eb166 100644 --- a/framework/core/src/Api/Handler/ModelNotFoundExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/ModelNotFoundExceptionHandler.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Api\Handler; +namespace Flarum\Api\ExceptionHandler; use Exception; use Illuminate\Database\Eloquent\ModelNotFoundException; diff --git a/framework/core/src/Api/Handler/PermissionDeniedExceptionHandler.php b/framework/core/src/Api/ExceptionHandler/PermissionDeniedExceptionHandler.php similarity index 90% rename from framework/core/src/Api/Handler/PermissionDeniedExceptionHandler.php rename to framework/core/src/Api/ExceptionHandler/PermissionDeniedExceptionHandler.php index d9c863e2d..a4b4f9d53 100644 --- a/framework/core/src/Api/Handler/PermissionDeniedExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/PermissionDeniedExceptionHandler.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Flarum\Api\Handler; +namespace Flarum\Api\ExceptionHandler; use Exception; -use Flarum\Core\Exception\PermissionDeniedException; +use Flarum\User\Exception\PermissionDeniedException; use Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface; use Tobscure\JsonApi\Exception\Handler\ResponseBag; diff --git a/framework/core/src/Api/Handler/RouteNotFoundExceptionHandler.php b/framework/core/src/Api/ExceptionHandler/RouteNotFoundExceptionHandler.php similarity index 95% rename from framework/core/src/Api/Handler/RouteNotFoundExceptionHandler.php rename to framework/core/src/Api/ExceptionHandler/RouteNotFoundExceptionHandler.php index 382c218ce..67c25d6a1 100644 --- a/framework/core/src/Api/Handler/RouteNotFoundExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/RouteNotFoundExceptionHandler.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Api\Handler; +namespace Flarum\Api\ExceptionHandler; use Exception; use Flarum\Http\Exception\RouteNotFoundException; diff --git a/framework/core/src/Api/Handler/TokenMismatchExceptionHandler.php b/framework/core/src/Api/ExceptionHandler/TokenMismatchExceptionHandler.php similarity index 95% rename from framework/core/src/Api/Handler/TokenMismatchExceptionHandler.php rename to framework/core/src/Api/ExceptionHandler/TokenMismatchExceptionHandler.php index c4abf7408..2258b4cd6 100644 --- a/framework/core/src/Api/Handler/TokenMismatchExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/TokenMismatchExceptionHandler.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Api\Handler; +namespace Flarum\Api\ExceptionHandler; use Exception; use Flarum\Http\Exception\TokenMismatchException; diff --git a/framework/core/src/Api/Handler/ValidationExceptionHandler.php b/framework/core/src/Api/ExceptionHandler/ValidationExceptionHandler.php similarity index 94% rename from framework/core/src/Api/Handler/ValidationExceptionHandler.php rename to framework/core/src/Api/ExceptionHandler/ValidationExceptionHandler.php index d165ff68f..f36b253fd 100644 --- a/framework/core/src/Api/Handler/ValidationExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/ValidationExceptionHandler.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Flarum\Api\Handler; +namespace Flarum\Api\ExceptionHandler; use Exception; -use Flarum\Core\Exception\ValidationException; +use Flarum\Foundation\ValidationException; use Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface; use Tobscure\JsonApi\Exception\Handler\ResponseBag; diff --git a/framework/core/src/Api/Serializer/AbstractSerializer.php b/framework/core/src/Api/Serializer/AbstractSerializer.php index 3f7b245e2..279c976a5 100644 --- a/framework/core/src/Api/Serializer/AbstractSerializer.php +++ b/framework/core/src/Api/Serializer/AbstractSerializer.php @@ -13,9 +13,9 @@ namespace Flarum\Api\Serializer; use Closure; use DateTime; -use Flarum\Core\User; +use Flarum\Api\Event\Serializing; use Flarum\Event\GetApiRelationship; -use Flarum\Event\PrepareApiAttributes; +use Flarum\User\User; use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Events\Dispatcher; use InvalidArgumentException; @@ -71,7 +71,7 @@ abstract class AbstractSerializer extends BaseAbstractSerializer $attributes = $this->getDefaultAttributes($model); static::$dispatcher->fire( - new PrepareApiAttributes($this, $model, $attributes) + new Serializing($this, $model, $attributes) ); return $attributes; diff --git a/framework/core/src/Api/Serializer/DiscussionBasicSerializer.php b/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php similarity index 71% rename from framework/core/src/Api/Serializer/DiscussionBasicSerializer.php rename to framework/core/src/Api/Serializer/BasicDiscussionSerializer.php index ec5040f9d..b03d6d002 100644 --- a/framework/core/src/Api/Serializer/DiscussionBasicSerializer.php +++ b/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php @@ -11,10 +11,10 @@ namespace Flarum\Api\Serializer; -use Flarum\Core\Discussion; +use Flarum\Discussion\Discussion; use InvalidArgumentException; -class DiscussionBasicSerializer extends AbstractSerializer +class BasicDiscussionSerializer extends AbstractSerializer { /** * {@inheritdoc} @@ -46,7 +46,7 @@ class DiscussionBasicSerializer extends AbstractSerializer */ 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) { - 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) { - 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) { - 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) { - 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) { - 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) { - return $this->hasOne($discussion, 'Flarum\Api\Serializer\UserBasicSerializer'); + return $this->hasOne($discussion, BasicUserSerializer::class); } } diff --git a/framework/core/src/Api/Serializer/PostBasicSerializer.php b/framework/core/src/Api/Serializer/BasicPostSerializer.php similarity index 81% rename from framework/core/src/Api/Serializer/PostBasicSerializer.php rename to framework/core/src/Api/Serializer/BasicPostSerializer.php index 962a7b28b..103bd8a06 100644 --- a/framework/core/src/Api/Serializer/PostBasicSerializer.php +++ b/framework/core/src/Api/Serializer/BasicPostSerializer.php @@ -11,11 +11,11 @@ namespace Flarum\Api\Serializer; -use Flarum\Core\Post; -use Flarum\Core\Post\CommentPost; +use Flarum\Post\CommentPost; +use Flarum\Post\Post; use InvalidArgumentException; -class PostBasicSerializer extends AbstractSerializer +class BasicPostSerializer extends AbstractSerializer { /** * {@inheritdoc} @@ -25,7 +25,7 @@ class PostBasicSerializer extends AbstractSerializer /** * {@inheritdoc} * - * @param \Flarum\Core\Post $post + * @param \Flarum\Post\Post $post * @throws InvalidArgumentException */ protected function getDefaultAttributes($post) @@ -57,7 +57,7 @@ class PostBasicSerializer extends AbstractSerializer */ 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) { - return $this->hasOne($post, 'Flarum\Api\Serializer\DiscussionBasicSerializer'); + return $this->hasOne($post, BasicDiscussionSerializer::class); } } diff --git a/framework/core/src/Api/Serializer/UserBasicSerializer.php b/framework/core/src/Api/Serializer/BasicUserSerializer.php similarity index 86% rename from framework/core/src/Api/Serializer/UserBasicSerializer.php rename to framework/core/src/Api/Serializer/BasicUserSerializer.php index f5919ebf5..3a6b3d46d 100644 --- a/framework/core/src/Api/Serializer/UserBasicSerializer.php +++ b/framework/core/src/Api/Serializer/BasicUserSerializer.php @@ -11,10 +11,10 @@ namespace Flarum\Api\Serializer; -use Flarum\Core\User; +use Flarum\User\User; use InvalidArgumentException; -class UserBasicSerializer extends AbstractSerializer +class BasicUserSerializer extends AbstractSerializer { /** * {@inheritdoc} @@ -47,6 +47,6 @@ class UserBasicSerializer extends AbstractSerializer */ protected function groups($user) { - return $this->hasMany($user, 'Flarum\Api\Serializer\GroupSerializer'); + return $this->hasMany($user, GroupSerializer::class); } } diff --git a/framework/core/src/Api/Serializer/DiscussionSerializer.php b/framework/core/src/Api/Serializer/DiscussionSerializer.php index eee9c38a0..88e5fb8fe 100644 --- a/framework/core/src/Api/Serializer/DiscussionSerializer.php +++ b/framework/core/src/Api/Serializer/DiscussionSerializer.php @@ -11,18 +11,18 @@ namespace Flarum\Api\Serializer; -use Flarum\Core\Access\Gate; -use Flarum\Core\Discussion; +use Flarum\Discussion\Discussion; +use Flarum\User\Gate; -class DiscussionSerializer extends DiscussionBasicSerializer +class DiscussionSerializer extends BasicDiscussionSerializer { /** - * @var Gate + * @var \Flarum\User\Gate */ protected $gate; /** - * @param \Flarum\Core\Access\Gate $gate + * @param \Flarum\User\Gate $gate */ public function __construct(Gate $gate) { diff --git a/framework/core/src/Api/Serializer/ForumSerializer.php b/framework/core/src/Api/Serializer/ForumSerializer.php index 852ec08a6..02dcdd6d6 100644 --- a/framework/core/src/Api/Serializer/ForumSerializer.php +++ b/framework/core/src/Api/Serializer/ForumSerializer.php @@ -11,8 +11,8 @@ namespace Flarum\Api\Serializer; -use Flarum\Forum\UrlGenerator; use Flarum\Foundation\Application; +use Flarum\Http\UrlGenerator; use Flarum\Settings\SettingsRepositoryInterface; class ForumSerializer extends AbstractSerializer @@ -97,7 +97,7 @@ class ForumSerializer extends AbstractSerializer */ 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'); - 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'); - return $faviconPath ? $this->url->toPath('assets/'.$faviconPath) : null; + return $faviconPath ? $this->url->to('forum')->path('assets/'.$faviconPath) : null; } } diff --git a/framework/core/src/Api/Serializer/GroupSerializer.php b/framework/core/src/Api/Serializer/GroupSerializer.php index ba07e7754..7207c0153 100644 --- a/framework/core/src/Api/Serializer/GroupSerializer.php +++ b/framework/core/src/Api/Serializer/GroupSerializer.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Serializer; -use Flarum\Core\Group; +use Flarum\Group\Group; use InvalidArgumentException; 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 * @return string diff --git a/framework/core/src/Api/Serializer/NotificationSerializer.php b/framework/core/src/Api/Serializer/NotificationSerializer.php index a599ffe31..55b809079 100644 --- a/framework/core/src/Api/Serializer/NotificationSerializer.php +++ b/framework/core/src/Api/Serializer/NotificationSerializer.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Serializer; -use Flarum\Core\Notification; +use Flarum\Notification\Notification; use InvalidArgumentException; class NotificationSerializer extends AbstractSerializer @@ -32,7 +32,7 @@ class NotificationSerializer extends AbstractSerializer /** * {@inheritdoc} * - * @param \Flarum\Core\Notification $notification + * @param \Flarum\Notification\Notification $notification * @throws InvalidArgumentException */ protected function getDefaultAttributes($notification) @@ -57,7 +57,7 @@ class NotificationSerializer extends AbstractSerializer */ 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) { - return $this->hasOne($notification, 'Flarum\Api\Serializer\UserBasicSerializer'); + return $this->hasOne($notification, BasicUserSerializer::class); } /** diff --git a/framework/core/src/Api/Serializer/PostSerializer.php b/framework/core/src/Api/Serializer/PostSerializer.php index 4290c5b03..ee807374b 100644 --- a/framework/core/src/Api/Serializer/PostSerializer.php +++ b/framework/core/src/Api/Serializer/PostSerializer.php @@ -11,18 +11,18 @@ namespace Flarum\Api\Serializer; -use Flarum\Core\Access\Gate; -use Flarum\Core\Post\CommentPost; +use Flarum\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; /** - * @param \Flarum\Core\Access\Gate $gate + * @param \Flarum\User\Gate $gate */ public function __construct(Gate $gate) { @@ -77,7 +77,7 @@ class PostSerializer extends PostBasicSerializer */ 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) { - 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) { - 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) { - return $this->hasOne($post, 'Flarum\Api\Serializer\UserBasicSerializer'); + return $this->hasOne($post, BasicUserSerializer::class); } } diff --git a/framework/core/src/Api/Serializer/UserSerializer.php b/framework/core/src/Api/Serializer/UserSerializer.php index 0a289284c..8a521f6cb 100644 --- a/framework/core/src/Api/Serializer/UserSerializer.php +++ b/framework/core/src/Api/Serializer/UserSerializer.php @@ -11,12 +11,12 @@ 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; diff --git a/framework/core/src/Api/Server.php b/framework/core/src/Api/Server.php deleted file mode 100644 index 79dbb03b6..000000000 --- a/framework/core/src/Api/Server.php +++ /dev/null @@ -1,62 +0,0 @@ - - * - * 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; - } -} diff --git a/framework/core/src/Api/routes.php b/framework/core/src/Api/routes.php new file mode 100644 index 000000000..b83c57ea9 --- /dev/null +++ b/framework/core/src/Api/routes.php @@ -0,0 +1,304 @@ + + * + * 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) + ); +}; diff --git a/framework/core/src/Bus/BusServiceProvider.php b/framework/core/src/Bus/BusServiceProvider.php new file mode 100644 index 000000000..c07b9b812 --- /dev/null +++ b/framework/core/src/Bus/BusServiceProvider.php @@ -0,0 +1,28 @@ + + * + * 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); + }); + }); + } +} diff --git a/framework/core/src/Bus/Dispatcher.php b/framework/core/src/Bus/Dispatcher.php new file mode 100644 index 000000000..c0836d129 --- /dev/null +++ b/framework/core/src/Bus/Dispatcher.php @@ -0,0 +1,28 @@ + + * + * 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); + } +} diff --git a/framework/core/src/Console/Command/AbstractCommand.php b/framework/core/src/Console/AbstractCommand.php similarity index 97% rename from framework/core/src/Console/Command/AbstractCommand.php rename to framework/core/src/Console/AbstractCommand.php index 771a85b6e..3d01d5ecc 100644 --- a/framework/core/src/Console/Command/AbstractCommand.php +++ b/framework/core/src/Console/AbstractCommand.php @@ -9,7 +9,7 @@ * 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\Input\InputInterface; diff --git a/framework/core/src/Console/Server.php b/framework/core/src/Console/Server.php index f58971735..36cdea59d 100644 --- a/framework/core/src/Console/Server.php +++ b/framework/core/src/Console/Server.php @@ -11,16 +11,32 @@ namespace Flarum\Console; -use Flarum\Console\Command\GenerateMigrationCommand; -use Flarum\Debug\Console\CacheClearCommand; -use Flarum\Debug\Console\InfoCommand; -use Flarum\Foundation\AbstractServer; +use Flarum\Database\Console\GenerateMigrationCommand; +use Flarum\Database\Console\MigrateCommand; +use Flarum\Foundation\Application; +use Flarum\Foundation\Console\CacheClearCommand; +use Flarum\Foundation\Console\InfoCommand; +use Flarum\Foundation\Site; use Flarum\Install\Console\InstallCommand; -use Flarum\Update\Console\MigrateCommand; -use Symfony\Component\Console\Application; +use Flarum\Install\InstallServiceProvider; +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() { $console = $this->getConsoleApplication(); @@ -29,14 +45,13 @@ class Server extends AbstractServer } /** - * @return Application + * @return ConsoleApplication */ protected function getConsoleApplication() { - $app = $this->getApp(); - $console = new Application('Flarum', $app->version()); + $console = new ConsoleApplication('Flarum', $this->app->version()); - $app->register('Flarum\Install\InstallServiceProvider'); + $this->app->register(InstallServiceProvider::class); $commands = [ InstallCommand::class, @@ -44,7 +59,7 @@ class Server extends AbstractServer GenerateMigrationCommand::class, ]; - if ($app->isInstalled()) { + if ($this->app->isInstalled()) { $commands = array_merge($commands, [ InfoCommand::class, CacheClearCommand::class @@ -52,9 +67,9 @@ class Server extends AbstractServer } foreach ($commands as $command) { - $console->add($app->make( + $console->add($this->app->make( $command, - ['config' => $app->isInstalled() ? $app->make('flarum.config') : []] + ['config' => $this->app->isInstalled() ? $this->app->make('flarum.config') : []] )); } diff --git a/framework/core/src/Core/Post/RegisteredTypesScope.php b/framework/core/src/Core/Post/RegisteredTypesScope.php deleted file mode 100644 index e0cf51707..000000000 --- a/framework/core/src/Core/Post/RegisteredTypesScope.php +++ /dev/null @@ -1,78 +0,0 @@ - - * - * 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)); - } -} diff --git a/framework/core/src/Console/Command/GenerateMigrationCommand.php b/framework/core/src/Database/Console/GenerateMigrationCommand.php similarity index 97% rename from framework/core/src/Console/Command/GenerateMigrationCommand.php rename to framework/core/src/Database/Console/GenerateMigrationCommand.php index cfdc59229..edf7a7024 100644 --- a/framework/core/src/Console/Command/GenerateMigrationCommand.php +++ b/framework/core/src/Database/Console/GenerateMigrationCommand.php @@ -9,8 +9,9 @@ * 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 Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; diff --git a/framework/core/src/Update/Console/MigrateCommand.php b/framework/core/src/Database/Console/MigrateCommand.php similarity index 96% rename from framework/core/src/Update/Console/MigrateCommand.php rename to framework/core/src/Database/Console/MigrateCommand.php index 1f2c62f83..f5782d13f 100644 --- a/framework/core/src/Update/Console/MigrateCommand.php +++ b/framework/core/src/Database/Console/MigrateCommand.php @@ -9,9 +9,9 @@ * 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; class MigrateCommand extends AbstractCommand diff --git a/framework/core/src/Database/DatabaseMigrationRepository.php b/framework/core/src/Database/DatabaseMigrationRepository.php index 49a1978e4..3e02ae84a 100755 --- a/framework/core/src/Database/DatabaseMigrationRepository.php +++ b/framework/core/src/Database/DatabaseMigrationRepository.php @@ -58,7 +58,8 @@ class DatabaseMigrationRepository implements MigrationRepositoryInterface return $this->table() ->where('extension', $extension) ->orderBy('migration', 'asc') - ->lists('migration'); + ->pluck('migration') + ->toArray(); } /** diff --git a/framework/core/src/Database/DatabaseServiceProvider.php b/framework/core/src/Database/DatabaseServiceProvider.php index 87324330c..8d3c08262 100644 --- a/framework/core/src/Database/DatabaseServiceProvider.php +++ b/framework/core/src/Database/DatabaseServiceProvider.php @@ -12,10 +12,8 @@ namespace Flarum\Database; use Flarum\Foundation\AbstractServiceProvider; -use Flarum\Foundation\Application; use Illuminate\Database\ConnectionResolver; use Illuminate\Database\Connectors\ConnectionFactory; -use PDO; class DatabaseServiceProvider extends AbstractServiceProvider { @@ -29,7 +27,6 @@ class DatabaseServiceProvider extends AbstractServiceProvider $connection = $factory->make($this->app->config('database')); $connection->setEventDispatcher($this->app->make('Illuminate\Contracts\Events\Dispatcher')); - $connection->setFetchMode(PDO::FETCH_CLASS); return $connection; }); @@ -46,14 +43,6 @@ class DatabaseServiceProvider extends AbstractServiceProvider }); $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()); - }); } /** diff --git a/framework/core/src/Database/MigrationServiceProvider.php b/framework/core/src/Database/MigrationServiceProvider.php new file mode 100644 index 000000000..5a21c9ada --- /dev/null +++ b/framework/core/src/Database/MigrationServiceProvider.php @@ -0,0 +1,32 @@ + + * + * 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()); + }); + } +} diff --git a/framework/core/src/Database/Migrator.php b/framework/core/src/Database/Migrator.php index 15477df4c..926d994c6 100755 --- a/framework/core/src/Database/Migrator.php +++ b/framework/core/src/Database/Migrator.php @@ -299,7 +299,7 @@ class Migrator /** * Get the migration repository instance. * - * @return \Illuminate\Database\Migrations\MigrationRepositoryInterface + * @return MigrationRepositoryInterface */ public function getRepository() { diff --git a/framework/core/src/Core/Support/ScopeVisibilityTrait.php b/framework/core/src/Database/ScopeVisibilityTrait.php similarity index 92% rename from framework/core/src/Core/Support/ScopeVisibilityTrait.php rename to framework/core/src/Database/ScopeVisibilityTrait.php index 2768cbe62..03c18e341 100644 --- a/framework/core/src/Core/Support/ScopeVisibilityTrait.php +++ b/framework/core/src/Database/ScopeVisibilityTrait.php @@ -9,10 +9,10 @@ * 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\User\User; use Illuminate\Database\Eloquent\Builder; trait ScopeVisibilityTrait diff --git a/framework/core/src/Core/Command/DeleteDiscussion.php b/framework/core/src/Discussion/Command/DeleteDiscussion.php similarity index 95% rename from framework/core/src/Core/Command/DeleteDiscussion.php rename to framework/core/src/Discussion/Command/DeleteDiscussion.php index 550ae5e17..f79525fb6 100644 --- a/framework/core/src/Core/Command/DeleteDiscussion.php +++ b/framework/core/src/Discussion/Command/DeleteDiscussion.php @@ -9,9 +9,9 @@ * 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 { diff --git a/framework/core/src/Core/Command/DeleteDiscussionHandler.php b/framework/core/src/Discussion/Command/DeleteDiscussionHandler.php similarity index 74% rename from framework/core/src/Core/Command/DeleteDiscussionHandler.php rename to framework/core/src/Discussion/Command/DeleteDiscussionHandler.php index 5f383f60d..de0bb03b3 100644 --- a/framework/core/src/Core/Command/DeleteDiscussionHandler.php +++ b/framework/core/src/Discussion/Command/DeleteDiscussionHandler.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Discussion\Command; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\Repository\DiscussionRepository; -use Flarum\Core\Support\DispatchEventsTrait; -use Flarum\Event\DiscussionWillBeDeleted; +use Flarum\Discussion\DiscussionRepository; +use Flarum\Discussion\Event\Deleting; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\User\AssertPermissionTrait; +use Flarum\User\Exception\PermissionDeniedException; use Illuminate\Contracts\Events\Dispatcher; class DeleteDiscussionHandler @@ -24,7 +24,7 @@ class DeleteDiscussionHandler use AssertPermissionTrait; /** - * @var DiscussionRepository + * @var \Flarum\Discussion\DiscussionRepository */ protected $discussions; @@ -40,7 +40,7 @@ class DeleteDiscussionHandler /** * @param DeleteDiscussion $command - * @return \Flarum\Core\Discussion + * @return \Flarum\Discussion\Discussion * @throws PermissionDeniedException */ public function handle(DeleteDiscussion $command) @@ -52,7 +52,7 @@ class DeleteDiscussionHandler $this->assertCan($actor, 'delete', $discussion); $this->events->fire( - new DiscussionWillBeDeleted($discussion, $actor, $command->data) + new Deleting($discussion, $actor, $command->data) ); $discussion->delete(); diff --git a/framework/core/src/Core/Command/EditDiscussion.php b/framework/core/src/Discussion/Command/EditDiscussion.php similarity index 85% rename from framework/core/src/Core/Command/EditDiscussion.php rename to framework/core/src/Discussion/Command/EditDiscussion.php index 23cb5e707..660ed8b0d 100644 --- a/framework/core/src/Core/Command/EditDiscussion.php +++ b/framework/core/src/Discussion/Command/EditDiscussion.php @@ -9,9 +9,9 @@ * 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 { @@ -25,7 +25,7 @@ class EditDiscussion /** * The user performing the action. * - * @var \Flarum\Core\User + * @var \Flarum\User\User */ public $actor; @@ -38,7 +38,7 @@ class EditDiscussion /** * @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. */ public function __construct($discussionId, User $actor, array $data) diff --git a/framework/core/src/Core/Command/EditDiscussionHandler.php b/framework/core/src/Discussion/Command/EditDiscussionHandler.php similarity index 80% rename from framework/core/src/Core/Command/EditDiscussionHandler.php rename to framework/core/src/Discussion/Command/EditDiscussionHandler.php index 151f66d4f..42e38f9e9 100644 --- a/framework/core/src/Core/Command/EditDiscussionHandler.php +++ b/framework/core/src/Discussion/Command/EditDiscussionHandler.php @@ -9,14 +9,13 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Discussion\Command; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\Repository\DiscussionRepository; -use Flarum\Core\Support\DispatchEventsTrait; -use Flarum\Core\Validator\DiscussionValidator; -use Flarum\Event\DiscussionWillBeSaved; +use Flarum\Discussion\DiscussionRepository; +use Flarum\Discussion\DiscussionValidator; +use Flarum\Discussion\Event\Saving; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\User\AssertPermissionTrait; use Illuminate\Contracts\Events\Dispatcher; class EditDiscussionHandler @@ -48,8 +47,8 @@ class EditDiscussionHandler /** * @param EditDiscussion $command - * @return \Flarum\Core\Discussion - * @throws PermissionDeniedException + * @return \Flarum\Discussion\Discussion + * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(EditDiscussion $command) { @@ -76,7 +75,7 @@ class EditDiscussionHandler } $this->events->fire( - new DiscussionWillBeSaved($discussion, $actor, $data) + new Saving($discussion, $actor, $data) ); $this->validator->assertValid($discussion->getDirty()); diff --git a/framework/core/src/Core/Command/ReadDiscussion.php b/framework/core/src/Discussion/Command/ReadDiscussion.php similarity index 94% rename from framework/core/src/Core/Command/ReadDiscussion.php rename to framework/core/src/Discussion/Command/ReadDiscussion.php index 00bb1a1db..c6a8826e3 100644 --- a/framework/core/src/Core/Command/ReadDiscussion.php +++ b/framework/core/src/Discussion/Command/ReadDiscussion.php @@ -9,9 +9,9 @@ * 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 { diff --git a/framework/core/src/Core/Command/ReadDiscussionHandler.php b/framework/core/src/Discussion/Command/ReadDiscussionHandler.php similarity index 76% rename from framework/core/src/Core/Command/ReadDiscussionHandler.php rename to framework/core/src/Discussion/Command/ReadDiscussionHandler.php index ed7a2d21b..0197d8684 100644 --- a/framework/core/src/Core/Command/ReadDiscussionHandler.php +++ b/framework/core/src/Discussion/Command/ReadDiscussionHandler.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Discussion\Command; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Repository\DiscussionRepository; -use Flarum\Core\Support\DispatchEventsTrait; -use Flarum\Event\DiscussionStateWillBeSaved; +use Flarum\Discussion\DiscussionRepository; +use Flarum\Discussion\Event\UserDataSaving; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\User\AssertPermissionTrait; use Illuminate\Contracts\Events\Dispatcher; class ReadDiscussionHandler @@ -39,8 +39,8 @@ class ReadDiscussionHandler /** * @param ReadDiscussion $command - * @return \Flarum\Core\DiscussionState - * @throws \Flarum\Core\Exception\PermissionDeniedException + * @return \Flarum\Discussion\UserState + * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(ReadDiscussion $command) { @@ -54,7 +54,7 @@ class ReadDiscussionHandler $state->read($command->readNumber); $this->events->fire( - new DiscussionStateWillBeSaved($state) + new UserDataSaving($state) ); $state->save(); diff --git a/framework/core/src/Core/Command/StartDiscussion.php b/framework/core/src/Discussion/Command/StartDiscussion.php similarity index 92% rename from framework/core/src/Core/Command/StartDiscussion.php rename to framework/core/src/Discussion/Command/StartDiscussion.php index 1840f9c0c..3b564c0f1 100644 --- a/framework/core/src/Core/Command/StartDiscussion.php +++ b/framework/core/src/Discussion/Command/StartDiscussion.php @@ -9,9 +9,9 @@ * 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 { diff --git a/framework/core/src/Core/Command/StartDiscussionHandler.php b/framework/core/src/Discussion/Command/StartDiscussionHandler.php similarity index 85% rename from framework/core/src/Core/Command/StartDiscussionHandler.php rename to framework/core/src/Discussion/Command/StartDiscussionHandler.php index fa1950259..c7399210a 100644 --- a/framework/core/src/Core/Command/StartDiscussionHandler.php +++ b/framework/core/src/Discussion/Command/StartDiscussionHandler.php @@ -9,14 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Discussion\Command; use Exception; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Discussion; -use Flarum\Core\Support\DispatchEventsTrait; -use Flarum\Core\Validator\DiscussionValidator; -use Flarum\Event\DiscussionWillBeSaved; +use Flarum\Discussion\Discussion; +use Flarum\Discussion\DiscussionValidator; +use Flarum\Discussion\Event\Saving; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\Post\Command\PostReply; +use Flarum\User\AssertPermissionTrait; use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher; use Illuminate\Contracts\Events\Dispatcher as EventDispatcher; @@ -31,14 +32,14 @@ class StartDiscussionHandler protected $bus; /** - * @var DiscussionValidator + * @var \Flarum\Discussion\DiscussionValidator */ protected $validator; /** * @param EventDispatcher $events * @param BusDispatcher $bus - * @param DiscussionValidator $validator + * @param \Flarum\Discussion\DiscussionValidator $validator */ public function __construct(EventDispatcher $events, BusDispatcher $bus, DiscussionValidator $validator) { @@ -70,7 +71,7 @@ class StartDiscussionHandler ); $this->events->fire( - new DiscussionWillBeSaved($discussion, $actor, $data) + new Saving($discussion, $actor, $data) ); $this->validator->assertValid($discussion->getAttributes()); diff --git a/framework/core/src/Core/Discussion.php b/framework/core/src/Discussion/Discussion.php similarity index 88% rename from framework/core/src/Core/Discussion.php rename to framework/core/src/Discussion/Discussion.php index a73e437e2..38e7bb048 100644 --- a/framework/core/src/Core/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -9,19 +9,22 @@ * 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\Event\DiscussionWasDeleted; -use Flarum\Event\DiscussionWasHidden; -use Flarum\Event\DiscussionWasRenamed; -use Flarum\Event\DiscussionWasRestored; -use Flarum\Event\DiscussionWasStarted; -use Flarum\Event\PostWasDeleted; +use Flarum\Database\ScopeVisibilityTrait; +use Flarum\Discussion\Event\Deleted; +use Flarum\Discussion\Event\Hidden; +use Flarum\Discussion\Event\Renamed; +use Flarum\Discussion\Event\Restored; +use Flarum\Discussion\Event\Started; 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; /** @@ -40,7 +43,7 @@ use Flarum\Util\Str; * @property int|null $last_post_number * @property \Carbon\Carbon|null $hide_time * @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 $comments * @property \Illuminate\Database\Eloquent\Collection $participants @@ -99,7 +102,7 @@ class Discussion extends AbstractModel parent::boot(); 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 // 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(); foreach ($posts->get() as $post) { - $discussion->raise(new PostWasDeleted($post)); + $discussion->raise(new PostDeleted($post)); } $posts->delete(); @@ -135,7 +138,7 @@ class Discussion extends AbstractModel $discussion->setRelation('startUser', $user); - $discussion->raise(new DiscussionWasStarted($discussion)); + $discussion->raise(new Started($discussion)); return $discussion; } @@ -152,7 +155,7 @@ class Discussion extends AbstractModel $oldTitle = $this->title; $this->title = $title; - $this->raise(new DiscussionWasRenamed($this, $oldTitle)); + $this->raise(new Renamed($this, $oldTitle)); } return $this; @@ -170,7 +173,7 @@ class Discussion extends AbstractModel $this->hide_time = time(); $this->hide_user_id = $actor ? $actor->id : null; - $this->raise(new DiscussionWasHidden($this)); + $this->raise(new Hidden($this)); } return $this; @@ -187,7 +190,7 @@ class Discussion extends AbstractModel $this->hide_time = null; $this->hide_user_id = null; - $this->raise(new DiscussionWasRestored($this)); + $this->raise(new Restored($this)); } return $this; @@ -270,7 +273,7 @@ class Discussion extends AbstractModel * DiscussionRenamedPost, and delete if the title has been reverted * 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 * was originally intended to be saved. It also may not exist, if the * merge logic resulted in deletion. @@ -301,7 +304,7 @@ class Discussion extends AbstractModel */ 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() { - 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() { - 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() { - 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() { - 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() { - 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; - 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. * * @param User $user - * @return \Flarum\Core\DiscussionState + * @return \Flarum\Discussion\UserState */ public function stateFor(User $user) { $state = $this->state($user)->first(); if (! $state) { - $state = new DiscussionState; + $state = new UserState; $state->discussion_id = $this->id; $state->user_id = $user->id; } diff --git a/framework/core/src/Core/Listener/DiscussionMetadataUpdater.php b/framework/core/src/Discussion/DiscussionMetadataUpdater.php similarity index 66% rename from framework/core/src/Core/Listener/DiscussionMetadataUpdater.php rename to framework/core/src/Discussion/DiscussionMetadataUpdater.php index b715e08ae..b1f894f4c 100755 --- a/framework/core/src/Core/Listener/DiscussionMetadataUpdater.php +++ b/framework/core/src/Discussion/DiscussionMetadataUpdater.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Listener; +namespace Flarum\Discussion; -use Flarum\Core\Post; -use Flarum\Event\PostWasDeleted; -use Flarum\Event\PostWasHidden; -use Flarum\Event\PostWasPosted; -use Flarum\Event\PostWasRestored; +use Flarum\Post\Event\Deleted; +use Flarum\Post\Event\Hidden; +use Flarum\Post\Event\Posted; +use Flarum\Post\Event\Restored; +use Flarum\Post\Post; use Illuminate\Contracts\Events\Dispatcher; class DiscussionMetadataUpdater @@ -25,16 +25,16 @@ class DiscussionMetadataUpdater */ public function subscribe(Dispatcher $events) { - $events->listen(PostWasPosted::class, [$this, 'whenPostWasPosted']); - $events->listen(PostWasDeleted::class, [$this, 'whenPostWasDeleted']); - $events->listen(PostWasHidden::class, [$this, 'whenPostWasHidden']); - $events->listen(PostWasRestored::class, [$this, 'whenPostWasRestored']); + $events->listen(Posted::class, [$this, 'whenPostWasPosted']); + $events->listen(Deleted::class, [$this, 'whenPostWasDeleted']); + $events->listen(Hidden::class, [$this, 'whenPostWasHidden']); + $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; @@ -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); @@ -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); } /** - * @param PostWasRestored $event + * @param Restored $event */ - public function whenPostWasRestored(PostWasRestored $event) + public function whenPostWasRestored(Restored $event) { $discussion = $event->post->discussion; diff --git a/framework/core/src/Core/Access/DiscussionPolicy.php b/framework/core/src/Discussion/DiscussionPolicy.php similarity index 93% rename from framework/core/src/Core/Access/DiscussionPolicy.php rename to framework/core/src/Discussion/DiscussionPolicy.php index 3abefa824..2839f239f 100644 --- a/framework/core/src/Core/Access/DiscussionPolicy.php +++ b/framework/core/src/Discussion/DiscussionPolicy.php @@ -9,14 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Access; +namespace Flarum\Discussion; use Carbon\Carbon; -use Flarum\Core\Discussion; -use Flarum\Core\User; use Flarum\Event\ScopeHiddenDiscussionVisibility; use Flarum\Event\ScopePrivateDiscussionVisibility; use Flarum\Settings\SettingsRepositoryInterface; +use Flarum\User\AbstractPolicy; +use Flarum\User\Gate; +use Flarum\User\User; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Database\Eloquent\Builder; @@ -98,7 +99,7 @@ class DiscussionPolicy extends AbstractPolicy /** * @param User $actor - * @param Discussion $discussion + * @param \Flarum\Discussion\Discussion $discussion * @return bool|null */ public function rename(User $actor, Discussion $discussion) @@ -116,7 +117,7 @@ class DiscussionPolicy extends AbstractPolicy /** * @param User $actor - * @param Discussion $discussion + * @param \Flarum\Discussion\Discussion $discussion * @return bool|null */ public function hide(User $actor, Discussion $discussion) diff --git a/framework/core/src/Core/Listener/DiscussionRenamedNotifier.php b/framework/core/src/Discussion/DiscussionRenamedLogger.php similarity index 73% rename from framework/core/src/Core/Listener/DiscussionRenamedNotifier.php rename to framework/core/src/Discussion/DiscussionRenamedLogger.php index 61d212d20..961bde5fb 100755 --- a/framework/core/src/Core/Listener/DiscussionRenamedNotifier.php +++ b/framework/core/src/Discussion/DiscussionRenamedLogger.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Listener; +namespace Flarum\Discussion; -use Flarum\Core\Notification\DiscussionRenamedBlueprint; -use Flarum\Core\Notification\NotificationSyncer; -use Flarum\Core\Post\DiscussionRenamedPost; -use Flarum\Event\DiscussionWasRenamed; +use Flarum\Discussion\Event\Renamed; +use Flarum\Notification\Blueprint\DiscussionRenamedBlueprint; +use Flarum\Notification\NotificationSyncer; +use Flarum\Post\DiscussionRenamedPost; use Illuminate\Contracts\Events\Dispatcher; -class DiscussionRenamedNotifier +class DiscussionRenamedLogger { /** * @var NotificationSyncer @@ -37,13 +37,13 @@ class DiscussionRenamedNotifier */ public function subscribe(Dispatcher $events) { - $events->listen(DiscussionWasRenamed::class, [$this, 'whenDiscussionWasRenamed']); + $events->listen(Renamed::class, [$this, 'whenDiscussionWasRenamed']); } /** - * @param \Flarum\Event\DiscussionWasRenamed $event + * @param \Flarum\Discussion\Event\Renamed $event */ - public function whenDiscussionWasRenamed(DiscussionWasRenamed $event) + public function whenDiscussionWasRenamed(Renamed $event) { $post = DiscussionRenamedPost::reply( $event->discussion->id, diff --git a/framework/core/src/Core/Repository/DiscussionRepository.php b/framework/core/src/Discussion/DiscussionRepository.php similarity index 91% rename from framework/core/src/Core/Repository/DiscussionRepository.php rename to framework/core/src/Discussion/DiscussionRepository.php index f76af650e..b5dbcfcb4 100644 --- a/framework/core/src/Core/Repository/DiscussionRepository.php +++ b/framework/core/src/Discussion/DiscussionRepository.php @@ -9,10 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Repository; +namespace Flarum\Discussion; -use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Query\Expression; @@ -34,7 +33,7 @@ class DiscussionRepository * * @param int $id * @param User $user - * @return \Flarum\Core\Discussion + * @return \Flarum\Discussion\Discussion */ public function findOrFail($id, User $user = null) { @@ -54,7 +53,7 @@ class DiscussionRepository return Discussion::leftJoin('users_discussions', 'users_discussions.discussion_id', '=', 'discussions.id') ->where('user_id', $user->id) ->where('read_number', '>=', new Expression('last_post_number')) - ->lists('id') + ->pluck('id') ->all(); } diff --git a/framework/core/src/Discussion/DiscussionServiceProvider.php b/framework/core/src/Discussion/DiscussionServiceProvider.php new file mode 100644 index 000000000..e1c0c466a --- /dev/null +++ b/framework/core/src/Discussion/DiscussionServiceProvider.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Discussion; + +use Flarum\Foundation\AbstractServiceProvider; + +class DiscussionServiceProvider extends AbstractServiceProvider +{ + /** + * {@inheritdoc} + */ + public function boot() + { + $events = $this->app->make('events'); + + $events->subscribe(DiscussionMetadataUpdater::class); + $events->subscribe(DiscussionPolicy::class); + $events->subscribe(DiscussionRenamedLogger::class); + } +} diff --git a/framework/core/src/Core/Validator/DiscussionValidator.php b/framework/core/src/Discussion/DiscussionValidator.php similarity index 85% rename from framework/core/src/Core/Validator/DiscussionValidator.php rename to framework/core/src/Discussion/DiscussionValidator.php index 7d67fd0a4..1511cd55d 100644 --- a/framework/core/src/Core/Validator/DiscussionValidator.php +++ b/framework/core/src/Discussion/DiscussionValidator.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Validator; +namespace Flarum\Discussion; + +use Flarum\Foundation\AbstractValidator; class DiscussionValidator extends AbstractValidator { diff --git a/framework/core/src/Event/DiscussionWasStarted.php b/framework/core/src/Discussion/Event/Deleted.php similarity index 72% rename from framework/core/src/Event/DiscussionWasStarted.php rename to framework/core/src/Discussion/Event/Deleted.php index 7a83e9f6f..d4b21bf87 100644 --- a/framework/core/src/Event/DiscussionWasStarted.php +++ b/framework/core/src/Discussion/Event/Deleted.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Discussion\Event; -use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\Discussion\Discussion; +use Flarum\User\User; -class DiscussionWasStarted +class Deleted { /** - * @var Discussion + * @var \Flarum\Discussion\Discussion */ public $discussion; @@ -27,7 +27,7 @@ class DiscussionWasStarted public $actor; /** - * @param Discussion $discussion + * @param \Flarum\Discussion\Discussion $discussion * @param User $actor */ public function __construct(Discussion $discussion, User $actor = null) diff --git a/framework/core/src/Event/DiscussionWillBeDeleted.php b/framework/core/src/Discussion/Event/Deleting.php similarity index 89% rename from framework/core/src/Event/DiscussionWillBeDeleted.php rename to framework/core/src/Discussion/Event/Deleting.php index 6508d1591..93f432192 100644 --- a/framework/core/src/Event/DiscussionWillBeDeleted.php +++ b/framework/core/src/Discussion/Event/Deleting.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Discussion\Event; -use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\Discussion\Discussion; +use Flarum\User\User; -class DiscussionWillBeDeleted +class Deleting { /** * The discussion that is going to be deleted. diff --git a/framework/core/src/Event/DiscussionWasDeleted.php b/framework/core/src/Discussion/Event/Hidden.php similarity index 72% rename from framework/core/src/Event/DiscussionWasDeleted.php rename to framework/core/src/Discussion/Event/Hidden.php index 62dee388c..6a2095a74 100644 --- a/framework/core/src/Event/DiscussionWasDeleted.php +++ b/framework/core/src/Discussion/Event/Hidden.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Discussion\Event; -use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\Discussion\Discussion; +use Flarum\User\User; -class DiscussionWasDeleted +class Hidden { /** - * @var Discussion + * @var \Flarum\Discussion\Discussion */ public $discussion; @@ -27,7 +27,7 @@ class DiscussionWasDeleted public $actor; /** - * @param Discussion $discussion + * @param \Flarum\Discussion\Discussion $discussion * @param User $actor */ public function __construct(Discussion $discussion, User $actor = null) diff --git a/framework/core/src/Event/DiscussionWasRenamed.php b/framework/core/src/Discussion/Event/Renamed.php similarity index 80% rename from framework/core/src/Event/DiscussionWasRenamed.php rename to framework/core/src/Discussion/Event/Renamed.php index c17656396..3d06b959b 100644 --- a/framework/core/src/Event/DiscussionWasRenamed.php +++ b/framework/core/src/Discussion/Event/Renamed.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Discussion\Event; -use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\Discussion\Discussion; +use Flarum\User\User; -class DiscussionWasRenamed +class Renamed { /** * @var Discussion @@ -32,7 +32,7 @@ class DiscussionWasRenamed public $actor; /** - * @param Discussion $discussion + * @param \Flarum\Discussion\Discussion $discussion * @param User $actor * @param string $oldTitle */ diff --git a/framework/core/src/Event/DiscussionWasHidden.php b/framework/core/src/Discussion/Event/Restored.php similarity index 72% rename from framework/core/src/Event/DiscussionWasHidden.php rename to framework/core/src/Discussion/Event/Restored.php index bcd6cc93b..eb276e755 100644 --- a/framework/core/src/Event/DiscussionWasHidden.php +++ b/framework/core/src/Discussion/Event/Restored.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Discussion\Event; -use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\Discussion\Discussion; +use Flarum\User\User; -class DiscussionWasHidden +class Restored { /** - * @var Discussion + * @var \Flarum\Discussion\Discussion */ public $discussion; @@ -27,7 +27,7 @@ class DiscussionWasHidden public $actor; /** - * @param Discussion $discussion + * @param \Flarum\Discussion\Discussion $discussion * @param User $actor */ public function __construct(Discussion $discussion, User $actor = null) diff --git a/framework/core/src/Event/DiscussionWillBeSaved.php b/framework/core/src/Discussion/Event/Saving.php similarity index 79% rename from framework/core/src/Event/DiscussionWillBeSaved.php rename to framework/core/src/Discussion/Event/Saving.php index 6a1d31f36..e6d25a0ae 100644 --- a/framework/core/src/Event/DiscussionWillBeSaved.php +++ b/framework/core/src/Discussion/Event/Saving.php @@ -9,17 +9,17 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Discussion\Event; -use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\Discussion\Discussion; +use Flarum\User\User; -class DiscussionWillBeSaved +class Saving { /** * The discussion that will be saved. * - * @var Discussion + * @var \Flarum\Discussion\Discussion */ public $discussion; @@ -38,7 +38,7 @@ class DiscussionWillBeSaved public $data; /** - * @param Discussion $discussion + * @param \Flarum\Discussion\Discussion $discussion * @param User $actor * @param array $data */ diff --git a/framework/core/src/Event/ConfigureDiscussionSearch.php b/framework/core/src/Discussion/Event/Searching.php similarity index 70% rename from framework/core/src/Event/ConfigureDiscussionSearch.php rename to framework/core/src/Discussion/Event/Searching.php index 90ff9b1a0..5735bffdc 100644 --- a/framework/core/src/Event/ConfigureDiscussionSearch.php +++ b/framework/core/src/Discussion/Event/Searching.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Discussion\Event; -use Flarum\Core\Search\Discussion\DiscussionSearch; -use Flarum\Core\Search\SearchCriteria; +use Flarum\Discussion\Search\DiscussionSearch; +use Flarum\Search\SearchCriteria; -class ConfigureDiscussionSearch +class Searching { /** * @var DiscussionSearch @@ -22,13 +22,13 @@ class ConfigureDiscussionSearch public $search; /** - * @var SearchCriteria + * @var \Flarum\Search\SearchCriteria */ public $criteria; /** * @param DiscussionSearch $search - * @param SearchCriteria $criteria + * @param \Flarum\Search\SearchCriteria $criteria */ public function __construct(DiscussionSearch $search, SearchCriteria $criteria) { diff --git a/framework/core/src/Event/DiscussionWasRestored.php b/framework/core/src/Discussion/Event/Started.php similarity index 72% rename from framework/core/src/Event/DiscussionWasRestored.php rename to framework/core/src/Discussion/Event/Started.php index b9ead6384..ddb640662 100644 --- a/framework/core/src/Event/DiscussionWasRestored.php +++ b/framework/core/src/Discussion/Event/Started.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Discussion\Event; -use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\Discussion\Discussion; +use Flarum\User\User; -class DiscussionWasRestored +class Started { /** - * @var Discussion + * @var \Flarum\Discussion\Discussion */ public $discussion; @@ -27,7 +27,7 @@ class DiscussionWasRestored public $actor; /** - * @param Discussion $discussion + * @param \Flarum\Discussion\Discussion $discussion * @param User $actor */ public function __construct(Discussion $discussion, User $actor = null) diff --git a/framework/core/src/Event/DiscussionStateWillBeSaved.php b/framework/core/src/Discussion/Event/UserDataSaving.php similarity index 67% rename from framework/core/src/Event/DiscussionStateWillBeSaved.php rename to framework/core/src/Discussion/Event/UserDataSaving.php index 05ddd45cc..52a85fe6b 100644 --- a/framework/core/src/Event/DiscussionStateWillBeSaved.php +++ b/framework/core/src/Discussion/Event/UserDataSaving.php @@ -9,21 +9,21 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Discussion\Event; -use Flarum\Core\DiscussionState; +use Flarum\Discussion\UserState; -class DiscussionStateWillBeSaved +class UserDataSaving { /** - * @var DiscussionState + * @var \Flarum\Discussion\UserState */ public $state; /** - * @param DiscussionState $state + * @param \Flarum\Discussion\UserState $state */ - public function __construct(DiscussionState $state) + public function __construct(UserState $state) { $this->state = $state; } diff --git a/framework/core/src/Event/DiscussionWasRead.php b/framework/core/src/Discussion/Event/UserRead.php similarity index 71% rename from framework/core/src/Event/DiscussionWasRead.php rename to framework/core/src/Discussion/Event/UserRead.php index cf8936310..972a20129 100644 --- a/framework/core/src/Event/DiscussionWasRead.php +++ b/framework/core/src/Discussion/Event/UserRead.php @@ -9,21 +9,21 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Discussion\Event; -use Flarum\Core\DiscussionState; +use Flarum\Discussion\UserState; -class DiscussionWasRead +class UserRead { /** - * @var DiscussionState + * @var UserState */ public $state; /** - * @param DiscussionState $state + * @param UserState $state */ - public function __construct(DiscussionState $state) + public function __construct(UserState $state) { $this->state = $state; } diff --git a/framework/core/src/Core/Search/Discussion/DiscussionSearch.php b/framework/core/src/Discussion/Search/DiscussionSearch.php similarity index 93% rename from framework/core/src/Core/Search/Discussion/DiscussionSearch.php rename to framework/core/src/Discussion/Search/DiscussionSearch.php index 8b1324cf8..8cb886e29 100644 --- a/framework/core/src/Core/Search/Discussion/DiscussionSearch.php +++ b/framework/core/src/Discussion/Search/DiscussionSearch.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\Discussion; +namespace Flarum\Discussion\Search; -use Flarum\Core\Search\AbstractSearch; +use Flarum\Search\AbstractSearch; /** * An object which represents the internal state of a search for discussions: diff --git a/framework/core/src/Core/Search/Discussion/DiscussionSearcher.php b/framework/core/src/Discussion/Search/DiscussionSearcher.php similarity index 88% rename from framework/core/src/Core/Search/Discussion/DiscussionSearcher.php rename to framework/core/src/Discussion/Search/DiscussionSearcher.php index b85df3f52..c3b5fdb59 100644 --- a/framework/core/src/Core/Search/Discussion/DiscussionSearcher.php +++ b/framework/core/src/Discussion/Search/DiscussionSearcher.php @@ -9,16 +9,16 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\Discussion; +namespace Flarum\Discussion\Search; -use Flarum\Core\Discussion; -use Flarum\Core\Repository\DiscussionRepository; -use Flarum\Core\Repository\PostRepository; -use Flarum\Core\Search\ApplySearchParametersTrait; -use Flarum\Core\Search\GambitManager; -use Flarum\Core\Search\SearchCriteria; -use Flarum\Core\Search\SearchResults; -use Flarum\Event\ConfigureDiscussionSearch; +use Flarum\Discussion\Discussion; +use Flarum\Discussion\DiscussionRepository; +use Flarum\Discussion\Event\Searching; +use Flarum\Post\PostRepository; +use Flarum\Search\ApplySearchParametersTrait; +use Flarum\Search\GambitManager; +use Flarum\Search\SearchCriteria; +use Flarum\Search\SearchResults; use Illuminate\Database\Eloquent\Collection; /** @@ -30,7 +30,7 @@ class DiscussionSearcher use ApplySearchParametersTrait; /** - * @var GambitManager + * @var \Flarum\Search\GambitManager */ protected $gambits; @@ -45,7 +45,7 @@ class DiscussionSearcher protected $posts; /** - * @param GambitManager $gambits + * @param \Flarum\Search\GambitManager $gambits * @param DiscussionRepository $discussions * @param PostRepository $posts */ @@ -83,7 +83,7 @@ class DiscussionSearcher $this->applyLimit($search, $limit + 1); // TODO: inject dispatcher - event(new ConfigureDiscussionSearch($search, $criteria)); + event(new Searching($search, $criteria)); // Execute the search query and retrieve the results. We get one more // results than the user asked for, so that we can say if there are more diff --git a/framework/core/src/Core/Search/Discussion/Fulltext/DriverInterface.php b/framework/core/src/Discussion/Search/Fulltext/DriverInterface.php similarity index 90% rename from framework/core/src/Core/Search/Discussion/Fulltext/DriverInterface.php rename to framework/core/src/Discussion/Search/Fulltext/DriverInterface.php index da90c44a0..bfcd37093 100644 --- a/framework/core/src/Core/Search/Discussion/Fulltext/DriverInterface.php +++ b/framework/core/src/Discussion/Search/Fulltext/DriverInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\Discussion\Fulltext; +namespace Flarum\Discussion\Search\Fulltext; interface DriverInterface { diff --git a/framework/core/src/Core/Search/Discussion/Fulltext/MySqlFulltextDriver.php b/framework/core/src/Discussion/Search/Fulltext/MySqlFulltextDriver.php similarity index 86% rename from framework/core/src/Core/Search/Discussion/Fulltext/MySqlFulltextDriver.php rename to framework/core/src/Discussion/Search/Fulltext/MySqlFulltextDriver.php index 402fefc4c..f3e1a0be2 100644 --- a/framework/core/src/Core/Search/Discussion/Fulltext/MySqlFulltextDriver.php +++ b/framework/core/src/Discussion/Search/Fulltext/MySqlFulltextDriver.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\Discussion\Fulltext; +namespace Flarum\Discussion\Search\Fulltext; -use Flarum\Core\Post; +use Flarum\Post\Post; class MySqlFulltextDriver implements DriverInterface { @@ -23,7 +23,7 @@ class MySqlFulltextDriver implements DriverInterface $discussionIds = Post::where('type', 'comment') ->whereRaw('MATCH (`content`) AGAINST (? IN BOOLEAN MODE)', [$string]) ->orderByRaw('MATCH (`content`) AGAINST (?) DESC', [$string]) - ->lists('discussion_id', 'id'); + ->pluck('discussion_id', 'id'); $relevantPostIds = []; diff --git a/framework/core/src/Core/Search/Discussion/Gambit/AuthorGambit.php b/framework/core/src/Discussion/Search/Gambit/AuthorGambit.php similarity index 78% rename from framework/core/src/Core/Search/Discussion/Gambit/AuthorGambit.php rename to framework/core/src/Discussion/Search/Gambit/AuthorGambit.php index 914fb6684..d3f4544ab 100644 --- a/framework/core/src/Core/Search/Discussion/Gambit/AuthorGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/AuthorGambit.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\Discussion\Gambit; +namespace Flarum\Discussion\Search\Gambit; -use Flarum\Core\Repository\UserRepository; -use Flarum\Core\Search\AbstractRegexGambit; -use Flarum\Core\Search\AbstractSearch; -use Flarum\Core\Search\Discussion\DiscussionSearch; +use Flarum\Discussion\Search\DiscussionSearch; +use Flarum\Search\AbstractRegexGambit; +use Flarum\Search\AbstractSearch; +use Flarum\User\UserRepository; use LogicException; class AuthorGambit extends AbstractRegexGambit @@ -25,12 +25,12 @@ class AuthorGambit extends AbstractRegexGambit protected $pattern = 'author:(.+)'; /** - * @var UserRepository + * @var \Flarum\User\UserRepository */ protected $users; /** - * @param \Flarum\Core\Repository\UserRepository $users + * @param \Flarum\User\UserRepository $users */ public function __construct(UserRepository $users) { diff --git a/framework/core/src/Core/Search/Discussion/Gambit/CreatedGambit.php b/framework/core/src/Discussion/Search/Gambit/CreatedGambit.php similarity index 87% rename from framework/core/src/Core/Search/Discussion/Gambit/CreatedGambit.php rename to framework/core/src/Discussion/Search/Gambit/CreatedGambit.php index e47bedfc4..6241c0e16 100644 --- a/framework/core/src/Core/Search/Discussion/Gambit/CreatedGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/CreatedGambit.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\Discussion\Gambit; +namespace Flarum\Discussion\Search\Gambit; -use Flarum\Core\Search\AbstractRegexGambit; -use Flarum\Core\Search\AbstractSearch; -use Flarum\Core\Search\Discussion\DiscussionSearch; +use Flarum\Discussion\Search\DiscussionSearch; +use Flarum\Search\AbstractRegexGambit; +use Flarum\Search\AbstractSearch; use LogicException; class CreatedGambit extends AbstractRegexGambit diff --git a/framework/core/src/Core/Search/Discussion/Gambit/FulltextGambit.php b/framework/core/src/Discussion/Search/Gambit/FulltextGambit.php similarity index 74% rename from framework/core/src/Core/Search/Discussion/Gambit/FulltextGambit.php rename to framework/core/src/Discussion/Search/Gambit/FulltextGambit.php index 6531ba915..3019f9f0f 100644 --- a/framework/core/src/Core/Search/Discussion/Gambit/FulltextGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/FulltextGambit.php @@ -9,23 +9,23 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\Discussion\Gambit; +namespace Flarum\Discussion\Search\Gambit; -use Flarum\Core\Search\AbstractSearch; -use Flarum\Core\Search\Discussion\DiscussionSearch; -use Flarum\Core\Search\Discussion\Fulltext\DriverInterface; -use Flarum\Core\Search\GambitInterface; +use Flarum\Discussion\Search\DiscussionSearch; +use Flarum\Discussion\Search\Fulltext\DriverInterface; +use Flarum\Search\AbstractSearch; +use Flarum\Search\GambitInterface; use LogicException; class FulltextGambit implements GambitInterface { /** - * @var DriverInterface + * @var \Flarum\Discussion\Search\Fulltext\DriverInterface */ protected $fulltext; /** - * @param DriverInterface $fulltext + * @param \Flarum\Discussion\Search\Fulltext\DriverInterface $fulltext */ public function __construct(DriverInterface $fulltext) { diff --git a/framework/core/src/Core/Search/Discussion/Gambit/HiddenGambit.php b/framework/core/src/Discussion/Search/Gambit/HiddenGambit.php similarity index 84% rename from framework/core/src/Core/Search/Discussion/Gambit/HiddenGambit.php rename to framework/core/src/Discussion/Search/Gambit/HiddenGambit.php index c27bf457a..907991546 100644 --- a/framework/core/src/Core/Search/Discussion/Gambit/HiddenGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/HiddenGambit.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\Discussion\Gambit; +namespace Flarum\Discussion\Search\Gambit; -use Flarum\Core\Search\AbstractRegexGambit; -use Flarum\Core\Search\AbstractSearch; -use Flarum\Core\Search\Discussion\DiscussionSearch; +use Flarum\Discussion\Search\DiscussionSearch; +use Flarum\Search\AbstractRegexGambit; +use Flarum\Search\AbstractSearch; use LogicException; class HiddenGambit extends AbstractRegexGambit diff --git a/framework/core/src/Core/Search/Discussion/Gambit/UnreadGambit.php b/framework/core/src/Discussion/Search/Gambit/UnreadGambit.php similarity index 80% rename from framework/core/src/Core/Search/Discussion/Gambit/UnreadGambit.php rename to framework/core/src/Discussion/Search/Gambit/UnreadGambit.php index 9c7890095..bd9a60629 100644 --- a/framework/core/src/Core/Search/Discussion/Gambit/UnreadGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/UnreadGambit.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\Discussion\Gambit; +namespace Flarum\Discussion\Search\Gambit; -use Flarum\Core\Repository\DiscussionRepository; -use Flarum\Core\Search\AbstractRegexGambit; -use Flarum\Core\Search\AbstractSearch; -use Flarum\Core\Search\Discussion\DiscussionSearch; +use Flarum\Discussion\DiscussionRepository; +use Flarum\Discussion\Search\DiscussionSearch; +use Flarum\Search\AbstractRegexGambit; +use Flarum\Search\AbstractSearch; use LogicException; class UnreadGambit extends AbstractRegexGambit @@ -25,12 +25,12 @@ class UnreadGambit extends AbstractRegexGambit protected $pattern = 'is:unread'; /** - * @var \Flarum\Core\Repository\DiscussionRepository + * @var \Flarum\Discussion\DiscussionRepository */ protected $discussions; /** - * @param DiscussionRepository $discussions + * @param \Flarum\Discussion\DiscussionRepository $discussions */ public function __construct(DiscussionRepository $discussions) { diff --git a/framework/core/src/Core/DiscussionState.php b/framework/core/src/Discussion/UserState.php similarity index 84% rename from framework/core/src/Core/DiscussionState.php rename to framework/core/src/Discussion/UserState.php index 2208a8ff4..a8df0651c 100644 --- a/framework/core/src/Core/DiscussionState.php +++ b/framework/core/src/Discussion/UserState.php @@ -9,11 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\Discussion; -use Flarum\Core\Support\EventGeneratorTrait; use Flarum\Database\AbstractModel; -use Flarum\Event\DiscussionWasRead; +use Flarum\Discussion\Event\UserRead; +use Flarum\Foundation\EventGeneratorTrait; +use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; /** @@ -28,9 +29,9 @@ use Illuminate\Database\Eloquent\Builder; * @property \Carbon\Carbon|null $read_time * @property int|null $read_number * @property Discussion $discussion - * @property \Flarum\Core\User $user + * @property \Flarum\User\User $user */ -class DiscussionState extends AbstractModel +class UserState extends AbstractModel { use EventGeneratorTrait; @@ -57,7 +58,7 @@ class DiscussionState extends AbstractModel $this->read_number = $number; $this->read_time = time(); - $this->raise(new DiscussionWasRead($this)); + $this->raise(new UserRead($this)); } return $this; @@ -70,7 +71,7 @@ class DiscussionState extends AbstractModel */ public function discussion() { - return $this->belongsTo('Flarum\Core\Discussion', 'discussion_id'); + return $this->belongsTo(Discussion::class, 'discussion_id'); } /** @@ -80,7 +81,7 @@ class DiscussionState extends AbstractModel */ public function user() { - return $this->belongsTo('Flarum\Core\User', 'user_id'); + return $this->belongsTo(User::class, 'user_id'); } /** diff --git a/framework/core/src/Event/AbstractConfigureGambits.php b/framework/core/src/Event/AbstractConfigureGambits.php index 1889ea861..0513eba48 100644 --- a/framework/core/src/Event/AbstractConfigureGambits.php +++ b/framework/core/src/Event/AbstractConfigureGambits.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Core\Search\GambitManager; +use Flarum\Search\GambitManager; abstract class AbstractConfigureGambits { @@ -21,7 +21,7 @@ abstract class AbstractConfigureGambits public $gambits; /** - * @param GambitManager $gambits + * @param \Flarum\Search\GambitManager $gambits */ public function __construct(GambitManager $gambits) { diff --git a/framework/core/src/Event/AbstractConfigureRoutes.php b/framework/core/src/Event/AbstractConfigureRoutes.php index fbd8d175c..3ce06cf61 100644 --- a/framework/core/src/Event/AbstractConfigureRoutes.php +++ b/framework/core/src/Event/AbstractConfigureRoutes.php @@ -11,8 +11,8 @@ namespace Flarum\Event; -use Flarum\Http\Handler\RouteHandlerFactory; use Flarum\Http\RouteCollection; +use Flarum\Http\RouteHandlerFactory; abstract class AbstractConfigureRoutes { @@ -28,7 +28,7 @@ abstract class AbstractConfigureRoutes /** * @param RouteCollection $routes - * @param RouteHandlerFactory $route + * @param \Flarum\Http\RouteHandlerFactory $route */ public function __construct(RouteCollection $routes, RouteHandlerFactory $route) { @@ -84,15 +84,6 @@ abstract class AbstractConfigureRoutes */ protected function route($method, $url, $name, $controller) { - $this->routes->$method($url, $name, $this->toController($controller)); - } - - /** - * @param string $controller - * @return callable - */ - protected function toController($controller) - { - return $this->route->toController($controller); + $this->routes->$method($url, $name, $this->route->toController($controller)); } } diff --git a/framework/core/src/Event/ConfigureClientView.php b/framework/core/src/Event/ConfigureClientView.php index 787b7ab9a..52375b9fe 100644 --- a/framework/core/src/Event/ConfigureClientView.php +++ b/framework/core/src/Event/ConfigureClientView.php @@ -11,9 +11,11 @@ namespace Flarum\Event; +use Flarum\Frontend\Event\Rendering; + /** * @deprecated */ -class ConfigureClientView extends ConfigureWebApp +class ConfigureClientView extends Rendering { } diff --git a/framework/core/src/Event/ConfigureForumRoutes.php b/framework/core/src/Event/ConfigureForumRoutes.php index d2beb7e0e..934f27a48 100644 --- a/framework/core/src/Event/ConfigureForumRoutes.php +++ b/framework/core/src/Event/ConfigureForumRoutes.php @@ -11,6 +11,8 @@ namespace Flarum\Event; +use Flarum\Forum\Controller\FrontendController; + /** * Configure forum routes. * @@ -21,7 +23,7 @@ class ConfigureForumRoutes extends AbstractConfigureRoutes /** * {@inheritdoc} */ - public function get($url, $name, $handler = 'Flarum\Forum\Controller\WebAppController') + public function get($url, $name, $handler = FrontendController::class) { parent::get($url, $name, $handler); } diff --git a/framework/core/src/Event/ConfigureMiddleware.php b/framework/core/src/Event/ConfigureMiddleware.php index 80ebb649f..e602d5532 100644 --- a/framework/core/src/Event/ConfigureMiddleware.php +++ b/framework/core/src/Event/ConfigureMiddleware.php @@ -11,10 +11,6 @@ namespace Flarum\Event; -use Flarum\Admin\Server as AdminServer; -use Flarum\Api\Server as ApiServer; -use Flarum\Forum\Server as ForumServer; -use Flarum\Foundation\AbstractServer; use Zend\Stratigility\MiddlewarePipe; class ConfigureMiddleware @@ -27,42 +23,35 @@ class ConfigureMiddleware /** * @var string */ - public $path; - - /** - * @var AbstractServer - */ - public $server; + public $stackName; /** * @param MiddlewarePipe $pipe - * @param string $path - * @param AbstractServer $server + * @param string $stackName */ - public function __construct(MiddlewarePipe $pipe, $path, AbstractServer $server) + public function __construct(MiddlewarePipe $pipe, $stackName) { $this->pipe = $pipe; - $this->path = $path; - $this->server = $server; + $this->stackName = $stackName; } public function pipe(callable $middleware) { - $this->pipe->pipe($this->path, $middleware); + $this->pipe->pipe($middleware); } public function isForum() { - return $this->server instanceof ForumServer; + return $this->stackName === 'forum'; } public function isAdmin() { - return $this->server instanceof AdminServer; + return $this->stackName === 'admin'; } public function isApi() { - return $this->server instanceof ApiServer; + return $this->stackName === 'api'; } } diff --git a/framework/core/src/Event/ConfigureNotificationTypes.php b/framework/core/src/Event/ConfigureNotificationTypes.php index 084701f0a..3c6eec2b7 100644 --- a/framework/core/src/Event/ConfigureNotificationTypes.php +++ b/framework/core/src/Event/ConfigureNotificationTypes.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Core\Notification\BlueprintInterface; +use Flarum\Notification\Blueprint\BlueprintInterface; use InvalidArgumentException; use ReflectionClass; diff --git a/framework/core/src/Event/ConfigureUserPreferences.php b/framework/core/src/Event/ConfigureUserPreferences.php index dbc18cdb1..db9e9d0c8 100644 --- a/framework/core/src/Event/ConfigureUserPreferences.php +++ b/framework/core/src/Event/ConfigureUserPreferences.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Core\User; +use Flarum\User\User; class ConfigureUserPreferences { diff --git a/framework/core/src/Event/ExtensionWasUninstalled.php b/framework/core/src/Event/ExtensionWasUninstalled.php deleted file mode 100644 index 4b50c4a64..000000000 --- a/framework/core/src/Event/ExtensionWasUninstalled.php +++ /dev/null @@ -1,30 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Flarum\Event; - -use Flarum\Extension\Extension; - -class ExtensionWasUninstalled -{ - /** - * @var Extension - */ - public $extension; - - /** - * @param Extension $extension - */ - public function __construct(Extension $extension) - { - $this->extension = $extension; - } -} diff --git a/framework/core/src/Event/GetDisplayName.php b/framework/core/src/Event/GetDisplayName.php index 71fbe6ba4..7983ee199 100644 --- a/framework/core/src/Event/GetDisplayName.php +++ b/framework/core/src/Event/GetDisplayName.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Core\User; +use Flarum\User\User; class GetDisplayName { diff --git a/framework/core/src/Event/GetPermission.php b/framework/core/src/Event/GetPermission.php index 78c93c83e..e18cb7ee8 100644 --- a/framework/core/src/Event/GetPermission.php +++ b/framework/core/src/Event/GetPermission.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Core\User; +use Flarum\User\User; class GetPermission { diff --git a/framework/core/src/Event/PrepareUserGroups.php b/framework/core/src/Event/PrepareUserGroups.php index d7e2ee868..fa03eb66a 100644 --- a/framework/core/src/Event/PrepareUserGroups.php +++ b/framework/core/src/Event/PrepareUserGroups.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Core\User; +use Flarum\User\User; /** * The `PrepareUserGroups` event. diff --git a/framework/core/src/Event/ScopeHiddenDiscussionVisibility.php b/framework/core/src/Event/ScopeHiddenDiscussionVisibility.php index 28235061e..411b89be6 100644 --- a/framework/core/src/Event/ScopeHiddenDiscussionVisibility.php +++ b/framework/core/src/Event/ScopeHiddenDiscussionVisibility.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Core\User; +use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; /** diff --git a/framework/core/src/Event/ScopeModelVisibility.php b/framework/core/src/Event/ScopeModelVisibility.php index ecf79e7d2..9eb5de654 100644 --- a/framework/core/src/Event/ScopeModelVisibility.php +++ b/framework/core/src/Event/ScopeModelVisibility.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Core\User; +use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; diff --git a/framework/core/src/Event/ScopePostVisibility.php b/framework/core/src/Event/ScopePostVisibility.php index a83ea20b1..d8d2304e2 100644 --- a/framework/core/src/Event/ScopePostVisibility.php +++ b/framework/core/src/Event/ScopePostVisibility.php @@ -11,8 +11,8 @@ namespace Flarum\Event; -use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\Discussion\Discussion; +use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; /** @@ -21,7 +21,7 @@ use Illuminate\Database\Eloquent\Builder; class ScopePostVisibility { /** - * @var Discussion + * @var \Flarum\Discussion\Discussion */ public $discussion; diff --git a/framework/core/src/Event/ScopePrivateDiscussionVisibility.php b/framework/core/src/Event/ScopePrivateDiscussionVisibility.php index 2e6782b9f..c0b2758fc 100644 --- a/framework/core/src/Event/ScopePrivateDiscussionVisibility.php +++ b/framework/core/src/Event/ScopePrivateDiscussionVisibility.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Core\User; +use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; /** diff --git a/framework/core/src/Event/ScopePrivatePostVisibility.php b/framework/core/src/Event/ScopePrivatePostVisibility.php index bd67deb06..bb84cda39 100644 --- a/framework/core/src/Event/ScopePrivatePostVisibility.php +++ b/framework/core/src/Event/ScopePrivatePostVisibility.php @@ -11,8 +11,8 @@ namespace Flarum\Event; -use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\Discussion\Discussion; +use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; /** @@ -21,7 +21,7 @@ use Illuminate\Database\Eloquent\Builder; class ScopePrivatePostVisibility { /** - * @var Discussion + * @var \Flarum\Discussion\Discussion */ public $discussion; @@ -36,7 +36,7 @@ class ScopePrivatePostVisibility public $actor; /** - * @param Discussion $discussion + * @param \Flarum\Discussion\Discussion $discussion * @param Builder $query * @param User $actor */ diff --git a/framework/core/src/Event/UserEmailWasChanged.php b/framework/core/src/Event/UserEmailWasChanged.php deleted file mode 100644 index 91117b840..000000000 --- a/framework/core/src/Event/UserEmailWasChanged.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Flarum\Event; - -use Flarum\Core\User; - -class UserEmailWasChanged -{ - /** - * @var User - */ - public $user; - - /** - * @var User - */ - public $actor; - - /** - * @param User $user - * @param User $actor - */ - public function __construct(User $user, User $actor = null) - { - $this->user = $user; - $this->actor = $actor; - } -} diff --git a/framework/core/src/Event/UserPasswordWasChanged.php b/framework/core/src/Event/UserPasswordWasChanged.php deleted file mode 100644 index 0798c3f58..000000000 --- a/framework/core/src/Event/UserPasswordWasChanged.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Flarum\Event; - -use Flarum\Core\User; - -class UserPasswordWasChanged -{ - /** - * @var User - */ - public $user; - - /** - * @var User - */ - public $actor; - - /** - * @param User $user - * @param User $actor - */ - public function __construct(User $user, User $actor = null) - { - $this->user = $user; - $this->actor = $actor; - } -} diff --git a/framework/core/src/Core/Listener/ExtensionValidator.php b/framework/core/src/Extension/DefaultLanguagePackGuard.php similarity index 54% rename from framework/core/src/Core/Listener/ExtensionValidator.php rename to framework/core/src/Extension/DefaultLanguagePackGuard.php index b7e3634d6..d8fd3dc8a 100644 --- a/framework/core/src/Core/Listener/ExtensionValidator.php +++ b/framework/core/src/Extension/DefaultLanguagePackGuard.php @@ -9,32 +9,43 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Listener; +namespace Flarum\Extension; -use Flarum\Event\ExtensionWillBeDisabled; +use Flarum\Extension\Event\Disabling; use Flarum\Http\Exception\ForbiddenException; +use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Events\Dispatcher; -class ExtensionValidator +class DefaultLanguagePackGuard { + /** + * @var SettingsRepositoryInterface + */ + protected $settings; + + public function __construct(SettingsRepositoryInterface $settings) + { + $this->settings = $settings; + } + /** * @param Dispatcher $events */ public function subscribe(Dispatcher $events) { - $events->listen(ExtensionWillBeDisabled::class, [$this, 'whenExtensionWillBeDisabled']); + $events->listen(Disabling::class, [$this, 'whenExtensionWillBeDisabled']); } /** - * @param ExtensionWillBeDisabled $event + * @param Disabling $event * @throws ForbiddenException */ - public function whenExtensionWillBeDisabled(ExtensionWillBeDisabled $event) + public function whenExtensionWillBeDisabled(Disabling $event) { if (in_array('flarum-locale', $event->extension->extra)) { - $default_locale = $this->app->make('flarum.settings')->get('default_locale'); + $defaultLocale = $this->settings->get('default_locale'); $locale = array_get($event->extension->extra, 'flarum-locale.code'); - if ($locale === $default_locale) { + if ($locale === $defaultLocale) { throw new ForbiddenException('You cannot disable the default language pack!'); } } diff --git a/framework/core/src/Event/ExtensionWasEnabled.php b/framework/core/src/Extension/Event/Disabled.php similarity index 90% rename from framework/core/src/Event/ExtensionWasEnabled.php rename to framework/core/src/Extension/Event/Disabled.php index d593fad42..4dd56fe97 100644 --- a/framework/core/src/Event/ExtensionWasEnabled.php +++ b/framework/core/src/Extension/Event/Disabled.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Extension\Event; use Flarum\Extension\Extension; -class ExtensionWasEnabled +class Disabled { /** * @var Extension diff --git a/framework/core/src/Event/ExtensionWasDisabled.php b/framework/core/src/Extension/Event/Disabling.php similarity index 90% rename from framework/core/src/Event/ExtensionWasDisabled.php rename to framework/core/src/Extension/Event/Disabling.php index a38bab60b..1660c684f 100644 --- a/framework/core/src/Event/ExtensionWasDisabled.php +++ b/framework/core/src/Extension/Event/Disabling.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Extension\Event; use Flarum\Extension\Extension; -class ExtensionWasDisabled +class Disabling { /** * @var Extension diff --git a/framework/core/src/Event/ExtensionWillBeEnabled.php b/framework/core/src/Extension/Event/Enabled.php similarity index 90% rename from framework/core/src/Event/ExtensionWillBeEnabled.php rename to framework/core/src/Extension/Event/Enabled.php index 6bcaed507..d467b82fe 100644 --- a/framework/core/src/Event/ExtensionWillBeEnabled.php +++ b/framework/core/src/Extension/Event/Enabled.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Extension\Event; use Flarum\Extension\Extension; -class ExtensionWillBeEnabled +class Enabled { /** * @var Extension diff --git a/framework/core/src/Event/ExtensionWillBeDisabled.php b/framework/core/src/Extension/Event/Enabling.php similarity index 89% rename from framework/core/src/Event/ExtensionWillBeDisabled.php rename to framework/core/src/Extension/Event/Enabling.php index e1deddba1..656dcd56f 100644 --- a/framework/core/src/Event/ExtensionWillBeDisabled.php +++ b/framework/core/src/Extension/Event/Enabling.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Extension\Event; use Flarum\Extension\Extension; -class ExtensionWillBeDisabled +class Enabling { /** * @var Extension diff --git a/framework/core/src/Extension/Event/Uninstalled.php b/framework/core/src/Extension/Event/Uninstalled.php new file mode 100644 index 000000000..647269665 --- /dev/null +++ b/framework/core/src/Extension/Event/Uninstalled.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Extension\Event; + +use Flarum\Extension\Extension; + +class Uninstalled +{ + /** + * @var Extension + */ + public $extension; + + /** + * @param Extension $extension + */ + public function __construct(Extension $extension) + { + $this->extension = $extension; + } +} diff --git a/framework/core/src/Extension/ExtensionManager.php b/framework/core/src/Extension/ExtensionManager.php index 69ab289d9..404638fd5 100644 --- a/framework/core/src/Extension/ExtensionManager.php +++ b/framework/core/src/Extension/ExtensionManager.php @@ -12,11 +12,11 @@ namespace Flarum\Extension; use Flarum\Database\Migrator; -use Flarum\Event\ExtensionWasDisabled; -use Flarum\Event\ExtensionWasEnabled; -use Flarum\Event\ExtensionWasUninstalled; -use Flarum\Event\ExtensionWillBeDisabled; -use Flarum\Event\ExtensionWillBeEnabled; +use Flarum\Extension\Event\Disabled; +use Flarum\Extension\Event\Disabling; +use Flarum\Extension\Event\Enabled; +use Flarum\Extension\Event\Enabling; +use Flarum\Extension\Event\Uninstalled; use Flarum\Foundation\Application; use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Events\Dispatcher; @@ -115,7 +115,7 @@ class ExtensionManager if (! $this->isEnabled($name)) { $extension = $this->getExtension($name); - $this->dispatcher->fire(new ExtensionWillBeEnabled($extension)); + $this->dispatcher->fire(new Enabling($extension)); $enabled = $this->getEnabled(); @@ -129,7 +129,7 @@ class ExtensionManager $extension->setEnabled(true); - $this->dispatcher->fire(new ExtensionWasEnabled($extension)); + $this->dispatcher->fire(new Enabled($extension)); } } @@ -145,7 +145,7 @@ class ExtensionManager if (($k = array_search($name, $enabled)) !== false) { $extension = $this->getExtension($name); - $this->dispatcher->fire(new ExtensionWillBeDisabled($extension)); + $this->dispatcher->fire(new Disabling($extension)); unset($enabled[$k]); @@ -153,7 +153,7 @@ class ExtensionManager $extension->setEnabled(false); - $this->dispatcher->fire(new ExtensionWasDisabled($extension)); + $this->dispatcher->fire(new Disabled($extension)); } } @@ -174,7 +174,7 @@ class ExtensionManager $extension->setInstalled(false); - $this->dispatcher->fire(new ExtensionWasUninstalled($extension)); + $this->dispatcher->fire(new Uninstalled($extension)); } /** diff --git a/framework/core/src/Extension/ExtensionServiceProvider.php b/framework/core/src/Extension/ExtensionServiceProvider.php index 522f9d9e5..77b88d3e5 100644 --- a/framework/core/src/Extension/ExtensionServiceProvider.php +++ b/framework/core/src/Extension/ExtensionServiceProvider.php @@ -20,7 +20,7 @@ class ExtensionServiceProvider extends AbstractServiceProvider */ public function register() { - $this->app->bind('flarum.extensions', 'Flarum\Extension\ExtensionManager'); + $this->app->bind('flarum.extensions', ExtensionManager::class); $bootstrappers = $this->app->make('flarum.extensions')->getEnabledBootstrappers(); @@ -30,4 +30,14 @@ class ExtensionServiceProvider extends AbstractServiceProvider $this->app->call($bootstrapper); } } + + /** + * {@inheritdoc} + */ + public function boot() + { + $events = $this->app->make('events'); + + $events->subscribe(DefaultLanguagePackGuard::class); + } } diff --git a/framework/core/src/Event/ConfigureFormatter.php b/framework/core/src/Formatter/Event/Configuring.php similarity index 90% rename from framework/core/src/Event/ConfigureFormatter.php rename to framework/core/src/Formatter/Event/Configuring.php index 1efd761c8..9d0efeb28 100644 --- a/framework/core/src/Event/ConfigureFormatter.php +++ b/framework/core/src/Formatter/Event/Configuring.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Formatter\Event; use s9e\TextFormatter\Configurator; -class ConfigureFormatter +class Configuring { /** * @var Configurator diff --git a/framework/core/src/Event/ConfigureFormatterParser.php b/framework/core/src/Formatter/Event/Parsing.php similarity index 92% rename from framework/core/src/Event/ConfigureFormatterParser.php rename to framework/core/src/Formatter/Event/Parsing.php index 642ab7a0f..e462021b8 100644 --- a/framework/core/src/Event/ConfigureFormatterParser.php +++ b/framework/core/src/Formatter/Event/Parsing.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Formatter\Event; use s9e\TextFormatter\Parser; -class ConfigureFormatterParser +class Parsing { /** * @var Parser diff --git a/framework/core/src/Event/ConfigureFormatterRenderer.php b/framework/core/src/Formatter/Event/Rendering.php similarity index 92% rename from framework/core/src/Event/ConfigureFormatterRenderer.php rename to framework/core/src/Formatter/Event/Rendering.php index 9c2aced54..97ae53687 100644 --- a/framework/core/src/Event/ConfigureFormatterRenderer.php +++ b/framework/core/src/Formatter/Event/Rendering.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Formatter\Event; use s9e\TextFormatter\Renderer; -class ConfigureFormatterRenderer +class Rendering { /** * @var Renderer diff --git a/framework/core/src/Formatter/Formatter.php b/framework/core/src/Formatter/Formatter.php index 2de082af9..c080dcc08 100644 --- a/framework/core/src/Formatter/Formatter.php +++ b/framework/core/src/Formatter/Formatter.php @@ -11,9 +11,9 @@ namespace Flarum\Formatter; -use Flarum\Event\ConfigureFormatter; -use Flarum\Event\ConfigureFormatterParser; -use Flarum\Event\ConfigureFormatterRenderer; +use Flarum\Formatter\Event\Configuring; +use Flarum\Formatter\Event\Parsing; +use Flarum\Formatter\Event\Rendering; use Illuminate\Contracts\Cache\Repository; use Illuminate\Contracts\Events\Dispatcher; use s9e\TextFormatter\Configurator; @@ -59,7 +59,7 @@ class Formatter { $parser = $this->getParser($context); - $this->events->fire(new ConfigureFormatterParser($parser, $context, $text)); + $this->events->fire(new Parsing($parser, $context, $text)); return $parser->parse($text); } @@ -75,7 +75,7 @@ class Formatter { $renderer = $this->getRenderer($context); - $this->events->fire(new ConfigureFormatterRenderer($renderer, $context, $xml)); + $this->events->fire(new Rendering($renderer, $context, $xml)); return $renderer->render($xml); } @@ -117,7 +117,7 @@ class Formatter $configurator->Autolink; $configurator->tags->onDuplicate('replace'); - $this->events->fire(new ConfigureFormatter($configurator)); + $this->events->fire(new Configuring($configurator)); $this->configureExternalLinks($configurator); diff --git a/framework/core/src/Formatter/FormatterServiceProvider.php b/framework/core/src/Formatter/FormatterServiceProvider.php index 60f43bc8f..25de9fe55 100644 --- a/framework/core/src/Formatter/FormatterServiceProvider.php +++ b/framework/core/src/Formatter/FormatterServiceProvider.php @@ -11,8 +11,8 @@ namespace Flarum\Formatter; -use Flarum\Event\ExtensionWasDisabled; -use Flarum\Event\ExtensionWasEnabled; +use Flarum\Extension\Event\Disabled; +use Flarum\Extension\Event\Enabled; use Flarum\Foundation\AbstractServiceProvider; use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Events\Dispatcher; @@ -24,8 +24,8 @@ class FormatterServiceProvider extends AbstractServiceProvider */ public function boot(Dispatcher $events) { - $events->listen(ExtensionWasEnabled::class, [$this, 'flushFormatter']); - $events->listen(ExtensionWasDisabled::class, [$this, 'flushFormatter']); + $events->listen(Enabled::class, [$this, 'flushFormatter']); + $events->listen(Disabled::class, [$this, 'flushFormatter']); } /** @@ -41,7 +41,7 @@ class FormatterServiceProvider extends AbstractServiceProvider ); }); - $this->app->alias('flarum.formatter', 'Flarum\Formatter\Formatter'); + $this->app->alias('flarum.formatter', Formatter::class); } public function flushFormatter() diff --git a/framework/core/src/Forum/AuthenticationResponseFactory.php b/framework/core/src/Forum/AuthenticationResponseFactory.php index 17cc1497f..90efc1771 100644 --- a/framework/core/src/Forum/AuthenticationResponseFactory.php +++ b/framework/core/src/Forum/AuthenticationResponseFactory.php @@ -11,10 +11,10 @@ namespace Flarum\Forum; -use Flarum\Core\AuthToken; -use Flarum\Core\User; use Flarum\Http\Rememberer; use Flarum\Http\SessionAuthenticator; +use Flarum\User\AuthToken; +use Flarum\User\User; use Psr\Http\Message\ServerRequestInterface as Request; use Zend\Diactoros\Response\HtmlResponse; diff --git a/framework/core/src/Forum/Controller/AuthorizedWebAppController.php b/framework/core/src/Forum/Controller/AuthorizedWebAppController.php index 51131479f..7f1a4890c 100644 --- a/framework/core/src/Forum/Controller/AuthorizedWebAppController.php +++ b/framework/core/src/Forum/Controller/AuthorizedWebAppController.php @@ -11,10 +11,10 @@ namespace Flarum\Forum\Controller; -use Flarum\Core\Exception\PermissionDeniedException; +use Flarum\User\Exception\PermissionDeniedException; use Psr\Http\Message\ServerRequestInterface as Request; -class AuthorizedWebAppController extends WebAppController +class AuthorizedWebAppController extends FrontendController { /** * {@inheritdoc} diff --git a/framework/core/src/Forum/Controller/ConfirmEmailController.php b/framework/core/src/Forum/Controller/ConfirmEmailController.php index 64727c693..5889fdfb6 100644 --- a/framework/core/src/Forum/Controller/ConfirmEmailController.php +++ b/framework/core/src/Forum/Controller/ConfirmEmailController.php @@ -11,11 +11,11 @@ namespace Flarum\Forum\Controller; -use Flarum\Core\Command\ConfirmEmail; -use Flarum\Core\Exception\InvalidConfirmationTokenException; use Flarum\Foundation\Application; use Flarum\Http\Controller\ControllerInterface; use Flarum\Http\SessionAuthenticator; +use Flarum\User\Command\ConfirmEmail; +use Flarum\User\Exception\InvalidConfirmationTokenException; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface as Request; use Zend\Diactoros\Response\HtmlResponse; diff --git a/framework/core/src/Forum/Controller/DiscussionController.php b/framework/core/src/Forum/Controller/DiscussionController.php index c7bb5dcd9..1c16d4669 100644 --- a/framework/core/src/Forum/Controller/DiscussionController.php +++ b/framework/core/src/Forum/Controller/DiscussionController.php @@ -12,17 +12,17 @@ namespace Flarum\Forum\Controller; use Flarum\Api\Client; -use Flarum\Core\User; -use Flarum\Forum\UrlGenerator; -use Flarum\Forum\WebApp; +use Flarum\Forum\Frontend; use Flarum\Http\Exception\RouteNotFoundException; +use Flarum\Http\UrlGenerator; +use Flarum\User\User; use Illuminate\Contracts\Events\Dispatcher; use Psr\Http\Message\ServerRequestInterface as Request; -class DiscussionController extends WebAppController +class DiscussionController extends FrontendController { /** - * @var ApiClient + * @var Client */ protected $api; @@ -34,7 +34,7 @@ class DiscussionController extends WebAppController /** * {@inheritdoc} */ - public function __construct(WebApp $webApp, Dispatcher $events, Client $api, UrlGenerator $url) + public function __construct(Frontend $webApp, Dispatcher $events, Client $api, UrlGenerator $url) { parent::__construct($webApp, $events); @@ -64,7 +64,7 @@ class DiscussionController extends WebAppController $document = $this->getDocument($request->getAttribute('actor'), $params); $getResource = function ($link) use ($document) { - return array_first($document->included, function ($key, $value) use ($link) { + return array_first($document->included, function ($value, $key) use ($link) { return $value->type === $link->type && $value->id === $link->id; }); }; @@ -73,7 +73,7 @@ class DiscussionController extends WebAppController $newQueryParams = array_merge($queryParams, $newQueryParams); $queryString = http_build_query($newQueryParams); - return $this->url->toRoute('discussion', ['id' => $document->data->id]). + return $this->url->to('forum')->route('discussion', ['id' => $document->data->id]). ($queryString ? '?'.$queryString : ''); }; @@ -87,7 +87,7 @@ class DiscussionController extends WebAppController $view->title = $document->data->attributes->title; $view->document = $document; - $view->content = app('view')->make('flarum::frontend.content.discussion', compact('document', 'page', 'getResource', 'posts', 'url')); + $view->content = app('view')->make('flarum.forum::content.discussion', compact('document', 'page', 'getResource', 'posts', 'url')); return $view; } diff --git a/framework/core/src/Forum/Controller/WebAppController.php b/framework/core/src/Forum/Controller/FrontendController.php similarity index 67% rename from framework/core/src/Forum/Controller/WebAppController.php rename to framework/core/src/Forum/Controller/FrontendController.php index e24405150..ba863c019 100644 --- a/framework/core/src/Forum/Controller/WebAppController.php +++ b/framework/core/src/Forum/Controller/FrontendController.php @@ -11,16 +11,16 @@ namespace Flarum\Forum\Controller; -use Flarum\Forum\WebApp; -use Flarum\Http\Controller\AbstractWebAppController; +use Flarum\Forum\Frontend; +use Flarum\Frontend\AbstractFrontendController; use Illuminate\Contracts\Events\Dispatcher; -class WebAppController extends AbstractWebAppController +class FrontendController extends AbstractFrontendController { /** * {@inheritdoc} */ - public function __construct(WebApp $webApp, Dispatcher $events) + public function __construct(Frontend $webApp, Dispatcher $events) { $this->webApp = $webApp; $this->events = $events; diff --git a/framework/core/src/Forum/Controller/IndexController.php b/framework/core/src/Forum/Controller/IndexController.php index 0a52ed7cd..62701be96 100644 --- a/framework/core/src/Forum/Controller/IndexController.php +++ b/framework/core/src/Forum/Controller/IndexController.php @@ -12,12 +12,12 @@ namespace Flarum\Forum\Controller; use Flarum\Api\Client as ApiClient; -use Flarum\Core\User; -use Flarum\Forum\WebApp; +use Flarum\Forum\Frontend; +use Flarum\User\User; use Illuminate\Contracts\Events\Dispatcher; use Psr\Http\Message\ServerRequestInterface as Request; -class IndexController extends WebAppController +class IndexController extends FrontendController { /** * @var ApiClient @@ -39,7 +39,7 @@ class IndexController extends WebAppController /** * {@inheritdoc} */ - public function __construct(WebApp $webApp, Dispatcher $events, ApiClient $api) + public function __construct(Frontend $webApp, Dispatcher $events, ApiClient $api) { parent::__construct($webApp, $events); @@ -68,7 +68,7 @@ class IndexController extends WebAppController $document = $this->getDocument($request->getAttribute('actor'), $params); $view->document = $document; - $view->content = app('view')->make('flarum::frontend.content.index', compact('document', 'page', 'forum')); + $view->content = app('view')->make('flarum.forum::content.index', compact('document', 'page', 'forum')); return $view; } diff --git a/framework/core/src/Forum/Controller/LogInController.php b/framework/core/src/Forum/Controller/LogInController.php index 8fc2fd879..02a8730ff 100644 --- a/framework/core/src/Forum/Controller/LogInController.php +++ b/framework/core/src/Forum/Controller/LogInController.php @@ -13,12 +13,12 @@ namespace Flarum\Forum\Controller; use Flarum\Api\Client; use Flarum\Api\Controller\TokenController; -use Flarum\Core\Repository\UserRepository; -use Flarum\Event\UserLoggedIn; use Flarum\Http\AccessToken; use Flarum\Http\Controller\ControllerInterface; use Flarum\Http\Rememberer; use Flarum\Http\SessionAuthenticator; +use Flarum\User\Event\LoggedIn; +use Flarum\User\UserRepository; use Psr\Http\Message\ServerRequestInterface as Request; use Zend\Diactoros\Response\EmptyResponse; use Zend\Diactoros\Response\JsonResponse; @@ -26,7 +26,7 @@ use Zend\Diactoros\Response\JsonResponse; class LogInController implements ControllerInterface { /** - * @var \Flarum\Core\Repository\UserRepository + * @var \Flarum\User\UserRepository */ protected $users; @@ -46,7 +46,7 @@ class LogInController implements ControllerInterface protected $rememberer; /** - * @param \Flarum\Core\Repository\UserRepository $users + * @param \Flarum\User\UserRepository $users * @param Client $apiClient * @param SessionAuthenticator $authenticator * @param Rememberer $rememberer @@ -79,7 +79,7 @@ class LogInController implements ControllerInterface $token = AccessToken::find($data->token); - event(new UserLoggedIn($this->users->findOrFail($data->userId), $token)); + event(new LoggedIn($this->users->findOrFail($data->userId), $token)); if (array_get($body, 'remember')) { $response = $this->rememberer->remember($response, $token); diff --git a/framework/core/src/Forum/Controller/LogOutController.php b/framework/core/src/Forum/Controller/LogOutController.php index f19b7ea9c..d3473a068 100644 --- a/framework/core/src/Forum/Controller/LogOutController.php +++ b/framework/core/src/Forum/Controller/LogOutController.php @@ -11,14 +11,14 @@ namespace Flarum\Forum\Controller; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Event\UserLoggedOut; -use Flarum\Forum\UrlGenerator; use Flarum\Foundation\Application; use Flarum\Http\Controller\ControllerInterface; use Flarum\Http\Exception\TokenMismatchException; use Flarum\Http\Rememberer; use Flarum\Http\SessionAuthenticator; +use Flarum\Http\UrlGenerator; +use Flarum\User\AssertPermissionTrait; +use Flarum\User\Event\LoggedOut; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\View\Factory; use Psr\Http\Message\ServerRequestInterface as Request; @@ -65,6 +65,7 @@ class LogOutController implements ControllerInterface * @param SessionAuthenticator $authenticator * @param Rememberer $rememberer * @param Factory $view + * @param UrlGenerator $url */ public function __construct( Application $app, @@ -118,7 +119,7 @@ class LogOutController implements ControllerInterface $actor->accessTokens()->delete(); - $this->events->fire(new UserLoggedOut($actor)); + $this->events->fire(new LoggedOut($actor)); return $this->rememberer->forget($response); } diff --git a/framework/core/src/Forum/Controller/RegisterController.php b/framework/core/src/Forum/Controller/RegisterController.php index 58f392f15..9a83610ea 100644 --- a/framework/core/src/Forum/Controller/RegisterController.php +++ b/framework/core/src/Forum/Controller/RegisterController.php @@ -12,6 +12,7 @@ namespace Flarum\Forum\Controller; use Flarum\Api\Client; +use Flarum\Api\Controller\CreateUserController; use Flarum\Http\Controller\ControllerInterface; use Flarum\Http\Rememberer; use Flarum\Http\SessionAuthenticator; @@ -53,7 +54,7 @@ class RegisterController implements ControllerInterface */ public function handle(Request $request) { - $controller = 'Flarum\Api\Controller\CreateUserController'; + $controller = CreateUserController::class; $actor = $request->getAttribute('actor'); $body = ['data' => ['attributes' => $request->getParsedBody()]]; diff --git a/framework/core/src/Forum/Controller/ResetPasswordController.php b/framework/core/src/Forum/Controller/ResetPasswordController.php index 278dc897e..3752ead21 100644 --- a/framework/core/src/Forum/Controller/ResetPasswordController.php +++ b/framework/core/src/Forum/Controller/ResetPasswordController.php @@ -12,9 +12,9 @@ namespace Flarum\Forum\Controller; use DateTime; -use Flarum\Core\Exception\InvalidConfirmationTokenException; -use Flarum\Core\PasswordToken; use Flarum\Http\Controller\AbstractHtmlController; +use Flarum\User\Exception\InvalidConfirmationTokenException; +use Flarum\User\PasswordToken; use Illuminate\Contracts\View\Factory; use Psr\Http\Message\ServerRequestInterface as Request; @@ -36,7 +36,7 @@ class ResetPasswordController extends AbstractHtmlController /** * @param Request $request * @return \Illuminate\Contracts\View\View - * @throws InvalidConfirmationTokenException + * @throws \Flarum\User\Exception\InvalidConfirmationTokenException */ public function render(Request $request) { diff --git a/framework/core/src/Forum/Controller/SavePasswordController.php b/framework/core/src/Forum/Controller/SavePasswordController.php index 3a9fc4605..ea3257062 100644 --- a/framework/core/src/Forum/Controller/SavePasswordController.php +++ b/framework/core/src/Forum/Controller/SavePasswordController.php @@ -11,13 +11,13 @@ namespace Flarum\Forum\Controller; -use Flarum\Core\PasswordToken; -use Flarum\Core\Validator\UserValidator; -use Flarum\Forum\UrlGenerator; use Flarum\Http\Controller\ControllerInterface; use Flarum\Http\SessionAuthenticator; +use Flarum\Http\UrlGenerator; +use Flarum\User\PasswordToken; +use Flarum\User\UserValidator; use Illuminate\Contracts\Validation\Factory; -use Illuminate\Contracts\Validation\ValidationException; +use Illuminate\Validation\ValidationException; use Psr\Http\Message\ServerRequestInterface as Request; use Zend\Diactoros\Response\RedirectResponse; @@ -29,7 +29,7 @@ class SavePasswordController implements ControllerInterface protected $url; /** - * @var UserValidator + * @var \Flarum\User\UserValidator */ protected $validator; @@ -82,7 +82,7 @@ class SavePasswordController implements ControllerInterface } catch (ValidationException $e) { $request->getAttribute('session')->set('errors', $e->errors()); - return new RedirectResponse($this->url->toRoute('resetPassword', ['token' => $token->id])); + return new RedirectResponse($this->url->to('forum')->route('resetPassword', ['token' => $token->id])); } $token->user->changePassword($password); @@ -93,6 +93,6 @@ class SavePasswordController implements ControllerInterface $session = $request->getAttribute('session'); $this->authenticator->logIn($session, $token->user->id); - return new RedirectResponse($this->url->toBase()); + return new RedirectResponse($this->url->to('forum')->base()); } } diff --git a/framework/core/src/Forum/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index 30741572d..f0a68d342 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -12,14 +12,25 @@ namespace Flarum\Forum; use Flarum\Event\ConfigureForumRoutes; -use Flarum\Event\ExtensionWasDisabled; -use Flarum\Event\ExtensionWasEnabled; -use Flarum\Event\SettingWasSet; +use Flarum\Event\ConfigureMiddleware; +use Flarum\Extension\Event\Disabled; +use Flarum\Extension\Event\Enabled; use Flarum\Foundation\AbstractServiceProvider; -use Flarum\Http\Handler\RouteHandlerFactory; +use Flarum\Http\Middleware\AuthenticateWithSession; +use Flarum\Http\Middleware\CollectGarbage; +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\RouteHandlerFactory; +use Flarum\Http\UrlGenerator; +use Flarum\Settings\Event\Saved; use Flarum\Settings\SettingsRepositoryInterface; use Symfony\Component\Translation\TranslatorInterface; +use Zend\Stratigility\MiddlewarePipe; class ForumServiceProvider extends AbstractServiceProvider { @@ -28,13 +39,35 @@ class ForumServiceProvider extends AbstractServiceProvider */ public function register() { - $this->app->singleton(UrlGenerator::class, function () { - return new UrlGenerator($this->app, $this->app->make('flarum.forum.routes')); + $this->app->extend(UrlGenerator::class, function (UrlGenerator $url) { + return $url->addCollection('forum', $this->app->make('flarum.forum.routes')); }); $this->app->singleton('flarum.forum.routes', function () { return new RouteCollection; }); + + $this->app->singleton('flarum.forum.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(CollectGarbage::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)); + + event(new ConfigureMiddleware($pipe, 'forum')); + + $pipe->pipe($app->make(DispatchRoute::class, ['routes' => $app->make('flarum.forum.routes')])); + + return $pipe; + }); } /** @@ -44,7 +77,7 @@ class ForumServiceProvider extends AbstractServiceProvider { $this->populateRoutes($this->app->make('flarum.forum.routes')); - $this->loadViewsFrom(__DIR__.'/../../views', 'flarum.forum'); + $this->loadViewsFrom(__DIR__.'/../../views/frontend', 'flarum.forum'); $this->app->make('view')->share([ 'translator' => $this->app->make(TranslatorInterface::class), @@ -63,82 +96,21 @@ class ForumServiceProvider extends AbstractServiceProvider */ protected function populateRoutes(RouteCollection $routes) { - $route = $this->app->make(RouteHandlerFactory::class); + $factory = $this->app->make(RouteHandlerFactory::class); - $routes->get( - '/all', - 'index', - $toDefaultController = $route->toController(Controller\IndexController::class) - ); - - $routes->get( - '/d/{id:\d+(?:-[^/]*)?}[/{near:[^/]*}]', - 'discussion', - $route->toController(Controller\DiscussionController::class) - ); - - $routes->get( - '/u/{username}[/{filter:[^/]*}]', - 'user', - $route->toController(Controller\WebAppController::class) - ); - - $routes->get( - '/settings', - 'settings', - $route->toController(Controller\AuthorizedWebAppController::class) - ); - - $routes->get( - '/notifications', - 'notifications', - $route->toController(Controller\AuthorizedWebAppController::class) - ); - - $routes->get( - '/logout', - 'logout', - $route->toController(Controller\LogOutController::class) - ); - - $routes->post( - '/login', - 'login', - $route->toController(Controller\LogInController::class) - ); - - $routes->post( - '/register', - 'register', - $route->toController(Controller\RegisterController::class) - ); - - $routes->get( - '/confirm-email/{token}', - 'confirmEmail', - $route->toController(Controller\ConfirmEmailController::class) - ); - - $routes->get( - '/reset-password/{token}', - 'resetPassword', - $route->toController(Controller\ResetPasswordController::class) - ); - - $routes->post( - '/reset-password', - 'savePassword', - $route->toController(Controller\SavePasswordController::class) - ); + $callback = include __DIR__.'/routes.php'; + $callback($routes, $factory); $this->app->make('events')->fire( - new ConfigureForumRoutes($routes, $route) + new ConfigureForumRoutes($routes, $factory) ); $defaultRoute = $this->app->make('flarum.settings')->get('default_route'); if (isset($routes->getRouteData()[0]['GET'][$defaultRoute])) { $toDefaultController = $routes->getRouteData()[0]['GET'][$defaultRoute]; + } else { + $toDefaultController = $factory->toController(Controller\IndexController::class); } $routes->get( @@ -150,7 +122,7 @@ class ForumServiceProvider extends AbstractServiceProvider 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)) { $this->getWebAppAssets()->flushCss(); } @@ -161,8 +133,8 @@ class ForumServiceProvider extends AbstractServiceProvider { $events = $this->app->make('events'); - $events->listen(ExtensionWasEnabled::class, [$this, 'flushWebAppAssets']); - $events->listen(ExtensionWasDisabled::class, [$this, 'flushWebAppAssets']); + $events->listen(Enabled::class, [$this, 'flushWebAppAssets']); + $events->listen(Disabled::class, [$this, 'flushWebAppAssets']); } public function flushWebAppAssets() @@ -171,10 +143,10 @@ class ForumServiceProvider extends AbstractServiceProvider } /** - * @return \Flarum\Http\WebApp\WebAppAssets + * @return \Flarum\Frontend\FrontendAssets */ protected function getWebAppAssets() { - return $this->app->make(WebApp::class)->getAssets(); + return $this->app->make(Frontend::class)->getAssets(); } } diff --git a/framework/core/src/Forum/WebApp.php b/framework/core/src/Forum/Frontend.php similarity index 83% rename from framework/core/src/Forum/WebApp.php rename to framework/core/src/Forum/Frontend.php index eecfbee44..1f07298ce 100644 --- a/framework/core/src/Forum/WebApp.php +++ b/framework/core/src/Forum/Frontend.php @@ -12,13 +12,13 @@ namespace Flarum\Forum; use Flarum\Formatter\Formatter; -use Flarum\Http\WebApp\AbstractWebApp; -use Flarum\Http\WebApp\WebAppAssetsFactory; -use Flarum\Http\WebApp\WebAppViewFactory; +use Flarum\Frontend\AbstractFrontend; +use Flarum\Frontend\FrontendAssetsFactory; +use Flarum\Frontend\FrontendViewFactory; use Flarum\Locale\LocaleManager; use Flarum\Settings\SettingsRepositoryInterface; -class WebApp extends AbstractWebApp +class Frontend extends AbstractFrontend { /** * @var Formatter @@ -29,8 +29,8 @@ class WebApp extends AbstractWebApp * {@inheritdoc} */ public function __construct( - WebAppAssetsFactory $assets, - WebAppViewFactory $view, + FrontendAssetsFactory $assets, + FrontendViewFactory $view, SettingsRepositoryInterface $settings, LocaleManager $locales, Formatter $formatter diff --git a/framework/core/src/Forum/Server.php b/framework/core/src/Forum/Server.php deleted file mode 100644 index 81072e964..000000000 --- a/framework/core/src/Forum/Server.php +++ /dev/null @@ -1,57 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Flarum\Forum; - -use Exception; -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(); - - $path = parse_url($app->url(), PHP_URL_PATH); - - $pipe->pipe($path, $app->make('Flarum\Http\Middleware\HandleErrors', ['debug' => $app->inDebugMode() || ! $app->isInstalled()])); - $pipe->pipe($path, $app->make('Flarum\Http\Middleware\StartSession')); - - if (! $app->isInstalled()) { - $app->register('Flarum\Install\InstallServiceProvider'); - - $pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.install.routes')])); - } elseif ($app->isUpToDate() && ! $app->isDownForMaintenance()) { - $pipe->pipe($path, $app->make('Flarum\Http\Middleware\ParseJsonBody')); - $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\Http\Middleware\ShareErrorsFromSession')); - - event(new ConfigureMiddleware($pipe, $path, $this)); - - $pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.forum.routes')])); - } else { - $pipe->pipe($path, function () { - throw new Exception('', 503); - }); - } - - return $pipe; - } -} diff --git a/framework/core/src/Forum/UrlGenerator.php b/framework/core/src/Forum/UrlGenerator.php deleted file mode 100644 index b18fbb42f..000000000 --- a/framework/core/src/Forum/UrlGenerator.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Flarum\Forum; - -use Flarum\Http\AbstractUrlGenerator; - -class UrlGenerator extends AbstractUrlGenerator -{ -} diff --git a/framework/core/src/Forum/routes.php b/framework/core/src/Forum/routes.php new file mode 100644 index 000000000..00f7bf303 --- /dev/null +++ b/framework/core/src/Forum/routes.php @@ -0,0 +1,82 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Forum\Controller; +use Flarum\Http\RouteCollection; +use Flarum\Http\RouteHandlerFactory; + +return function (RouteCollection $map, RouteHandlerFactory $route) { + $map->get( + '/all', + 'index', + $route->toController(Controller\IndexController::class) + ); + + $map->get( + '/d/{id:\d+(?:-[^/]*)?}[/{near:[^/]*}]', + 'discussion', + $route->toController(Controller\DiscussionController::class) + ); + + $map->get( + '/u/{username}[/{filter:[^/]*}]', + 'user', + $route->toController(Controller\FrontendController::class) + ); + + $map->get( + '/settings', + 'settings', + $route->toController(Controller\AuthorizedWebAppController::class) + ); + + $map->get( + '/notifications', + 'notifications', + $route->toController(Controller\AuthorizedWebAppController::class) + ); + + $map->get( + '/logout', + 'logout', + $route->toController(Controller\LogOutController::class) + ); + + $map->post( + '/login', + 'login', + $route->toController(Controller\LogInController::class) + ); + + $map->post( + '/register', + 'register', + $route->toController(Controller\RegisterController::class) + ); + + $map->get( + '/confirm/{token}', + 'confirmEmail', + $route->toController(Controller\ConfirmEmailController::class) + ); + + $map->get( + '/reset/{token}', + 'resetPassword', + $route->toController(Controller\ResetPasswordController::class) + ); + + $map->post( + '/reset', + 'savePassword', + $route->toController(Controller\SavePasswordController::class) + ); +}; diff --git a/framework/core/src/Core/Validator/AbstractValidator.php b/framework/core/src/Foundation/AbstractValidator.php similarity index 91% rename from framework/core/src/Core/Validator/AbstractValidator.php rename to framework/core/src/Foundation/AbstractValidator.php index e1c138ecb..25108526f 100644 --- a/framework/core/src/Core/Validator/AbstractValidator.php +++ b/framework/core/src/Foundation/AbstractValidator.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Validator; +namespace Flarum\Foundation; -use Flarum\Event\ConfigureValidator; +use Flarum\Foundation\Event\Validating; use Illuminate\Contracts\Events\Dispatcher; -use Illuminate\Contracts\Validation\ValidationException; use Illuminate\Validation\Factory; +use Illuminate\Validation\ValidationException; use Symfony\Component\Translation\TranslatorInterface; abstract class AbstractValidator @@ -94,7 +94,7 @@ abstract class AbstractValidator $validator = $this->validator->make($attributes, $rules, $this->getMessages()); $this->events->fire( - new ConfigureValidator($this, $validator) + new Validating($this, $validator) ); return $validator; diff --git a/framework/core/src/Foundation/Application.php b/framework/core/src/Foundation/Application.php index b3edee9fe..697f6c2fe 100644 --- a/framework/core/src/Foundation/Application.php +++ b/framework/core/src/Foundation/Application.php @@ -11,6 +11,7 @@ namespace Flarum\Foundation; +use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Container\Container; use Illuminate\Contracts\Foundation\Application as ApplicationContract; use Illuminate\Events\EventServiceProvider; @@ -125,7 +126,7 @@ class Application extends Container implements ApplicationContract public function isUpToDate() { - $settings = $this->make('Flarum\Settings\SettingsRepositoryInterface'); + $settings = $this->make(SettingsRepositoryInterface::class); try { $version = $settings->get('version'); @@ -736,4 +737,22 @@ class Application extends Container implements ApplicationContract $this->loadedProviders = []; } + + /** + * Get the path to the cached packages.php file. + * + * @return string + */ + public function getCachedPackagesPath() + { + return storage_path('app/cache/packages.php'); + } + + /** + * @return string + */ + public function resourcePath() + { + return storage_path('resources'); + } } diff --git a/framework/core/src/Debug/Console/CacheClearCommand.php b/framework/core/src/Foundation/Console/CacheClearCommand.php similarity index 91% rename from framework/core/src/Debug/Console/CacheClearCommand.php rename to framework/core/src/Foundation/Console/CacheClearCommand.php index 97142ad6e..6bd6650da 100644 --- a/framework/core/src/Debug/Console/CacheClearCommand.php +++ b/framework/core/src/Foundation/Console/CacheClearCommand.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Debug\Console; +namespace Flarum\Foundation\Console; -use Flarum\Admin\WebApp as AdminWebApp; -use Flarum\Console\Command\AbstractCommand; -use Flarum\Forum\WebApp as ForumWebApp; +use Flarum\Admin\Frontend as AdminWebApp; +use Flarum\Console\AbstractCommand; +use Flarum\Forum\Frontend as ForumWebApp; use Flarum\Foundation\Application; use Illuminate\Contracts\Cache\Store; diff --git a/framework/core/src/Debug/Console/InfoCommand.php b/framework/core/src/Foundation/Console/InfoCommand.php similarity index 97% rename from framework/core/src/Debug/Console/InfoCommand.php rename to framework/core/src/Foundation/Console/InfoCommand.php index 9f3c36831..1a467051a 100644 --- a/framework/core/src/Debug/Console/InfoCommand.php +++ b/framework/core/src/Foundation/Console/InfoCommand.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Debug\Console; +namespace Flarum\Foundation\Console; -use Flarum\Console\Command\AbstractCommand; +use Flarum\Console\AbstractCommand; use Flarum\Extension\ExtensionManager; use Flarum\Foundation\Application; diff --git a/framework/core/src/Core/Support/DispatchEventsTrait.php b/framework/core/src/Foundation/DispatchEventsTrait.php similarity index 92% rename from framework/core/src/Core/Support/DispatchEventsTrait.php rename to framework/core/src/Foundation/DispatchEventsTrait.php index 39266d1bc..081bfc64b 100644 --- a/framework/core/src/Core/Support/DispatchEventsTrait.php +++ b/framework/core/src/Foundation/DispatchEventsTrait.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Support; +namespace Flarum\Foundation; -use Flarum\Core\User; +use Flarum\User\User; use Illuminate\Contracts\Events\Dispatcher; trait DispatchEventsTrait diff --git a/framework/core/src/Event/ConfigureValidator.php b/framework/core/src/Foundation/Event/Validating.php similarity index 78% rename from framework/core/src/Event/ConfigureValidator.php rename to framework/core/src/Foundation/Event/Validating.php index c9343f761..fc231abc9 100644 --- a/framework/core/src/Event/ConfigureValidator.php +++ b/framework/core/src/Foundation/Event/Validating.php @@ -9,20 +9,20 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Foundation\Event; -use Flarum\Core\Validator\AbstractValidator; +use Flarum\Foundation\AbstractValidator; use Illuminate\Validation\Validator; /** - * The `ConfigureModelValidator` event is called when a validator instance for a + * The `Validating` event is called when a validator instance for a * model is being built. This event can be used to add custom rules/extensions * to the validator for when validation takes place. */ -class ConfigureValidator +class Validating { /** - * @var AbstractValidator + * @var \Flarum\Foundation\AbstractValidator */ public $type; diff --git a/framework/core/src/Core/Support/EventGeneratorTrait.php b/framework/core/src/Foundation/EventGeneratorTrait.php similarity index 95% rename from framework/core/src/Core/Support/EventGeneratorTrait.php rename to framework/core/src/Foundation/EventGeneratorTrait.php index c12402ba5..e24ceda13 100644 --- a/framework/core/src/Core/Support/EventGeneratorTrait.php +++ b/framework/core/src/Foundation/EventGeneratorTrait.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Support; +namespace Flarum\Foundation; trait EventGeneratorTrait { diff --git a/framework/core/src/Foundation/AbstractServer.php b/framework/core/src/Foundation/Site.php similarity index 59% rename from framework/core/src/Foundation/AbstractServer.php rename to framework/core/src/Foundation/Site.php index e98ec05cf..a86f7d6e1 100644 --- a/framework/core/src/Foundation/AbstractServer.php +++ b/framework/core/src/Foundation/Site.php @@ -11,12 +11,36 @@ namespace Flarum\Foundation; +use Flarum\Admin\AdminServiceProvider; +use Flarum\Api\ApiServiceProvider; +use Flarum\Bus\BusServiceProvider as BusProvider; +use Flarum\Database\DatabaseServiceProvider; +use Flarum\Database\MigrationServiceProvider; +use Flarum\Discussion\DiscussionServiceProvider; +use Flarum\Extension\ExtensionServiceProvider; +use Flarum\Formatter\FormatterServiceProvider; +use Flarum\Forum\ForumServiceProvider; +use Flarum\Group\GroupServiceProvider; +use Flarum\Locale\LocaleServiceProvider; +use Flarum\Notification\NotificationServiceProvider; +use Flarum\Post\PostServiceProvider; +use Flarum\Search\SearchServiceProvider; +use Flarum\Settings\SettingsRepositoryInterface; +use Flarum\Settings\SettingsServiceProvider; +use Flarum\User\UserServiceProvider; +use Illuminate\Bus\BusServiceProvider; use Illuminate\Config\Repository as ConfigRepository; +use Illuminate\Filesystem\FilesystemServiceProvider; +use Illuminate\Hashing\HashServiceProvider; +use Illuminate\Mail\MailServiceProvider; +use Illuminate\Validation\ValidationServiceProvider; +use Illuminate\View\ViewServiceProvider; use Monolog\Formatter\LineFormatter; use Monolog\Handler\StreamHandler; use Monolog\Logger; -abstract class AbstractServer +// TODO: This should be an interface maybe? +class Site { /** * @var Application @@ -43,109 +67,79 @@ abstract class AbstractServer */ protected $config; - /** - * @var callable[] - */ - protected $extendCallbacks = []; + protected $extenders = []; - /** - * @param null $basePath - * @param null $publicPath - */ - public function __construct($basePath = null, $publicPath = null) + public function __construct() { - if ($basePath === null) { - $basePath = getcwd(); - } - - if ($publicPath === null) { - $publicPath = $basePath; - } - - $this->basePath = $basePath; - $this->publicPath = $publicPath; - - if (file_exists($file = $this->basePath.'/config.php')) { - $this->config = include $file; - } - } - - /** - * @return string - */ - public function getBasePath() - { - return $this->basePath; - } - - /** - * @return string - */ - public function getPublicPath() - { - return $this->publicPath; - } - - /** - * @return string - */ - public function getStoragePath() - { - return $this->storagePath; - } - - /** - * @param $basePath - */ - public function setBasePath($basePath) - { - $this->basePath = $basePath; - } - - /** - * @param $publicPath - */ - public function setPublicPath($publicPath) - { - $this->publicPath = $publicPath; - } - - /** - * @param $storagePath - */ - public function setStoragePath($storagePath) - { - $this->storagePath = $storagePath; - } - - /** - * @return array - */ - public function getConfig() - { - return $this->config; - } - - /** - * @param array $config - */ - public function setConfig(array $config) - { - $this->config = $config; - } - - /** - * @param callable $callback - */ - public function extend(callable $callback) - { - $this->extendCallbacks[] = $callback; + $this->basePath = getcwd(); + $this->publicPath = $this->basePath; } /** * @return Application */ - public function getApp() + public function boot() + { + return $this->getApp(); + } + + /** + * @param $basePath + * @return static + */ + public function setBasePath($basePath) + { + $this->basePath = $basePath; + + return $this; + } + + /** + * @param $publicPath + * @return static + */ + public function setPublicPath($publicPath) + { + $this->publicPath = $publicPath; + + return $this; + } + + /** + * @param $storagePath + * @return static + */ + public function setStoragePath($storagePath) + { + $this->storagePath = $storagePath; + + return $this; + } + + /** + * @param array $config + * @return static + */ + public function setConfig(array $config) + { + $this->config = $config; + + return $this; + } + + protected function getConfig() + { + if (empty($this->config) && file_exists($file = $this->basePath.'/config.php')) { + $this->config = include $file; + } + + return $this->config; + } + + /** + * @return Application + */ + protected function getApp() { if ($this->app !== null) { return $this->app; @@ -160,25 +154,28 @@ abstract class AbstractServer } $app->instance('env', 'production'); - $app->instance('flarum.config', $this->config); + $app->instance('flarum.config', $this->getConfig()); $app->instance('config', $config = $this->getIlluminateConfig($app)); $this->registerLogger($app); $this->registerCache($app); - $app->register('Flarum\Database\DatabaseServiceProvider'); - $app->register('Flarum\Settings\SettingsServiceProvider'); - $app->register('Flarum\Locale\LocaleServiceProvider'); - $app->register('Illuminate\Bus\BusServiceProvider'); - $app->register('Illuminate\Filesystem\FilesystemServiceProvider'); - $app->register('Illuminate\Hashing\HashServiceProvider'); - $app->register('Illuminate\Mail\MailServiceProvider'); - $app->register('Illuminate\View\ViewServiceProvider'); - $app->register('Illuminate\Validation\ValidationServiceProvider'); + $app->register(DatabaseServiceProvider::class); + $app->register(MigrationServiceProvider::class); + $app->register(SettingsServiceProvider::class); + $app->register(LocaleServiceProvider::class); + $app->register(BusServiceProvider::class); + $app->register(FilesystemServiceProvider::class); + $app->register(HashServiceProvider::class); + $app->register(MailServiceProvider::class); + $app->register(ViewServiceProvider::class); + $app->register(ValidationServiceProvider::class); + + $app->register(BusProvider::class); if ($app->isInstalled() && $app->isUpToDate()) { - $settings = $app->make('Flarum\Settings\SettingsRepositoryInterface'); + $settings = $app->make(SettingsRepositoryInterface::class); $config->set('mail.driver', $settings->get('mail_driver')); $config->set('mail.host', $settings->get('mail_host')); @@ -189,16 +186,24 @@ abstract class AbstractServer $config->set('mail.username', $settings->get('mail_username')); $config->set('mail.password', $settings->get('mail_password')); - $app->register('Flarum\Core\CoreServiceProvider'); - $app->register('Flarum\Api\ApiServiceProvider'); - $app->register('Flarum\Forum\ForumServiceProvider'); - $app->register('Flarum\Admin\AdminServiceProvider'); + $app->register(DiscussionServiceProvider::class); + $app->register(FormatterServiceProvider::class); + $app->register(GroupServiceProvider::class); + $app->register(NotificationServiceProvider::class); + $app->register(PostServiceProvider::class); + $app->register(SearchServiceProvider::class); + $app->register(UserServiceProvider::class); - foreach ($this->extendCallbacks as $callback) { - $app->call($callback); + $app->register(ApiServiceProvider::class); + $app->register(ForumServiceProvider::class); + $app->register(AdminServiceProvider::class); + + foreach ($this->extenders as $extender) { + // TODO: Create extenders architecture + // $extender->apply($app); } - $app->register('Flarum\Extension\ExtensionServiceProvider'); + $app->register(ExtensionServiceProvider::class); } $app->boot(); diff --git a/framework/core/src/Core/Exception/ValidationException.php b/framework/core/src/Foundation/ValidationException.php similarity index 96% rename from framework/core/src/Core/Exception/ValidationException.php rename to framework/core/src/Foundation/ValidationException.php index 51c33f653..84cf53084 100644 --- a/framework/core/src/Core/Exception/ValidationException.php +++ b/framework/core/src/Foundation/ValidationException.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Exception; +namespace Flarum\Foundation; use Exception; diff --git a/framework/core/src/Http/WebApp/AbstractWebApp.php b/framework/core/src/Frontend/AbstractFrontend.php similarity index 81% rename from framework/core/src/Http/WebApp/AbstractWebApp.php rename to framework/core/src/Frontend/AbstractFrontend.php index 68f9b80f5..94c480a9c 100644 --- a/framework/core/src/Http/WebApp/AbstractWebApp.php +++ b/framework/core/src/Frontend/AbstractFrontend.php @@ -9,20 +9,20 @@ * file that was distributed with this source code. */ -namespace Flarum\Http\WebApp; +namespace Flarum\Frontend; use Flarum\Locale\LocaleManager; use Flarum\Settings\SettingsRepositoryInterface; -abstract class AbstractWebApp +abstract class AbstractFrontend { /** - * @var WebAppAssetsFactory + * @var FrontendAssetsFactory */ protected $assets; /** - * @var WebAppViewFactory + * @var FrontendViewFactory */ protected $view; @@ -37,12 +37,12 @@ abstract class AbstractWebApp protected $locales; /** - * @param WebAppAssetsFactory $assets - * @param WebAppViewFactory $view + * @param FrontendAssetsFactory $assets + * @param FrontendViewFactory $view * @param SettingsRepositoryInterface $settings * @param LocaleManager $locales */ - public function __construct(WebAppAssetsFactory $assets, WebAppViewFactory $view, SettingsRepositoryInterface $settings, LocaleManager $locales) + public function __construct(FrontendAssetsFactory $assets, FrontendViewFactory $view, SettingsRepositoryInterface $settings, LocaleManager $locales) { $this->assets = $assets; $this->view = $view; @@ -51,7 +51,7 @@ abstract class AbstractWebApp } /** - * @return WebAppView + * @return FrontendView */ public function getView() { @@ -65,7 +65,7 @@ abstract class AbstractWebApp } /** - * @return WebAppAssets + * @return FrontendAssets */ public function getAssets() { @@ -86,7 +86,7 @@ abstract class AbstractWebApp */ protected function getLayout() { - return 'flarum::frontend.'.$this->getName(); + return 'flarum.forum::'.$this->getName(); } /** @@ -100,11 +100,11 @@ abstract class AbstractWebApp } /** - * @param WebAppView $view + * @param FrontendView $view */ - private function addDefaultAssets(WebAppView $view) + private function addDefaultAssets(FrontendView $view) { - $root = __DIR__.'/../../..'; + $root = __DIR__.'/../..'; $name = $this->getName(); $view->getJs()->addFile("$root/js/$name/dist/app.js"); @@ -112,9 +112,9 @@ abstract class AbstractWebApp } /** - * @param WebAppView $view + * @param FrontendView $view */ - private function addCustomLess(WebAppView $view) + private function addCustomLess(FrontendView $view) { $css = $view->getCss(); $localeCss = $view->getLocaleCss(); @@ -150,11 +150,11 @@ abstract class AbstractWebApp } /** - * @param WebAppView $view + * @param FrontendView $view */ - private function addTranslations(WebAppView $view) + private function addTranslations(FrontendView $view) { - $translations = array_get($this->locales->getTranslator()->getMessages(), 'messages', []); + $translations = array_get($this->locales->getTranslator()->getCatalogue()->all(), 'messages', []); $translations = $this->filterTranslations($translations); diff --git a/framework/core/src/Http/Controller/AbstractWebAppController.php b/framework/core/src/Frontend/AbstractFrontendController.php similarity index 75% rename from framework/core/src/Http/Controller/AbstractWebAppController.php rename to framework/core/src/Frontend/AbstractFrontendController.php index a9af1f576..cd7eba06b 100644 --- a/framework/core/src/Http/Controller/AbstractWebAppController.php +++ b/framework/core/src/Frontend/AbstractFrontendController.php @@ -9,18 +9,18 @@ * file that was distributed with this source code. */ -namespace Flarum\Http\Controller; +namespace Flarum\Frontend; use Flarum\Event\ConfigureClientView; -use Flarum\Event\ConfigureWebApp; -use Flarum\Http\WebApp\AbstractWebApp; +use Flarum\Frontend\Event\Rendering; +use Flarum\Http\Controller\AbstractHtmlController; use Illuminate\Contracts\Events\Dispatcher; use Psr\Http\Message\ServerRequestInterface as Request; -abstract class AbstractWebAppController extends AbstractHtmlController +abstract class AbstractFrontendController extends AbstractHtmlController { /** - * @var AbstractWebApp + * @var AbstractFrontend */ protected $webApp; @@ -40,7 +40,7 @@ abstract class AbstractWebAppController extends AbstractHtmlController new ConfigureClientView($this, $view, $request) ); $this->events->fire( - new ConfigureWebApp($this, $view, $request) + new Rendering($this, $view, $request) ); return $view->render($request); @@ -48,7 +48,7 @@ abstract class AbstractWebAppController extends AbstractHtmlController /** * @param Request $request - * @return \Flarum\Http\WebApp\WebAppView + * @return \Flarum\Frontend\FrontendView */ protected function getView(Request $request) { diff --git a/framework/core/src/Asset/CompilerInterface.php b/framework/core/src/Frontend/Asset/CompilerInterface.php similarity index 95% rename from framework/core/src/Asset/CompilerInterface.php rename to framework/core/src/Frontend/Asset/CompilerInterface.php index 5e65eb596..2fb113ab5 100644 --- a/framework/core/src/Asset/CompilerInterface.php +++ b/framework/core/src/Frontend/Asset/CompilerInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Asset; +namespace Flarum\Frontend\Asset; interface CompilerInterface { diff --git a/framework/core/src/Asset/JsCompiler.php b/framework/core/src/Frontend/Asset/JsCompiler.php similarity index 98% rename from framework/core/src/Asset/JsCompiler.php rename to framework/core/src/Frontend/Asset/JsCompiler.php index 55771ead5..f99880a19 100644 --- a/framework/core/src/Asset/JsCompiler.php +++ b/framework/core/src/Frontend/Asset/JsCompiler.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Asset; +namespace Flarum\Frontend\Asset; use Exception; use Illuminate\Cache\Repository; diff --git a/framework/core/src/Asset/LessCompiler.php b/framework/core/src/Frontend/Asset/LessCompiler.php similarity index 97% rename from framework/core/src/Asset/LessCompiler.php rename to framework/core/src/Frontend/Asset/LessCompiler.php index d498b08d9..4a5990778 100644 --- a/framework/core/src/Asset/LessCompiler.php +++ b/framework/core/src/Frontend/Asset/LessCompiler.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Asset; +namespace Flarum\Frontend\Asset; use Less_Exception_Parser; use Less_Parser; diff --git a/framework/core/src/Locale/JsCompiler.php b/framework/core/src/Frontend/Asset/LocaleJsCompiler.php similarity index 88% rename from framework/core/src/Locale/JsCompiler.php rename to framework/core/src/Frontend/Asset/LocaleJsCompiler.php index db1d0b1e5..87b3d52a2 100644 --- a/framework/core/src/Locale/JsCompiler.php +++ b/framework/core/src/Frontend/Asset/LocaleJsCompiler.php @@ -9,11 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Locale; +namespace Flarum\Frontend\Asset; -use Flarum\Asset\JsCompiler as BaseJsCompiler; - -class JsCompiler extends BaseJsCompiler +class LocaleJsCompiler extends JsCompiler { protected $translations = []; diff --git a/framework/core/src/Asset/RevisionCompiler.php b/framework/core/src/Frontend/Asset/RevisionCompiler.php similarity index 99% rename from framework/core/src/Asset/RevisionCompiler.php rename to framework/core/src/Frontend/Asset/RevisionCompiler.php index 9911c5b11..18889a905 100644 --- a/framework/core/src/Asset/RevisionCompiler.php +++ b/framework/core/src/Frontend/Asset/RevisionCompiler.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Asset; +namespace Flarum\Frontend\Asset; class RevisionCompiler implements CompilerInterface { diff --git a/framework/core/src/Event/ConfigureWebApp.php b/framework/core/src/Frontend/Event/Rendering.php similarity index 64% rename from framework/core/src/Event/ConfigureWebApp.php rename to framework/core/src/Frontend/Event/Rendering.php index a4d1b71ee..a5d81c949 100644 --- a/framework/core/src/Event/ConfigureWebApp.php +++ b/framework/core/src/Frontend/Event/Rendering.php @@ -9,23 +9,23 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Frontend\Event; -use Flarum\Admin\Controller\WebAppController as AdminWebAppController; -use Flarum\Forum\Controller\WebAppController as ForumWebAppController; -use Flarum\Http\Controller\AbstractWebAppController; -use Flarum\Http\WebApp\WebAppView; +use Flarum\Admin\Controller\FrontendController as AdminFrontendController; +use Flarum\Forum\Controller\FrontendController as ForumFrontendController; +use Flarum\Frontend\AbstractFrontendController; +use Flarum\Frontend\FrontendView; use Psr\Http\Message\ServerRequestInterface; -class ConfigureWebApp +class Rendering { /** - * @var AbstractWebAppController + * @var AbstractFrontendController */ public $controller; /** - * @var WebAppView + * @var FrontendView */ public $view; @@ -35,11 +35,11 @@ class ConfigureWebApp public $request; /** - * @param AbstractWebAppController $controller - * @param WebAppView $view + * @param AbstractFrontendController $controller + * @param FrontendView $view * @param ServerRequestInterface $request */ - public function __construct(AbstractWebAppController $controller, WebAppView $view, ServerRequestInterface $request) + public function __construct(AbstractFrontendController $controller, FrontendView $view, ServerRequestInterface $request) { $this->controller = $controller; $this->view = $view; @@ -48,12 +48,12 @@ class ConfigureWebApp public function isForum() { - return $this->controller instanceof ForumWebAppController; + return $this->controller instanceof ForumFrontendController; } public function isAdmin() { - return $this->controller instanceof AdminWebAppController; + return $this->controller instanceof AdminFrontendController; } public function addAssets($files) diff --git a/framework/core/src/Http/WebApp/WebAppAssets.php b/framework/core/src/Frontend/FrontendAssets.php similarity index 94% rename from framework/core/src/Http/WebApp/WebAppAssets.php rename to framework/core/src/Frontend/FrontendAssets.php index 92a7539be..277b39547 100644 --- a/framework/core/src/Http/WebApp/WebAppAssets.php +++ b/framework/core/src/Frontend/FrontendAssets.php @@ -9,16 +9,16 @@ * file that was distributed with this source code. */ -namespace Flarum\Http\WebApp; +namespace Flarum\Frontend; -use Flarum\Asset\JsCompiler; -use Flarum\Asset\LessCompiler; use Flarum\Foundation\Application; -use Flarum\Locale\JsCompiler as LocaleJsCompiler; +use Flarum\Frontend\Asset\JsCompiler; +use Flarum\Frontend\Asset\LessCompiler; +use Flarum\Frontend\Asset\LocaleJsCompiler as LocaleJsCompiler; use Flarum\Locale\LocaleManager; use Illuminate\Contracts\Cache\Repository; -class WebAppAssets +class FrontendAssets { /** * @var string diff --git a/framework/core/src/Http/WebApp/WebAppAssetsFactory.php b/framework/core/src/Frontend/FrontendAssetsFactory.php similarity index 84% rename from framework/core/src/Http/WebApp/WebAppAssetsFactory.php rename to framework/core/src/Frontend/FrontendAssetsFactory.php index cb32ed30f..781963c41 100644 --- a/framework/core/src/Http/WebApp/WebAppAssetsFactory.php +++ b/framework/core/src/Frontend/FrontendAssetsFactory.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -namespace Flarum\Http\WebApp; +namespace Flarum\Frontend; use Flarum\Foundation\Application; use Flarum\Locale\LocaleManager; use Illuminate\Contracts\Cache\Repository; -class WebAppAssetsFactory +class FrontendAssetsFactory { /** * @var Application @@ -46,10 +46,10 @@ class WebAppAssetsFactory /** * @param string $name - * @return WebAppAssets + * @return FrontendAssets */ public function make($name) { - return new WebAppAssets($name, $this->app, $this->cache, $this->locales); + return new FrontendAssets($name, $this->app, $this->cache, $this->locales); } } diff --git a/framework/core/src/Api/UrlGenerator.php b/framework/core/src/Frontend/FrontendServiceProvider.php similarity index 52% rename from framework/core/src/Api/UrlGenerator.php rename to framework/core/src/Frontend/FrontendServiceProvider.php index 71dfbfc40..aa4ba6064 100644 --- a/framework/core/src/Api/UrlGenerator.php +++ b/framework/core/src/Frontend/FrontendServiceProvider.php @@ -9,14 +9,17 @@ * file that was distributed with this source code. */ -namespace Flarum\Api; +namespace Flarum\Frontend; -use Flarum\Http\AbstractUrlGenerator; +use Flarum\Foundation\AbstractServiceProvider; -class UrlGenerator extends AbstractUrlGenerator +class FrontendServiceProvider extends AbstractServiceProvider { /** * {@inheritdoc} */ - protected $path = 'api'; + public function boot() + { + $this->loadViewsFrom(__DIR__.'/../../views', 'flarum'); + } } diff --git a/framework/core/src/Http/WebApp/WebAppView.php b/framework/core/src/Frontend/FrontendView.php similarity index 95% rename from framework/core/src/Http/WebApp/WebAppView.php rename to framework/core/src/Frontend/FrontendView.php index 78af25540..05bd9f3e9 100644 --- a/framework/core/src/Http/WebApp/WebAppView.php +++ b/framework/core/src/Frontend/FrontendView.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -namespace Flarum\Http\WebApp; +namespace Flarum\Frontend; use Flarum\Api\Client; use Flarum\Api\Serializer\AbstractSerializer; -use Flarum\Asset\CompilerInterface; use Flarum\Foundation\Application; -use Flarum\Locale\JsCompiler; +use Flarum\Frontend\Asset\CompilerInterface; +use Flarum\Frontend\Asset\LocaleJsCompiler; use Flarum\Locale\LocaleManager; use Illuminate\View\Factory; use Psr\Http\Message\ServerRequestInterface as Request; @@ -25,7 +25,7 @@ use Tobscure\JsonApi\Resource; /** * This class represents a view which boots up Flarum's client. */ -class WebAppView +class FrontendView { /** * The title of the document, displayed in the