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 tag. @@ -135,7 +135,7 @@ class WebAppView protected $localeCss; /** - * @var WebAppAssets + * @var FrontendAssets */ protected $assets; @@ -166,14 +166,14 @@ class WebAppView /** * @param string $layout - * @param WebAppAssets $assets + * @param FrontendAssets $assets * @param Client $api * @param Factory $view * @param LocaleManager $locales * @param AbstractSerializer $userSerializer * @param Application $app */ - public function __construct($layout, WebAppAssets $assets, Client $api, Factory $view, LocaleManager $locales, AbstractSerializer $userSerializer, Application $app) + public function __construct($layout, FrontendAssets $assets, Client $api, Factory $view, LocaleManager $locales, AbstractSerializer $userSerializer, Application $app) { $this->layout = $layout; $this->api = $api; @@ -287,7 +287,7 @@ class WebAppView $this->view->share('forum', array_get($forum, 'data')); $this->view->share('debug', $this->app->inDebugMode()); - $view = $this->view->make('flarum::frontend.app'); + $view = $this->view->make('flarum.forum::app'); $view->title = $this->buildTitle(array_get($forum, 'data.attributes.title')); $view->description = $this->description ?: array_get($forum, 'data.attributes.description'); @@ -345,7 +345,7 @@ class WebAppView protected function buildContent() { - $view = $this->view->make('flarum::frontend.content'); + $view = $this->view->make('flarum.forum::content'); $view->content = $this->content; @@ -397,7 +397,7 @@ class WebAppView } /** - * @return JsCompiler + * @return LocaleJsCompiler */ public function getLocaleJs() { diff --git a/framework/core/src/Http/WebApp/WebAppViewFactory.php b/framework/core/src/Frontend/FrontendViewFactory.php similarity index 81% rename from framework/core/src/Http/WebApp/WebAppViewFactory.php rename to framework/core/src/Frontend/FrontendViewFactory.php index 037a162e9..82682c22a 100644 --- a/framework/core/src/Http/WebApp/WebAppViewFactory.php +++ b/framework/core/src/Frontend/FrontendViewFactory.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Http\WebApp; +namespace Flarum\Frontend; use Flarum\Api\Client; use Flarum\Api\Serializer\CurrentUserSerializer; @@ -17,7 +17,7 @@ use Flarum\Foundation\Application; use Flarum\Locale\LocaleManager; use Illuminate\Contracts\View\Factory; -class WebAppViewFactory +class FrontendViewFactory { /** * @var Client @@ -62,11 +62,11 @@ class WebAppViewFactory /** * @param string $layout - * @param WebAppAssets $assets - * @return WebAppView + * @param FrontendAssets $assets + * @return FrontendView */ - public function make($layout, WebAppAssets $assets) + public function make($layout, FrontendAssets $assets) { - return new WebAppView($layout, $assets, $this->api, $this->view, $this->locales, $this->userSerializer, $this->app); + return new FrontendView($layout, $assets, $this->api, $this->view, $this->locales, $this->userSerializer, $this->app); } } diff --git a/framework/core/src/Core/Command/CreateGroup.php b/framework/core/src/Group/Command/CreateGroup.php similarity index 92% rename from framework/core/src/Core/Command/CreateGroup.php rename to framework/core/src/Group/Command/CreateGroup.php index 9ed912ce7..e20fb6154 100644 --- a/framework/core/src/Core/Command/CreateGroup.php +++ b/framework/core/src/Group/Command/CreateGroup.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Group\Command; -use Flarum\Core\User; +use Flarum\User\User; class CreateGroup { diff --git a/framework/core/src/Core/Command/CreateGroupHandler.php b/framework/core/src/Group/Command/CreateGroupHandler.php similarity index 73% rename from framework/core/src/Core/Command/CreateGroupHandler.php rename to framework/core/src/Group/Command/CreateGroupHandler.php index fce5fd598..e18ac566b 100644 --- a/framework/core/src/Core/Command/CreateGroupHandler.php +++ b/framework/core/src/Group/Command/CreateGroupHandler.php @@ -9,14 +9,13 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Group\Command; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\Group; -use Flarum\Core\Support\DispatchEventsTrait; -use Flarum\Core\Validator\GroupValidator; -use Flarum\Event\GroupWillBeSaved; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\Group\Event\Saving; +use Flarum\Group\Group; +use Flarum\Group\GroupValidator; +use Flarum\User\AssertPermissionTrait; use Illuminate\Contracts\Events\Dispatcher; class CreateGroupHandler @@ -25,13 +24,13 @@ class CreateGroupHandler use AssertPermissionTrait; /** - * @var GroupValidator + * @var \Flarum\Group\GroupValidator */ protected $validator; /** * @param Dispatcher $events - * @param GroupValidator $validator + * @param \Flarum\Group\GroupValidator $validator */ public function __construct(Dispatcher $events, GroupValidator $validator) { @@ -41,8 +40,8 @@ class CreateGroupHandler /** * @param CreateGroup $command - * @return Group - * @throws PermissionDeniedException + * @return \Flarum\Group\Group + * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(CreateGroup $command) { @@ -59,7 +58,7 @@ class CreateGroupHandler ); $this->events->fire( - new GroupWillBeSaved($group, $actor, $data) + new Saving($group, $actor, $data) ); $this->validator->assertValid($group->getAttributes()); diff --git a/framework/core/src/Core/Command/DeleteGroup.php b/framework/core/src/Group/Command/DeleteGroup.php similarity index 95% rename from framework/core/src/Core/Command/DeleteGroup.php rename to framework/core/src/Group/Command/DeleteGroup.php index 2f9c6a574..b2bb6873e 100644 --- a/framework/core/src/Core/Command/DeleteGroup.php +++ b/framework/core/src/Group/Command/DeleteGroup.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Group\Command; -use Flarum\Core\User; +use Flarum\User\User; class DeleteGroup { diff --git a/framework/core/src/Core/Command/DeleteGroupHandler.php b/framework/core/src/Group/Command/DeleteGroupHandler.php similarity index 75% rename from framework/core/src/Core/Command/DeleteGroupHandler.php rename to framework/core/src/Group/Command/DeleteGroupHandler.php index 7592eb97b..568f92802 100644 --- a/framework/core/src/Core/Command/DeleteGroupHandler.php +++ b/framework/core/src/Group/Command/DeleteGroupHandler.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Group\Command; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\Repository\GroupRepository; -use Flarum\Core\Support\DispatchEventsTrait; -use Flarum\Event\GroupWillBeDeleted; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\Group\Event\Deleting; +use Flarum\Group\GroupRepository; +use Flarum\User\AssertPermissionTrait; +use Flarum\User\Exception\PermissionDeniedException; use Illuminate\Contracts\Events\Dispatcher; class DeleteGroupHandler @@ -39,7 +39,7 @@ class DeleteGroupHandler /** * @param DeleteGroup $command - * @return \Flarum\Core\Group + * @return \Flarum\Group\Group * @throws PermissionDeniedException */ public function handle(DeleteGroup $command) @@ -51,7 +51,7 @@ class DeleteGroupHandler $this->assertCan($actor, 'delete', $group); $this->events->fire( - new GroupWillBeDeleted($group, $actor, $command->data) + new Deleting($group, $actor, $command->data) ); $group->delete(); diff --git a/framework/core/src/Core/Command/EditGroup.php b/framework/core/src/Group/Command/EditGroup.php similarity index 94% rename from framework/core/src/Core/Command/EditGroup.php rename to framework/core/src/Group/Command/EditGroup.php index 233843a8c..e64cb9913 100644 --- a/framework/core/src/Core/Command/EditGroup.php +++ b/framework/core/src/Group/Command/EditGroup.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Group\Command; -use Flarum\Core\User; +use Flarum\User\User; class EditGroup { diff --git a/framework/core/src/Core/Command/EditGroupHandler.php b/framework/core/src/Group/Command/EditGroupHandler.php similarity index 81% rename from framework/core/src/Core/Command/EditGroupHandler.php rename to framework/core/src/Group/Command/EditGroupHandler.php index 0f2ad59af..d82020328 100644 --- a/framework/core/src/Core/Command/EditGroupHandler.php +++ b/framework/core/src/Group/Command/EditGroupHandler.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Group\Command; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\Group; -use Flarum\Core\Repository\GroupRepository; -use Flarum\Core\Support\DispatchEventsTrait; -use Flarum\Core\Validator\GroupValidator; -use Flarum\Event\GroupWillBeSaved; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\Group\Event\Saving; +use Flarum\Group\Group; +use Flarum\Group\GroupRepository; +use Flarum\Group\GroupValidator; +use Flarum\User\AssertPermissionTrait; +use Flarum\User\Exception\PermissionDeniedException; use Illuminate\Contracts\Events\Dispatcher; class EditGroupHandler @@ -26,7 +26,7 @@ class EditGroupHandler use AssertPermissionTrait; /** - * @var GroupRepository + * @var \Flarum\Group\GroupRepository */ protected $groups; @@ -76,7 +76,7 @@ class EditGroupHandler } $this->events->fire( - new GroupWillBeSaved($group, $actor, $data) + new Saving($group, $actor, $data) ); $this->validator->assertValid($group->getDirty()); diff --git a/framework/core/src/Event/GroupWasDeleted.php b/framework/core/src/Group/Event/Created.php similarity index 81% rename from framework/core/src/Event/GroupWasDeleted.php rename to framework/core/src/Group/Event/Created.php index 21600c175..109c615d6 100644 --- a/framework/core/src/Event/GroupWasDeleted.php +++ b/framework/core/src/Group/Event/Created.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Group\Event; -use Flarum\Core\Group; -use Flarum\Core\User; +use Flarum\Group\Group; +use Flarum\User\User; -class GroupWasDeleted +class Created { /** - * @var Group + * @var \Flarum\Group\Group */ public $group; diff --git a/framework/core/src/Event/GroupWasCreated.php b/framework/core/src/Group/Event/Deleted.php similarity index 75% rename from framework/core/src/Event/GroupWasCreated.php rename to framework/core/src/Group/Event/Deleted.php index a4e5f7536..6fbc5fbc1 100644 --- a/framework/core/src/Event/GroupWasCreated.php +++ b/framework/core/src/Group/Event/Deleted.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Group\Event; -use Flarum\Core\Group; -use Flarum\Core\User; +use Flarum\Group\Group; +use Flarum\User\User; -class GroupWasCreated +class Deleted { /** - * @var Group + * @var \Flarum\Group\Group */ public $group; @@ -27,7 +27,7 @@ class GroupWasCreated public $actor; /** - * @param Group $group + * @param \Flarum\Group\Group $group * @param User $actor */ public function __construct(Group $group, User $actor = null) diff --git a/framework/core/src/Event/GroupWillBeDeleted.php b/framework/core/src/Group/Event/Deleting.php similarity index 90% rename from framework/core/src/Event/GroupWillBeDeleted.php rename to framework/core/src/Group/Event/Deleting.php index 3b8955a83..1c91063e1 100644 --- a/framework/core/src/Event/GroupWillBeDeleted.php +++ b/framework/core/src/Group/Event/Deleting.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Group\Event; -use Flarum\Core\Group; -use Flarum\Core\User; +use Flarum\Group\Group; +use Flarum\User\User; -class GroupWillBeDeleted +class Deleting { /** * The group that will be deleted. diff --git a/framework/core/src/Event/GroupWasRenamed.php b/framework/core/src/Group/Event/Renamed.php similarity index 75% rename from framework/core/src/Event/GroupWasRenamed.php rename to framework/core/src/Group/Event/Renamed.php index 30034f2be..c9c201872 100644 --- a/framework/core/src/Event/GroupWasRenamed.php +++ b/framework/core/src/Group/Event/Renamed.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Group\Event; -use Flarum\Core\Group; -use Flarum\Core\User; +use Flarum\Group\Group; +use Flarum\User\User; -class GroupWasRenamed +class Renamed { /** - * @var Group + * @var \Flarum\Group\Group */ public $group; @@ -27,7 +27,7 @@ class GroupWasRenamed public $actor; /** - * @param Group $group + * @param \Flarum\Group\Group $group * @param User $actor */ public function __construct(Group $group, User $actor = null) diff --git a/framework/core/src/Event/GroupWillBeSaved.php b/framework/core/src/Group/Event/Saving.php similarity index 88% rename from framework/core/src/Event/GroupWillBeSaved.php rename to framework/core/src/Group/Event/Saving.php index 51df92592..2dd019dca 100644 --- a/framework/core/src/Event/GroupWillBeSaved.php +++ b/framework/core/src/Group/Event/Saving.php @@ -9,17 +9,17 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Group\Event; -use Flarum\Core\Group; -use Flarum\Core\User; +use Flarum\Group\Group; +use Flarum\User\User; -class GroupWillBeSaved +class Saving { /** * The group that will be saved. * - * @var Group + * @var \Flarum\Group\Group */ public $group; diff --git a/framework/core/src/Core/Group.php b/framework/core/src/Group/Group.php similarity index 83% rename from framework/core/src/Core/Group.php rename to framework/core/src/Group/Group.php index ad265e6f0..14daf1b69 100755 --- a/framework/core/src/Core/Group.php +++ b/framework/core/src/Group/Group.php @@ -9,14 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\Group; -use Flarum\Core\Support\EventGeneratorTrait; -use Flarum\Core\Support\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; -use Flarum\Event\GroupWasCreated; -use Flarum\Event\GroupWasDeleted; -use Flarum\Event\GroupWasRenamed; +use Flarum\Database\ScopeVisibilityTrait; +use Flarum\Foundation\EventGeneratorTrait; +use Flarum\Group\Event\Created; +use Flarum\Group\Event\Deleted; +use Flarum\Group\Event\Renamed; +use Flarum\User\User; /** * @property int $id @@ -67,7 +68,7 @@ class Group extends AbstractModel parent::boot(); static::deleted(function (Group $group) { - $group->raise(new GroupWasDeleted($group)); + $group->raise(new Deleted($group)); $group->permissions()->delete(); }); @@ -91,7 +92,7 @@ class Group extends AbstractModel $group->color = $color; $group->icon = $icon; - $group->raise(new GroupWasCreated($group)); + $group->raise(new Created($group)); return $group; } @@ -108,7 +109,7 @@ class Group extends AbstractModel $this->name_singular = $nameSingular; $this->name_plural = $namePlural; - $this->raise(new GroupWasRenamed($this)); + $this->raise(new Renamed($this)); return $this; } @@ -120,7 +121,7 @@ class Group extends AbstractModel */ public function users() { - return $this->belongsToMany('Flarum\Core\User', 'users_groups'); + return $this->belongsToMany(User::class, 'users_groups'); } /** @@ -130,6 +131,6 @@ class Group extends AbstractModel */ public function permissions() { - return $this->hasMany('Flarum\Core\Permission'); + return $this->hasMany(Permission::class); } } diff --git a/framework/core/src/Core/Access/GroupPolicy.php b/framework/core/src/Group/GroupPolicy.php similarity index 88% rename from framework/core/src/Core/Access/GroupPolicy.php rename to framework/core/src/Group/GroupPolicy.php index 097077335..91af563a8 100644 --- a/framework/core/src/Core/Access/GroupPolicy.php +++ b/framework/core/src/Group/GroupPolicy.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Access; +namespace Flarum\Group; -use Flarum\Core\Group; -use Flarum\Core\User; +use Flarum\User\AbstractPolicy; +use Flarum\User\User; class GroupPolicy extends AbstractPolicy { diff --git a/framework/core/src/Core/Repository/GroupRepository.php b/framework/core/src/Group/GroupRepository.php similarity index 94% rename from framework/core/src/Core/Repository/GroupRepository.php rename to framework/core/src/Group/GroupRepository.php index 658c3739b..4372fa560 100644 --- a/framework/core/src/Core/Repository/GroupRepository.php +++ b/framework/core/src/Group/GroupRepository.php @@ -9,10 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Repository; +namespace Flarum\Group; -use Flarum\Core\Group; -use Flarum\Core\User; +use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; class GroupRepository @@ -33,7 +32,7 @@ class GroupRepository * * @param int $id * @param User $actor - * @return Group + * @return \Flarum\Group\Group * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ diff --git a/framework/core/src/Admin/UrlGenerator.php b/framework/core/src/Group/GroupServiceProvider.php similarity index 50% rename from framework/core/src/Admin/UrlGenerator.php rename to framework/core/src/Group/GroupServiceProvider.php index efa1a8a45..ad923df9f 100644 --- a/framework/core/src/Admin/UrlGenerator.php +++ b/framework/core/src/Group/GroupServiceProvider.php @@ -9,14 +9,18 @@ * file that was distributed with this source code. */ -namespace Flarum\Admin; +namespace Flarum\Group; -use Flarum\Http\AbstractUrlGenerator; +use Flarum\Foundation\AbstractServiceProvider; -class UrlGenerator extends AbstractUrlGenerator +class GroupServiceProvider extends AbstractServiceProvider { /** * {@inheritdoc} */ - protected $path = 'admin'; + public function boot() + { + $events = $this->app->make('events'); + $events->subscribe(GroupPolicy::class); + } } diff --git a/framework/core/src/Core/Validator/GroupValidator.php b/framework/core/src/Group/GroupValidator.php similarity index 85% rename from framework/core/src/Core/Validator/GroupValidator.php rename to framework/core/src/Group/GroupValidator.php index a66f52dd4..58d8aee16 100644 --- a/framework/core/src/Core/Validator/GroupValidator.php +++ b/framework/core/src/Group/GroupValidator.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Validator; +namespace Flarum\Group; + +use Flarum\Foundation\AbstractValidator; class GroupValidator extends AbstractValidator { diff --git a/framework/core/src/Core/Permission.php b/framework/core/src/Group/Permission.php similarity index 93% rename from framework/core/src/Core/Permission.php rename to framework/core/src/Group/Permission.php index 21bd7d88a..110c365b0 100755 --- a/framework/core/src/Core/Permission.php +++ b/framework/core/src/Group/Permission.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\Group; use Flarum\Database\AbstractModel; use Illuminate\Database\Eloquent\Builder; @@ -31,7 +31,7 @@ class Permission extends AbstractModel */ public function group() { - return $this->belongsTo('Flarum\Core\Group', 'group_id'); + return $this->belongsTo(Group::class, 'group_id'); } /** diff --git a/framework/core/src/Http/AbstractServer.php b/framework/core/src/Http/AbstractServer.php deleted file mode 100644 index ae676755a..000000000 --- a/framework/core/src/Http/AbstractServer.php +++ /dev/null @@ -1,81 +0,0 @@ -<?php - -/* - * This file is part of Flarum. - * - * (c) Toby Zerner <toby.zerner@gmail.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Flarum\Http; - -use Flarum\Core\AuthToken; -use Flarum\Core\EmailToken; -use Flarum\Core\PasswordToken; -use Flarum\Foundation\AbstractServer as BaseAbstractServer; -use Flarum\Foundation\Application; -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface; -use Zend\Diactoros\Server; -use Zend\Stratigility\MiddlewareInterface; -use Zend\Stratigility\NoopFinalHandler; - -abstract class AbstractServer extends BaseAbstractServer -{ - public function listen() - { - Server::createServer( - $this, - $_SERVER, - $_GET, - $_POST, - $_COOKIE, - $_FILES - )->listen(new NoopFinalHandler()); - } - - /** - * Use as PSR-7 middleware. - * - * @param ServerRequestInterface $request - * @param ResponseInterface $response - * @param callable $out - * @return ResponseInterface - */ - public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out) - { - $app = $this->getApp(); - - $this->collectGarbage($app); - - $middleware = $this->getMiddleware($app); - - return $middleware($request, $response, $out); - } - - /** - * @param Application $app - * @return MiddlewareInterface - */ - abstract protected function getMiddleware(Application $app); - - private function collectGarbage() - { - if ($this->hitsLottery()) { - AccessToken::whereRaw('last_activity <= ? - lifetime', [time()])->delete(); - - $earliestToKeep = date('Y-m-d H:i:s', time() - 24 * 60 * 60); - - EmailToken::where('created_at', '<=', $earliestToKeep)->delete(); - PasswordToken::where('created_at', '<=', $earliestToKeep)->delete(); - AuthToken::where('created_at', '<=', $earliestToKeep)->delete(); - } - } - - private function hitsLottery() - { - return mt_rand(1, 100) <= 2; - } -} diff --git a/framework/core/src/Http/AccessToken.php b/framework/core/src/Http/AccessToken.php index 45557f3c8..dad24ae3b 100644 --- a/framework/core/src/Http/AccessToken.php +++ b/framework/core/src/Http/AccessToken.php @@ -18,7 +18,7 @@ use Flarum\Database\AbstractModel; * @property int $user_id * @property int $last_activity * @property int $lifetime - * @property \Flarum\Core\User|null $user + * @property \Flarum\User\User|null $user */ class AccessToken extends AbstractModel { @@ -67,6 +67,6 @@ class AccessToken extends AbstractModel */ public function user() { - return $this->belongsTo('Flarum\Core\User'); + return $this->belongsTo('Flarum\User\User'); } } diff --git a/framework/core/src/Http/Handler/ControllerRouteHandler.php b/framework/core/src/Http/ControllerRouteHandler.php similarity index 98% rename from framework/core/src/Http/Handler/ControllerRouteHandler.php rename to framework/core/src/Http/ControllerRouteHandler.php index 6e2f4855a..b65e106de 100644 --- a/framework/core/src/Http/Handler/ControllerRouteHandler.php +++ b/framework/core/src/Http/ControllerRouteHandler.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Http\Handler; +namespace Flarum\Http; use Flarum\Http\Controller\ControllerInterface; use Illuminate\Contracts\Container\Container; diff --git a/framework/core/src/Http/FullStackServer.php b/framework/core/src/Http/FullStackServer.php deleted file mode 100644 index 70b331aba..000000000 --- a/framework/core/src/Http/FullStackServer.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -/* - * This file is part of Flarum. - * - * (c) Toby Zerner <toby.zerner@gmail.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Flarum\Http; - -use Flarum\Admin\Server as AdminServer; -use Flarum\Api\Server as ApiServer; -use Flarum\Forum\Server as ForumServer; -use Flarum\Foundation\Application; -use Zend\Stratigility\MiddlewarePipe; - -class FullStackServer extends AbstractServer -{ - /** - * @param Application $app - * @return \Zend\Stratigility\MiddlewareInterface - */ - protected function getMiddleware(Application $app) - { - $pipe = new MiddlewarePipe; - $pipe->raiseThrowables(); - - $pipe->pipe(new ApiServer); - $pipe->pipe(new AdminServer); - $pipe->pipe(new ForumServer); - - return $pipe; - } -} diff --git a/framework/core/src/Http/Middleware/AuthenticateWithHeader.php b/framework/core/src/Http/Middleware/AuthenticateWithHeader.php index dfb3f8e9c..78de30f69 100644 --- a/framework/core/src/Http/Middleware/AuthenticateWithHeader.php +++ b/framework/core/src/Http/Middleware/AuthenticateWithHeader.php @@ -12,8 +12,8 @@ namespace Flarum\Http\Middleware; use Flarum\Api\ApiKey; -use Flarum\Core\User; use Flarum\Http\AccessToken; +use Flarum\User\User; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Zend\Stratigility\MiddlewareInterface; diff --git a/framework/core/src/Http/Middleware/AuthenticateWithSession.php b/framework/core/src/Http/Middleware/AuthenticateWithSession.php index d4d0ac624..e9aee0698 100644 --- a/framework/core/src/Http/Middleware/AuthenticateWithSession.php +++ b/framework/core/src/Http/Middleware/AuthenticateWithSession.php @@ -11,8 +11,8 @@ namespace Flarum\Http\Middleware; -use Flarum\Core\Guest; -use Flarum\Core\User; +use Flarum\User\Guest; +use Flarum\User\User; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Symfony\Component\HttpFoundation\Session\SessionInterface; diff --git a/framework/core/src/Http/Middleware/CollectGarbage.php b/framework/core/src/Http/Middleware/CollectGarbage.php new file mode 100644 index 000000000..0a04da16e --- /dev/null +++ b/framework/core/src/Http/Middleware/CollectGarbage.php @@ -0,0 +1,55 @@ +<?php + +/* + * This file is part of Flarum. + * + * (c) Toby Zerner <toby.zerner@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Http\Middleware; + +use Flarum\Http\AccessToken; +use Flarum\User\AuthToken; +use Flarum\User\EmailToken; +use Flarum\User\PasswordToken; +use Psr\Http\Message\ResponseInterface as Response; +use Psr\Http\Message\ServerRequestInterface as Request; +use Zend\Stratigility\MiddlewareInterface; + +class CollectGarbage implements MiddlewareInterface +{ + /** + * {@inheritdoc} + */ + public function __invoke(Request $request, Response $response, callable $out = null) + { + $this->collectGarbageSometimes(); + + return $out ? $out($request, $response) : $response; + } + + private function collectGarbageSometimes() + { + // In order to save performance, we only execute this query + // from time to time (with 50% chance). + if (! $this->hit()) { + return; + } + + AccessToken::whereRaw('last_activity <= ? - lifetime', [time()])->delete(); + + $earliestToKeep = date('Y-m-d H:i:s', time() - 24 * 60 * 60); + + EmailToken::where('created_at', '<=', $earliestToKeep)->delete(); + PasswordToken::where('created_at', '<=', $earliestToKeep)->delete(); + AuthToken::where('created_at', '<=', $earliestToKeep)->delete(); + } + + private function hit() + { + return mt_rand(1, 100) <= 2; + } +} diff --git a/framework/core/src/Http/Middleware/HandleErrors.php b/framework/core/src/Http/Middleware/HandleErrors.php index d72b6ed81..0c8aa168f 100644 --- a/framework/core/src/Http/Middleware/HandleErrors.php +++ b/framework/core/src/Http/Middleware/HandleErrors.php @@ -51,6 +51,8 @@ class HandleErrors /** * @param ViewFactory $view * @param LoggerInterface $logger + * @param TranslatorInterface $translator + * @param SettingsRepositoryInterface $settings * @param bool $debug */ public function __construct(ViewFactory $view, LoggerInterface $logger, TranslatorInterface $translator, SettingsRepositoryInterface $settings, $debug = false) @@ -99,8 +101,8 @@ class HandleErrors // Log the exception (with trace) $this->logger->debug($error); - if (! $this->view->exists($name = 'flarum::error.'.$status)) { - $name = 'flarum::error.default'; + if (! $this->view->exists($name = 'flarum.forum::error.'.$status)) { + $name = 'flarum.forum::error.default'; } $view = $this->view->make($name) diff --git a/framework/core/src/Http/AbstractUrlGenerator.php b/framework/core/src/Http/RouteCollectionUrlGenerator.php similarity index 64% rename from framework/core/src/Http/AbstractUrlGenerator.php rename to framework/core/src/Http/RouteCollectionUrlGenerator.php index ccd0d78ef..dbcb8927e 100644 --- a/framework/core/src/Http/AbstractUrlGenerator.php +++ b/framework/core/src/Http/RouteCollectionUrlGenerator.php @@ -11,14 +11,12 @@ namespace Flarum\Http; -use Flarum\Foundation\Application; - -class AbstractUrlGenerator +class RouteCollectionUrlGenerator { /** - * @var Application + * @var string|null */ - protected $app; + protected $baseUrl; /** * @var RouteCollection @@ -26,17 +24,12 @@ class AbstractUrlGenerator protected $routes; /** - * @var string|null - */ - protected $path; - - /** - * @param Application $app + * @param string $baseUrl * @param RouteCollection $routes */ - public function __construct(Application $app, RouteCollection $routes) + public function __construct($baseUrl, RouteCollection $routes) { - $this->app = $app; + $this->baseUrl = $baseUrl; $this->routes = $routes; } @@ -47,12 +40,12 @@ class AbstractUrlGenerator * @param array $parameters * @return string */ - public function toRoute($name, $parameters = []) + public function route($name, $parameters = []) { $path = $this->routes->getPath($name, $parameters); $path = ltrim($path, '/'); - return $this->toBase().'/'.$path; + return $this->baseUrl.'/'.$path; } /** @@ -61,9 +54,9 @@ class AbstractUrlGenerator * @param string $path * @return string */ - public function toPath($path) + public function path($path) { - return $this->toBase().'/'.$path; + return $this->baseUrl.'/'.$path; } /** @@ -71,8 +64,8 @@ class AbstractUrlGenerator * * @return string */ - public function toBase() + public function base() { - return $this->app->url($this->path); + return $this->baseUrl; } } diff --git a/framework/core/src/Http/Handler/RouteHandlerFactory.php b/framework/core/src/Http/RouteHandlerFactory.php similarity index 95% rename from framework/core/src/Http/Handler/RouteHandlerFactory.php rename to framework/core/src/Http/RouteHandlerFactory.php index a225fc2ac..4831bb39c 100644 --- a/framework/core/src/Http/Handler/RouteHandlerFactory.php +++ b/framework/core/src/Http/RouteHandlerFactory.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Http\Handler; +namespace Flarum\Http; use Illuminate\Contracts\Container\Container; diff --git a/framework/core/src/Http/Server.php b/framework/core/src/Http/Server.php new file mode 100644 index 000000000..80e507d43 --- /dev/null +++ b/framework/core/src/Http/Server.php @@ -0,0 +1,153 @@ +<?php + +/* + * This file is part of Flarum. + * + * (c) Toby Zerner <toby.zerner@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Http; + +use Flarum\Foundation\Application; +use Flarum\Foundation\Site; +use Flarum\Http\Middleware\DispatchRoute; +use Flarum\Http\Middleware\HandleErrors; +use Flarum\Http\Middleware\StartSession; +use Flarum\Install\InstallServiceProvider; +use Flarum\Update\UpdateServiceProvider; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use Zend\Diactoros\Response\HtmlResponse; +use Zend\Diactoros\Server as DiactorosServer; +use Zend\Stratigility\MiddlewareInterface; +use Zend\Stratigility\MiddlewarePipe; +use Zend\Stratigility\NoopFinalHandler; + +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() + { + DiactorosServer::createServer( + $this, + $_SERVER, + $_GET, + $_POST, + $_COOKIE, + $_FILES + )->listen(new NoopFinalHandler()); + } + + /** + * Use as PSR-7 middleware. + * + * @param ServerRequestInterface $request + * @param ResponseInterface $response + * @param callable $out + * @return ResponseInterface + */ + public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out) + { + $middleware = $this->getMiddleware($request->getUri()->getPath()); + + return $middleware($request, $response, $out); + } + + /** + * @param string $requestPath + * @return MiddlewareInterface + */ + protected function getMiddleware($requestPath) + { + $pipe = new MiddlewarePipe; + $pipe->raiseThrowables(); + + if (! $this->app->isInstalled()) { + return $this->getInstallerMiddleware($pipe); + } + + if ($this->app->isDownForMaintenance()) { + return $this->getMaintenanceMiddleware($pipe); + } + + if (! $this->app->isUpToDate()) { + return $this->getUpdaterMiddleware($pipe); + } + + $api = parse_url($this->app->url('api'), PHP_URL_PATH); + $admin = parse_url($this->app->url('admin'), PHP_URL_PATH); + $forum = parse_url($this->app->url(''), PHP_URL_PATH) ?: '/'; + + if ($this->pathStartsWith($requestPath, $api)) { + $pipe->pipe($api, $this->app->make('flarum.api.middleware')); + } elseif ($this->pathStartsWith($requestPath, $admin)) { + $pipe->pipe($admin, $this->app->make('flarum.admin.middleware')); + } else { + $pipe->pipe($forum, $this->app->make('flarum.forum.middleware')); + } + + return $pipe; + } + + private function pathStartsWith($path, $prefix) + { + return $path === $prefix || starts_with($path, "$prefix/"); + } + + protected function getInstallerMiddleware(MiddlewarePipe $pipe) + { + $this->app->register(InstallServiceProvider::class); + + // FIXME: Re-enable HandleErrors middleware, if possible + // (Right now it tries to resolve a database connection because of the injected settings repo instance) + // We could register a different settings repo when Flarum is not installed + //$pipe->pipe($this->app->make(HandleErrors::class, ['debug' => true])); + $pipe->pipe($this->app->make(StartSession::class)); + $pipe->pipe($this->app->make(DispatchRoute::class, ['routes' => $this->app->make('flarum.install.routes')])); + + return $pipe; + } + + protected function getMaintenanceMiddleware(MiddlewarePipe $pipe) + { + $pipe->pipe(function () { + return new HtmlResponse(file_get_contents($this->getErrorDir().'/503.html', 503)); + }); + + // TODO: FOR API render JSON-API error document for HTTP 503 + + return $pipe; + } + + protected function getUpdaterMiddleware(MiddlewarePipe $pipe) + { + $this->app->register(UpdateServiceProvider::class); + + $pipe->pipe($this->app->make(DispatchRoute::class, ['routes' => $this->app->make('flarum.update.routes')])); + + // TODO: FOR API render JSON-API error document for HTTP 503 + + return $pipe; + } + + private function getErrorDir() + { + return __DIR__.'/../../error'; + } +} diff --git a/framework/core/src/Http/UrlGenerator.php b/framework/core/src/Http/UrlGenerator.php new file mode 100644 index 000000000..86e814731 --- /dev/null +++ b/framework/core/src/Http/UrlGenerator.php @@ -0,0 +1,59 @@ +<?php + +/* + * This file is part of Flarum. + * + * (c) Toby Zerner <toby.zerner@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Http; + +use Flarum\Foundation\Application; + +class UrlGenerator +{ + /** + * @var array + */ + protected $routes = []; + + /** + * @param Application $app + */ + public function __construct(Application $app) + { + $this->app = $app; + } + + /** + * Register a named route collection for URL generation. + * + * @param string $key + * @param RouteCollection $routes + * @param string $prefix + * @return static + */ + public function addCollection($key, RouteCollection $routes, $prefix = null) + { + $this->routes[$key] = new RouteCollectionUrlGenerator( + $this->app->url($prefix), + $routes + ); + + return $this; + } + + /** + * Retrieve an URL generator instance for the given named route collection. + * + * @param string $collection + * @return RouteCollectionUrlGenerator + */ + public function to($collection) + { + return $this->routes[$collection]; + } +} diff --git a/framework/core/src/Install/Console/InstallCommand.php b/framework/core/src/Install/Console/InstallCommand.php index 6dacaeb6f..61c473f72 100644 --- a/framework/core/src/Install/Console/InstallCommand.php +++ b/framework/core/src/Install/Console/InstallCommand.php @@ -12,12 +12,27 @@ namespace Flarum\Install\Console; use Exception; -use Flarum\Console\Command\AbstractCommand; -use Flarum\Core\Group; -use Flarum\Core\Permission; -use Flarum\Core\User; +use Flarum\Console\AbstractCommand; use Flarum\Database\AbstractModel; +use Flarum\Database\Migrator; +use Flarum\Discussion\DiscussionServiceProvider; +use Flarum\Extension\ExtensionManager; +use Flarum\Formatter\FormatterServiceProvider; +use Flarum\Group\Group; +use Flarum\Group\GroupServiceProvider; +use Flarum\Group\Permission; +use Flarum\Install\Prerequisite\PrerequisiteInterface; +use Flarum\Notification\NotificationServiceProvider; +use Flarum\Post\PostServiceProvider; +use Flarum\Search\SearchServiceProvider; +use Flarum\Settings\SettingsRepositoryInterface; +use Flarum\User\User; +use Flarum\User\UserServiceProvider; use Illuminate\Contracts\Foundation\Application; +use Illuminate\Contracts\Translation\Translator; +use Illuminate\Database\ConnectionInterface; +use Illuminate\Database\ConnectionResolverInterface; +use Illuminate\Database\Schema\Builder; use Illuminate\Filesystem\Filesystem; use Illuminate\Validation\Factory; use PDO; @@ -163,7 +178,7 @@ class InstallCommand extends AbstractCommand $this->storeConfiguration(); - $resolver = $this->application->make('Illuminate\Database\ConnectionResolverInterface'); + $resolver = $this->application->make(ConnectionResolverInterface::class); AbstractModel::setConnectionResolver($resolver); AbstractModel::setEventDispatcher($this->application->make('events')); @@ -171,7 +186,13 @@ class InstallCommand extends AbstractCommand $this->writeSettings(); - $this->application->register('Flarum\Core\CoreServiceProvider'); + $this->application->register(UserServiceProvider::class); + $this->application->register(FormatterServiceProvider::class); + $this->application->register(DiscussionServiceProvider::class); + $this->application->register(GroupServiceProvider::class); + $this->application->register(NotificationServiceProvider::class); + $this->application->register(SearchServiceProvider::class); + $this->application->register(PostServiceProvider::class); $this->seedGroups(); $this->seedPermissions(); @@ -234,11 +255,11 @@ class InstallCommand extends AbstractCommand protected function runMigrations() { - $this->application->bind('Illuminate\Database\Schema\Builder', function ($container) { - return $container->make('Illuminate\Database\ConnectionInterface')->getSchemaBuilder(); + $this->application->bind(Builder::class, function ($container) { + return $container->make(ConnectionInterface::class)->getSchemaBuilder(); }); - $migrator = $this->application->make('Flarum\Database\Migrator'); + $migrator = $this->application->make(Migrator::class); $migrator->getRepository()->createRepository(); $migrator->run(__DIR__.'/../../../migrations'); @@ -250,7 +271,7 @@ class InstallCommand extends AbstractCommand protected function writeSettings() { - $settings = $this->application->make('Flarum\Settings\SettingsRepositoryInterface'); + $settings = $this->application->make(SettingsRepositoryInterface::class); $this->info('Writing default settings'); @@ -335,7 +356,7 @@ class InstallCommand extends AbstractCommand protected function enableBundledExtensions() { - $extensions = $this->application->make('Flarum\Extension\ExtensionManager'); + $extensions = $this->application->make(ExtensionManager::class); $migrator = $extensions->getMigrator(); @@ -380,7 +401,7 @@ class InstallCommand extends AbstractCommand */ protected function getPrerequisites() { - return $this->application->make('Flarum\Install\Prerequisite\PrerequisiteInterface'); + return $this->application->make(PrerequisiteInterface::class); } /** @@ -388,7 +409,7 @@ class InstallCommand extends AbstractCommand */ protected function getValidator() { - return new Factory($this->application->make('Symfony\Component\Translation\TranslatorInterface')); + return new Factory($this->application->make(Translator::class)); } protected function showErrors($errors) diff --git a/framework/core/src/Install/Controller/IndexController.php b/framework/core/src/Install/Controller/IndexController.php index 680b647b0..e96110969 100644 --- a/framework/core/src/Install/Controller/IndexController.php +++ b/framework/core/src/Install/Controller/IndexController.php @@ -40,7 +40,7 @@ class IndexController extends AbstractHtmlController /** * @param Request $request - * @return \Psr\Http\Message\ResponseInterface + * @return \Illuminate\Contracts\Support\Renderable */ public function render(Request $request) { diff --git a/framework/core/src/Install/InstallServiceProvider.php b/framework/core/src/Install/InstallServiceProvider.php index e796f3895..e57f47ab1 100644 --- a/framework/core/src/Install/InstallServiceProvider.php +++ b/framework/core/src/Install/InstallServiceProvider.php @@ -12,11 +12,12 @@ namespace Flarum\Install; use Flarum\Foundation\AbstractServiceProvider; -use Flarum\Http\Handler\RouteHandlerFactory; use Flarum\Http\RouteCollection; +use Flarum\Http\RouteHandlerFactory; use Flarum\Install\Prerequisite\Composite; use Flarum\Install\Prerequisite\PhpExtensions; use Flarum\Install\Prerequisite\PhpVersion; +use Flarum\Install\Prerequisite\PrerequisiteInterface; use Flarum\Install\Prerequisite\WritablePaths; class InstallServiceProvider extends AbstractServiceProvider @@ -27,7 +28,7 @@ class InstallServiceProvider extends AbstractServiceProvider public function register() { $this->app->bind( - 'Flarum\Install\Prerequisite\PrerequisiteInterface', + PrerequisiteInterface::class, function () { return new Composite( new PhpVersion('5.5.0'), diff --git a/framework/core/src/Locale/LocaleManager.php b/framework/core/src/Locale/LocaleManager.php index 7be082085..5fdd4d492 100644 --- a/framework/core/src/Locale/LocaleManager.php +++ b/framework/core/src/Locale/LocaleManager.php @@ -11,12 +11,10 @@ namespace Flarum\Locale; -use Symfony\Component\Translation\Translator as SymfonyTranslator; - class LocaleManager { /** - * @var SymfonyTranslator + * @var Translator */ protected $translator; @@ -26,52 +24,49 @@ class LocaleManager protected $css = []; - /** - * @param SymfonyTranslator $translator - */ - public function __construct(SymfonyTranslator $translator) + public function __construct(Translator $translator) { $this->translator = $translator; } - public function getLocale() + public function getLocale(): string { return $this->translator->getLocale(); } - public function setLocale($locale) + public function setLocale(string $locale) { $this->translator->setLocale($locale); } - public function addLocale($locale, $name) + public function addLocale(string $locale, string $name) { $this->locales[$locale] = $name; } - public function getLocales() + public function getLocales(): array { return $this->locales; } - public function hasLocale($locale) + public function hasLocale(string $locale): bool { return isset($this->locales[$locale]); } - public function addTranslations($locale, $file, $module = null) + public function addTranslations(string $locale, $file, string $module = null) { $prefix = $module ? $module.'::' : ''; $this->translator->addResource('prefixed_yaml', compact('file', 'prefix'), $locale); } - public function addJsFile($locale, $js) + public function addJsFile(string $locale, string $js) { $this->js[$locale][] = $js; } - public function getJsFiles($locale) + public function getJsFiles(string $locale): array { $files = array_get($this->js, $locale, []); @@ -84,12 +79,12 @@ class LocaleManager return $files; } - public function addCssFile($locale, $css) + public function addCssFile(string $locale, string $css) { $this->css[$locale][] = $css; } - public function getCssFiles($locale) + public function getCssFiles(string $locale): array { $files = array_get($this->css, $locale, []); @@ -102,18 +97,12 @@ class LocaleManager return $files; } - /** - * @return SymfonyTranslator - */ - public function getTranslator() + public function getTranslator(): Translator { return $this->translator; } - /** - * @param SymfonyTranslator $translator - */ - public function setTranslator(SymfonyTranslator $translator) + public function setTranslator(Translator $translator) { $this->translator = $translator; } diff --git a/framework/core/src/Locale/LocaleServiceProvider.php b/framework/core/src/Locale/LocaleServiceProvider.php index d9b75383c..73eb156f5 100644 --- a/framework/core/src/Locale/LocaleServiceProvider.php +++ b/framework/core/src/Locale/LocaleServiceProvider.php @@ -14,6 +14,9 @@ namespace Flarum\Locale; use Flarum\Event\ConfigureLocales; use Flarum\Foundation\AbstractServiceProvider; use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Contracts\Translation\Translator as TranslatorContract; +use Symfony\Component\Translation\MessageSelector; +use Symfony\Component\Translation\TranslatorInterface; class LocaleServiceProvider extends AbstractServiceProvider { @@ -34,23 +37,22 @@ class LocaleServiceProvider extends AbstractServiceProvider */ public function register() { - $this->app->singleton('Flarum\Locale\LocaleManager'); - $this->app->alias('Flarum\Locale\LocaleManager', 'flarum.localeManager'); + $this->app->singleton(LocaleManager::class); + $this->app->alias(LocaleManager::class, 'flarum.localeManager'); $this->app->singleton('translator', function () { - $defaultLocale = $this->getDefaultLocale(); - - $translator = new Translator($defaultLocale, null, $this->app->storagePath().'/locale', $this->app->inDebugMode()); - $translator->setFallbackLocales([$defaultLocale, 'en']); + $translator = new Translator($this->getDefaultLocale(), new MessageSelector()); + $translator->setFallbackLocales(['en']); $translator->addLoader('prefixed_yaml', new PrefixedYamlFileLoader()); return $translator; }); - $this->app->alias('translator', 'Symfony\Component\Translation\Translator'); - $this->app->alias('translator', 'Symfony\Component\Translation\TranslatorInterface'); + $this->app->alias('translator', Translator::class); + $this->app->alias('translator', TranslatorContract::class); + $this->app->alias('translator', TranslatorInterface::class); } - private function getDefaultLocale() + private function getDefaultLocale(): string { return $this->app->isInstalled() && $this->app->isUpToDate() ? $this->app->make('flarum.settings')->get('default_locale', 'en') diff --git a/framework/core/src/Locale/Translator.php b/framework/core/src/Locale/Translator.php index 0e68b8280..70acf299d 100644 --- a/framework/core/src/Locale/Translator.php +++ b/framework/core/src/Locale/Translator.php @@ -11,10 +11,11 @@ namespace Flarum\Locale; +use Illuminate\Contracts\Translation\Translator as TranslatorContract; use Symfony\Component\Translation\MessageCatalogueInterface; use Symfony\Component\Translation\Translator as BaseTranslator; -class Translator extends BaseTranslator +class Translator extends BaseTranslator implements TranslatorContract { const REFERENCE_REGEX = '/^=>\s*([a-z0-9_\-\.]+)$/i'; diff --git a/framework/core/src/Core/Notification/BlueprintInterface.php b/framework/core/src/Notification/Blueprint/BlueprintInterface.php similarity index 93% rename from framework/core/src/Core/Notification/BlueprintInterface.php rename to framework/core/src/Notification/Blueprint/BlueprintInterface.php index 93f33f8c4..ed8273396 100644 --- a/framework/core/src/Core/Notification/BlueprintInterface.php +++ b/framework/core/src/Notification/Blueprint/BlueprintInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Notification; +namespace Flarum\Notification\Blueprint; /** * A notification BlueprintInterface, when instantiated, represents a notification about @@ -21,7 +21,7 @@ interface BlueprintInterface /** * Get the user that sent the notification. * - * @return \Flarum\Core\User|null + * @return \Flarum\User\User|null */ public function getSender(); diff --git a/framework/core/src/Core/Notification/DiscussionRenamedBlueprint.php b/framework/core/src/Notification/Blueprint/DiscussionRenamedBlueprint.php similarity index 84% rename from framework/core/src/Core/Notification/DiscussionRenamedBlueprint.php rename to framework/core/src/Notification/Blueprint/DiscussionRenamedBlueprint.php index 5a19d8c7b..50d2e6146 100644 --- a/framework/core/src/Core/Notification/DiscussionRenamedBlueprint.php +++ b/framework/core/src/Notification/Blueprint/DiscussionRenamedBlueprint.php @@ -9,14 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Notification; +namespace Flarum\Notification\Blueprint; -use Flarum\Core\Post\DiscussionRenamedPost; +use Flarum\Discussion\Discussion; +use Flarum\Post\DiscussionRenamedPost; class DiscussionRenamedBlueprint implements BlueprintInterface { /** - * @var DiscussionRenamedPost + * @var \Flarum\Post\DiscussionRenamedPost */ protected $post; @@ -65,6 +66,6 @@ class DiscussionRenamedBlueprint implements BlueprintInterface */ public static function getSubjectModel() { - return 'Flarum\Core\Discussion'; + return Discussion::class; } } diff --git a/framework/core/src/Core/Command/ReadAllNotifications.php b/framework/core/src/Notification/Command/ReadAllNotifications.php similarity index 89% rename from framework/core/src/Core/Command/ReadAllNotifications.php rename to framework/core/src/Notification/Command/ReadAllNotifications.php index bbf6b2252..d0ee62429 100644 --- a/framework/core/src/Core/Command/ReadAllNotifications.php +++ b/framework/core/src/Notification/Command/ReadAllNotifications.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Notification\Command; -use Flarum\Core\User; +use Flarum\User\User; class ReadAllNotifications { diff --git a/framework/core/src/Core/Command/ReadAllNotificationsHandler.php b/framework/core/src/Notification/Command/ReadAllNotificationsHandler.php similarity index 81% rename from framework/core/src/Core/Command/ReadAllNotificationsHandler.php rename to framework/core/src/Notification/Command/ReadAllNotificationsHandler.php index 56f04f217..4d99dfdf5 100644 --- a/framework/core/src/Core/Command/ReadAllNotificationsHandler.php +++ b/framework/core/src/Notification/Command/ReadAllNotificationsHandler.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Notification\Command; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Repository\NotificationRepository; +use Flarum\Notification\NotificationRepository; +use Flarum\User\AssertPermissionTrait; class ReadAllNotificationsHandler { @@ -33,7 +33,7 @@ class ReadAllNotificationsHandler /** * @param ReadAllNotifications $command - * @throws \Flarum\Core\Exception\PermissionDeniedException + * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(ReadAllNotifications $command) { diff --git a/framework/core/src/Core/Command/ReadNotification.php b/framework/core/src/Notification/Command/ReadNotification.php similarity index 92% rename from framework/core/src/Core/Command/ReadNotification.php rename to framework/core/src/Notification/Command/ReadNotification.php index bbeddee96..93a139ea8 100644 --- a/framework/core/src/Core/Command/ReadNotification.php +++ b/framework/core/src/Notification/Command/ReadNotification.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Notification\Command; -use Flarum\Core\User; +use Flarum\User\User; class ReadNotification { diff --git a/framework/core/src/Core/Command/ReadNotificationHandler.php b/framework/core/src/Notification/Command/ReadNotificationHandler.php similarity index 79% rename from framework/core/src/Core/Command/ReadNotificationHandler.php rename to framework/core/src/Notification/Command/ReadNotificationHandler.php index 7adbf6039..41da8e781 100644 --- a/framework/core/src/Core/Command/ReadNotificationHandler.php +++ b/framework/core/src/Notification/Command/ReadNotificationHandler.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Notification\Command; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Notification; +use Flarum\Notification\Notification; +use Flarum\User\AssertPermissionTrait; class ReadNotificationHandler { @@ -20,8 +20,8 @@ class ReadNotificationHandler /** * @param ReadNotification $command - * @return \Flarum\Core\Notification - * @throws \Flarum\Core\Exception\PermissionDeniedException + * @return \Flarum\Notification\Notification + * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(ReadNotification $command) { diff --git a/framework/core/src/Event/NotificationWillBeSent.php b/framework/core/src/Notification/Event/Sending.php similarity index 74% rename from framework/core/src/Event/NotificationWillBeSent.php rename to framework/core/src/Notification/Event/Sending.php index fc428ae40..5633ada9a 100644 --- a/framework/core/src/Event/NotificationWillBeSent.php +++ b/framework/core/src/Notification/Event/Sending.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Notification\Event; -use Flarum\Core\Notification\BlueprintInterface; +use Flarum\Notification\Blueprint\BlueprintInterface; -class NotificationWillBeSent +class Sending { /** * The blueprint for the notification. @@ -30,8 +30,8 @@ class NotificationWillBeSent public $users; /** - * @param BlueprintInterface $blueprint - * @param \Flarum\Core\User[] $users + * @param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint + * @param \Flarum\User\User[] $users */ public function __construct(BlueprintInterface $blueprint, array &$users) { diff --git a/framework/core/src/Core/Notification/MailableInterface.php b/framework/core/src/Notification/MailableInterface.php similarity index 93% rename from framework/core/src/Core/Notification/MailableInterface.php rename to framework/core/src/Notification/MailableInterface.php index c276a32e9..0d059af8e 100644 --- a/framework/core/src/Core/Notification/MailableInterface.php +++ b/framework/core/src/Notification/MailableInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Notification; +namespace Flarum\Notification; interface MailableInterface { diff --git a/framework/core/src/Core/Notification.php b/framework/core/src/Notification/Notification.php similarity index 92% rename from framework/core/src/Core/Notification.php rename to framework/core/src/Notification/Notification.php index 78b2dbf98..ad289ca08 100644 --- a/framework/core/src/Core/Notification.php +++ b/framework/core/src/Notification/Notification.php @@ -9,9 +9,10 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\Notification; use Flarum\Database\AbstractModel; +use Flarum\User\User; /** * Models a notification record in the database. @@ -36,8 +37,8 @@ use Flarum\Database\AbstractModel; * @property \Carbon\Carbon $time * @property bool $is_read * @property bool $is_deleted - * @property \Flarum\Core\User|null $user - * @property \Flarum\Core\User|null $sender + * @property \Flarum\User\User|null $user + * @property \Flarum\User\User|null $sender * @property \Flarum\Database\AbstractModel|null $subject */ class Notification extends AbstractModel @@ -56,7 +57,7 @@ class Notification extends AbstractModel * A map of notification types and the model classes to use for their * subjects. For example, the 'discussionRenamed' notification type, which * represents that a user's discussion was renamed, has the subject model - * class 'Flarum\Core\Discussion'. + * class 'Flarum\Discussion\Discussion'. * * @var array */ @@ -113,7 +114,7 @@ class Notification extends AbstractModel */ public function user() { - return $this->belongsTo('Flarum\Core\User', 'user_id'); + return $this->belongsTo(User::class, 'user_id'); } /** @@ -123,7 +124,7 @@ class Notification extends AbstractModel */ public function sender() { - return $this->belongsTo('Flarum\Core\User', 'sender_id'); + return $this->belongsTo(User::class, 'sender_id'); } /** diff --git a/framework/core/src/Core/Notification/NotificationMailer.php b/framework/core/src/Notification/NotificationMailer.php similarity index 94% rename from framework/core/src/Core/Notification/NotificationMailer.php rename to framework/core/src/Notification/NotificationMailer.php index 691e3e7d6..2bee77e5a 100644 --- a/framework/core/src/Core/Notification/NotificationMailer.php +++ b/framework/core/src/Notification/NotificationMailer.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Notification; +namespace Flarum\Notification; -use Flarum\Core\User; +use Flarum\User\User; use Illuminate\Contracts\Mail\Mailer; use Illuminate\Mail\Message; diff --git a/framework/core/src/Core/Repository/NotificationRepository.php b/framework/core/src/Notification/NotificationRepository.php similarity index 94% rename from framework/core/src/Core/Repository/NotificationRepository.php rename to framework/core/src/Notification/NotificationRepository.php index 3d1e5f6a0..ae70ea600 100644 --- a/framework/core/src/Core/Repository/NotificationRepository.php +++ b/framework/core/src/Notification/NotificationRepository.php @@ -9,10 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Repository; +namespace Flarum\Notification; -use Flarum\Core\Notification; -use Flarum\Core\User; +use Flarum\User\User; class NotificationRepository { diff --git a/framework/core/src/Core/Notification/NotificationServiceProvider.php b/framework/core/src/Notification/NotificationServiceProvider.php similarity index 86% rename from framework/core/src/Core/Notification/NotificationServiceProvider.php rename to framework/core/src/Notification/NotificationServiceProvider.php index 54a9b0dd1..8771198a0 100644 --- a/framework/core/src/Core/Notification/NotificationServiceProvider.php +++ b/framework/core/src/Notification/NotificationServiceProvider.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Notification; +namespace Flarum\Notification; -use Flarum\Core\Notification; -use Flarum\Core\User; use Flarum\Event\ConfigureNotificationTypes; use Flarum\Foundation\AbstractServiceProvider; +use Flarum\Notification\Blueprint\DiscussionRenamedBlueprint; +use Flarum\User\User; use ReflectionClass; class NotificationServiceProvider extends AbstractServiceProvider @@ -33,7 +33,7 @@ class NotificationServiceProvider extends AbstractServiceProvider public function registerNotificationTypes() { $blueprints = [ - 'Flarum\Core\Notification\DiscussionRenamedBlueprint' => ['alert'] + DiscussionRenamedBlueprint::class => ['alert'] ]; $this->app->make('events')->fire( @@ -52,7 +52,7 @@ class NotificationServiceProvider extends AbstractServiceProvider in_array('alert', $enabled) ); - if ((new ReflectionClass($blueprint))->implementsInterface('Flarum\Core\Notification\MailableInterface')) { + if ((new ReflectionClass($blueprint))->implementsInterface(MailableInterface::class)) { User::addPreference( User::getNotificationPreferenceKey($type, 'email'), 'boolval', diff --git a/framework/core/src/Core/Notification/NotificationSyncer.php b/framework/core/src/Notification/NotificationSyncer.php similarity index 88% rename from framework/core/src/Core/Notification/NotificationSyncer.php rename to framework/core/src/Notification/NotificationSyncer.php index 5b56ad9d5..5dc3a1843 100644 --- a/framework/core/src/Core/Notification/NotificationSyncer.php +++ b/framework/core/src/Notification/NotificationSyncer.php @@ -9,13 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Notification; +namespace Flarum\Notification; use Carbon\Carbon; -use Flarum\Core\Notification; -use Flarum\Core\Repository\NotificationRepository; -use Flarum\Core\User; -use Flarum\Event\NotificationWillBeSent; +use Flarum\Notification\Blueprint\BlueprintInterface; +use Flarum\Notification\Event\Sending; +use Flarum\User\User; /** * The Notification Syncer commits notification blueprints to the database, and @@ -66,11 +65,11 @@ class NotificationSyncer * visible to anyone else. If it is being made visible for the first time, * attempt to send the user an email. * - * @param BlueprintInterface $blueprint + * @param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint * @param User[] $users * @return void */ - public function sync(BlueprintInterface $blueprint, array $users) + public function sync(Blueprint\BlueprintInterface $blueprint, array $users) { $attributes = $this->getAttributes($blueprint); @@ -107,7 +106,7 @@ class NotificationSyncer // removed from this collection by the above loop. Un-delete the // existing records that we want to keep. if (count($toDelete)) { - $this->setDeleted($toDelete->lists('id')->all(), true); + $this->setDeleted($toDelete->pluck('id')->all(), true); } if (count($toUndelete)) { @@ -125,7 +124,7 @@ class NotificationSyncer /** * Delete a notification for all users. * - * @param BlueprintInterface $blueprint + * @param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint * @return void */ public function delete(BlueprintInterface $blueprint) @@ -165,14 +164,14 @@ class NotificationSyncer * Create a notification record and send an email (depending on user * preference) from a blueprint to a list of recipients. * - * @param BlueprintInterface $blueprint + * @param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint * @param User[] $recipients */ - protected function sendNotifications(BlueprintInterface $blueprint, array $recipients) + protected function sendNotifications(Blueprint\BlueprintInterface $blueprint, array $recipients) { $now = Carbon::now('utc')->toDateTimeString(); - event(new NotificationWillBeSent($blueprint, $recipients)); + event(new Sending($blueprint, $recipients)); $attributes = $this->getAttributes($blueprint); @@ -220,10 +219,10 @@ class NotificationSyncer * Construct an array of attributes to be stored in a notification record in * the database, given a notification blueprint. * - * @param BlueprintInterface $blueprint + * @param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint * @return array */ - protected function getAttributes(BlueprintInterface $blueprint) + protected function getAttributes(Blueprint\BlueprintInterface $blueprint) { return [ 'type' => $blueprint::getType(), diff --git a/framework/core/src/Core/Post/AbstractEventPost.php b/framework/core/src/Post/AbstractEventPost.php similarity index 93% rename from framework/core/src/Core/Post/AbstractEventPost.php rename to framework/core/src/Post/AbstractEventPost.php index 10d242750..0e949c963 100755 --- a/framework/core/src/Core/Post/AbstractEventPost.php +++ b/framework/core/src/Post/AbstractEventPost.php @@ -9,9 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Post; - -use Flarum\Core\Post; +namespace Flarum\Post; abstract class AbstractEventPost extends Post { diff --git a/framework/core/src/Core/Command/DeletePost.php b/framework/core/src/Post/Command/DeletePost.php similarity index 95% rename from framework/core/src/Core/Command/DeletePost.php rename to framework/core/src/Post/Command/DeletePost.php index 3e363e245..27d79dc09 100644 --- a/framework/core/src/Core/Command/DeletePost.php +++ b/framework/core/src/Post/Command/DeletePost.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Post\Command; -use Flarum\Core\User; +use Flarum\User\User; class DeletePost { diff --git a/framework/core/src/Core/Command/DeletePostHandler.php b/framework/core/src/Post/Command/DeletePostHandler.php similarity index 68% rename from framework/core/src/Core/Command/DeletePostHandler.php rename to framework/core/src/Post/Command/DeletePostHandler.php index a5010cf6d..f21845ea4 100644 --- a/framework/core/src/Core/Command/DeletePostHandler.php +++ b/framework/core/src/Post/Command/DeletePostHandler.php @@ -9,13 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Post\Command; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\Repository\PostRepository; -use Flarum\Core\Support\DispatchEventsTrait; -use Flarum\Event\PostWillBeDeleted; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\Post\Event\Deleting; +use Flarum\Post\PostRepository; +use Flarum\User\AssertPermissionTrait; use Illuminate\Contracts\Events\Dispatcher; class DeletePostHandler @@ -24,13 +23,13 @@ class DeletePostHandler use AssertPermissionTrait; /** - * @var PostRepository + * @var \Flarum\Post\PostRepository */ protected $posts; /** * @param Dispatcher $events - * @param PostRepository $posts + * @param \Flarum\Post\PostRepository $posts */ public function __construct(Dispatcher $events, PostRepository $posts) { @@ -40,8 +39,8 @@ class DeletePostHandler /** * @param DeletePost $command - * @return \Flarum\Core\Post - * @throws PermissionDeniedException + * @return \Flarum\Post\Post + * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(DeletePost $command) { @@ -52,7 +51,7 @@ class DeletePostHandler $this->assertCan($actor, 'delete', $post); $this->events->fire( - new PostWillBeDeleted($post, $actor, $command->data) + new Deleting($post, $actor, $command->data) ); $post->delete(); diff --git a/framework/core/src/Core/Command/EditPost.php b/framework/core/src/Post/Command/EditPost.php similarity index 94% rename from framework/core/src/Core/Command/EditPost.php rename to framework/core/src/Post/Command/EditPost.php index 6a576a130..270756d30 100644 --- a/framework/core/src/Core/Command/EditPost.php +++ b/framework/core/src/Post/Command/EditPost.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Post\Command; -use Flarum\Core\User; +use Flarum\User\User; class EditPost { diff --git a/framework/core/src/Core/Command/EditPostHandler.php b/framework/core/src/Post/Command/EditPostHandler.php similarity index 77% rename from framework/core/src/Core/Command/EditPostHandler.php rename to framework/core/src/Post/Command/EditPostHandler.php index f49e4443a..e4e3269e8 100644 --- a/framework/core/src/Core/Command/EditPostHandler.php +++ b/framework/core/src/Post/Command/EditPostHandler.php @@ -9,14 +9,14 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Post\Command; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Post\CommentPost; -use Flarum\Core\Repository\PostRepository; -use Flarum\Core\Support\DispatchEventsTrait; -use Flarum\Core\Validator\PostValidator; -use Flarum\Event\PostWillBeSaved; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\Post\CommentPost; +use Flarum\Post\Event\Saving; +use Flarum\Post\PostRepository; +use Flarum\Post\PostValidator; +use Flarum\User\AssertPermissionTrait; use Illuminate\Contracts\Events\Dispatcher; class EditPostHandler @@ -25,19 +25,19 @@ class EditPostHandler use AssertPermissionTrait; /** - * @var PostRepository + * @var \Flarum\Post\PostRepository */ protected $posts; /** - * @var PostValidator + * @var \Flarum\Post\PostValidator */ protected $validator; /** * @param Dispatcher $events * @param PostRepository $posts - * @param PostValidator $validator + * @param \Flarum\Post\PostValidator $validator */ public function __construct(Dispatcher $events, PostRepository $posts, PostValidator $validator) { @@ -48,8 +48,8 @@ class EditPostHandler /** * @param EditPost $command - * @return \Flarum\Core\Post - * @throws \Flarum\Core\Exception\PermissionDeniedException + * @return \Flarum\Post\Post + * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(EditPost $command) { @@ -79,7 +79,7 @@ class EditPostHandler } $this->events->fire( - new PostWillBeSaved($post, $actor, $data) + new Saving($post, $actor, $data) ); $this->validator->assertValid($post->getDirty()); diff --git a/framework/core/src/Core/Command/PostReply.php b/framework/core/src/Post/Command/PostReply.php similarity index 95% rename from framework/core/src/Core/Command/PostReply.php rename to framework/core/src/Post/Command/PostReply.php index a9518f00e..cc7575707 100644 --- a/framework/core/src/Core/Command/PostReply.php +++ b/framework/core/src/Post/Command/PostReply.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Post\Command; -use Flarum\Core\User; +use Flarum\User\User; class PostReply { diff --git a/framework/core/src/Core/Command/PostReplyHandler.php b/framework/core/src/Post/Command/PostReplyHandler.php similarity index 83% rename from framework/core/src/Core/Command/PostReplyHandler.php rename to framework/core/src/Post/Command/PostReplyHandler.php index fb84877a9..519f515ec 100644 --- a/framework/core/src/Core/Command/PostReplyHandler.php +++ b/framework/core/src/Post/Command/PostReplyHandler.php @@ -9,16 +9,16 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Post\Command; use DateTime; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Notification\NotificationSyncer; -use Flarum\Core\Post\CommentPost; -use Flarum\Core\Repository\DiscussionRepository; -use Flarum\Core\Support\DispatchEventsTrait; -use Flarum\Core\Validator\PostValidator; -use Flarum\Event\PostWillBeSaved; +use Flarum\Discussion\DiscussionRepository; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\Notification\NotificationSyncer; +use Flarum\Post\CommentPost; +use Flarum\Post\Event\Saving; +use Flarum\Post\PostValidator; +use Flarum\User\AssertPermissionTrait; use Illuminate\Contracts\Events\Dispatcher; class PostReplyHandler @@ -32,19 +32,19 @@ class PostReplyHandler protected $discussions; /** - * @var NotificationSyncer + * @var \Flarum\Notification\NotificationSyncer */ protected $notifications; /** - * @var PostValidator + * @var \Flarum\Post\PostValidator */ protected $validator; /** * @param Dispatcher $events * @param DiscussionRepository $discussions - * @param NotificationSyncer $notifications + * @param \Flarum\Notification\NotificationSyncer $notifications * @param PostValidator $validator */ public function __construct( @@ -62,7 +62,7 @@ class PostReplyHandler /** * @param PostReply $command * @return CommentPost - * @throws \Flarum\Core\Exception\PermissionDeniedException + * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(PostReply $command) { @@ -96,7 +96,7 @@ class PostReplyHandler } $this->events->fire( - new PostWillBeSaved($post, $actor, $command->data) + new Saving($post, $actor, $command->data) ); $this->validator->assertValid($post->getAttributes()); diff --git a/framework/core/src/Core/Post/CommentPost.php b/framework/core/src/Post/CommentPost.php similarity index 90% rename from framework/core/src/Core/Post/CommentPost.php rename to framework/core/src/Post/CommentPost.php index 3db0c7555..37ebd0e04 100755 --- a/framework/core/src/Core/Post/CommentPost.php +++ b/framework/core/src/Post/CommentPost.php @@ -9,15 +9,14 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Post; +namespace Flarum\Post; -use Flarum\Core\Post; -use Flarum\Core\User; -use Flarum\Event\PostWasHidden; -use Flarum\Event\PostWasPosted; -use Flarum\Event\PostWasRestored; -use Flarum\Event\PostWasRevised; use Flarum\Formatter\Formatter; +use Flarum\Post\Event\Hidden; +use Flarum\Post\Event\Posted; +use Flarum\Post\Event\Restored; +use Flarum\Post\Event\Revised; +use Flarum\User\User; /** * A standard comment in a discussion. @@ -61,7 +60,7 @@ class CommentPost extends Post // Set content last, as the parsing may rely on other post attributes. $post->content = $content; - $post->raise(new PostWasPosted($post)); + $post->raise(new Posted($post)); return $post; } @@ -81,7 +80,7 @@ class CommentPost extends Post $this->edit_time = time(); $this->edit_user_id = $actor->id; - $this->raise(new PostWasRevised($this)); + $this->raise(new Revised($this)); } return $this; @@ -99,7 +98,7 @@ class CommentPost extends Post $this->hide_time = time(); $this->hide_user_id = $actor ? $actor->id : null; - $this->raise(new PostWasHidden($this)); + $this->raise(new Hidden($this)); } return $this; @@ -116,7 +115,7 @@ class CommentPost extends Post $this->hide_time = null; $this->hide_user_id = null; - $this->raise(new PostWasRestored($this)); + $this->raise(new Restored($this)); } return $this; diff --git a/framework/core/src/Core/Post/DiscussionRenamedPost.php b/framework/core/src/Post/DiscussionRenamedPost.php similarity index 97% rename from framework/core/src/Core/Post/DiscussionRenamedPost.php rename to framework/core/src/Post/DiscussionRenamedPost.php index 75cb3f764..21243d902 100755 --- a/framework/core/src/Core/Post/DiscussionRenamedPost.php +++ b/framework/core/src/Post/DiscussionRenamedPost.php @@ -9,9 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Post; - -use Flarum\Core\Post; +namespace Flarum\Post; /** * A post which indicates that a discussion's title was changed. diff --git a/framework/core/src/Event/PostWasPosted.php b/framework/core/src/Post/Event/Deleted.php similarity index 75% rename from framework/core/src/Event/PostWasPosted.php rename to framework/core/src/Post/Event/Deleted.php index 5b944778a..4fba65f8c 100644 --- a/framework/core/src/Event/PostWasPosted.php +++ b/framework/core/src/Post/Event/Deleted.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Post\Event; -use Flarum\Core\Post; -use Flarum\Core\User; +use Flarum\Post\Post; +use Flarum\User\User; -class PostWasPosted +class Deleted { /** - * @var \Flarum\Core\Post + * @var \Flarum\Post\Post */ public $post; @@ -27,7 +27,7 @@ class PostWasPosted public $actor; /** - * @param \Flarum\Core\Post $post + * @param \Flarum\Post\Post $post */ public function __construct(Post $post, User $actor = null) { diff --git a/framework/core/src/Event/PostWillBeDeleted.php b/framework/core/src/Post/Event/Deleting.php similarity index 82% rename from framework/core/src/Event/PostWillBeDeleted.php rename to framework/core/src/Post/Event/Deleting.php index f2875a54f..899b17997 100644 --- a/framework/core/src/Event/PostWillBeDeleted.php +++ b/framework/core/src/Post/Event/Deleting.php @@ -9,17 +9,17 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Post\Event; -use Flarum\Core\Post; -use Flarum\Core\User; +use Flarum\Post\Post; +use Flarum\User\User; -class PostWillBeDeleted +class Deleting { /** * The post that is going to be deleted. * - * @var \Flarum\Core\Post + * @var \Flarum\Post\Post */ public $post; @@ -38,7 +38,7 @@ class PostWillBeDeleted public $data; /** - * @param \Flarum\Core\Post $post + * @param \Flarum\Post\Post $post * @param User $actor * @param array $data */ diff --git a/framework/core/src/Event/PostWasHidden.php b/framework/core/src/Post/Event/Hidden.php similarity index 84% rename from framework/core/src/Event/PostWasHidden.php rename to framework/core/src/Post/Event/Hidden.php index 4c7841c90..aeeb104e3 100644 --- a/framework/core/src/Event/PostWasHidden.php +++ b/framework/core/src/Post/Event/Hidden.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Post\Event; -use Flarum\Core\Post\CommentPost; -use Flarum\Core\User; +use Flarum\Post\CommentPost; +use Flarum\User\User; -class PostWasHidden +class Hidden { /** * @var CommentPost diff --git a/framework/core/src/Event/PostWasDeleted.php b/framework/core/src/Post/Event/Posted.php similarity index 74% rename from framework/core/src/Event/PostWasDeleted.php rename to framework/core/src/Post/Event/Posted.php index 994ef0915..9b6ab19c8 100644 --- a/framework/core/src/Event/PostWasDeleted.php +++ b/framework/core/src/Post/Event/Posted.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Post\Event; -use Flarum\Core\Post; -use Flarum\Core\User; +use Flarum\Post\Post; +use Flarum\User\User; -class PostWasDeleted +class Posted { /** - * @var \Flarum\Core\Post + * @var \Flarum\Post\Post */ public $post; @@ -27,7 +27,7 @@ class PostWasDeleted public $actor; /** - * @param \Flarum\Core\Post $post + * @param \Flarum\Post\Post $post */ public function __construct(Post $post, User $actor = null) { diff --git a/framework/core/src/Event/PostWasRestored.php b/framework/core/src/Post/Event/Restored.php similarity index 72% rename from framework/core/src/Event/PostWasRestored.php rename to framework/core/src/Post/Event/Restored.php index bfc9fc801..fdd5dc4ae 100644 --- a/framework/core/src/Event/PostWasRestored.php +++ b/framework/core/src/Post/Event/Restored.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Post\Event; -use Flarum\Core\Post\CommentPost; -use Flarum\Core\User; +use Flarum\Post\CommentPost; +use Flarum\User\User; -class PostWasRestored +class Restored { /** - * @var CommentPost + * @var \Flarum\Post\CommentPost */ public $post; @@ -27,7 +27,7 @@ class PostWasRestored public $actor; /** - * @param CommentPost $post + * @param \Flarum\Post\CommentPost $post */ public function __construct(CommentPost $post, User $actor = null) { diff --git a/framework/core/src/Event/PostWasRevised.php b/framework/core/src/Post/Event/Revised.php similarity index 73% rename from framework/core/src/Event/PostWasRevised.php rename to framework/core/src/Post/Event/Revised.php index cbffc9322..62d602e0e 100644 --- a/framework/core/src/Event/PostWasRevised.php +++ b/framework/core/src/Post/Event/Revised.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Post\Event; -use Flarum\Core\Post\CommentPost; -use Flarum\Core\User; +use Flarum\Post\CommentPost; +use Flarum\User\User; -class PostWasRevised +class Revised { /** - * @var CommentPost + * @var \Flarum\Post\CommentPost */ public $post; @@ -27,7 +27,7 @@ class PostWasRevised public $actor; /** - * @param CommentPost $post + * @param \Flarum\Post\CommentPost $post */ public function __construct(CommentPost $post, User $actor = null) { diff --git a/framework/core/src/Event/PostWillBeSaved.php b/framework/core/src/Post/Event/Saving.php similarity index 82% rename from framework/core/src/Event/PostWillBeSaved.php rename to framework/core/src/Post/Event/Saving.php index 0dfb282c7..f9d2092ea 100644 --- a/framework/core/src/Event/PostWillBeSaved.php +++ b/framework/core/src/Post/Event/Saving.php @@ -9,17 +9,17 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Post\Event; -use Flarum\Core\Post; -use Flarum\Core\User; +use Flarum\Post\Post; +use Flarum\User\User; -class PostWillBeSaved +class Saving { /** * The post that will be saved. * - * @var \Flarum\Core\Post + * @var \Flarum\Post\Post */ public $post; @@ -38,7 +38,7 @@ class PostWillBeSaved public $data; /** - * @param \Flarum\Core\Post $post + * @param \Flarum\Post\Post $post * @param User $actor * @param array $data */ diff --git a/framework/core/src/Core/Exception/FloodingException.php b/framework/core/src/Post/Exception/FloodingException.php similarity index 89% rename from framework/core/src/Core/Exception/FloodingException.php rename to framework/core/src/Post/Exception/FloodingException.php index 9174539b8..f9221b934 100644 --- a/framework/core/src/Core/Exception/FloodingException.php +++ b/framework/core/src/Post/Exception/FloodingException.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Exception; +namespace Flarum\Post\Exception; use Exception; diff --git a/framework/core/src/Core/Post/Floodgate.php b/framework/core/src/Post/Floodgate.php similarity index 82% rename from framework/core/src/Core/Post/Floodgate.php rename to framework/core/src/Post/Floodgate.php index ff735cb5a..94cc66d79 100644 --- a/framework/core/src/Core/Post/Floodgate.php +++ b/framework/core/src/Post/Floodgate.php @@ -9,18 +9,17 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Post; +namespace Flarum\Post; use DateTime; -use Flarum\Core\Exception\FloodingException; -use Flarum\Core\Post; -use Flarum\Core\User; +use Flarum\Post\Exception\FloodingException; +use Flarum\User\User; class Floodgate { /** * @param User $actor - * @throws FloodingException + * @throws \Flarum\Post\Exception\FloodingException */ public function assertNotFlooding(User $actor) { diff --git a/framework/core/src/Core/Post/MergeableInterface.php b/framework/core/src/Post/MergeableInterface.php similarity index 91% rename from framework/core/src/Core/Post/MergeableInterface.php rename to framework/core/src/Post/MergeableInterface.php index e1932522e..ea85bca29 100644 --- a/framework/core/src/Core/Post/MergeableInterface.php +++ b/framework/core/src/Post/MergeableInterface.php @@ -9,9 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Post; - -use Flarum\Core\Post; +namespace Flarum\Post; /** * A post that has the ability to be merged into an adjacent post. @@ -26,7 +24,7 @@ interface MergeableInterface * Save the model, given that it is going to appear immediately after the * passed model. * - * @param Post|null $previous + * @param \Flarum\Post\Post|null $previous * @return Post The model resulting after the merge. If the merge is * unsuccessful, this should be the current model instance. Otherwise, * it should be the model that was merged into. diff --git a/framework/core/src/Core/Post.php b/framework/core/src/Post/Post.php similarity index 90% rename from framework/core/src/Core/Post.php rename to framework/core/src/Post/Post.php index cb6717f4d..d603c0e03 100755 --- a/framework/core/src/Core/Post.php +++ b/framework/core/src/Post/Post.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\Post; -use Flarum\Core\Post\RegisteredTypesScope; -use Flarum\Core\Support\EventGeneratorTrait; -use Flarum\Core\Support\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; -use Flarum\Event\PostWasDeleted; +use Flarum\Database\ScopeVisibilityTrait; +use Flarum\Foundation\EventGeneratorTrait; +use Flarum\Post\Event\Deleted; +use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; /** @@ -30,7 +30,7 @@ use Illuminate\Database\Eloquent\Builder; * @property int|null $edit_user_id * @property \Carbon\Carbon|null $hide_time * @property int|null $hide_user_id - * @property \Flarum\Core\Discussion|null $discussion + * @property \Flarum\Discussion\Discussion|null $discussion * @property User|null $user * @property User|null $editUser * @property User|null $hideUser @@ -97,7 +97,7 @@ class Post extends AbstractModel }); static::deleted(function (Post $post) { - $post->raise(new PostWasDeleted($post)); + $post->raise(new Deleted($post)); }); static::addGlobalScope(new RegisteredTypesScope); @@ -129,7 +129,7 @@ class Post extends AbstractModel */ public function discussion() { - return $this->belongsTo('Flarum\Core\Discussion', 'discussion_id'); + return $this->belongsTo('Flarum\Discussion\Discussion', 'discussion_id'); } /** @@ -139,7 +139,7 @@ class Post extends AbstractModel */ public function user() { - return $this->belongsTo('Flarum\Core\User', 'user_id'); + return $this->belongsTo('Flarum\User\User', 'user_id'); } /** @@ -149,7 +149,7 @@ class Post extends AbstractModel */ public function editUser() { - return $this->belongsTo('Flarum\Core\User', 'edit_user_id'); + return $this->belongsTo('Flarum\User\User', 'edit_user_id'); } /** @@ -159,7 +159,7 @@ class Post extends AbstractModel */ public function hideUser() { - return $this->belongsTo('Flarum\Core\User', 'hide_user_id'); + return $this->belongsTo('Flarum\User\User', 'hide_user_id'); } /** diff --git a/framework/core/src/Core/Access/PostPolicy.php b/framework/core/src/Post/PostPolicy.php similarity index 96% rename from framework/core/src/Core/Access/PostPolicy.php rename to framework/core/src/Post/PostPolicy.php index afc0addb5..bc63b7ebc 100644 --- a/framework/core/src/Core/Access/PostPolicy.php +++ b/framework/core/src/Post/PostPolicy.php @@ -9,14 +9,14 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Access; +namespace Flarum\Post; use Carbon\Carbon; -use Flarum\Core\Post; -use Flarum\Core\User; use Flarum\Event\ScopePostVisibility; use Flarum\Event\ScopePrivatePostVisibility; use Flarum\Settings\SettingsRepositoryInterface; +use Flarum\User\AbstractPolicy; +use Flarum\User\User; use Illuminate\Contracts\Events\Dispatcher; class PostPolicy extends AbstractPolicy @@ -57,7 +57,7 @@ class PostPolicy extends AbstractPolicy /** * @param User $actor * @param string $ability - * @param Post $post + * @param \Flarum\Post\Post $post * @return bool|null */ public function after(User $actor, $ability, Post $post) diff --git a/framework/core/src/Core/Repository/PostRepository.php b/framework/core/src/Post/PostRepository.php similarity index 92% rename from framework/core/src/Core/Repository/PostRepository.php rename to framework/core/src/Post/PostRepository.php index 93f74a7ce..d85fe4aa5 100644 --- a/framework/core/src/Core/Repository/PostRepository.php +++ b/framework/core/src/Post/PostRepository.php @@ -9,12 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Repository; +namespace Flarum\Post; -use Flarum\Core\Discussion; -use Flarum\Core\Post; -use Flarum\Core\User; +use Flarum\Discussion\Discussion; use Flarum\Event\ScopePostVisibility; +use Flarum\User\User; use Illuminate\Database\Eloquent\ModelNotFoundException; class PostRepository @@ -34,8 +33,8 @@ class PostRepository * user, or throw an exception. * * @param int $id - * @param \Flarum\Core\User $actor - * @return \Flarum\Core\Post + * @param \Flarum\User\User $actor + * @return \Flarum\Post\Post * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ @@ -55,7 +54,7 @@ class PostRepository * are visible to a certain user, and/or using other criteria. * * @param array $where - * @param \Flarum\Core\User|null $actor + * @param \Flarum\User\User|null $actor * @param array $sort * @param int $count * @param int $start @@ -71,7 +70,7 @@ class PostRepository $query->orderBy($field, $order); } - $ids = $query->lists('id')->all(); + $ids = $query->pluck('id')->all(); return $this->findByIds($ids, $actor); } @@ -81,7 +80,7 @@ class PostRepository * certain user. * * @param array $ids - * @param \Flarum\Core\User|null $actor + * @param \Flarum\User\User|null $actor * @return \Illuminate\Database\Eloquent\Collection */ public function findByIds(array $ids, User $actor = null) @@ -112,7 +111,7 @@ class PostRepository */ public function filterVisibleIds(array $ids, User $actor) { - return $this->queryIds($ids, $actor)->lists('id')->all(); + return $this->queryIds($ids, $actor)->pluck('id')->all(); } /** @@ -122,7 +121,7 @@ class PostRepository * * @param int $discussionId * @param int $number - * @param \Flarum\Core\User|null $actor + * @param \Flarum\User\User|null $actor * @return int */ public function getIndexForNumber($discussionId, $number, User $actor = null) diff --git a/framework/core/src/Post/PostServiceProvider.php b/framework/core/src/Post/PostServiceProvider.php new file mode 100644 index 000000000..b597f875c --- /dev/null +++ b/framework/core/src/Post/PostServiceProvider.php @@ -0,0 +1,47 @@ +<?php + +/* + * This file is part of Flarum. + * + * (c) Toby Zerner <toby.zerner@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Post; + +use Flarum\Event\ConfigurePostTypes; +use Flarum\Foundation\AbstractServiceProvider; + +class PostServiceProvider extends AbstractServiceProvider +{ + /** + * {@inheritdoc} + */ + public function boot() + { + CommentPost::setFormatter($this->app->make('flarum.formatter')); + + $this->registerPostTypes(); + + $events = $this->app->make('events'); + $events->subscribe('Flarum\Post\PostPolicy'); + } + + public function registerPostTypes() + { + $models = [ + 'Flarum\Post\CommentPost', + 'Flarum\Post\DiscussionRenamedPost' + ]; + + $this->app->make('events')->fire( + new ConfigurePostTypes($models) + ); + + foreach ($models as $model) { + Post::setModel($model::$type, $model); + } + } +} diff --git a/framework/core/src/Core/Validator/PostValidator.php b/framework/core/src/Post/PostValidator.php similarity index 85% rename from framework/core/src/Core/Validator/PostValidator.php rename to framework/core/src/Post/PostValidator.php index 3fe573845..0306b592f 100644 --- a/framework/core/src/Core/Validator/PostValidator.php +++ b/framework/core/src/Post/PostValidator.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Validator; +namespace Flarum\Post; + +use Flarum\Foundation\AbstractValidator; class PostValidator extends AbstractValidator { diff --git a/framework/core/src/Post/RegisteredTypesScope.php b/framework/core/src/Post/RegisteredTypesScope.php new file mode 100644 index 000000000..8d27eb4f1 --- /dev/null +++ b/framework/core/src/Post/RegisteredTypesScope.php @@ -0,0 +1,32 @@ +<?php + +/* + * This file is part of Flarum. + * + * (c) Toby Zerner <toby.zerner@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Post; + +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Scope; + +class RegisteredTypesScope implements Scope +{ + /** + * Apply the scope to a given Eloquent query builder. + * + * @param Builder $builder + * @param Model $post + */ + public function apply(Builder $builder, Model $post) + { + $query = $builder->getQuery(); + $types = array_keys($post::getModels()); + $query->whereIn('type', $types); + } +} diff --git a/framework/core/src/Core/Search/AbstractRegexGambit.php b/framework/core/src/Search/AbstractRegexGambit.php similarity index 97% rename from framework/core/src/Core/Search/AbstractRegexGambit.php rename to framework/core/src/Search/AbstractRegexGambit.php index b15a83ddf..4771783a6 100644 --- a/framework/core/src/Core/Search/AbstractRegexGambit.php +++ b/framework/core/src/Search/AbstractRegexGambit.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search; +namespace Flarum\Search; abstract class AbstractRegexGambit implements GambitInterface { diff --git a/framework/core/src/Core/Search/AbstractSearch.php b/framework/core/src/Search/AbstractSearch.php similarity index 97% rename from framework/core/src/Core/Search/AbstractSearch.php rename to framework/core/src/Search/AbstractSearch.php index 581afdf95..23e7c4b78 100644 --- a/framework/core/src/Core/Search/AbstractSearch.php +++ b/framework/core/src/Search/AbstractSearch.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search; +namespace Flarum\Search; -use Flarum\Core\User; +use Flarum\User\User; use Illuminate\Database\Query\Builder; /** diff --git a/framework/core/src/Core/Search/ApplySearchParametersTrait.php b/framework/core/src/Search/ApplySearchParametersTrait.php similarity index 97% rename from framework/core/src/Core/Search/ApplySearchParametersTrait.php rename to framework/core/src/Search/ApplySearchParametersTrait.php index 4854eefb5..58691946c 100644 --- a/framework/core/src/Core/Search/ApplySearchParametersTrait.php +++ b/framework/core/src/Search/ApplySearchParametersTrait.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search; +namespace Flarum\Search; trait ApplySearchParametersTrait { diff --git a/framework/core/src/Core/Search/GambitInterface.php b/framework/core/src/Search/GambitInterface.php similarity index 95% rename from framework/core/src/Core/Search/GambitInterface.php rename to framework/core/src/Search/GambitInterface.php index 7ecb13fda..bcc9f4c9f 100644 --- a/framework/core/src/Core/Search/GambitInterface.php +++ b/framework/core/src/Search/GambitInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search; +namespace Flarum\Search; interface GambitInterface { diff --git a/framework/core/src/Core/Search/GambitManager.php b/framework/core/src/Search/GambitManager.php similarity index 99% rename from framework/core/src/Core/Search/GambitManager.php rename to framework/core/src/Search/GambitManager.php index 6a912f14f..391b42f0c 100644 --- a/framework/core/src/Core/Search/GambitManager.php +++ b/framework/core/src/Search/GambitManager.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search; +namespace Flarum\Search; use Illuminate\Contracts\Container\Container; use LogicException; diff --git a/framework/core/src/Core/Search/SearchCriteria.php b/framework/core/src/Search/SearchCriteria.php similarity index 96% rename from framework/core/src/Core/Search/SearchCriteria.php rename to framework/core/src/Search/SearchCriteria.php index 2bacfb2c3..be5d598b0 100644 --- a/framework/core/src/Core/Search/SearchCriteria.php +++ b/framework/core/src/Search/SearchCriteria.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search; +namespace Flarum\Search; -use Flarum\Core\User; +use Flarum\User\User; /** * Represents the criteria that will determine the entire result set of a diff --git a/framework/core/src/Core/Search/SearchResults.php b/framework/core/src/Search/SearchResults.php similarity index 96% rename from framework/core/src/Core/Search/SearchResults.php rename to framework/core/src/Search/SearchResults.php index 1d85b67e3..d7841320b 100644 --- a/framework/core/src/Core/Search/SearchResults.php +++ b/framework/core/src/Search/SearchResults.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search; +namespace Flarum\Search; use Illuminate\Database\Eloquent\Collection; diff --git a/framework/core/src/Core/Search/SearchServiceProvider.php b/framework/core/src/Search/SearchServiceProvider.php similarity index 55% rename from framework/core/src/Core/Search/SearchServiceProvider.php rename to framework/core/src/Search/SearchServiceProvider.php index 3f5a80065..71d316d54 100644 --- a/framework/core/src/Core/Search/SearchServiceProvider.php +++ b/framework/core/src/Search/SearchServiceProvider.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search; +namespace Flarum\Search; use Flarum\Event\ConfigureDiscussionGambits; use Flarum\Event\ConfigureUserGambits; @@ -26,8 +26,8 @@ class SearchServiceProvider extends AbstractServiceProvider public function register() { $this->app->bind( - 'Flarum\Core\Search\Discussion\Fulltext\DriverInterface', - 'Flarum\Core\Search\Discussion\Fulltext\MySqlFulltextDriver' + 'Flarum\Discussion\Search\Fulltext\DriverInterface', + 'Flarum\Discussion\Search\Fulltext\MySqlFulltextDriver' ); $this->registerDiscussionGambits(); @@ -37,14 +37,14 @@ class SearchServiceProvider extends AbstractServiceProvider public function registerUserGambits() { - $this->app->when('Flarum\Core\Search\User\UserSearcher') - ->needs('Flarum\Core\Search\GambitManager') + $this->app->when('Flarum\User\Search\UserSearcher') + ->needs('Flarum\Search\GambitManager') ->give(function (Container $app) { $gambits = new GambitManager($app); - $gambits->setFulltextGambit('Flarum\Core\Search\User\Gambit\FulltextGambit'); - $gambits->add('Flarum\Core\Search\User\Gambit\EmailGambit'); - $gambits->add('Flarum\Core\Search\User\Gambit\GroupGambit'); + $gambits->setFulltextGambit('Flarum\User\Search\Gambit\FulltextGambit'); + $gambits->add('Flarum\User\Search\Gambit\EmailGambit'); + $gambits->add('Flarum\User\Search\Gambit\GroupGambit'); $app->make('events')->fire( new ConfigureUserGambits($gambits) @@ -56,16 +56,16 @@ class SearchServiceProvider extends AbstractServiceProvider public function registerDiscussionGambits() { - $this->app->when('Flarum\Core\Search\Discussion\DiscussionSearcher') - ->needs('Flarum\Core\Search\GambitManager') + $this->app->when('Flarum\Discussion\Search\DiscussionSearcher') + ->needs('Flarum\Search\GambitManager') ->give(function (Container $app) { $gambits = new GambitManager($app); - $gambits->setFulltextGambit('Flarum\Core\Search\Discussion\Gambit\FulltextGambit'); - $gambits->add('Flarum\Core\Search\Discussion\Gambit\AuthorGambit'); - $gambits->add('Flarum\Core\Search\Discussion\Gambit\CreatedGambit'); - $gambits->add('Flarum\Core\Search\Discussion\Gambit\HiddenGambit'); - $gambits->add('Flarum\Core\Search\Discussion\Gambit\UnreadGambit'); + $gambits->setFulltextGambit('Flarum\Discussion\Search\Gambit\FulltextGambit'); + $gambits->add('Flarum\Discussion\Search\Gambit\AuthorGambit'); + $gambits->add('Flarum\Discussion\Search\Gambit\CreatedGambit'); + $gambits->add('Flarum\Discussion\Search\Gambit\HiddenGambit'); + $gambits->add('Flarum\Discussion\Search\Gambit\UnreadGambit'); $app->make('events')->fire( new ConfigureDiscussionGambits($gambits) diff --git a/framework/core/src/Settings/DatabaseSettingsRepository.php b/framework/core/src/Settings/DatabaseSettingsRepository.php index 3179d23b9..d0700a8e5 100644 --- a/framework/core/src/Settings/DatabaseSettingsRepository.php +++ b/framework/core/src/Settings/DatabaseSettingsRepository.php @@ -24,7 +24,7 @@ class DatabaseSettingsRepository implements SettingsRepositoryInterface public function all() { - return $this->database->table('settings')->lists('value', 'key'); + return $this->database->table('settings')->pluck('value', 'key')->all(); } public function get($key, $default = null) diff --git a/framework/core/src/Event/PrepareUnserializedSettings.php b/framework/core/src/Settings/Event/Deserializing.php similarity index 92% rename from framework/core/src/Event/PrepareUnserializedSettings.php rename to framework/core/src/Settings/Event/Deserializing.php index f75e27f66..d07bae483 100644 --- a/framework/core/src/Event/PrepareUnserializedSettings.php +++ b/framework/core/src/Settings/Event/Deserializing.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Settings\Event; /** * Prepare settings for display in the client. @@ -17,7 +17,7 @@ namespace Flarum\Event; * This event is fired when settings have been retrieved from the database and * are being unserialized for display in the client. */ -class PrepareUnserializedSettings +class Deserializing { /** * The settings array to be unserialized. diff --git a/framework/core/src/Event/SettingWasSet.php b/framework/core/src/Settings/Event/Saved.php similarity index 93% rename from framework/core/src/Event/SettingWasSet.php rename to framework/core/src/Settings/Event/Saved.php index 7210e2599..216a68411 100644 --- a/framework/core/src/Event/SettingWasSet.php +++ b/framework/core/src/Settings/Event/Saved.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Settings\Event; -class SettingWasSet +class Saved { /** * The setting key that was set. diff --git a/framework/core/src/Event/PrepareSerializedSetting.php b/framework/core/src/Settings/Event/Serializing.php similarity index 92% rename from framework/core/src/Event/PrepareSerializedSetting.php rename to framework/core/src/Settings/Event/Serializing.php index 620ccb404..40643ced1 100644 --- a/framework/core/src/Event/PrepareSerializedSetting.php +++ b/framework/core/src/Settings/Event/Serializing.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Settings\Event; -class PrepareSerializedSetting +class Serializing { /** * The settings key being saved. diff --git a/framework/core/src/Settings/SettingsServiceProvider.php b/framework/core/src/Settings/SettingsServiceProvider.php index 1050e80ae..6955083ba 100644 --- a/framework/core/src/Settings/SettingsServiceProvider.php +++ b/framework/core/src/Settings/SettingsServiceProvider.php @@ -20,7 +20,7 @@ class SettingsServiceProvider extends AbstractServiceProvider */ public function register() { - $this->app->singleton('Flarum\Settings\SettingsRepositoryInterface', function () { + $this->app->singleton(SettingsRepositoryInterface::class, function () { return new MemoryCacheSettingsRepository( new DatabaseSettingsRepository( $this->app->make('Illuminate\Database\ConnectionInterface') @@ -28,6 +28,6 @@ class SettingsServiceProvider extends AbstractServiceProvider ); }); - $this->app->alias('Flarum\Settings\SettingsRepositoryInterface', 'flarum.settings'); + $this->app->alias(SettingsRepositoryInterface::class, 'flarum.settings'); } } diff --git a/framework/core/src/Update/Controller/UpdateController.php b/framework/core/src/Update/Controller/UpdateController.php index 9b20ede72..390aff798 100644 --- a/framework/core/src/Update/Controller/UpdateController.php +++ b/framework/core/src/Update/Controller/UpdateController.php @@ -12,9 +12,9 @@ namespace Flarum\Update\Controller; use Exception; +use Flarum\Database\Console\MigrateCommand; use Flarum\Foundation\Application; use Flarum\Http\Controller\ControllerInterface; -use Flarum\Update\Console\MigrateCommand; use Psr\Http\Message\ServerRequestInterface as Request; use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\StreamOutput; diff --git a/framework/core/src/Update/UpdateServiceProvider.php b/framework/core/src/Update/UpdateServiceProvider.php index 17b225f35..7fc93cdc0 100644 --- a/framework/core/src/Update/UpdateServiceProvider.php +++ b/framework/core/src/Update/UpdateServiceProvider.php @@ -12,8 +12,8 @@ namespace Flarum\Update; use Flarum\Foundation\AbstractServiceProvider; -use Flarum\Http\Handler\RouteHandlerFactory; use Flarum\Http\RouteCollection; +use Flarum\Http\RouteHandlerFactory; class UpdateServiceProvider extends AbstractServiceProvider { diff --git a/framework/core/src/Core/Access/AbstractPolicy.php b/framework/core/src/User/AbstractPolicy.php similarity index 98% rename from framework/core/src/Core/Access/AbstractPolicy.php rename to framework/core/src/User/AbstractPolicy.php index d9b8f457f..745b6642b 100644 --- a/framework/core/src/Core/Access/AbstractPolicy.php +++ b/framework/core/src/User/AbstractPolicy.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Access; +namespace Flarum\User; use Flarum\Event\GetPermission; use Flarum\Event\ScopeModelVisibility; diff --git a/framework/core/src/Core/Access/AssertPermissionTrait.php b/framework/core/src/User/AssertPermissionTrait.php similarity index 90% rename from framework/core/src/Core/Access/AssertPermissionTrait.php rename to framework/core/src/User/AssertPermissionTrait.php index cb2d9aff3..d6310440a 100644 --- a/framework/core/src/Core/Access/AssertPermissionTrait.php +++ b/framework/core/src/User/AssertPermissionTrait.php @@ -9,10 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Access; +namespace Flarum\User; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\User; +use Flarum\User\Exception\PermissionDeniedException; trait AssertPermissionTrait { @@ -40,7 +39,7 @@ trait AssertPermissionTrait /** * @param User $actor - * @throws PermissionDeniedException + * @throws \Flarum\User\Exception\PermissionDeniedException */ protected function assertGuest(User $actor) { diff --git a/framework/core/src/Core/AuthToken.php b/framework/core/src/User/AuthToken.php similarity index 92% rename from framework/core/src/Core/AuthToken.php rename to framework/core/src/User/AuthToken.php index 57dd83c28..2458baca5 100644 --- a/framework/core/src/Core/AuthToken.php +++ b/framework/core/src/User/AuthToken.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\User; use DateTime; -use Flarum\Core\Exception\InvalidConfirmationTokenException; use Flarum\Database\AbstractModel; +use Flarum\User\Exception\InvalidConfirmationTokenException; /** * @todo document database columns with @property @@ -82,7 +82,7 @@ class AuthToken extends AbstractModel * @param \Illuminate\Database\Eloquent\Builder $query * @param string $id * - * @throws InvalidConfirmationTokenException + * @throws \Flarum\User\Exception\InvalidConfirmationTokenException * * @return static */ diff --git a/framework/core/src/Core/AvatarUploader.php b/framework/core/src/User/AvatarUploader.php similarity index 89% rename from framework/core/src/Core/AvatarUploader.php rename to framework/core/src/User/AvatarUploader.php index 394a966e6..29f1e9e2e 100755 --- a/framework/core/src/Core/AvatarUploader.php +++ b/framework/core/src/User/AvatarUploader.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\User; use Illuminate\Support\Str; use Intervention\Image\Image; @@ -24,6 +24,10 @@ class AvatarUploader $this->uploadDir = $uploadDir; } + /** + * @param User $user + * @param Image $image + */ public function upload(User $user, Image $image) { if (extension_loaded('exif')) { @@ -32,7 +36,7 @@ class AvatarUploader $encodedImage = $image->fit(100, 100)->encode('png'); - $avatarPath = Str::quickRandom().'.png'; + $avatarPath = Str::random().'.png'; $this->remove($user); $user->changeAvatarPath($avatarPath); diff --git a/framework/core/src/Core/Validator/AvatarValidator.php b/framework/core/src/User/AvatarValidator.php similarity index 86% rename from framework/core/src/Core/Validator/AvatarValidator.php rename to framework/core/src/User/AvatarValidator.php index 4546cfed0..e40ca45f1 100644 --- a/framework/core/src/Core/Validator/AvatarValidator.php +++ b/framework/core/src/User/AvatarValidator.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Validator; +namespace Flarum\User; + +use Flarum\Foundation\AbstractValidator; class AvatarValidator extends AbstractValidator { diff --git a/framework/core/src/Core/Command/ConfirmEmail.php b/framework/core/src/User/Command/ConfirmEmail.php similarity index 94% rename from framework/core/src/Core/Command/ConfirmEmail.php rename to framework/core/src/User/Command/ConfirmEmail.php index 1b9f5ab0c..b07fd38a2 100644 --- a/framework/core/src/Core/Command/ConfirmEmail.php +++ b/framework/core/src/User/Command/ConfirmEmail.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; class ConfirmEmail { diff --git a/framework/core/src/Core/Command/ConfirmEmailHandler.php b/framework/core/src/User/Command/ConfirmEmailHandler.php similarity index 79% rename from framework/core/src/Core/Command/ConfirmEmailHandler.php rename to framework/core/src/User/Command/ConfirmEmailHandler.php index 5ee4d5190..cef9f70b8 100644 --- a/framework/core/src/Core/Command/ConfirmEmailHandler.php +++ b/framework/core/src/User/Command/ConfirmEmailHandler.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; -use Flarum\Core\EmailToken; -use Flarum\Core\Repository\UserRepository; -use Flarum\Core\Support\DispatchEventsTrait; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\User\EmailToken; +use Flarum\User\UserRepository; use Illuminate\Contracts\Events\Dispatcher; class ConfirmEmailHandler @@ -21,12 +21,12 @@ class ConfirmEmailHandler use DispatchEventsTrait; /** - * @var UserRepository + * @var \Flarum\User\UserRepository */ protected $users; /** - * @param UserRepository $users + * @param \Flarum\User\UserRepository $users */ public function __construct(Dispatcher $events, UserRepository $users) { @@ -36,7 +36,7 @@ class ConfirmEmailHandler /** * @param ConfirmEmail $command - * @return \Flarum\Core\User + * @return \Flarum\User\User */ public function handle(ConfirmEmail $command) { diff --git a/framework/core/src/Core/Command/DeleteAvatar.php b/framework/core/src/User/Command/DeleteAvatar.php similarity index 93% rename from framework/core/src/Core/Command/DeleteAvatar.php rename to framework/core/src/User/Command/DeleteAvatar.php index 9503d00e5..23593c245 100644 --- a/framework/core/src/Core/Command/DeleteAvatar.php +++ b/framework/core/src/User/Command/DeleteAvatar.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; -use Flarum\Core\User; +use Flarum\User\User; class DeleteAvatar { diff --git a/framework/core/src/Core/Command/DeleteAvatarHandler.php b/framework/core/src/User/Command/DeleteAvatarHandler.php similarity index 76% rename from framework/core/src/Core/Command/DeleteAvatarHandler.php rename to framework/core/src/User/Command/DeleteAvatarHandler.php index 2e735582d..25eb3b39f 100644 --- a/framework/core/src/Core/Command/DeleteAvatarHandler.php +++ b/framework/core/src/User/Command/DeleteAvatarHandler.php @@ -9,14 +9,13 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\AvatarUploader; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\Repository\UserRepository; -use Flarum\Core\Support\DispatchEventsTrait; -use Flarum\Event\AvatarWillBeDeleted; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\User\AssertPermissionTrait; +use Flarum\User\AvatarUploader; +use Flarum\User\Event\AvatarDeleting; +use Flarum\User\UserRepository; use Illuminate\Contracts\Events\Dispatcher; class DeleteAvatarHandler @@ -48,8 +47,8 @@ class DeleteAvatarHandler /** * @param DeleteAvatar $command - * @return \Flarum\Core\User - * @throws PermissionDeniedException + * @return \Flarum\User\User + * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(DeleteAvatar $command) { @@ -64,7 +63,7 @@ class DeleteAvatarHandler $this->uploader->remove($user); $this->events->fire( - new AvatarWillBeDeleted($user, $actor) + new AvatarDeleting($user, $actor) ); $user->save(); diff --git a/framework/core/src/Core/Command/DeleteUser.php b/framework/core/src/User/Command/DeleteUser.php similarity index 95% rename from framework/core/src/Core/Command/DeleteUser.php rename to framework/core/src/User/Command/DeleteUser.php index 16cd44cf9..43bfd555c 100644 --- a/framework/core/src/Core/Command/DeleteUser.php +++ b/framework/core/src/User/Command/DeleteUser.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; -use Flarum\Core\User; +use Flarum\User\User; class DeleteUser { diff --git a/framework/core/src/Core/Command/DeleteUserHandler.php b/framework/core/src/User/Command/DeleteUserHandler.php similarity index 75% rename from framework/core/src/Core/Command/DeleteUserHandler.php rename to framework/core/src/User/Command/DeleteUserHandler.php index a4058465d..006d5e17b 100644 --- a/framework/core/src/Core/Command/DeleteUserHandler.php +++ b/framework/core/src/User/Command/DeleteUserHandler.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\Repository\UserRepository; -use Flarum\Core\Support\DispatchEventsTrait; -use Flarum\Event\UserWillBeDeleted; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\User\AssertPermissionTrait; +use Flarum\User\Event\Deleting; +use Flarum\User\Exception\PermissionDeniedException; +use Flarum\User\UserRepository; use Illuminate\Contracts\Events\Dispatcher; class DeleteUserHandler @@ -40,7 +40,7 @@ class DeleteUserHandler /** * @param DeleteUser $command - * @return \Flarum\Core\User + * @return \Flarum\User\User * @throws PermissionDeniedException */ public function handle(DeleteUser $command) @@ -51,7 +51,7 @@ class DeleteUserHandler $this->assertCan($actor, 'delete', $user); $this->events->fire( - new UserWillBeDeleted($user, $actor, $command->data) + new Deleting($user, $actor, $command->data) ); $user->delete(); diff --git a/framework/core/src/Core/Command/EditUser.php b/framework/core/src/User/Command/EditUser.php similarity index 94% rename from framework/core/src/Core/Command/EditUser.php rename to framework/core/src/User/Command/EditUser.php index 200fad5cb..9ac9382de 100644 --- a/framework/core/src/Core/Command/EditUser.php +++ b/framework/core/src/User/Command/EditUser.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; -use Flarum\Core\User; +use Flarum\User\User; class EditUser { diff --git a/framework/core/src/Core/Command/EditUserHandler.php b/framework/core/src/User/Command/EditUserHandler.php similarity index 87% rename from framework/core/src/Core/Command/EditUserHandler.php rename to framework/core/src/User/Command/EditUserHandler.php index 7b336ae93..3554038b5 100644 --- a/framework/core/src/Core/Command/EditUserHandler.php +++ b/framework/core/src/User/Command/EditUserHandler.php @@ -9,20 +9,20 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; use Exception; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\AvatarUploader; -use Flarum\Core\Repository\UserRepository; -use Flarum\Core\Support\DispatchEventsTrait; -use Flarum\Core\User; -use Flarum\Core\Validator\UserValidator; -use Flarum\Event\UserGroupsWereChanged; -use Flarum\Event\UserWillBeSaved; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\User\AssertPermissionTrait; +use Flarum\User\AvatarUploader; +use Flarum\User\Event\GroupsChanged; +use Flarum\User\Event\Saving; +use Flarum\User\User; +use Flarum\User\UserRepository; +use Flarum\User\UserValidator; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Validation\Factory; -use Illuminate\Contracts\Validation\ValidationException; +use Illuminate\Validation\ValidationException; use Intervention\Image\ImageManager; class EditUserHandler @@ -31,7 +31,7 @@ class EditUserHandler use AssertPermissionTrait; /** - * @var UserRepository + * @var \Flarum\User\UserRepository */ protected $users; @@ -52,7 +52,7 @@ class EditUserHandler /** * @param Dispatcher $events - * @param UserRepository $users + * @param \Flarum\User\UserRepository $users * @param UserValidator $validator * @param AvatarUploader $avatarUploader * @param Factory $validatorFactory @@ -69,7 +69,7 @@ class EditUserHandler /** * @param EditUser $command * @return User - * @throws \Flarum\Core\Exception\PermissionDeniedException + * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(EditUser $command) { @@ -138,7 +138,7 @@ class EditUserHandler } $user->raise( - new UserGroupsWereChanged($user, $user->groups()->get()->all()) + new GroupsChanged($user, $user->groups()->get()->all()) ); $user->afterSave(function (User $user) use ($newGroupIds) { @@ -165,7 +165,7 @@ class EditUserHandler } $this->events->fire( - new UserWillBeSaved($user, $actor, $data) + new Saving($user, $actor, $data) ); $this->validator->setUser($user); diff --git a/framework/core/src/Core/Command/RegisterUser.php b/framework/core/src/User/Command/RegisterUser.php similarity index 93% rename from framework/core/src/Core/Command/RegisterUser.php rename to framework/core/src/User/Command/RegisterUser.php index 57230324f..47494cf25 100644 --- a/framework/core/src/Core/Command/RegisterUser.php +++ b/framework/core/src/User/Command/RegisterUser.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; -use Flarum\Core\User; +use Flarum\User\User; class RegisterUser { diff --git a/framework/core/src/Core/Command/RegisterUserHandler.php b/framework/core/src/User/Command/RegisterUserHandler.php similarity index 88% rename from framework/core/src/Core/Command/RegisterUserHandler.php rename to framework/core/src/User/Command/RegisterUserHandler.php index 809b5b38e..fdd95b434 100644 --- a/framework/core/src/Core/Command/RegisterUserHandler.php +++ b/framework/core/src/User/Command/RegisterUserHandler.php @@ -9,21 +9,21 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; use Exception; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\AuthToken; -use Flarum\Core\AvatarUploader; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\Support\DispatchEventsTrait; -use Flarum\Core\User; -use Flarum\Core\Validator\UserValidator; -use Flarum\Event\UserWillBeSaved; +use Flarum\Foundation\DispatchEventsTrait; use Flarum\Settings\SettingsRepositoryInterface; +use Flarum\User\AssertPermissionTrait; +use Flarum\User\AuthToken; +use Flarum\User\AvatarUploader; +use Flarum\User\Event\Saving; +use Flarum\User\Exception\PermissionDeniedException; +use Flarum\User\User; +use Flarum\User\UserValidator; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Validation\Factory; -use Illuminate\Contracts\Validation\ValidationException; +use Illuminate\Validation\ValidationException; use Intervention\Image\ImageManager; class RegisterUserHandler @@ -71,7 +71,7 @@ class RegisterUserHandler * @param RegisterUser $command * @throws PermissionDeniedException if signup is closed and the actor is * not an administrator. - * @throws \Flarum\Core\Exception\InvalidConfirmationTokenException if an + * @throws \Flarum\User\Exception\InvalidConfirmationTokenException if an * email confirmation token is provided but is invalid. * @return User */ @@ -118,6 +118,12 @@ class RegisterUserHandler $user->activate(); } + $this->events->fire( + new Saving($user, $actor, $data) + ); + + $this->validator->assertValid(array_merge($user->getAttributes(), compact('password'))); + if ($avatarUrl = array_get($data, 'attributes.avatarUrl')) { $validation = $this->validatorFactory->make(compact('avatarUrl'), ['avatarUrl' => 'url']); @@ -134,12 +140,6 @@ class RegisterUserHandler } } - $this->events->fire( - new UserWillBeSaved($user, $actor, $data) - ); - - $this->validator->assertValid(array_merge($user->getAttributes(), compact('password'))); - $user->save(); if (isset($token)) { diff --git a/framework/core/src/Core/Command/RequestPasswordReset.php b/framework/core/src/User/Command/RequestPasswordReset.php similarity index 94% rename from framework/core/src/Core/Command/RequestPasswordReset.php rename to framework/core/src/User/Command/RequestPasswordReset.php index 7a59942ae..fd997179d 100644 --- a/framework/core/src/Core/Command/RequestPasswordReset.php +++ b/framework/core/src/User/Command/RequestPasswordReset.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; class RequestPasswordReset { diff --git a/framework/core/src/Core/Command/RequestPasswordResetHandler.php b/framework/core/src/User/Command/RequestPasswordResetHandler.php similarity index 84% rename from framework/core/src/Core/Command/RequestPasswordResetHandler.php rename to framework/core/src/User/Command/RequestPasswordResetHandler.php index 3318c9882..357c7963e 100644 --- a/framework/core/src/Core/Command/RequestPasswordResetHandler.php +++ b/framework/core/src/User/Command/RequestPasswordResetHandler.php @@ -9,19 +9,18 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; -use Flarum\Core; -use Flarum\Core\PasswordToken; -use Flarum\Core\Repository\UserRepository; -use Flarum\Forum\UrlGenerator; +use Flarum\Http\UrlGenerator; use Flarum\Settings\SettingsRepositoryInterface; +use Flarum\User\PasswordToken; +use Flarum\User\UserRepository; use Illuminate\Contracts\Mail\Mailer; +use Illuminate\Contracts\Translation\Translator; use Illuminate\Contracts\Validation\Factory; -use Illuminate\Contracts\Validation\ValidationException; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Mail\Message; -use Symfony\Component\Translation\TranslatorInterface; +use Illuminate\Validation\ValidationException; class RequestPasswordResetHandler { @@ -46,7 +45,7 @@ class RequestPasswordResetHandler protected $url; /** - * @var TranslatorInterface + * @var Translator */ protected $translator; @@ -60,7 +59,7 @@ class RequestPasswordResetHandler * @param SettingsRepositoryInterface $settings * @param Mailer $mailer * @param UrlGenerator $url - * @param TranslatorInterface $translator + * @param Translator $translator * @param Factory $validatorFactory */ public function __construct( @@ -68,7 +67,7 @@ class RequestPasswordResetHandler SettingsRepositoryInterface $settings, Mailer $mailer, UrlGenerator $url, - TranslatorInterface $translator, + Translator $translator, Factory $validatorFactory ) { $this->users = $users; @@ -81,7 +80,7 @@ class RequestPasswordResetHandler /** * @param RequestPasswordReset $command - * @return \Flarum\Core\User + * @return \Flarum\User\User * @throws ModelNotFoundException */ public function handle(RequestPasswordReset $command) @@ -108,7 +107,7 @@ class RequestPasswordResetHandler $data = [ '{username}' => $user->display_name, - '{url}' => $this->url->toRoute('resetPassword', ['token' => $token->id]), + '{url}' => $this->url->to('forum')->route('resetPassword', ['token' => $token->id]), '{forum}' => $this->settings->get('forum_title'), ]; diff --git a/framework/core/src/Core/Command/UploadAvatar.php b/framework/core/src/User/Command/UploadAvatar.php similarity index 95% rename from framework/core/src/Core/Command/UploadAvatar.php rename to framework/core/src/User/Command/UploadAvatar.php index 988ecc26d..6a06cf852 100644 --- a/framework/core/src/Core/Command/UploadAvatar.php +++ b/framework/core/src/User/Command/UploadAvatar.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; -use Flarum\Core\User; +use Flarum\User\User; use Psr\Http\Message\UploadedFileInterface; class UploadAvatar diff --git a/framework/core/src/Core/Command/UploadAvatarHandler.php b/framework/core/src/User/Command/UploadAvatarHandler.php similarity index 82% rename from framework/core/src/Core/Command/UploadAvatarHandler.php rename to framework/core/src/User/Command/UploadAvatarHandler.php index 0750ff0b7..18fa84c00 100644 --- a/framework/core/src/Core/Command/UploadAvatarHandler.php +++ b/framework/core/src/User/Command/UploadAvatarHandler.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\AvatarUploader; -use Flarum\Core\Repository\UserRepository; -use Flarum\Core\Support\DispatchEventsTrait; -use Flarum\Core\Validator\AvatarValidator; -use Flarum\Event\AvatarWillBeSaved; use Flarum\Foundation\Application; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\User\AssertPermissionTrait; +use Flarum\User\AvatarUploader; +use Flarum\User\AvatarValidator; +use Flarum\User\Event\AvatarSaving; +use Flarum\User\UserRepository; use Illuminate\Contracts\Events\Dispatcher; use Intervention\Image\ImageManager; use Symfony\Component\HttpFoundation\File\UploadedFile; @@ -28,7 +28,7 @@ class UploadAvatarHandler use AssertPermissionTrait; /** - * @var UserRepository + * @var \Flarum\User\UserRepository */ protected $users; @@ -43,7 +43,7 @@ class UploadAvatarHandler protected $uploader; /** - * @var AvatarValidator + * @var \Flarum\User\AvatarValidator */ protected $validator; @@ -65,8 +65,8 @@ class UploadAvatarHandler /** * @param UploadAvatar $command - * @return \Flarum\Core\User - * @throws \Flarum\Core\Exception\PermissionDeniedException + * @return \Flarum\User\User + * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(UploadAvatar $command) { @@ -98,7 +98,7 @@ class UploadAvatarHandler $image = (new ImageManager)->make($tmpFile); $this->events->fire( - new AvatarWillBeSaved($user, $actor, $image) + new AvatarSaving($user, $actor, $image) ); $this->uploader->upload($user, $image); diff --git a/framework/core/src/Core/Listener/EmailConfirmationMailer.php b/framework/core/src/User/EmailConfirmationMailer.php similarity index 74% rename from framework/core/src/Core/Listener/EmailConfirmationMailer.php rename to framework/core/src/User/EmailConfirmationMailer.php index 6c7583cad..642a641a3 100755 --- a/framework/core/src/Core/Listener/EmailConfirmationMailer.php +++ b/framework/core/src/User/EmailConfirmationMailer.php @@ -9,19 +9,16 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Listener; +namespace Flarum\User; -use Flarum\Core; -use Flarum\Core\EmailToken; -use Flarum\Core\User; -use Flarum\Event\UserEmailChangeWasRequested; -use Flarum\Event\UserWasRegistered; -use Flarum\Forum\UrlGenerator; +use Flarum\Http\UrlGenerator; use Flarum\Settings\SettingsRepositoryInterface; +use Flarum\User\Event\EmailChangeRequested; +use Flarum\User\Event\Registered; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Mail\Mailer; +use Illuminate\Contracts\Translation\Translator; use Illuminate\Mail\Message; -use Symfony\Component\Translation\TranslatorInterface; class EmailConfirmationMailer { @@ -41,7 +38,7 @@ class EmailConfirmationMailer protected $url; /** - * @var TranslatorInterface + * @var Translator */ protected $translator; @@ -49,9 +46,9 @@ class EmailConfirmationMailer * @param \Flarum\Settings\SettingsRepositoryInterface $settings * @param Mailer $mailer * @param UrlGenerator $url - * @param TranslatorInterface $translator + * @param Translator $translator */ - public function __construct(SettingsRepositoryInterface $settings, Mailer $mailer, UrlGenerator $url, TranslatorInterface $translator) + public function __construct(SettingsRepositoryInterface $settings, Mailer $mailer, UrlGenerator $url, Translator $translator) { $this->settings = $settings; $this->mailer = $mailer; @@ -64,14 +61,14 @@ class EmailConfirmationMailer */ public function subscribe(Dispatcher $events) { - $events->listen(UserWasRegistered::class, [$this, 'whenUserWasRegistered']); - $events->listen(UserEmailChangeWasRequested::class, [$this, 'whenUserEmailChangeWasRequested']); + $events->listen(Registered::class, [$this, 'whenUserWasRegistered']); + $events->listen(EmailChangeRequested::class, [$this, 'whenUserEmailChangeWasRequested']); } /** - * @param \Flarum\Event\UserWasRegistered $event + * @param \Flarum\User\Event\Registered $event */ - public function whenUserWasRegistered(UserWasRegistered $event) + public function whenUserWasRegistered(Registered $event) { $user = $event->user; @@ -90,9 +87,9 @@ class EmailConfirmationMailer } /** - * @param \Flarum\Event\UserEmailChangeWasRequested $event + * @param \Flarum\User\Event\EmailChangeRequested $event */ - public function whenUserEmailChangeWasRequested(UserEmailChangeWasRequested $event) + public function whenUserEmailChangeWasRequested(EmailChangeRequested $event) { $email = $event->email; $data = $this->getEmailData($event->user, $email); @@ -131,7 +128,7 @@ class EmailConfirmationMailer return [ '{username}' => $user->display_name, - '{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/Core/EmailToken.php b/framework/core/src/User/EmailToken.php similarity index 92% rename from framework/core/src/Core/EmailToken.php rename to framework/core/src/User/EmailToken.php index 257d62211..ac143ea12 100644 --- a/framework/core/src/Core/EmailToken.php +++ b/framework/core/src/User/EmailToken.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\User; use DateTime; -use Flarum\Core\Exception\InvalidConfirmationTokenException; use Flarum\Database\AbstractModel; +use Flarum\User\Exception\InvalidConfirmationTokenException; /** * @todo document database columns with @property @@ -64,7 +64,7 @@ class EmailToken extends AbstractModel */ public function user() { - return $this->belongsTo('Flarum\Core\User'); + return $this->belongsTo('Flarum\User'); } /** diff --git a/framework/core/src/Event/UserWasRenamed.php b/framework/core/src/User/Event/Activated.php similarity index 88% rename from framework/core/src/Event/UserWasRenamed.php rename to framework/core/src/User/Event/Activated.php index 671e64080..d4ad87dff 100644 --- a/framework/core/src/Event/UserWasRenamed.php +++ b/framework/core/src/User/Event/Activated.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\User\Event; -use Flarum\Core\User; +use Flarum\User\User; -class UserWasRenamed +class Activated { /** * @var User diff --git a/framework/core/src/User/Event/AvatarChanged.php b/framework/core/src/User/Event/AvatarChanged.php new file mode 100644 index 000000000..1754d0538 --- /dev/null +++ b/framework/core/src/User/Event/AvatarChanged.php @@ -0,0 +1,37 @@ +<?php + +/* + * This file is part of Flarum. + * + * (c) Toby Zerner <toby.zerner@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\User\Event; + +use Flarum\User\User; + +class AvatarChanged +{ + /** + * @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/AvatarWillBeDeleted.php b/framework/core/src/User/Event/AvatarDeleting.php similarity index 90% rename from framework/core/src/Event/AvatarWillBeDeleted.php rename to framework/core/src/User/Event/AvatarDeleting.php index 9828fa674..c991acb8d 100644 --- a/framework/core/src/Event/AvatarWillBeDeleted.php +++ b/framework/core/src/User/Event/AvatarDeleting.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\User\Event; -use Flarum\Core\User; +use Flarum\User\User; -class AvatarWillBeDeleted +class AvatarDeleting { /** * The user whose avatar will be deleted. diff --git a/framework/core/src/Event/AvatarWillBeSaved.php b/framework/core/src/User/Event/AvatarSaving.php similarity index 92% rename from framework/core/src/Event/AvatarWillBeSaved.php rename to framework/core/src/User/Event/AvatarSaving.php index 0c52399cc..4e25adc95 100644 --- a/framework/core/src/Event/AvatarWillBeSaved.php +++ b/framework/core/src/User/Event/AvatarSaving.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\User\Event; -use Flarum\Core\User; +use Flarum\User\User; use Intervention\Image\Image; -class AvatarWillBeSaved +class AvatarSaving { /** * The user whose avatar will be saved. diff --git a/framework/core/src/Event/UserWasActivated.php b/framework/core/src/User/Event/BioChanged.php similarity index 88% rename from framework/core/src/Event/UserWasActivated.php rename to framework/core/src/User/Event/BioChanged.php index 2245caed4..2751516f6 100644 --- a/framework/core/src/Event/UserWasActivated.php +++ b/framework/core/src/User/Event/BioChanged.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\User\Event; -use Flarum\Core\User; +use Flarum\User\User; -class UserWasActivated +class BioChanged { /** * @var User diff --git a/framework/core/src/Event/CheckUserPassword.php b/framework/core/src/User/Event/CheckingPassword.php similarity index 87% rename from framework/core/src/Event/CheckUserPassword.php rename to framework/core/src/User/Event/CheckingPassword.php index ee86252c6..97f73227c 100644 --- a/framework/core/src/Event/CheckUserPassword.php +++ b/framework/core/src/User/Event/CheckingPassword.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\User\Event; -use Flarum\Core\User; +use Flarum\User\User; -class CheckUserPassword +class CheckingPassword { /** * @var User diff --git a/framework/core/src/Event/UserWasDeleted.php b/framework/core/src/User/Event/Deleted.php similarity index 88% rename from framework/core/src/Event/UserWasDeleted.php rename to framework/core/src/User/Event/Deleted.php index 5f041b284..0b3a574ef 100644 --- a/framework/core/src/Event/UserWasDeleted.php +++ b/framework/core/src/User/Event/Deleted.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\User\Event; -use Flarum\Core\User; +use Flarum\User\User; -class UserWasDeleted +class Deleted { /** * @var User diff --git a/framework/core/src/Event/UserWillBeDeleted.php b/framework/core/src/User/Event/Deleting.php similarity index 92% rename from framework/core/src/Event/UserWillBeDeleted.php rename to framework/core/src/User/Event/Deleting.php index 5ecc8685a..1ff7766f5 100644 --- a/framework/core/src/Event/UserWillBeDeleted.php +++ b/framework/core/src/User/Event/Deleting.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\User\Event; -use Flarum\Core\User; +use Flarum\User\User; -class UserWillBeDeleted +class Deleting { /** * The user who will be deleted. diff --git a/framework/core/src/Event/UserEmailChangeWasRequested.php b/framework/core/src/User/Event/EmailChangeRequested.php similarity index 89% rename from framework/core/src/Event/UserEmailChangeWasRequested.php rename to framework/core/src/User/Event/EmailChangeRequested.php index 1b4498699..0a237c1c6 100644 --- a/framework/core/src/Event/UserEmailChangeWasRequested.php +++ b/framework/core/src/User/Event/EmailChangeRequested.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\User\Event; -use Flarum\Core\User; +use Flarum\User\User; -class UserEmailChangeWasRequested +class EmailChangeRequested { /** * The user who requested the email change. diff --git a/framework/core/src/Event/UserWasRegistered.php b/framework/core/src/User/Event/EmailChanged.php similarity index 88% rename from framework/core/src/Event/UserWasRegistered.php rename to framework/core/src/User/Event/EmailChanged.php index 2cc82ce5b..fa1bf7759 100644 --- a/framework/core/src/Event/UserWasRegistered.php +++ b/framework/core/src/User/Event/EmailChanged.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\User\Event; -use Flarum\Core\User; +use Flarum\User\User; -class UserWasRegistered +class EmailChanged { /** * @var User diff --git a/framework/core/src/Event/UserGroupsWereChanged.php b/framework/core/src/User/Event/GroupsChanged.php similarity index 82% rename from framework/core/src/Event/UserGroupsWereChanged.php rename to framework/core/src/User/Event/GroupsChanged.php index 91822f158..310d70fb7 100644 --- a/framework/core/src/Event/UserGroupsWereChanged.php +++ b/framework/core/src/User/Event/GroupsChanged.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\User\Event; -use Flarum\Core\User; +use Flarum\User\User; -class UserGroupsWereChanged +class GroupsChanged { /** * The user whose groups were changed. @@ -23,7 +23,7 @@ class UserGroupsWereChanged public $user; /** - * @var \Flarum\Core\Group[] + * @var \Flarum\Group\Group[] */ public $oldGroups; @@ -34,7 +34,7 @@ class UserGroupsWereChanged /** * @param User $user The user whose groups were changed. - * @param \Flarum\Core\Group[] $oldGroups + * @param \Flarum\Group\Group[] $oldGroups * @param User $actor */ public function __construct(User $user, array $oldGroups, User $actor = null) diff --git a/framework/core/src/Event/UserLoggedIn.php b/framework/core/src/User/Event/LoggedIn.php similarity index 86% rename from framework/core/src/Event/UserLoggedIn.php rename to framework/core/src/User/Event/LoggedIn.php index 175994a71..3659a0e40 100644 --- a/framework/core/src/Event/UserLoggedIn.php +++ b/framework/core/src/User/Event/LoggedIn.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\User\Event; -use Flarum\Core\User; use Flarum\Http\AccessToken; +use Flarum\User\User; -class UserLoggedIn +class LoggedIn { public $user; diff --git a/framework/core/src/Event/UserLoggedOut.php b/framework/core/src/User/Event/LoggedOut.php similarity index 83% rename from framework/core/src/Event/UserLoggedOut.php rename to framework/core/src/User/Event/LoggedOut.php index 9e4680c16..103026983 100644 --- a/framework/core/src/Event/UserLoggedOut.php +++ b/framework/core/src/User/Event/LoggedOut.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\User\Event; -use Flarum\Core\User; +use Flarum\User\User; -class UserLoggedOut +class LoggedOut { public $user; diff --git a/framework/core/src/Event/UserAvatarWasChanged.php b/framework/core/src/User/Event/PasswordChanged.php similarity index 88% rename from framework/core/src/Event/UserAvatarWasChanged.php rename to framework/core/src/User/Event/PasswordChanged.php index a328bdd00..855348676 100644 --- a/framework/core/src/Event/UserAvatarWasChanged.php +++ b/framework/core/src/User/Event/PasswordChanged.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\User\Event; -use Flarum\Core\User; +use Flarum\User\User; -class UserAvatarWasChanged +class PasswordChanged { /** * @var User diff --git a/framework/core/src/User/Event/Registered.php b/framework/core/src/User/Event/Registered.php new file mode 100644 index 000000000..5deedfc5d --- /dev/null +++ b/framework/core/src/User/Event/Registered.php @@ -0,0 +1,37 @@ +<?php + +/* + * This file is part of Flarum. + * + * (c) Toby Zerner <toby.zerner@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\User\Event; + +use Flarum\User\User; + +class Registered +{ + /** + * @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/User/Event/Renamed.php b/framework/core/src/User/Event/Renamed.php new file mode 100644 index 000000000..1e453d64a --- /dev/null +++ b/framework/core/src/User/Event/Renamed.php @@ -0,0 +1,37 @@ +<?php + +/* + * This file is part of Flarum. + * + * (c) Toby Zerner <toby.zerner@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\User\Event; + +use Flarum\User\User; + +class Renamed +{ + /** + * @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/UserWillBeSaved.php b/framework/core/src/User/Event/Saving.php similarity index 93% rename from framework/core/src/Event/UserWillBeSaved.php rename to framework/core/src/User/Event/Saving.php index 5b0d39b80..b8f09f371 100644 --- a/framework/core/src/Event/UserWillBeSaved.php +++ b/framework/core/src/User/Event/Saving.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\User\Event; -use Flarum\Core\User; +use Flarum\User\User; -class UserWillBeSaved +class Saving { /** * The user that will be saved. diff --git a/framework/core/src/Event/ConfigureUserSearch.php b/framework/core/src/User/Event/Searching.php similarity index 78% rename from framework/core/src/Event/ConfigureUserSearch.php rename to framework/core/src/User/Event/Searching.php index fec2e6820..5f6b0695f 100644 --- a/framework/core/src/Event/ConfigureUserSearch.php +++ b/framework/core/src/User/Event/Searching.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\User\Event; -use Flarum\Core\Search\SearchCriteria; -use Flarum\Core\Search\User\UserSearch; +use Flarum\Search\SearchCriteria; +use Flarum\User\Search\UserSearch; -class ConfigureUserSearch +class Searching { /** - * @var UserSearch + * @var \Flarum\User\Search\UserSearch */ public $search; diff --git a/framework/core/src/Core/Exception/InvalidConfirmationTokenException.php b/framework/core/src/User/Exception/InvalidConfirmationTokenException.php similarity index 90% rename from framework/core/src/Core/Exception/InvalidConfirmationTokenException.php rename to framework/core/src/User/Exception/InvalidConfirmationTokenException.php index c3bb44091..c8e9240b2 100644 --- a/framework/core/src/Core/Exception/InvalidConfirmationTokenException.php +++ b/framework/core/src/User/Exception/InvalidConfirmationTokenException.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Exception; +namespace Flarum\User\Exception; use Exception; diff --git a/framework/core/src/Core/Exception/PermissionDeniedException.php b/framework/core/src/User/Exception/PermissionDeniedException.php similarity index 93% rename from framework/core/src/Core/Exception/PermissionDeniedException.php rename to framework/core/src/User/Exception/PermissionDeniedException.php index a80289fdc..1bbeb766c 100644 --- a/framework/core/src/Core/Exception/PermissionDeniedException.php +++ b/framework/core/src/User/Exception/PermissionDeniedException.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Exception; +namespace Flarum\User\Exception; use Exception; diff --git a/framework/core/src/Core/Access/Gate.php b/framework/core/src/User/Gate.php similarity index 89% rename from framework/core/src/Core/Access/Gate.php rename to framework/core/src/User/Gate.php index f6eba5078..7d9ac895c 100644 --- a/framework/core/src/Core/Access/Gate.php +++ b/framework/core/src/User/Gate.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Access; +namespace Flarum\User; use Illuminate\Contracts\Auth\Access\Gate as GateContract; use Illuminate\Contracts\Container\Container; @@ -353,4 +353,51 @@ class Gate implements GateContract { return call_user_func($this->userResolver); } + + /** + * Register a callback to run after all Gate checks. + * + * @param callable $callback + * @return GateContract + */ + public function after(callable $callback) + { + // TODO: Implement after() method. + } + + /** + * Determine if any one of the given abilities should be granted for the current user. + * + * @param iterable|string $abilities + * @param array|mixed $arguments + * @return bool + */ + public function any($abilities, $arguments = []) + { + // TODO: Implement any() method. + } + + /** + * Determine if the given ability should be granted for the current user. + * + * @param string $ability + * @param array|mixed $arguments + * @return \Illuminate\Auth\Access\Response + * + * @throws \Illuminate\Auth\Access\AuthorizationException + */ + public function authorize($ability, $arguments = []) + { + // TODO: Implement authorize() method. + } + + /** + * Get all of the defined abilities. + * + * @return array + */ + public function abilities() + { + // TODO: Implement abilities() method. + } } diff --git a/framework/core/src/Core/Guest.php b/framework/core/src/User/Guest.php similarity index 91% rename from framework/core/src/Core/Guest.php rename to framework/core/src/User/Guest.php index 0fbf00748..e7dc3f502 100755 --- a/framework/core/src/Core/Guest.php +++ b/framework/core/src/User/Guest.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\User; + +use Flarum\Group\Group; class Guest extends User { @@ -23,7 +25,7 @@ class Guest extends User /** * Get the guest's group, containing only the 'guests' group model. * - * @return Group + * @return \Flarum\Group\Group */ public function getGroupsAttribute() { diff --git a/framework/core/src/Core/PasswordToken.php b/framework/core/src/User/PasswordToken.php similarity index 93% rename from framework/core/src/Core/PasswordToken.php rename to framework/core/src/User/PasswordToken.php index 5d08e3867..53b955eda 100644 --- a/framework/core/src/Core/PasswordToken.php +++ b/framework/core/src/User/PasswordToken.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\User; use Flarum\Database\AbstractModel; @@ -59,6 +59,6 @@ class PasswordToken extends AbstractModel */ public function user() { - return $this->belongsTo('Flarum\Core\User'); + return $this->belongsTo('Flarum\User'); } } diff --git a/framework/core/src/Core/Search/User/Gambit/EmailGambit.php b/framework/core/src/User/Search/Gambit/EmailGambit.php similarity index 79% rename from framework/core/src/Core/Search/User/Gambit/EmailGambit.php rename to framework/core/src/User/Search/Gambit/EmailGambit.php index 4f8d1254d..27a155141 100644 --- a/framework/core/src/Core/Search/User/Gambit/EmailGambit.php +++ b/framework/core/src/User/Search/Gambit/EmailGambit.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\User\Gambit; +namespace Flarum\User\Search\Gambit; -use Flarum\Core\Repository\UserRepository; -use Flarum\Core\Search\AbstractRegexGambit; -use Flarum\Core\Search\AbstractSearch; -use Flarum\Core\Search\User\UserSearch; +use Flarum\Search\AbstractRegexGambit; +use Flarum\Search\AbstractSearch; +use Flarum\User\Search\UserSearch; +use Flarum\User\UserRepository; use LogicException; class EmailGambit extends AbstractRegexGambit @@ -25,12 +25,12 @@ class EmailGambit extends AbstractRegexGambit protected $pattern = 'email:(.+)'; /** - * @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/User/Gambit/FulltextGambit.php b/framework/core/src/User/Search/Gambit/FulltextGambit.php similarity index 78% rename from framework/core/src/Core/Search/User/Gambit/FulltextGambit.php rename to framework/core/src/User/Search/Gambit/FulltextGambit.php index 2f7c4c4c3..a41821693 100644 --- a/framework/core/src/Core/Search/User/Gambit/FulltextGambit.php +++ b/framework/core/src/User/Search/Gambit/FulltextGambit.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\User\Gambit; +namespace Flarum\User\Search\Gambit; -use Flarum\Core\Repository\UserRepository; -use Flarum\Core\Search\AbstractSearch; -use Flarum\Core\Search\GambitInterface; +use Flarum\Search\AbstractSearch; +use Flarum\Search\GambitInterface; +use Flarum\User\UserRepository; class FulltextGambit implements GambitInterface { @@ -23,7 +23,7 @@ class FulltextGambit implements GambitInterface protected $users; /** - * @param UserRepository $users + * @param \Flarum\User\UserRepository $users */ public function __construct(UserRepository $users) { diff --git a/framework/core/src/Core/Search/User/Gambit/GroupGambit.php b/framework/core/src/User/Search/Gambit/GroupGambit.php similarity index 85% rename from framework/core/src/Core/Search/User/Gambit/GroupGambit.php rename to framework/core/src/User/Search/Gambit/GroupGambit.php index 4f020904d..e690d93e5 100644 --- a/framework/core/src/Core/Search/User/Gambit/GroupGambit.php +++ b/framework/core/src/User/Search/Gambit/GroupGambit.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\User\Gambit; +namespace Flarum\User\Search\Gambit; -use Flarum\Core\Repository\GroupRepository; -use Flarum\Core\Search\AbstractRegexGambit; -use Flarum\Core\Search\AbstractSearch; -use Flarum\Core\Search\User\UserSearch; +use Flarum\Group\GroupRepository; +use Flarum\Search\AbstractRegexGambit; +use Flarum\Search\AbstractSearch; +use Flarum\User\Search\UserSearch; use LogicException; class GroupGambit extends AbstractRegexGambit @@ -30,7 +30,7 @@ class GroupGambit extends AbstractRegexGambit protected $groups; /** - * @param \Flarum\Core\Repository\GroupRepository $groups + * @param \Flarum\Group\GroupRepository $groups */ public function __construct(GroupRepository $groups) { diff --git a/framework/core/src/Core/Search/User/UserSearch.php b/framework/core/src/User/Search/UserSearch.php similarity index 78% rename from framework/core/src/Core/Search/User/UserSearch.php rename to framework/core/src/User/Search/UserSearch.php index dc3554499..d3a7ba28b 100644 --- a/framework/core/src/Core/Search/User/UserSearch.php +++ b/framework/core/src/User/Search/UserSearch.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\User; +namespace Flarum\User\Search; -use Flarum\Core\Search\AbstractSearch; +use Flarum\Search\AbstractSearch; class UserSearch extends AbstractSearch { diff --git a/framework/core/src/Core/Search/User/UserSearcher.php b/framework/core/src/User/Search/UserSearcher.php similarity index 84% rename from framework/core/src/Core/Search/User/UserSearcher.php rename to framework/core/src/User/Search/UserSearcher.php index 855726dfd..7bc268c23 100644 --- a/framework/core/src/Core/Search/User/UserSearcher.php +++ b/framework/core/src/User/Search/UserSearcher.php @@ -9,14 +9,14 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\User; +namespace Flarum\User\Search; -use Flarum\Core\Repository\UserRepository; -use Flarum\Core\Search\ApplySearchParametersTrait; -use Flarum\Core\Search\GambitManager; -use Flarum\Core\Search\SearchCriteria; -use Flarum\Core\Search\SearchResults; -use Flarum\Event\ConfigureUserSearch; +use Flarum\Search\ApplySearchParametersTrait; +use Flarum\Search\GambitManager; +use Flarum\Search\SearchCriteria; +use Flarum\Search\SearchResults; +use Flarum\User\Event\Searching; +use Flarum\User\UserRepository; /** * Takes a UserSearchCriteria object, performs a search using gambits, @@ -38,7 +38,7 @@ class UserSearcher /** * @param GambitManager $gambits - * @param UserRepository $users + * @param \Flarum\User\UserRepository $users */ public function __construct(GambitManager $gambits, UserRepository $users) { @@ -69,7 +69,7 @@ class UserSearcher $this->applyOffset($search, $offset); $this->applyLimit($search, $limit + 1); - event(new ConfigureUserSearch($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/Listener/SelfDemotionGuard.php b/framework/core/src/User/SelfDemotionGuard.php similarity index 82% rename from framework/core/src/Core/Listener/SelfDemotionGuard.php rename to framework/core/src/User/SelfDemotionGuard.php index 1fbfe3e89..1aec59e6c 100644 --- a/framework/core/src/Core/Listener/SelfDemotionGuard.php +++ b/framework/core/src/User/SelfDemotionGuard.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Listener; +namespace Flarum\User; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\Group; -use Flarum\Event\UserWillBeSaved; +use Flarum\Group\Group; +use Flarum\User\Event\Saving; +use Flarum\User\Exception\PermissionDeniedException; use Illuminate\Contracts\Events\Dispatcher; class SelfDemotionGuard @@ -23,15 +23,15 @@ class SelfDemotionGuard */ public function subscribe(Dispatcher $events) { - $events->listen(UserWillBeSaved::class, [$this, 'whenUserWillBeSaved']); + $events->listen(Saving::class, [$this, 'whenUserWillBeSaved']); } /** * Prevent an admin from removing their admin permission via the API. - * @param UserWillBeSaved $event + * @param Saving $event * @throws PermissionDeniedException */ - public function whenUserWillBeSaved(UserWillBeSaved $event) + public function whenUserWillBeSaved(Saving $event) { // Non-admin users pose no problem if (! $event->actor->isAdmin()) { diff --git a/framework/core/src/Core/User.php b/framework/core/src/User/User.php similarity index 90% rename from framework/core/src/Core/User.php rename to framework/core/src/User/User.php index 13f57e728..7c02c882d 100755 --- a/framework/core/src/Core/User.php +++ b/framework/core/src/User/User.php @@ -9,28 +9,30 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\User; use DomainException; -use Flarum\Core\Access\Gate; -use Flarum\Core\Support\EventGeneratorTrait; -use Flarum\Core\Support\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; -use Flarum\Event\CheckUserPassword; +use Flarum\Database\ScopeVisibilityTrait; use Flarum\Event\ConfigureUserPreferences; use Flarum\Event\GetDisplayName; -use Flarum\Event\PostWasDeleted; use Flarum\Event\PrepareUserGroups; -use Flarum\Event\UserAvatarWasChanged; -use Flarum\Event\UserEmailChangeWasRequested; -use Flarum\Event\UserEmailWasChanged; -use Flarum\Event\UserPasswordWasChanged; -use Flarum\Event\UserWasActivated; -use Flarum\Event\UserWasDeleted; -use Flarum\Event\UserWasRegistered; -use Flarum\Event\UserWasRenamed; -use Flarum\Forum\UrlGenerator; use Flarum\Foundation\Application; +use Flarum\Foundation\EventGeneratorTrait; +use Flarum\Group\Group; +use Flarum\Group\Permission; +use Flarum\Http\UrlGenerator; +use Flarum\Notification\Notification; +use Flarum\Post\Event\Deleted as PostDeleted; +use Flarum\User\Event\Activated; +use Flarum\User\Event\AvatarChanged; +use Flarum\User\Event\CheckingPassword; +use Flarum\User\Event\Deleted; +use Flarum\User\Event\EmailChanged; +use Flarum\User\Event\EmailChangeRequested; +use Flarum\User\Event\PasswordChanged; +use Flarum\User\Event\Registered; +use Flarum\User\Event\Renamed; use Illuminate\Contracts\Hashing\Hasher; use Symfony\Component\HttpFoundation\Session\SessionInterface; @@ -125,7 +127,7 @@ class User extends AbstractModel }); static::deleted(function (User $user) { - $user->raise(new UserWasDeleted($user)); + $user->raise(new Deleted($user)); // Delete all of the posts by the user. Before we delete them // in a big batch query, we will loop through them and raise a @@ -133,7 +135,7 @@ class User extends AbstractModel $posts = $user->posts()->allTypes(); foreach ($posts->get() as $post) { - $user->raise(new PostWasDeleted($post)); + $user->raise(new PostDeleted($post)); } $posts->delete(); @@ -166,7 +168,7 @@ class User extends AbstractModel $user->password = $password; $user->join_time = time(); - $user->raise(new UserWasRegistered($user)); + $user->raise(new Registered($user)); return $user; } @@ -198,7 +200,7 @@ class User extends AbstractModel if ($username !== $this->username) { $this->username = $username; - $this->raise(new UserWasRenamed($this)); + $this->raise(new Renamed($this)); } return $this; @@ -215,7 +217,7 @@ class User extends AbstractModel if ($email !== $this->email) { $this->email = $email; - $this->raise(new UserEmailWasChanged($this)); + $this->raise(new EmailChanged($this)); } return $this; @@ -230,7 +232,7 @@ class User extends AbstractModel public function requestEmailChange($email) { if ($email !== $this->email) { - $this->raise(new UserEmailChangeWasRequested($this, $email)); + $this->raise(new EmailChangeRequested($this, $email)); } return $this; @@ -246,7 +248,7 @@ class User extends AbstractModel { $this->password = $password; - $this->raise(new UserPasswordWasChanged($this)); + $this->raise(new PasswordChanged($this)); return $this; } @@ -295,7 +297,7 @@ class User extends AbstractModel { $this->avatar_path = $path; - $this->raise(new UserAvatarWasChanged($this)); + $this->raise(new AvatarChanged($this)); return $this; } @@ -313,7 +315,7 @@ class User extends AbstractModel return $this->avatar_path; } - return app(UrlGenerator::class)->toPath('assets/avatars/'.$this->avatar_path); + return app(UrlGenerator::class)->to('forum')->path('assets/avatars/'.$this->avatar_path); } } @@ -347,7 +349,7 @@ class User extends AbstractModel */ public function checkPassword($password) { - $valid = static::$dispatcher->until(new CheckUserPassword($this, $password)); + $valid = static::$dispatcher->until(new CheckingPassword($this, $password)); if ($valid !== null) { return $valid; @@ -366,7 +368,7 @@ class User extends AbstractModel if ($this->is_activated !== true) { $this->is_activated = true; - $this->raise(new UserWasActivated($this)); + $this->raise(new Activated($this)); } return $this; @@ -481,9 +483,9 @@ class User extends AbstractModel */ public function getPreferencesAttribute($value) { - $defaults = array_build(static::$preferences, function ($key, $value) { - return [$key, $value['default']]; - }); + $defaults = array_map(function ($value) { + return $value['default']; + }, static::$preferences); $user = array_only((array) json_decode($value, true), array_keys(static::$preferences)); @@ -599,7 +601,7 @@ class User extends AbstractModel */ public function posts() { - return $this->hasMany('Flarum\Core\Post'); + return $this->hasMany('Flarum\Post\Post'); } /** @@ -609,7 +611,7 @@ class User extends AbstractModel */ public function read() { - return $this->belongsToMany('Flarum\Core\Discussion', 'users_discussions'); + return $this->belongsToMany('Flarum\Discussion\Discussion', 'users_discussions'); } /** @@ -619,7 +621,7 @@ class User extends AbstractModel */ public function groups() { - return $this->belongsToMany('Flarum\Core\Group', 'users_groups'); + return $this->belongsToMany('Flarum\Group\Group', 'users_groups'); } /** @@ -629,7 +631,7 @@ class User extends AbstractModel */ public function notifications() { - return $this->hasMany('Flarum\Core\Notification'); + return $this->hasMany('Flarum\Notification\Notification'); } /** @@ -647,7 +649,7 @@ class User extends AbstractModel // standard 'member' group, as well as any other groups they've been // assigned to. if ($this->is_activated) { - $groupIds = array_merge($groupIds, [Group::MEMBER_ID], $this->groups->lists('id')->all()); + $groupIds = array_merge($groupIds, [Group::MEMBER_ID], $this->groups->pluck('id')->all()); } event(new PrepareUserGroups($this, $groupIds)); @@ -662,7 +664,7 @@ class User extends AbstractModel */ public function getPermissions() { - return $this->permissions()->lists('permission')->all(); + return $this->permissions()->pluck('permission')->all(); } /** diff --git a/framework/core/src/Core/Listener/UserMetadataUpdater.php b/framework/core/src/User/UserMetadataUpdater.php similarity index 50% rename from framework/core/src/Core/Listener/UserMetadataUpdater.php rename to framework/core/src/User/UserMetadataUpdater.php index 2e85c2d5c..a690813dd 100755 --- a/framework/core/src/Core/Listener/UserMetadataUpdater.php +++ b/framework/core/src/User/UserMetadataUpdater.php @@ -9,16 +9,16 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Listener; +namespace Flarum\User; -use Flarum\Core\Discussion; -use Flarum\Core\Post; -use Flarum\Event\DiscussionWasDeleted; -use Flarum\Event\DiscussionWasStarted; -use Flarum\Event\PostWasDeleted; -use Flarum\Event\PostWasHidden; -use Flarum\Event\PostWasPosted; -use Flarum\Event\PostWasRestored; +use Flarum\Discussion\Discussion; +use Flarum\Discussion\Event\Deleted as DiscussionDeleted; +use Flarum\Discussion\Event\Started; +use Flarum\Post\Event\Deleted as PostDeleted; +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 UserMetadataUpdater @@ -28,58 +28,58 @@ class UserMetadataUpdater */ 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(DiscussionWasStarted::class, [$this, 'whenDiscussionWasStarted']); - $events->listen(DiscussionWasDeleted::class, [$this, 'whenDiscussionWasDeleted']); + $events->listen(Posted::class, [$this, 'whenPostWasPosted']); + $events->listen(PostDeleted::class, [$this, 'whenPostWasDeleted']); + $events->listen(Hidden::class, [$this, 'whenPostWasHidden']); + $events->listen(Restored::class, [$this, 'whenPostWasRestored']); + $events->listen(Started::class, [$this, 'whenDiscussionWasStarted']); + $events->listen(DiscussionDeleted::class, [$this, 'whenDiscussionWasDeleted']); } /** - * @param PostWasPosted $event + * @param \Flarum\Post\Event\Posted $event */ - public function whenPostWasPosted(PostWasPosted $event) + public function whenPostWasPosted(Posted $event) { $this->updateCommentsCount($event->post, 1); } /** - * @param \Flarum\Event\PostWasDeleted $event + * @param \Flarum\Post\Event\Deleted $event */ - public function whenPostWasDeleted(PostWasDeleted $event) + public function whenPostWasDeleted(PostDeleted $event) { $this->updateCommentsCount($event->post, -1); } /** - * @param PostWasHidden $event + * @param \Flarum\Post\Event\Hidden $event */ - public function whenPostWasHidden(PostWasHidden $event) + public function whenPostWasHidden(Hidden $event) { $this->updateCommentsCount($event->post, -1); } /** - * @param \Flarum\Event\PostWasRestored $event + * @param \Flarum\Post\Event\Restored $event */ - public function whenPostWasRestored(PostWasRestored $event) + public function whenPostWasRestored(Restored $event) { $this->updateCommentsCount($event->post, 1); } /** - * @param \Flarum\Events\DiscussionWasStarted $event + * @param \Flarum\Discussion\Event\Started $event */ - public function whenDiscussionWasStarted(DiscussionWasStarted $event) + public function whenDiscussionWasStarted(Started $event) { $this->updateDiscussionsCount($event->discussion, 1); } /** - * @param \Flarum\Event\DiscussionWasDeleted $event + * @param \Flarum\Discussion\Event\Deleted $event */ - public function whenDiscussionWasDeleted(DiscussionWasDeleted $event) + public function whenDiscussionWasDeleted(DiscussionDeleted $event) { $this->updateDiscussionsCount($event->discussion, -1); } @@ -99,7 +99,7 @@ class UserMetadataUpdater } /** - * @param Discussion $discussion + * @param \Flarum\Discussion\Discussion $discussion * @param int $amount */ protected function updateDiscussionsCount(Discussion $discussion, $amount) diff --git a/framework/core/src/Core/Access/UserPolicy.php b/framework/core/src/User/UserPolicy.php similarity index 94% rename from framework/core/src/Core/Access/UserPolicy.php rename to framework/core/src/User/UserPolicy.php index 24b95e25a..73754f0b8 100644 --- a/framework/core/src/Core/Access/UserPolicy.php +++ b/framework/core/src/User/UserPolicy.php @@ -9,9 +9,8 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Access; +namespace Flarum\User; -use Flarum\Core\User; use Illuminate\Database\Eloquent\Builder; class UserPolicy extends AbstractPolicy diff --git a/framework/core/src/Core/Repository/UserRepository.php b/framework/core/src/User/UserRepository.php similarity index 95% rename from framework/core/src/Core/Repository/UserRepository.php rename to framework/core/src/User/UserRepository.php index a350f9f10..8619446b9 100644 --- a/framework/core/src/Core/Repository/UserRepository.php +++ b/framework/core/src/User/UserRepository.php @@ -9,9 +9,8 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Repository; +namespace Flarum\User; -use Flarum\Core\User; use Illuminate\Database\Eloquent\Builder; class UserRepository @@ -95,7 +94,7 @@ class UserRepository ->orderByRaw('username = ? desc', [$string]) ->orderByRaw('username like ? desc', [$string.'%']); - return $this->scopeVisibleTo($query, $actor)->lists('id'); + return $this->scopeVisibleTo($query, $actor)->pluck('id')->all(); } /** diff --git a/framework/core/src/Core/CoreServiceProvider.php b/framework/core/src/User/UserServiceProvider.php similarity index 57% rename from framework/core/src/Core/CoreServiceProvider.php rename to framework/core/src/User/UserServiceProvider.php index 713e5758e..03f3cbf55 100644 --- a/framework/core/src/Core/CoreServiceProvider.php +++ b/framework/core/src/User/UserServiceProvider.php @@ -9,18 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\User; -use Flarum\Core\Access\Gate; -use Flarum\Core\Post\CommentPost; -use Flarum\Event\ConfigurePostTypes; use Flarum\Event\ConfigureUserPreferences; use Flarum\Event\GetPermission; use Flarum\Foundation\AbstractServiceProvider; use Illuminate\Contracts\Container\Container; use RuntimeException; -class CoreServiceProvider extends AbstractServiceProvider +class UserServiceProvider extends AbstractServiceProvider { /** * {@inheritdoc} @@ -34,13 +31,9 @@ class CoreServiceProvider extends AbstractServiceProvider }); $this->app->alias('flarum.gate', 'Illuminate\Contracts\Auth\Access\Gate'); - $this->app->alias('flarum.gate', 'Flarum\Core\Access\Gate'); + $this->app->alias('flarum.gate', Gate::class); $this->registerAvatarsFilesystem(); - - $this->app->register('Flarum\Core\Notification\NotificationServiceProvider'); - $this->app->register('Flarum\Core\Search\SearchServiceProvider'); - $this->app->register('Flarum\Formatter\FormatterServiceProvider'); } protected function registerAvatarsFilesystem() @@ -49,7 +42,7 @@ class CoreServiceProvider extends AbstractServiceProvider return $app->make('Illuminate\Contracts\Filesystem\Factory')->disk('flarum-avatars')->getDriver(); }; - $this->app->when('Flarum\Core\AvatarUploader') + $this->app->when(AvatarUploader::class) ->needs('League\Flysystem\FilesystemInterface') ->give($avatarsFilesystem); } @@ -59,12 +52,6 @@ class CoreServiceProvider extends AbstractServiceProvider */ public function boot() { - $this->loadViewsFrom(__DIR__.'/../../views', 'flarum'); - - $this->app->make('Illuminate\Contracts\Bus\Dispatcher')->mapUsing(function ($command) { - return get_class($command).'Handler@handle'; - }); - $this->app->make('flarum.gate')->before(function (User $actor, $ability, $model = null) { // Fire an event so that core and extension policies can hook into // this permission query and explicitly grant or deny the @@ -87,46 +74,19 @@ class CoreServiceProvider extends AbstractServiceProvider return false; }); - $this->registerPostTypes(); - - CommentPost::setFormatter($this->app->make('flarum.formatter')); - User::setHasher($this->app->make('hash')); User::setGate($this->app->make('flarum.gate')); $events = $this->app->make('events'); - $events->subscribe('Flarum\Core\Listener\SelfDemotionGuard'); - $events->subscribe('Flarum\Core\Listener\DiscussionMetadataUpdater'); - $events->subscribe('Flarum\Core\Listener\UserMetadataUpdater'); - $events->subscribe('Flarum\Core\Listener\ExtensionValidator'); - $events->subscribe('Flarum\Core\Listener\EmailConfirmationMailer'); - $events->subscribe('Flarum\Core\Listener\DiscussionRenamedNotifier'); - - $events->subscribe('Flarum\Core\Access\DiscussionPolicy'); - $events->subscribe('Flarum\Core\Access\GroupPolicy'); - $events->subscribe('Flarum\Core\Access\PostPolicy'); - $events->subscribe('Flarum\Core\Access\UserPolicy'); + $events->subscribe(SelfDemotionGuard::class); + $events->subscribe(EmailConfirmationMailer::class); + $events->subscribe(UserMetadataUpdater::class); + $events->subscribe(UserPolicy::class); $events->listen(ConfigureUserPreferences::class, [$this, 'configureUserPreferences']); } - public function registerPostTypes() - { - $models = [ - 'Flarum\Core\Post\CommentPost', - 'Flarum\Core\Post\DiscussionRenamedPost' - ]; - - $this->app->make('events')->fire( - new ConfigurePostTypes($models) - ); - - foreach ($models as $model) { - Post::setModel($model::$type, $model); - } - } - /** * @param ConfigureUserPreferences $event */ diff --git a/framework/core/src/Core/Validator/UserValidator.php b/framework/core/src/User/UserValidator.php similarity index 95% rename from framework/core/src/Core/Validator/UserValidator.php rename to framework/core/src/User/UserValidator.php index f58d9d42b..a994a999f 100644 --- a/framework/core/src/Core/Validator/UserValidator.php +++ b/framework/core/src/User/UserValidator.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Validator; +namespace Flarum\User; -use Flarum\Core\User; +use Flarum\Foundation\AbstractValidator; class UserValidator extends AbstractValidator { diff --git a/framework/core/tests/Flarum/Api/Handler/FloodingExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/FloodingExceptionHandlerTest.php index 0b57f03b6..3abfbeade 100644 --- a/framework/core/tests/Flarum/Api/Handler/FloodingExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/FloodingExceptionHandlerTest.php @@ -12,8 +12,8 @@ namespace Tests\Flarum\Api\Handler; use Exception; -use Flarum\Api\Handler\FloodingExceptionHandler; -use Flarum\Core\Exception\FloodingException; +use Flarum\Api\ExceptionHandler\FloodingExceptionHandler; +use Flarum\Post\Exception\FloodingException; use Tests\Test\TestCase; class FloodingExceptionHandlerTest extends TestCase diff --git a/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php index 2830d723a..fbdf16559 100644 --- a/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php @@ -12,10 +12,11 @@ namespace Tests\Flarum\Api\Handler; use Exception; -use Flarum\Api\Handler\IlluminateValidationExceptionHandler; -use Illuminate\Contracts\Validation\ValidationException; +use Flarum\Api\ExceptionHandler\IlluminateValidationExceptionHandler; +use Illuminate\Translation\ArrayLoader; +use Illuminate\Translation\Translator; use Illuminate\Validation\Factory; -use Symfony\Component\Translation\Translator; +use Illuminate\Validation\ValidationException; use Tests\Test\TestCase; class IlluminateValidationExceptionHandlerTest extends TestCase @@ -54,7 +55,7 @@ class IlluminateValidationExceptionHandlerTest extends TestCase private function makeValidator($data = [], $rules = []) { - $translator = new Translator('en'); + $translator = new Translator(new ArrayLoader(), 'en'); $factory = new Factory($translator); return $factory->make($data, $rules); diff --git a/framework/core/tests/Flarum/Api/Handler/InvalidAccessTokenExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/InvalidAccessTokenExceptionHandlerTest.php index 244523505..86620c558 100644 --- a/framework/core/tests/Flarum/Api/Handler/InvalidAccessTokenExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/InvalidAccessTokenExceptionHandlerTest.php @@ -13,7 +13,7 @@ namespace Tests\Flarum\Api\Handler; use Exception; use Flarum\Api\Exception\InvalidAccessTokenException; -use Flarum\Api\Handler\InvalidAccessTokenExceptionHandler; +use Flarum\Api\ExceptionHandler\InvalidAccessTokenExceptionHandler; use Tests\Test\TestCase; class InvalidAccessTokenExceptionHandlerTest extends TestCase diff --git a/framework/core/tests/Flarum/Api/Handler/InvalidConfirmationTokenExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/InvalidConfirmationTokenExceptionHandlerTest.php index d11910065..19b918d2c 100644 --- a/framework/core/tests/Flarum/Api/Handler/InvalidConfirmationTokenExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/InvalidConfirmationTokenExceptionHandlerTest.php @@ -12,8 +12,8 @@ namespace Tests\Flarum\Api\Handler; use Exception; -use Flarum\Api\Handler\InvalidConfirmationTokenExceptionHandler; -use Flarum\Core\Exception\InvalidConfirmationTokenException; +use Flarum\Api\ExceptionHandler\InvalidConfirmationTokenExceptionHandler; +use Flarum\User\Exception\InvalidConfirmationTokenException; use Tests\Test\TestCase; class InvalidConfirmationTokenExceptionHandlerTest extends TestCase diff --git a/framework/core/tests/Flarum/Api/Handler/MethodNotAllowedExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/MethodNotAllowedExceptionHandlerTest.php index a03233ff0..e9c2b4e95 100644 --- a/framework/core/tests/Flarum/Api/Handler/MethodNotAllowedExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/MethodNotAllowedExceptionHandlerTest.php @@ -12,7 +12,7 @@ namespace Tests\Flarum\Api\Handler; use Exception; -use Flarum\Api\Handler\MethodNotAllowedExceptionHandler; +use Flarum\Api\ExceptionHandler\MethodNotAllowedExceptionHandler; use Flarum\Http\Exception\MethodNotAllowedException; use Tests\Test\TestCase; diff --git a/framework/core/tests/Flarum/Api/Handler/ModelNotFoundExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/ModelNotFoundExceptionHandlerTest.php index aa20afd6f..fa0b88b9d 100644 --- a/framework/core/tests/Flarum/Api/Handler/ModelNotFoundExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/ModelNotFoundExceptionHandlerTest.php @@ -12,7 +12,7 @@ namespace Tests\Flarum\Api\Handler; use Exception; -use Flarum\Api\Handler\ModelNotFoundExceptionHandler; +use Flarum\Api\ExceptionHandler\ModelNotFoundExceptionHandler; use Illuminate\Database\Eloquent\ModelNotFoundException; use Tests\Test\TestCase; diff --git a/framework/core/tests/Flarum/Api/Handler/PermissionDeniedExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/PermissionDeniedExceptionHandlerTest.php index 4f5e19729..0494f6240 100644 --- a/framework/core/tests/Flarum/Api/Handler/PermissionDeniedExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/PermissionDeniedExceptionHandlerTest.php @@ -12,8 +12,8 @@ namespace Tests\Flarum\Api\Handler; use Exception; -use Flarum\Api\Handler\PermissionDeniedExceptionHandler; -use Flarum\Core\Exception\PermissionDeniedException; +use Flarum\Api\ExceptionHandler\PermissionDeniedExceptionHandler; +use Flarum\User\Exception\PermissionDeniedException; use Tests\Test\TestCase; class PermissionDeniedExceptionHandlerTest extends TestCase diff --git a/framework/core/tests/Flarum/Api/Handler/RouteNotFoundExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/RouteNotFoundExceptionHandlerTest.php index 570a8a9ce..6c2cca427 100644 --- a/framework/core/tests/Flarum/Api/Handler/RouteNotFoundExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/RouteNotFoundExceptionHandlerTest.php @@ -12,7 +12,7 @@ namespace Tests\Flarum\Api\Handler; use Exception; -use Flarum\Api\Handler\RouteNotFoundExceptionHandler; +use Flarum\Api\ExceptionHandler\RouteNotFoundExceptionHandler; use Flarum\Http\Exception\RouteNotFoundException; use Tests\Test\TestCase; diff --git a/framework/core/tests/Flarum/Api/Handler/TokenMismatchExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/TokenMismatchExceptionHandlerTest.php index 0a4dba406..4faf9b7c8 100644 --- a/framework/core/tests/Flarum/Api/Handler/TokenMismatchExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/TokenMismatchExceptionHandlerTest.php @@ -12,7 +12,7 @@ namespace Tests\Flarum\Api\Handler; use Exception; -use Flarum\Api\Handler\TokenMismatchExceptionHandler; +use Flarum\Api\ExceptionHandler\TokenMismatchExceptionHandler; use Flarum\Http\Exception\TokenMismatchException; use Tests\Test\TestCase; diff --git a/framework/core/tests/Flarum/Api/Handler/ValidationExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/ValidationExceptionHandlerTest.php index d32bcc6cc..d3440f52f 100644 --- a/framework/core/tests/Flarum/Api/Handler/ValidationExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/ValidationExceptionHandlerTest.php @@ -12,8 +12,8 @@ namespace Tests\Flarum\Api\Handler; use Exception; -use Flarum\Api\Handler\ValidationExceptionHandler; -use Flarum\Core\Exception\ValidationException; +use Flarum\Api\ExceptionHandler\ValidationExceptionHandler; +use Flarum\Foundation\ValidationException; use Tests\Test\TestCase; class ValidationExceptionHandlerTest extends TestCase diff --git a/framework/core/tests/Test/TestCase.php b/framework/core/tests/Test/TestCase.php index 5a25ceb8b..864eb3b5d 100644 --- a/framework/core/tests/Test/TestCase.php +++ b/framework/core/tests/Test/TestCase.php @@ -12,9 +12,9 @@ namespace Tests\Test; use Mockery; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase as Test; -abstract class TestCase extends PHPUnit_Framework_TestCase +abstract class TestCase extends Test { public function setUp() { diff --git a/framework/core/views/frontend/app.blade.php b/framework/core/views/frontend/app.blade.php index 198fde143..671f51665 100644 --- a/framework/core/views/frontend/app.blade.php +++ b/framework/core/views/frontend/app.blade.php @@ -49,7 +49,8 @@ if (module.default) module.default(app); } - app.boot({!! json_encode($payload, JSON_HEX_TAG) !!}); + app.boot(@json($payload)); + @if (! $debug) } catch (e) { window.location += (window.location.search ? '&' : '?') + 'nojs=1'; diff --git a/framework/core/views/frontend/content/index.blade.php b/framework/core/views/frontend/content/index.blade.php index cbde0cff7..ce3a54feb 100644 --- a/framework/core/views/frontend/content/index.blade.php +++ b/framework/core/views/frontend/content/index.blade.php @@ -1,5 +1,5 @@ <?php -$url = app('Flarum\Forum\UrlGenerator'); +$url = app('Flarum\Http\UrlGenerator'); ?> <div class="container"> <h2>{{ $translator->trans('core.views.index.all_discussions_heading') }}</h2> @@ -7,7 +7,7 @@ $url = app('Flarum\Forum\UrlGenerator'); <ul> @foreach ($document->data as $discussion) <li> - <a href="{{ $url->toRoute('discussion', [ + <a href="{{ $url->to('forum')->route('discussion', [ 'id' => $discussion->id . '-' . $discussion->attributes->slug ]) }}"> {{ $discussion->attributes->title }} @@ -16,5 +16,5 @@ $url = app('Flarum\Forum\UrlGenerator'); @endforeach </ul> - <a href="{{ $url->toRoute('index') }}?page={{ $page + 1 }}">{{ $translator->trans('core.views.index.next_page_button') }} »</a> + <a href="{{ $url->to('forum')->route('index') }}?page={{ $page + 1 }}">{{ $translator->trans('core.views.index.next_page_button') }} »</a> </div>