From 0e2de956012e5ecb71934367af0a8e5d7babda19 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 24 Jun 2017 11:11:55 +0200 Subject: [PATCH 001/172] Restructure Flarum\Admin namespace --- .../core/src/Admin/AdminServiceProvider.php | 11 ++++------ ...pController.php => FrontendController.php} | 8 +++---- .../src/Admin/{WebApp.php => Frontend.php} | 2 +- framework/core/src/Admin/routes.php | 22 +++++++++++++++++++ .../src/Debug/Console/CacheClearCommand.php | 4 ++-- framework/core/src/Event/ConfigureWebApp.php | 2 +- 6 files changed, 34 insertions(+), 15 deletions(-) rename framework/core/src/Admin/Controller/{WebAppController.php => FrontendController.php} (85%) rename framework/core/src/Admin/{WebApp.php => Frontend.php} (91%) create mode 100644 framework/core/src/Admin/routes.php diff --git a/framework/core/src/Admin/AdminServiceProvider.php b/framework/core/src/Admin/AdminServiceProvider.php index 576f0e7bd..80713c37e 100644 --- a/framework/core/src/Admin/AdminServiceProvider.php +++ b/framework/core/src/Admin/AdminServiceProvider.php @@ -55,13 +55,10 @@ 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() @@ -91,6 +88,6 @@ class AdminServiceProvider extends AbstractServiceProvider */ protected function getWebAppAssets() { - return $this->app->make(WebApp::class)->getAssets(); + return $this->app->make(Frontend::class)->getAssets(); } } diff --git a/framework/core/src/Admin/Controller/WebAppController.php b/framework/core/src/Admin/Controller/FrontendController.php similarity index 85% rename from framework/core/src/Admin/Controller/WebAppController.php rename to framework/core/src/Admin/Controller/FrontendController.php index d0870900a..db8cc5c41 100644 --- a/framework/core/src/Admin/Controller/WebAppController.php +++ b/framework/core/src/Admin/Controller/FrontendController.php @@ -11,7 +11,7 @@ namespace Flarum\Admin\Controller; -use Flarum\Admin\WebApp; +use Flarum\Admin\Frontend; use Flarum\Core\Permission; use Flarum\Event\PrepareUnserializedSettings; use Flarum\Extension\ExtensionManager; @@ -20,7 +20,7 @@ use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Events\Dispatcher; use Psr\Http\Message\ServerRequestInterface; -class WebAppController extends AbstractWebAppController +class FrontendController extends AbstractWebAppController { /** * @var SettingsRepositoryInterface @@ -33,12 +33,12 @@ class WebAppController extends AbstractWebAppController protected $extensions; /** - * @param WebApp $webApp + * @param Frontend $webApp * @param Dispatcher $events * @param SettingsRepositoryInterface $settings * @param ExtensionManager $extensions */ - public function __construct(WebApp $webApp, Dispatcher $events, SettingsRepositoryInterface $settings, ExtensionManager $extensions) + public function __construct(Frontend $webApp, Dispatcher $events, SettingsRepositoryInterface $settings, ExtensionManager $extensions) { $this->webApp = $webApp; $this->events = $events; diff --git a/framework/core/src/Admin/WebApp.php b/framework/core/src/Admin/Frontend.php similarity index 91% rename from framework/core/src/Admin/WebApp.php rename to framework/core/src/Admin/Frontend.php index 5e130130d..65be577f0 100644 --- a/framework/core/src/Admin/WebApp.php +++ b/framework/core/src/Admin/Frontend.php @@ -13,7 +13,7 @@ namespace Flarum\Admin; use Flarum\Http\WebApp\AbstractWebApp; -class WebApp extends AbstractWebApp +class Frontend extends AbstractWebApp { /** * {@inheritdoc} diff --git a/framework/core/src/Admin/routes.php b/framework/core/src/Admin/routes.php new file mode 100644 index 000000000..76f1aad4a --- /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\Handler\RouteHandlerFactory; +use Flarum\Http\RouteCollection; + +return function (RouteCollection $map, RouteHandlerFactory $route) { + $map->get( + '/', + 'index', + $route->toController(Controller\FrontendController::class) + ); +}; diff --git a/framework/core/src/Debug/Console/CacheClearCommand.php b/framework/core/src/Debug/Console/CacheClearCommand.php index cf8e4b466..554e24824 100644 --- a/framework/core/src/Debug/Console/CacheClearCommand.php +++ b/framework/core/src/Debug/Console/CacheClearCommand.php @@ -11,7 +11,7 @@ namespace Flarum\Debug\Console; -use Flarum\Admin\WebApp as AdminWebApp; +use Flarum\Admin\Frontend as AdminWebApp; use Flarum\Console\Command\AbstractCommand; use Flarum\Forum\WebApp as ForumWebApp; use Illuminate\Contracts\Cache\Store; @@ -29,7 +29,7 @@ class CacheClearCommand extends AbstractCommand protected $forum; /** - * @var \Flarum\Admin\WebApp + * @var \Flarum\Admin\Frontend */ protected $admin; diff --git a/framework/core/src/Event/ConfigureWebApp.php b/framework/core/src/Event/ConfigureWebApp.php index a4d1b71ee..014672ffc 100644 --- a/framework/core/src/Event/ConfigureWebApp.php +++ b/framework/core/src/Event/ConfigureWebApp.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Admin\Controller\WebAppController as AdminWebAppController; +use Flarum\Admin\Controller\FrontendController as AdminWebAppController; use Flarum\Forum\Controller\WebAppController as ForumWebAppController; use Flarum\Http\Controller\AbstractWebAppController; use Flarum\Http\WebApp\WebAppView; From b3ce1cd141fee50928757ce587f595738faa6d04 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 24 Jun 2017 11:25:07 +0200 Subject: [PATCH 002/172] Restructure Flarum\Api namespace --- framework/core/src/Api/ApiServiceProvider.php | 313 +----------------- .../Controller/AbstractCreateController.php | 2 +- ...troller.php => AbstractListController.php} | 2 +- ...troller.php => AbstractShowController.php} | 2 +- .../Api/Controller/DeleteAvatarController.php | 2 +- .../Controller/ListDiscussionsController.php | 2 +- .../Api/Controller/ListGroupsController.php | 2 +- .../ListNotificationsController.php | 2 +- .../Api/Controller/ListPostsController.php | 2 +- .../Api/Controller/ListUsersController.php | 2 +- .../Controller/ShowDiscussionController.php | 2 +- .../Api/Controller/ShowForumController.php | 2 +- .../src/Api/Controller/ShowPostController.php | 2 +- .../src/Api/Controller/ShowUserController.php | 2 +- .../Controller/UpdateDiscussionController.php | 2 +- .../Api/Controller/UpdateGroupController.php | 2 +- .../UpdateNotificationController.php | 2 +- .../Api/Controller/UpdatePostController.php | 2 +- .../Api/Controller/UpdateUserController.php | 2 +- .../Api/Controller/UploadAvatarController.php | 2 +- .../FloodingExceptionHandler.php | 2 +- .../IlluminateValidationExceptionHandler.php | 2 +- .../InvalidAccessTokenExceptionHandler.php | 2 +- ...validConfirmationTokenExceptionHandler.php | 2 +- .../MethodNotAllowedExceptionHandler.php | 2 +- .../ModelNotFoundExceptionHandler.php | 2 +- .../PermissionDeniedExceptionHandler.php | 2 +- .../RouteNotFoundExceptionHandler.php | 2 +- .../TokenMismatchExceptionHandler.php | 2 +- .../ValidationExceptionHandler.php | 2 +- ...izer.php => BasicDiscussionSerializer.php} | 2 +- ...Serializer.php => BasicPostSerializer.php} | 2 +- ...Serializer.php => BasicUserSerializer.php} | 2 +- .../Api/Serializer/DiscussionSerializer.php | 2 +- .../src/Api/Serializer/PostSerializer.php | 2 +- .../src/Api/Serializer/UserSerializer.php | 2 +- framework/core/src/Api/routes.php | 304 +++++++++++++++++ .../Handler/FloodingExceptionHandlerTest.php | 2 +- ...luminateValidationExceptionHandlerTest.php | 2 +- ...InvalidAccessTokenExceptionHandlerTest.php | 2 +- ...dConfirmationTokenExceptionHandlerTest.php | 2 +- .../MethodNotAllowedExceptionHandlerTest.php | 2 +- .../ModelNotFoundExceptionHandlerTest.php | 2 +- .../PermissionDeniedExceptionHandlerTest.php | 2 +- .../RouteNotFoundExceptionHandlerTest.php | 2 +- .../TokenMismatchExceptionHandlerTest.php | 2 +- .../ValidationExceptionHandlerTest.php | 2 +- 47 files changed, 363 insertions(+), 344 deletions(-) rename framework/core/src/Api/Controller/{AbstractCollectionController.php => AbstractListController.php} (86%) rename framework/core/src/Api/Controller/{AbstractResourceController.php => AbstractShowController.php} (86%) rename framework/core/src/Api/{Handler => ExceptionHandler}/FloodingExceptionHandler.php (95%) rename framework/core/src/Api/{Handler => ExceptionHandler}/IlluminateValidationExceptionHandler.php (97%) rename framework/core/src/Api/{Handler => ExceptionHandler}/InvalidAccessTokenExceptionHandler.php (95%) rename framework/core/src/Api/{Handler => ExceptionHandler}/InvalidConfirmationTokenExceptionHandler.php (96%) rename framework/core/src/Api/{Handler => ExceptionHandler}/MethodNotAllowedExceptionHandler.php (95%) rename framework/core/src/Api/{Handler => ExceptionHandler}/ModelNotFoundExceptionHandler.php (95%) rename framework/core/src/Api/{Handler => ExceptionHandler}/PermissionDeniedExceptionHandler.php (95%) rename framework/core/src/Api/{Handler => ExceptionHandler}/RouteNotFoundExceptionHandler.php (95%) rename framework/core/src/Api/{Handler => ExceptionHandler}/TokenMismatchExceptionHandler.php (95%) rename framework/core/src/Api/{Handler => ExceptionHandler}/ValidationExceptionHandler.php (97%) rename framework/core/src/Api/Serializer/{DiscussionBasicSerializer.php => BasicDiscussionSerializer.php} (97%) rename framework/core/src/Api/Serializer/{PostBasicSerializer.php => BasicPostSerializer.php} (96%) rename framework/core/src/Api/Serializer/{UserBasicSerializer.php => BasicUserSerializer.php} (95%) create mode 100644 framework/core/src/Api/routes.php diff --git a/framework/core/src/Api/ApiServiceProvider.php b/framework/core/src/Api/ApiServiceProvider.php index 7aa246cd3..24020af42 100644 --- a/framework/core/src/Api/ApiServiceProvider.php +++ b/framework/core/src/Api/ApiServiceProvider.php @@ -41,16 +41,16 @@ class ApiServiceProvider extends AbstractServiceProvider $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())); @@ -100,298 +100,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/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/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/DeleteAvatarController.php b/framework/core/src/Api/Controller/DeleteAvatarController.php index b360b87e4..73cbe9dd1 100644 --- a/framework/core/src/Api/Controller/DeleteAvatarController.php +++ b/framework/core/src/Api/Controller/DeleteAvatarController.php @@ -16,7 +16,7 @@ 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/ListDiscussionsController.php b/framework/core/src/Api/Controller/ListDiscussionsController.php index ab8b21283..c39d2d6a4 100644 --- a/framework/core/src/Api/Controller/ListDiscussionsController.php +++ b/framework/core/src/Api/Controller/ListDiscussionsController.php @@ -17,7 +17,7 @@ use Flarum\Core\Search\SearchCriteria; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class ListDiscussionsController extends AbstractCollectionController +class ListDiscussionsController extends AbstractListController { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/ListGroupsController.php b/framework/core/src/Api/Controller/ListGroupsController.php index 01ac443e0..66d734917 100644 --- a/framework/core/src/Api/Controller/ListGroupsController.php +++ b/framework/core/src/Api/Controller/ListGroupsController.php @@ -15,7 +15,7 @@ use Flarum\Core\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 7af1cd561..dd7303efa 100644 --- a/framework/core/src/Api/Controller/ListNotificationsController.php +++ b/framework/core/src/Api/Controller/ListNotificationsController.php @@ -17,7 +17,7 @@ use Flarum\Core\Repository\NotificationRepository; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class ListNotificationsController extends AbstractCollectionController +class ListNotificationsController extends AbstractListController { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/ListPostsController.php b/framework/core/src/Api/Controller/ListPostsController.php index e202acd36..c50490d07 100644 --- a/framework/core/src/Api/Controller/ListPostsController.php +++ b/framework/core/src/Api/Controller/ListPostsController.php @@ -18,7 +18,7 @@ use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; use Tobscure\JsonApi\Exception\InvalidParameterException; -class ListPostsController extends AbstractCollectionController +class ListPostsController extends AbstractListController { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/ListUsersController.php b/framework/core/src/Api/Controller/ListUsersController.php index 733f25e79..eb42a97db 100644 --- a/framework/core/src/Api/Controller/ListUsersController.php +++ b/framework/core/src/Api/Controller/ListUsersController.php @@ -18,7 +18,7 @@ use Flarum\Core\Search\User\UserSearcher; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class ListUsersController extends AbstractCollectionController +class ListUsersController extends AbstractListController { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/ShowDiscussionController.php b/framework/core/src/Api/Controller/ShowDiscussionController.php index 7f04ca167..58417fae4 100644 --- a/framework/core/src/Api/Controller/ShowDiscussionController.php +++ b/framework/core/src/Api/Controller/ShowDiscussionController.php @@ -18,7 +18,7 @@ use Flarum\Core\User; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class ShowDiscussionController extends AbstractResourceController +class ShowDiscussionController extends AbstractShowController { /** * @var DiscussionRepository diff --git a/framework/core/src/Api/Controller/ShowForumController.php b/framework/core/src/Api/Controller/ShowForumController.php index 5449df604..d221646e8 100644 --- a/framework/core/src/Api/Controller/ShowForumController.php +++ b/framework/core/src/Api/Controller/ShowForumController.php @@ -15,7 +15,7 @@ use Flarum\Core\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..25e2f0e79 100644 --- a/framework/core/src/Api/Controller/ShowPostController.php +++ b/framework/core/src/Api/Controller/ShowPostController.php @@ -15,7 +15,7 @@ use Flarum\Core\Repository\PostRepository; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class ShowPostController extends AbstractResourceController +class ShowPostController extends AbstractShowController { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/ShowUserController.php b/framework/core/src/Api/Controller/ShowUserController.php index fd35b2867..2879a3c8b 100644 --- a/framework/core/src/Api/Controller/ShowUserController.php +++ b/framework/core/src/Api/Controller/ShowUserController.php @@ -15,7 +15,7 @@ use Flarum\Core\Repository\UserRepository; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class ShowUserController extends AbstractResourceController +class ShowUserController extends AbstractShowController { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/UpdateDiscussionController.php b/framework/core/src/Api/Controller/UpdateDiscussionController.php index fc7070be0..09ba078c5 100644 --- a/framework/core/src/Api/Controller/UpdateDiscussionController.php +++ b/framework/core/src/Api/Controller/UpdateDiscussionController.php @@ -18,7 +18,7 @@ use Illuminate\Database\Eloquent\Collection; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; -class UpdateDiscussionController extends AbstractResourceController +class UpdateDiscussionController extends AbstractShowController { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/UpdateGroupController.php b/framework/core/src/Api/Controller/UpdateGroupController.php index 748d35231..ccb6a8b6e 100644 --- a/framework/core/src/Api/Controller/UpdateGroupController.php +++ b/framework/core/src/Api/Controller/UpdateGroupController.php @@ -16,7 +16,7 @@ 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..01e305bc7 100644 --- a/framework/core/src/Api/Controller/UpdateNotificationController.php +++ b/framework/core/src/Api/Controller/UpdateNotificationController.php @@ -16,7 +16,7 @@ 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..bb5a5f08a 100644 --- a/framework/core/src/Api/Controller/UpdatePostController.php +++ b/framework/core/src/Api/Controller/UpdatePostController.php @@ -16,7 +16,7 @@ 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..78c009012 100644 --- a/framework/core/src/Api/Controller/UpdateUserController.php +++ b/framework/core/src/Api/Controller/UpdateUserController.php @@ -17,7 +17,7 @@ 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..ac3619d24 100644 --- a/framework/core/src/Api/Controller/UploadAvatarController.php +++ b/framework/core/src/Api/Controller/UploadAvatarController.php @@ -16,7 +16,7 @@ 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/Handler/FloodingExceptionHandler.php b/framework/core/src/Api/ExceptionHandler/FloodingExceptionHandler.php similarity index 95% rename from framework/core/src/Api/Handler/FloodingExceptionHandler.php rename to framework/core/src/Api/ExceptionHandler/FloodingExceptionHandler.php index f589baa0a..53b6de082 100644 --- a/framework/core/src/Api/Handler/FloodingExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/FloodingExceptionHandler.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\Core\Exception\FloodingException; diff --git a/framework/core/src/Api/Handler/IlluminateValidationExceptionHandler.php b/framework/core/src/Api/ExceptionHandler/IlluminateValidationExceptionHandler.php similarity index 97% rename from framework/core/src/Api/Handler/IlluminateValidationExceptionHandler.php rename to framework/core/src/Api/ExceptionHandler/IlluminateValidationExceptionHandler.php index 16ccb3eff..ab5bfadcf 100644 --- a/framework/core/src/Api/Handler/IlluminateValidationExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/IlluminateValidationExceptionHandler.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\Contracts\Validation\ValidationException; 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 96% rename from framework/core/src/Api/Handler/InvalidConfirmationTokenExceptionHandler.php rename to framework/core/src/Api/ExceptionHandler/InvalidConfirmationTokenExceptionHandler.php index bce460c0d..7c2465dce 100644 --- a/framework/core/src/Api/Handler/InvalidConfirmationTokenExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/InvalidConfirmationTokenExceptionHandler.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\Core\Exception\InvalidConfirmationTokenException; 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 95% rename from framework/core/src/Api/Handler/PermissionDeniedExceptionHandler.php rename to framework/core/src/Api/ExceptionHandler/PermissionDeniedExceptionHandler.php index d9c863e2d..059c9369d 100644 --- a/framework/core/src/Api/Handler/PermissionDeniedExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/PermissionDeniedExceptionHandler.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\Core\Exception\PermissionDeniedException; 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 97% rename from framework/core/src/Api/Handler/ValidationExceptionHandler.php rename to framework/core/src/Api/ExceptionHandler/ValidationExceptionHandler.php index d165ff68f..9a1f77ec1 100644 --- a/framework/core/src/Api/Handler/ValidationExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/ValidationExceptionHandler.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\Core\Exception\ValidationException; diff --git a/framework/core/src/Api/Serializer/DiscussionBasicSerializer.php b/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php similarity index 97% rename from framework/core/src/Api/Serializer/DiscussionBasicSerializer.php rename to framework/core/src/Api/Serializer/BasicDiscussionSerializer.php index 39bee72ff..82b4536c1 100644 --- a/framework/core/src/Api/Serializer/DiscussionBasicSerializer.php +++ b/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php @@ -14,7 +14,7 @@ namespace Flarum\Api\Serializer; use Flarum\Core\Discussion; use InvalidArgumentException; -class DiscussionBasicSerializer extends AbstractSerializer +class BasicDiscussionSerializer extends AbstractSerializer { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Serializer/PostBasicSerializer.php b/framework/core/src/Api/Serializer/BasicPostSerializer.php similarity index 96% rename from framework/core/src/Api/Serializer/PostBasicSerializer.php rename to framework/core/src/Api/Serializer/BasicPostSerializer.php index 962a7b28b..7bee512bd 100644 --- a/framework/core/src/Api/Serializer/PostBasicSerializer.php +++ b/framework/core/src/Api/Serializer/BasicPostSerializer.php @@ -15,7 +15,7 @@ use Flarum\Core\Post; use Flarum\Core\Post\CommentPost; use InvalidArgumentException; -class PostBasicSerializer extends AbstractSerializer +class BasicPostSerializer extends AbstractSerializer { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Serializer/UserBasicSerializer.php b/framework/core/src/Api/Serializer/BasicUserSerializer.php similarity index 95% rename from framework/core/src/Api/Serializer/UserBasicSerializer.php rename to framework/core/src/Api/Serializer/BasicUserSerializer.php index 2699c8714..1d854c330 100644 --- a/framework/core/src/Api/Serializer/UserBasicSerializer.php +++ b/framework/core/src/Api/Serializer/BasicUserSerializer.php @@ -14,7 +14,7 @@ namespace Flarum\Api\Serializer; use Flarum\Core\User; use InvalidArgumentException; -class UserBasicSerializer extends AbstractSerializer +class BasicUserSerializer extends AbstractSerializer { /** * {@inheritdoc} diff --git a/framework/core/src/Api/Serializer/DiscussionSerializer.php b/framework/core/src/Api/Serializer/DiscussionSerializer.php index 47ef8c0ea..e26f8929b 100644 --- a/framework/core/src/Api/Serializer/DiscussionSerializer.php +++ b/framework/core/src/Api/Serializer/DiscussionSerializer.php @@ -14,7 +14,7 @@ namespace Flarum\Api\Serializer; use Flarum\Core\Access\Gate; use Flarum\Core\Discussion; -class DiscussionSerializer extends DiscussionBasicSerializer +class DiscussionSerializer extends BasicDiscussionSerializer { /** * @var Gate diff --git a/framework/core/src/Api/Serializer/PostSerializer.php b/framework/core/src/Api/Serializer/PostSerializer.php index cb6a40457..bb584dd3e 100644 --- a/framework/core/src/Api/Serializer/PostSerializer.php +++ b/framework/core/src/Api/Serializer/PostSerializer.php @@ -14,7 +14,7 @@ namespace Flarum\Api\Serializer; use Flarum\Core\Access\Gate; use Flarum\Core\Post\CommentPost; -class PostSerializer extends PostBasicSerializer +class PostSerializer extends BasicPostSerializer { /** * @var \Flarum\Core\Access\Gate diff --git a/framework/core/src/Api/Serializer/UserSerializer.php b/framework/core/src/Api/Serializer/UserSerializer.php index 5db640678..7bf6f62b2 100644 --- a/framework/core/src/Api/Serializer/UserSerializer.php +++ b/framework/core/src/Api/Serializer/UserSerializer.php @@ -13,7 +13,7 @@ namespace Flarum\Api\Serializer; use Flarum\Core\Access\Gate; -class UserSerializer extends UserBasicSerializer +class UserSerializer extends BasicUserSerializer { /** * @var Gate diff --git a/framework/core/src/Api/routes.php b/framework/core/src/Api/routes.php new file mode 100644 index 000000000..0203b6131 --- /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\Handler\RouteHandlerFactory; +use Flarum\Http\RouteCollection; + +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/tests/Flarum/Api/Handler/FloodingExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/FloodingExceptionHandlerTest.php index 0b57f03b6..6a70a96bc 100644 --- a/framework/core/tests/Flarum/Api/Handler/FloodingExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/FloodingExceptionHandlerTest.php @@ -12,7 +12,7 @@ namespace Tests\Flarum\Api\Handler; use Exception; -use Flarum\Api\Handler\FloodingExceptionHandler; +use Flarum\Api\ExceptionHandler\FloodingExceptionHandler; use Flarum\Core\Exception\FloodingException; use Tests\Test\TestCase; diff --git a/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php index 2830d723a..4960aba36 100644 --- a/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php @@ -12,7 +12,7 @@ namespace Tests\Flarum\Api\Handler; use Exception; -use Flarum\Api\Handler\IlluminateValidationExceptionHandler; +use Flarum\Api\ExceptionHandler\IlluminateValidationExceptionHandler; use Illuminate\Contracts\Validation\ValidationException; use Illuminate\Validation\Factory; use Symfony\Component\Translation\Translator; 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..6591fff1f 100644 --- a/framework/core/tests/Flarum/Api/Handler/InvalidConfirmationTokenExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/InvalidConfirmationTokenExceptionHandlerTest.php @@ -12,7 +12,7 @@ namespace Tests\Flarum\Api\Handler; use Exception; -use Flarum\Api\Handler\InvalidConfirmationTokenExceptionHandler; +use Flarum\Api\ExceptionHandler\InvalidConfirmationTokenExceptionHandler; use Flarum\Core\Exception\InvalidConfirmationTokenException; use Tests\Test\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..10d52b19f 100644 --- a/framework/core/tests/Flarum/Api/Handler/PermissionDeniedExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/PermissionDeniedExceptionHandlerTest.php @@ -12,7 +12,7 @@ namespace Tests\Flarum\Api\Handler; use Exception; -use Flarum\Api\Handler\PermissionDeniedExceptionHandler; +use Flarum\Api\ExceptionHandler\PermissionDeniedExceptionHandler; use Flarum\Core\Exception\PermissionDeniedException; use Tests\Test\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..2d2130cf1 100644 --- a/framework/core/tests/Flarum/Api/Handler/ValidationExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/ValidationExceptionHandlerTest.php @@ -12,7 +12,7 @@ namespace Tests\Flarum\Api\Handler; use Exception; -use Flarum\Api\Handler\ValidationExceptionHandler; +use Flarum\Api\ExceptionHandler\ValidationExceptionHandler; use Flarum\Core\Exception\ValidationException; use Tests\Test\TestCase; From cc653412a146e419efb6224fe88af6bdba9274ab Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 24 Jun 2017 11:29:44 +0200 Subject: [PATCH 003/172] Restructure Flarum\Console namespace --- framework/core/src/Console/{Command => }/AbstractCommand.php | 2 +- framework/core/src/Console/Server.php | 2 +- .../Command => Database/Console}/GenerateMigrationCommand.php | 3 ++- framework/core/src/Debug/Console/CacheClearCommand.php | 2 +- framework/core/src/Debug/Console/InfoCommand.php | 2 +- framework/core/src/Install/Console/InstallCommand.php | 2 +- framework/core/src/Update/Console/MigrateCommand.php | 2 +- 7 files changed, 8 insertions(+), 7 deletions(-) rename framework/core/src/Console/{Command => }/AbstractCommand.php (97%) rename framework/core/src/{Console/Command => Database/Console}/GenerateMigrationCommand.php (97%) 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..ecbf3f8ab 100644 --- a/framework/core/src/Console/Server.php +++ b/framework/core/src/Console/Server.php @@ -11,7 +11,7 @@ namespace Flarum\Console; -use Flarum\Console\Command\GenerateMigrationCommand; +use Flarum\Database\Console\GenerateMigrationCommand; use Flarum\Debug\Console\CacheClearCommand; use Flarum\Debug\Console\InfoCommand; use Flarum\Foundation\AbstractServer; 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/Debug/Console/CacheClearCommand.php b/framework/core/src/Debug/Console/CacheClearCommand.php index 554e24824..76b66b3b0 100644 --- a/framework/core/src/Debug/Console/CacheClearCommand.php +++ b/framework/core/src/Debug/Console/CacheClearCommand.php @@ -12,7 +12,7 @@ namespace Flarum\Debug\Console; use Flarum\Admin\Frontend as AdminWebApp; -use Flarum\Console\Command\AbstractCommand; +use Flarum\Console\AbstractCommand; use Flarum\Forum\WebApp as ForumWebApp; use Illuminate\Contracts\Cache\Store; diff --git a/framework/core/src/Debug/Console/InfoCommand.php b/framework/core/src/Debug/Console/InfoCommand.php index 9f3c36831..e14fb8468 100644 --- a/framework/core/src/Debug/Console/InfoCommand.php +++ b/framework/core/src/Debug/Console/InfoCommand.php @@ -11,7 +11,7 @@ namespace Flarum\Debug\Console; -use Flarum\Console\Command\AbstractCommand; +use Flarum\Console\AbstractCommand; use Flarum\Extension\ExtensionManager; use Flarum\Foundation\Application; diff --git a/framework/core/src/Install/Console/InstallCommand.php b/framework/core/src/Install/Console/InstallCommand.php index 6dacaeb6f..1a7317830 100644 --- a/framework/core/src/Install/Console/InstallCommand.php +++ b/framework/core/src/Install/Console/InstallCommand.php @@ -12,7 +12,7 @@ namespace Flarum\Install\Console; use Exception; -use Flarum\Console\Command\AbstractCommand; +use Flarum\Console\AbstractCommand; use Flarum\Core\Group; use Flarum\Core\Permission; use Flarum\Core\User; diff --git a/framework/core/src/Update/Console/MigrateCommand.php b/framework/core/src/Update/Console/MigrateCommand.php index 1f2c62f83..bdff208c0 100644 --- a/framework/core/src/Update/Console/MigrateCommand.php +++ b/framework/core/src/Update/Console/MigrateCommand.php @@ -11,7 +11,7 @@ namespace Flarum\Update\Console; -use Flarum\Console\Command\AbstractCommand; +use Flarum\Console\AbstractCommand; use Illuminate\Contracts\Container\Container; class MigrateCommand extends AbstractCommand From 925ef227a3adc6a5b6d0207d0fa8f96e524d16ea Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 24 Jun 2017 11:34:29 +0200 Subject: [PATCH 004/172] Restructure Flarum\Database namespace --- framework/core/src/Console/Server.php | 2 +- .../Console/MigrateCommand.php | 2 +- .../src/Database/DatabaseServiceProvider.php | 9 ------ .../src/Database/MigrationServiceProvider.php | 32 +++++++++++++++++++ .../Update/Controller/UpdateController.php | 2 +- 5 files changed, 35 insertions(+), 12 deletions(-) rename framework/core/src/{Update => Database}/Console/MigrateCommand.php (98%) create mode 100644 framework/core/src/Database/MigrationServiceProvider.php diff --git a/framework/core/src/Console/Server.php b/framework/core/src/Console/Server.php index ecbf3f8ab..d18533e42 100644 --- a/framework/core/src/Console/Server.php +++ b/framework/core/src/Console/Server.php @@ -16,7 +16,7 @@ use Flarum\Debug\Console\CacheClearCommand; use Flarum\Debug\Console\InfoCommand; use Flarum\Foundation\AbstractServer; use Flarum\Install\Console\InstallCommand; -use Flarum\Update\Console\MigrateCommand; +use Flarum\Database\Console\MigrateCommand; use Symfony\Component\Console\Application; class Server extends AbstractServer diff --git a/framework/core/src/Update/Console/MigrateCommand.php b/framework/core/src/Database/Console/MigrateCommand.php similarity index 98% rename from framework/core/src/Update/Console/MigrateCommand.php rename to framework/core/src/Database/Console/MigrateCommand.php index bdff208c0..f5782d13f 100644 --- a/framework/core/src/Update/Console/MigrateCommand.php +++ b/framework/core/src/Database/Console/MigrateCommand.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Update\Console; +namespace Flarum\Database\Console; use Flarum\Console\AbstractCommand; use Illuminate\Contracts\Container\Container; diff --git a/framework/core/src/Database/DatabaseServiceProvider.php b/framework/core/src/Database/DatabaseServiceProvider.php index 87324330c..c4b349074 100644 --- a/framework/core/src/Database/DatabaseServiceProvider.php +++ b/framework/core/src/Database/DatabaseServiceProvider.php @@ -12,7 +12,6 @@ namespace Flarum\Database; use Flarum\Foundation\AbstractServiceProvider; -use Flarum\Foundation\Application; use Illuminate\Database\ConnectionResolver; use Illuminate\Database\Connectors\ConnectionFactory; use PDO; @@ -46,14 +45,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/Update/Controller/UpdateController.php b/framework/core/src/Update/Controller/UpdateController.php index 9b20ede72..2a0335030 100644 --- a/framework/core/src/Update/Controller/UpdateController.php +++ b/framework/core/src/Update/Controller/UpdateController.php @@ -14,7 +14,7 @@ namespace Flarum\Update\Controller; use Exception; use Flarum\Foundation\Application; use Flarum\Http\Controller\ControllerInterface; -use Flarum\Update\Console\MigrateCommand; +use Flarum\Database\Console\MigrateCommand; use Psr\Http\Message\ServerRequestInterface as Request; use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\StreamOutput; From 064752f1eb08440cd15c2e775734f1871cd8e95c Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 24 Jun 2017 11:36:24 +0200 Subject: [PATCH 005/172] Get rid of Flarum\Debug namespace --- framework/core/src/Console/Server.php | 4 ++-- .../src/{Debug => Foundation}/Console/CacheClearCommand.php | 2 +- .../core/src/{Debug => Foundation}/Console/InfoCommand.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename framework/core/src/{Debug => Foundation}/Console/CacheClearCommand.php (97%) rename framework/core/src/{Debug => Foundation}/Console/InfoCommand.php (98%) diff --git a/framework/core/src/Console/Server.php b/framework/core/src/Console/Server.php index d18533e42..45366ec83 100644 --- a/framework/core/src/Console/Server.php +++ b/framework/core/src/Console/Server.php @@ -12,8 +12,8 @@ namespace Flarum\Console; use Flarum\Database\Console\GenerateMigrationCommand; -use Flarum\Debug\Console\CacheClearCommand; -use Flarum\Debug\Console\InfoCommand; +use Flarum\Foundation\Console\CacheClearCommand; +use Flarum\Foundation\Console\InfoCommand; use Flarum\Foundation\AbstractServer; use Flarum\Install\Console\InstallCommand; use Flarum\Database\Console\MigrateCommand; diff --git a/framework/core/src/Debug/Console/CacheClearCommand.php b/framework/core/src/Foundation/Console/CacheClearCommand.php similarity index 97% rename from framework/core/src/Debug/Console/CacheClearCommand.php rename to framework/core/src/Foundation/Console/CacheClearCommand.php index 76b66b3b0..f669205bd 100644 --- a/framework/core/src/Debug/Console/CacheClearCommand.php +++ b/framework/core/src/Foundation/Console/CacheClearCommand.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Debug\Console; +namespace Flarum\Foundation\Console; use Flarum\Admin\Frontend as AdminWebApp; use Flarum\Console\AbstractCommand; diff --git a/framework/core/src/Debug/Console/InfoCommand.php b/framework/core/src/Foundation/Console/InfoCommand.php similarity index 98% rename from framework/core/src/Debug/Console/InfoCommand.php rename to framework/core/src/Foundation/Console/InfoCommand.php index e14fb8468..1a467051a 100644 --- a/framework/core/src/Debug/Console/InfoCommand.php +++ b/framework/core/src/Foundation/Console/InfoCommand.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Debug\Console; +namespace Flarum\Foundation\Console; use Flarum\Console\AbstractCommand; use Flarum\Extension\ExtensionManager; From aecfe31f9aaf0d215de3bbd2f3dd9d9c6620d96a Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 24 Jun 2017 11:38:23 +0200 Subject: [PATCH 006/172] Register new MigrationServiceProvider --- framework/core/src/Foundation/AbstractServer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/core/src/Foundation/AbstractServer.php b/framework/core/src/Foundation/AbstractServer.php index e98ec05cf..34ef520d2 100644 --- a/framework/core/src/Foundation/AbstractServer.php +++ b/framework/core/src/Foundation/AbstractServer.php @@ -168,6 +168,7 @@ abstract class AbstractServer $this->registerCache($app); $app->register('Flarum\Database\DatabaseServiceProvider'); + $app->register('Flarum\Database\MigrationServiceProvider'); $app->register('Flarum\Settings\SettingsServiceProvider'); $app->register('Flarum\Locale\LocaleServiceProvider'); $app->register('Illuminate\Bus\BusServiceProvider'); From 88d34192f1300f3e50714dd08b7f2c38cef17c3b Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 24 Jun 2017 11:40:45 +0200 Subject: [PATCH 007/172] Fix serializer class names --- .../src/Api/Serializer/BasicDiscussionSerializer.php | 10 +++++----- .../core/src/Api/Serializer/BasicPostSerializer.php | 4 ++-- .../core/src/Api/Serializer/NotificationSerializer.php | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php b/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php index 82b4536c1..1fb175601 100644 --- a/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php +++ b/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php @@ -46,7 +46,7 @@ class BasicDiscussionSerializer extends AbstractSerializer */ protected function startUser($discussion) { - return $this->hasOne($discussion, 'Flarum\Api\Serializer\UserBasicSerializer'); + return $this->hasOne($discussion, 'Flarum\Api\Serializer\BasicUserSerializer'); } /** @@ -54,7 +54,7 @@ class BasicDiscussionSerializer extends AbstractSerializer */ protected function startPost($discussion) { - return $this->hasOne($discussion, 'Flarum\Api\Serializer\PostBasicSerializer'); + return $this->hasOne($discussion, 'Flarum\Api\Serializer\BasicPostSerializer'); } /** @@ -62,7 +62,7 @@ class BasicDiscussionSerializer extends AbstractSerializer */ protected function lastUser($discussion) { - return $this->hasOne($discussion, 'Flarum\Api\Serializer\UserBasicSerializer'); + return $this->hasOne($discussion, 'Flarum\Api\Serializer\BasicUserSerializer'); } /** @@ -70,7 +70,7 @@ class BasicDiscussionSerializer extends AbstractSerializer */ protected function lastPost($discussion) { - return $this->hasOne($discussion, 'Flarum\Api\Serializer\PostBasicSerializer'); + return $this->hasOne($discussion, 'Flarum\Api\Serializer\BasicPostSerializer'); } /** @@ -86,6 +86,6 @@ class BasicDiscussionSerializer extends AbstractSerializer */ protected function relevantPosts($discussion) { - return $this->hasMany($discussion, 'Flarum\Api\Serializer\PostBasicSerializer'); + return $this->hasMany($discussion, 'Flarum\Api\Serializer\BasicPostSerializer'); } } diff --git a/framework/core/src/Api/Serializer/BasicPostSerializer.php b/framework/core/src/Api/Serializer/BasicPostSerializer.php index 7bee512bd..2988a6343 100644 --- a/framework/core/src/Api/Serializer/BasicPostSerializer.php +++ b/framework/core/src/Api/Serializer/BasicPostSerializer.php @@ -57,7 +57,7 @@ class BasicPostSerializer extends AbstractSerializer */ protected function user($post) { - return $this->hasOne($post, 'Flarum\Api\Serializer\UserBasicSerializer'); + return $this->hasOne($post, 'Flarum\Api\Serializer\BasicUserSerializer'); } /** @@ -65,6 +65,6 @@ class BasicPostSerializer extends AbstractSerializer */ protected function discussion($post) { - return $this->hasOne($post, 'Flarum\Api\Serializer\DiscussionBasicSerializer'); + return $this->hasOne($post, 'Flarum\Api\Serializer\BasicDiscussionSerializer'); } } diff --git a/framework/core/src/Api/Serializer/NotificationSerializer.php b/framework/core/src/Api/Serializer/NotificationSerializer.php index a599ffe31..bfbd8e943 100644 --- a/framework/core/src/Api/Serializer/NotificationSerializer.php +++ b/framework/core/src/Api/Serializer/NotificationSerializer.php @@ -57,7 +57,7 @@ class NotificationSerializer extends AbstractSerializer */ protected function user($notification) { - return $this->hasOne($notification, 'Flarum\Api\Serializer\UserBasicSerializer'); + return $this->hasOne($notification, 'Flarum\Api\Serializer\BasicUserSerializer'); } /** @@ -65,7 +65,7 @@ class NotificationSerializer extends AbstractSerializer */ protected function sender($notification) { - return $this->hasOne($notification, 'Flarum\Api\Serializer\UserBasicSerializer'); + return $this->hasOne($notification, 'Flarum\Api\Serializer\BasicUserSerializer'); } /** From 5e9308fb4c246858cd5a88d1e54a9be6f471b249 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 24 Jun 2017 11:52:53 +0200 Subject: [PATCH 008/172] Create new Flarum\Frontend namespace It replaces the old Http\WebApp namespace and swallows other namespaces and files, such as Flarum\Asset. --- .../core/src/Admin/AdminServiceProvider.php | 2 +- .../Admin/Controller/FrontendController.php | 4 +-- framework/core/src/Admin/Frontend.php | 4 +-- framework/core/src/Event/ConfigureWebApp.php | 16 +++++----- .../Controller/AuthorizedWebAppController.php | 2 +- .../Forum/Controller/DiscussionController.php | 6 ++-- .../src/Forum/Controller/IndexController.php | 6 ++-- .../src/Forum/Controller/WebAppController.php | 8 ++--- .../core/src/Forum/ForumServiceProvider.php | 6 ++-- framework/core/src/Forum/WebApp.php | 12 ++++---- .../Foundation/Console/CacheClearCommand.php | 4 +-- .../AbstractFrontend.php} | 30 +++++++++---------- .../AbstractFrontendController.php} | 10 +++---- .../Asset/CompilerInterface.php | 2 +- .../src/{ => Frontend}/Asset/JsCompiler.php | 2 +- .../src/{ => Frontend}/Asset/LessCompiler.php | 2 +- .../Asset/LocaleJsCompiler.php} | 6 ++-- .../{ => Frontend}/Asset/RevisionCompiler.php | 2 +- .../FrontendAssets.php} | 10 +++---- .../FrontendAssetsFactory.php} | 8 ++--- .../FrontendView.php} | 16 +++++----- .../FrontendViewFactory.php} | 12 ++++---- 22 files changed, 84 insertions(+), 86 deletions(-) rename framework/core/src/{Http/WebApp/AbstractWebApp.php => Frontend/AbstractFrontend.php} (85%) rename framework/core/src/{Http/Controller/AbstractWebAppController.php => Frontend/AbstractFrontendController.php} (82%) rename framework/core/src/{ => Frontend}/Asset/CompilerInterface.php (95%) rename framework/core/src/{ => Frontend}/Asset/JsCompiler.php (98%) rename framework/core/src/{ => Frontend}/Asset/LessCompiler.php (97%) rename framework/core/src/{Locale/JsCompiler.php => Frontend/Asset/LocaleJsCompiler.php} (88%) rename framework/core/src/{ => Frontend}/Asset/RevisionCompiler.php (99%) rename framework/core/src/{Http/WebApp/WebAppAssets.php => Frontend/FrontendAssets.php} (94%) rename framework/core/src/{Http/WebApp/WebAppAssetsFactory.php => Frontend/FrontendAssetsFactory.php} (84%) rename framework/core/src/{Http/WebApp/WebAppView.php => Frontend/FrontendView.php} (96%) rename framework/core/src/{Http/WebApp/WebAppViewFactory.php => Frontend/FrontendViewFactory.php} (81%) diff --git a/framework/core/src/Admin/AdminServiceProvider.php b/framework/core/src/Admin/AdminServiceProvider.php index 80713c37e..2cbd60a78 100644 --- a/framework/core/src/Admin/AdminServiceProvider.php +++ b/framework/core/src/Admin/AdminServiceProvider.php @@ -84,7 +84,7 @@ class AdminServiceProvider extends AbstractServiceProvider } /** - * @return \Flarum\Http\WebApp\WebAppAssets + * @return \Flarum\Frontend\FrontendAssets */ protected function getWebAppAssets() { diff --git a/framework/core/src/Admin/Controller/FrontendController.php b/framework/core/src/Admin/Controller/FrontendController.php index db8cc5c41..eb691f88f 100644 --- a/framework/core/src/Admin/Controller/FrontendController.php +++ b/framework/core/src/Admin/Controller/FrontendController.php @@ -15,12 +15,12 @@ use Flarum\Admin\Frontend; use Flarum\Core\Permission; use Flarum\Event\PrepareUnserializedSettings; use Flarum\Extension\ExtensionManager; -use Flarum\Http\Controller\AbstractWebAppController; +use Flarum\Frontend\AbstractFrontendController; use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Events\Dispatcher; use Psr\Http\Message\ServerRequestInterface; -class FrontendController extends AbstractWebAppController +class FrontendController extends AbstractFrontendController { /** * @var SettingsRepositoryInterface diff --git a/framework/core/src/Admin/Frontend.php b/framework/core/src/Admin/Frontend.php index 65be577f0..b984e15e2 100644 --- a/framework/core/src/Admin/Frontend.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 Frontend extends AbstractWebApp +class Frontend extends AbstractFrontend { /** * {@inheritdoc} diff --git a/framework/core/src/Event/ConfigureWebApp.php b/framework/core/src/Event/ConfigureWebApp.php index 014672ffc..a7f26591e 100644 --- a/framework/core/src/Event/ConfigureWebApp.php +++ b/framework/core/src/Event/ConfigureWebApp.php @@ -12,20 +12,20 @@ namespace Flarum\Event; use Flarum\Admin\Controller\FrontendController as AdminWebAppController; -use Flarum\Forum\Controller\WebAppController as ForumWebAppController; -use Flarum\Http\Controller\AbstractWebAppController; -use Flarum\Http\WebApp\WebAppView; +use Flarum\Forum\Controller\FrontendController as ForumWebAppController; +use Flarum\Frontend\AbstractFrontendController; +use Flarum\Frontend\FrontendView; use Psr\Http\Message\ServerRequestInterface; class ConfigureWebApp { /** - * @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; diff --git a/framework/core/src/Forum/Controller/AuthorizedWebAppController.php b/framework/core/src/Forum/Controller/AuthorizedWebAppController.php index 51131479f..05a5baf96 100644 --- a/framework/core/src/Forum/Controller/AuthorizedWebAppController.php +++ b/framework/core/src/Forum/Controller/AuthorizedWebAppController.php @@ -14,7 +14,7 @@ namespace Flarum\Forum\Controller; use Flarum\Core\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/DiscussionController.php b/framework/core/src/Forum/Controller/DiscussionController.php index ebc7ab0de..f12b1092e 100644 --- a/framework/core/src/Forum/Controller/DiscussionController.php +++ b/framework/core/src/Forum/Controller/DiscussionController.php @@ -14,12 +14,12 @@ 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 Illuminate\Contracts\Events\Dispatcher; use Psr\Http\Message\ServerRequestInterface as Request; -class DiscussionController extends WebAppController +class DiscussionController extends FrontendController { /** * @var ApiClient @@ -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); diff --git a/framework/core/src/Forum/Controller/IndexController.php b/framework/core/src/Forum/Controller/IndexController.php index a4c059f34..8deeb7867 100644 --- a/framework/core/src/Forum/Controller/IndexController.php +++ b/framework/core/src/Forum/Controller/IndexController.php @@ -13,11 +13,11 @@ namespace Flarum\Forum\Controller; use Flarum\Api\Client as ApiClient; use Flarum\Core\User; -use Flarum\Forum\WebApp; +use Flarum\Forum\Frontend; 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); diff --git a/framework/core/src/Forum/Controller/WebAppController.php b/framework/core/src/Forum/Controller/WebAppController.php index e24405150..ba863c019 100644 --- a/framework/core/src/Forum/Controller/WebAppController.php +++ b/framework/core/src/Forum/Controller/WebAppController.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/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index 43f4c2bed..4c1fa33f7 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -73,7 +73,7 @@ class ForumServiceProvider extends AbstractServiceProvider $routes->get( '/u/{username}[/{filter:[^/]*}]', 'user', - $route->toController(Controller\WebAppController::class) + $route->toController(Controller\FrontendController::class) ); $routes->get( @@ -164,10 +164,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/WebApp.php index 310532922..c59ce5345 100644 --- a/framework/core/src/Forum/WebApp.php +++ b/framework/core/src/Forum/WebApp.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/Foundation/Console/CacheClearCommand.php b/framework/core/src/Foundation/Console/CacheClearCommand.php index f669205bd..957c33478 100644 --- a/framework/core/src/Foundation/Console/CacheClearCommand.php +++ b/framework/core/src/Foundation/Console/CacheClearCommand.php @@ -13,7 +13,7 @@ namespace Flarum\Foundation\Console; use Flarum\Admin\Frontend as AdminWebApp; use Flarum\Console\AbstractCommand; -use Flarum\Forum\WebApp as ForumWebApp; +use Flarum\Forum\Frontend as ForumWebApp; use Illuminate\Contracts\Cache\Store; class CacheClearCommand extends AbstractCommand @@ -24,7 +24,7 @@ class CacheClearCommand extends AbstractCommand protected $cache; /** - * @var \Flarum\Forum\WebApp + * @var \Flarum\Forum\Frontend */ protected $forum; diff --git a/framework/core/src/Http/WebApp/AbstractWebApp.php b/framework/core/src/Frontend/AbstractFrontend.php similarity index 85% rename from framework/core/src/Http/WebApp/AbstractWebApp.php rename to framework/core/src/Frontend/AbstractFrontend.php index 0e2bc24aa..d556e81b8 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() { @@ -100,9 +100,9 @@ abstract class AbstractWebApp } /** - * @param WebAppView $view + * @param FrontendView $view */ - private function addDefaultAssets(WebAppView $view) + private function addDefaultAssets(FrontendView $view) { $root = __DIR__.'/../../..'; $name = $this->getName(); @@ -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(); @@ -154,9 +154,9 @@ 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', []); diff --git a/framework/core/src/Http/Controller/AbstractWebAppController.php b/framework/core/src/Frontend/AbstractFrontendController.php similarity index 82% rename from framework/core/src/Http/Controller/AbstractWebAppController.php rename to framework/core/src/Frontend/AbstractFrontendController.php index a9af1f576..52eed3ac4 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\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; @@ -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 382a1b210..e1b74af0c 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 3993b90a7..74670af1f 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/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..e3bce2f16 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\Frontend\Asset\JsCompiler; +use Flarum\Frontend\Asset\LessCompiler; use Flarum\Foundation\Application; -use Flarum\Locale\JsCompiler as LocaleJsCompiler; +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/Http/WebApp/WebAppView.php b/framework/core/src/Frontend/FrontendView.php similarity index 96% rename from framework/core/src/Http/WebApp/WebAppView.php rename to framework/core/src/Frontend/FrontendView.php index d38e95839..f564443ea 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\Frontend\Asset\CompilerInterface; use Flarum\Foundation\Application; -use Flarum\Locale\JsCompiler; +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; @@ -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); } } From 0324045f6c06dc9dfc79643ccd02c1f39f320d42 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 12:08:04 +0200 Subject: [PATCH 009/172] Restructure Flarum\Forum namespace --- .../core/src/Forum/ForumServiceProvider.php | 73 ++--------------- .../src/Forum/{WebApp.php => Frontend.php} | 0 framework/core/src/Forum/routes.php | 82 +++++++++++++++++++ 3 files changed, 88 insertions(+), 67 deletions(-) rename framework/core/src/Forum/{WebApp.php => Frontend.php} (100%) create mode 100644 framework/core/src/Forum/routes.php diff --git a/framework/core/src/Forum/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index 4c1fa33f7..86ef67d31 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -56,82 +56,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\FrontendController::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/{token}', - 'confirmEmail', - $route->toController(Controller\ConfirmEmailController::class) - ); - - $routes->get( - '/reset/{token}', - 'resetPassword', - $route->toController(Controller\ResetPasswordController::class) - ); - - $routes->post( - '/reset', - '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( diff --git a/framework/core/src/Forum/WebApp.php b/framework/core/src/Forum/Frontend.php similarity index 100% rename from framework/core/src/Forum/WebApp.php rename to framework/core/src/Forum/Frontend.php diff --git a/framework/core/src/Forum/routes.php b/framework/core/src/Forum/routes.php new file mode 100644 index 000000000..96e26dc3a --- /dev/null +++ b/framework/core/src/Forum/routes.php @@ -0,0 +1,82 @@ +<?php + +/* + * This file is part of Flarum. + * + * (c) Toby Zerner <toby.zerner@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Forum\Controller; +use Flarum\Http\Handler\RouteHandlerFactory; +use Flarum\Http\RouteCollection; + +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) + ); +}; From be685d72e605e9eeea64f11da398044f40862e89 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 12:09:22 +0200 Subject: [PATCH 010/172] Move ScopeVisibilityTrait to Database namespace --- framework/core/src/Core/Discussion.php | 2 +- framework/core/src/Core/Group.php | 2 +- framework/core/src/Core/Post.php | 2 +- framework/core/src/Core/User.php | 2 +- .../src/{Core/Support => Database}/ScopeVisibilityTrait.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) rename framework/core/src/{Core/Support => Database}/ScopeVisibilityTrait.php (95%) diff --git a/framework/core/src/Core/Discussion.php b/framework/core/src/Core/Discussion.php index a73e437e2..2d510ede5 100644 --- a/framework/core/src/Core/Discussion.php +++ b/framework/core/src/Core/Discussion.php @@ -13,7 +13,7 @@ namespace Flarum\Core; use Flarum\Core\Post\MergeableInterface; use Flarum\Core\Support\EventGeneratorTrait; -use Flarum\Core\Support\ScopeVisibilityTrait; +use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; use Flarum\Event\DiscussionWasDeleted; use Flarum\Event\DiscussionWasHidden; diff --git a/framework/core/src/Core/Group.php b/framework/core/src/Core/Group.php index ad265e6f0..db081ffe5 100755 --- a/framework/core/src/Core/Group.php +++ b/framework/core/src/Core/Group.php @@ -12,7 +12,7 @@ namespace Flarum\Core; use Flarum\Core\Support\EventGeneratorTrait; -use Flarum\Core\Support\ScopeVisibilityTrait; +use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; use Flarum\Event\GroupWasCreated; use Flarum\Event\GroupWasDeleted; diff --git a/framework/core/src/Core/Post.php b/framework/core/src/Core/Post.php index cb6717f4d..6d4ad5620 100755 --- a/framework/core/src/Core/Post.php +++ b/framework/core/src/Core/Post.php @@ -13,7 +13,7 @@ namespace Flarum\Core; use Flarum\Core\Post\RegisteredTypesScope; use Flarum\Core\Support\EventGeneratorTrait; -use Flarum\Core\Support\ScopeVisibilityTrait; +use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; use Flarum\Event\PostWasDeleted; use Illuminate\Database\Eloquent\Builder; diff --git a/framework/core/src/Core/User.php b/framework/core/src/Core/User.php index 32f58e86a..fd175c998 100755 --- a/framework/core/src/Core/User.php +++ b/framework/core/src/Core/User.php @@ -14,7 +14,7 @@ namespace Flarum\Core; use DomainException; use Flarum\Core\Access\Gate; use Flarum\Core\Support\EventGeneratorTrait; -use Flarum\Core\Support\ScopeVisibilityTrait; +use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; use Flarum\Event\CheckUserPassword; use Flarum\Event\ConfigureUserPreferences; diff --git a/framework/core/src/Core/Support/ScopeVisibilityTrait.php b/framework/core/src/Database/ScopeVisibilityTrait.php similarity index 95% rename from framework/core/src/Core/Support/ScopeVisibilityTrait.php rename to framework/core/src/Database/ScopeVisibilityTrait.php index 2768cbe62..0cfe43fc3 100644 --- a/framework/core/src/Core/Support/ScopeVisibilityTrait.php +++ b/framework/core/src/Database/ScopeVisibilityTrait.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Support; +namespace Flarum\Database; use Flarum\Core\User; use Flarum\Event\ScopeModelVisibility; From ea484732ed382867227d78976d5dc9b51af92de2 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 12:15:48 +0200 Subject: [PATCH 011/172] Rename controller file --- .../Controller/{WebAppController.php => FrontendController.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename framework/core/src/Forum/Controller/{WebAppController.php => FrontendController.php} (100%) diff --git a/framework/core/src/Forum/Controller/WebAppController.php b/framework/core/src/Forum/Controller/FrontendController.php similarity index 100% rename from framework/core/src/Forum/Controller/WebAppController.php rename to framework/core/src/Forum/Controller/FrontendController.php From a12686ac803d15d742e4e6cde5300112177b2faf Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 12:16:00 +0200 Subject: [PATCH 012/172] Flarum\Frontend: Fix view paths after renaming namespace --- framework/core/src/Frontend/AbstractFrontend.php | 4 ++-- framework/core/src/Frontend/FrontendView.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/core/src/Frontend/AbstractFrontend.php b/framework/core/src/Frontend/AbstractFrontend.php index d556e81b8..af4fc954e 100644 --- a/framework/core/src/Frontend/AbstractFrontend.php +++ b/framework/core/src/Frontend/AbstractFrontend.php @@ -86,7 +86,7 @@ abstract class AbstractFrontend */ protected function getLayout() { - return __DIR__.'/../../../views/'.$this->getName().'.blade.php'; + return __DIR__.'/../../views/'.$this->getName().'.blade.php'; } /** @@ -104,7 +104,7 @@ abstract class AbstractFrontend */ private function addDefaultAssets(FrontendView $view) { - $root = __DIR__.'/../../..'; + $root = __DIR__.'/../..'; $name = $this->getName(); $view->getJs()->addFile("$root/js/$name/dist/app.js"); diff --git a/framework/core/src/Frontend/FrontendView.php b/framework/core/src/Frontend/FrontendView.php index f564443ea..0593e070a 100644 --- a/framework/core/src/Frontend/FrontendView.php +++ b/framework/core/src/Frontend/FrontendView.php @@ -287,7 +287,7 @@ class FrontendView $this->view->share('forum', array_get($forum, 'data')); $this->view->share('debug', $this->app->inDebugMode()); - $view = $this->view->file(__DIR__.'/../../../views/app.blade.php'); + $view = $this->view->file(__DIR__.'/../../views/app.blade.php'); $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 FrontendView protected function buildContent() { - $view = $this->view->file(__DIR__.'/../../../views/content.blade.php'); + $view = $this->view->file(__DIR__.'/../../views/content.blade.php'); $view->content = $this->content; From 614f83803b1210a90e51f0c48b100403a87a08dd Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 12:19:59 +0200 Subject: [PATCH 013/172] Flarum\Frontend: Rename ConfigureWebApp event to Rendering --- framework/core/src/Event/ConfigureClientView.php | 4 +++- framework/core/src/Frontend/AbstractFrontendController.php | 4 ++-- .../ConfigureWebApp.php => Frontend/Event/Rendering.php} | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) rename framework/core/src/{Event/ConfigureWebApp.php => Frontend/Event/Rendering.php} (97%) 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/Frontend/AbstractFrontendController.php b/framework/core/src/Frontend/AbstractFrontendController.php index 52eed3ac4..cd7eba06b 100644 --- a/framework/core/src/Frontend/AbstractFrontendController.php +++ b/framework/core/src/Frontend/AbstractFrontendController.php @@ -12,7 +12,7 @@ namespace Flarum\Frontend; use Flarum\Event\ConfigureClientView; -use Flarum\Event\ConfigureWebApp; +use Flarum\Frontend\Event\Rendering; use Flarum\Http\Controller\AbstractHtmlController; use Illuminate\Contracts\Events\Dispatcher; use Psr\Http\Message\ServerRequestInterface as Request; @@ -40,7 +40,7 @@ abstract class AbstractFrontendController extends AbstractHtmlController new ConfigureClientView($this, $view, $request) ); $this->events->fire( - new ConfigureWebApp($this, $view, $request) + new Rendering($this, $view, $request) ); return $view->render($request); diff --git a/framework/core/src/Event/ConfigureWebApp.php b/framework/core/src/Frontend/Event/Rendering.php similarity index 97% rename from framework/core/src/Event/ConfigureWebApp.php rename to framework/core/src/Frontend/Event/Rendering.php index a7f26591e..6219c557f 100644 --- a/framework/core/src/Event/ConfigureWebApp.php +++ b/framework/core/src/Frontend/Event/Rendering.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Frontend\Event; use Flarum\Admin\Controller\FrontendController as AdminWebAppController; use Flarum\Forum\Controller\FrontendController as ForumWebAppController; @@ -17,7 +17,7 @@ use Flarum\Frontend\AbstractFrontendController; use Flarum\Frontend\FrontendView; use Psr\Http\Message\ServerRequestInterface; -class ConfigureWebApp +class Rendering { /** * @var AbstractFrontendController From a39103a472ebdd3d5fcb22cc3cc6ab4533bac0f8 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 12:55:22 +0200 Subject: [PATCH 014/172] Extract new Flarum\User namespace --- framework/core/src/Api/Client.php | 2 +- .../Controller/ForgotPasswordController.php | 6 +-- .../ListNotificationsController.php | 2 +- .../Api/Controller/ListUsersController.php | 4 +- .../SendConfirmationEmailController.php | 4 +- .../Controller/ShowDiscussionController.php | 2 +- .../src/Api/Controller/ShowUserController.php | 6 +-- .../src/Api/Controller/TokenController.php | 6 +-- .../Api/Controller/UpdateUserController.php | 2 +- ...validConfirmationTokenExceptionHandler.php | 2 +- .../PermissionDeniedExceptionHandler.php | 2 +- .../src/Api/Serializer/AbstractSerializer.php | 2 +- .../Api/Serializer/BasicUserSerializer.php | 2 +- .../Api/Serializer/DiscussionSerializer.php | 6 +-- .../src/Api/Serializer/PostSerializer.php | 6 +-- .../src/Api/Serializer/UserSerializer.php | 4 +- .../src/Core/Access/AssertPermissionTrait.php | 6 +-- .../core/src/Core/Access/DiscussionPolicy.php | 4 +- .../core/src/Core/Access/GroupPolicy.php | 3 +- framework/core/src/Core/Access/PostPolicy.php | 3 +- .../src/Core/Command/ConfirmEmailHandler.php | 10 ++--- .../core/src/Core/Command/CreateGroup.php | 2 +- .../src/Core/Command/CreateGroupHandler.php | 4 +- .../core/src/Core/Command/DeleteAvatar.php | 2 +- .../src/Core/Command/DeleteAvatarHandler.php | 8 ++-- .../src/Core/Command/DeleteDiscussion.php | 2 +- .../Core/Command/DeleteDiscussionHandler.php | 2 +- .../core/src/Core/Command/DeleteGroup.php | 2 +- .../src/Core/Command/DeleteGroupHandler.php | 2 +- .../core/src/Core/Command/DeletePost.php | 2 +- .../src/Core/Command/DeletePostHandler.php | 4 +- .../core/src/Core/Command/DeleteUser.php | 2 +- .../src/Core/Command/DeleteUserHandler.php | 10 ++--- .../core/src/Core/Command/EditDiscussion.php | 6 +-- .../Core/Command/EditDiscussionHandler.php | 4 +- framework/core/src/Core/Command/EditGroup.php | 2 +- .../src/Core/Command/EditGroupHandler.php | 2 +- framework/core/src/Core/Command/EditPost.php | 2 +- .../core/src/Core/Command/EditPostHandler.php | 2 +- framework/core/src/Core/Command/EditUser.php | 2 +- .../core/src/Core/Command/EditUserHandler.php | 20 ++++----- framework/core/src/Core/Command/PostReply.php | 2 +- .../src/Core/Command/PostReplyHandler.php | 2 +- .../src/Core/Command/ReadAllNotifications.php | 2 +- .../Command/ReadAllNotificationsHandler.php | 2 +- .../core/src/Core/Command/ReadDiscussion.php | 2 +- .../Core/Command/ReadDiscussionHandler.php | 2 +- .../src/Core/Command/ReadNotification.php | 2 +- .../Core/Command/ReadNotificationHandler.php | 2 +- .../core/src/Core/Command/RegisterUser.php | 2 +- .../src/Core/Command/RegisterUserHandler.php | 14 +++--- .../Command/RequestPasswordResetHandler.php | 8 ++-- .../core/src/Core/Command/StartDiscussion.php | 2 +- .../core/src/Core/Command/UploadAvatar.php | 2 +- .../src/Core/Command/UploadAvatarHandler.php | 14 +++--- .../core/src/Core/CoreServiceProvider.php | 11 ++--- framework/core/src/Core/Discussion.php | 8 ++-- framework/core/src/Core/DiscussionState.php | 4 +- framework/core/src/Core/Group.php | 2 +- framework/core/src/Core/Notification.php | 8 ++-- .../Core/Notification/BlueprintInterface.php | 2 +- .../Core/Notification/NotificationMailer.php | 2 +- .../NotificationServiceProvider.php | 2 +- .../Core/Notification/NotificationSyncer.php | 2 +- framework/core/src/Core/Post.php | 6 +-- framework/core/src/Core/Post/CommentPost.php | 2 +- framework/core/src/Core/Post/Floodgate.php | 2 +- .../Core/Repository/DiscussionRepository.php | 2 +- .../src/Core/Repository/GroupRepository.php | 2 +- .../Repository/NotificationRepository.php | 2 +- .../src/Core/Repository/PostRepository.php | 10 ++--- .../core/src/Core/Search/AbstractSearch.php | 2 +- .../Search/Discussion/Gambit/AuthorGambit.php | 6 +-- .../core/src/Core/Search/SearchCriteria.php | 2 +- .../src/Core/Search/SearchServiceProvider.php | 8 ++-- .../src/Core/Support/DispatchEventsTrait.php | 2 +- .../src/Database/ScopeVisibilityTrait.php | 2 +- .../core/src/Event/AvatarWillBeDeleted.php | 2 +- .../core/src/Event/AvatarWillBeSaved.php | 2 +- .../core/src/Event/CheckUserPassword.php | 2 +- .../src/Event/ConfigureUserPreferences.php | 2 +- .../core/src/Event/ConfigureUserSearch.php | 4 +- .../core/src/Event/DiscussionWasDeleted.php | 2 +- .../core/src/Event/DiscussionWasHidden.php | 2 +- .../core/src/Event/DiscussionWasRenamed.php | 2 +- .../core/src/Event/DiscussionWasRestored.php | 2 +- .../core/src/Event/DiscussionWasStarted.php | 2 +- .../src/Event/DiscussionWillBeDeleted.php | 2 +- .../core/src/Event/DiscussionWillBeSaved.php | 2 +- framework/core/src/Event/GetPermission.php | 2 +- framework/core/src/Event/GroupWasCreated.php | 2 +- framework/core/src/Event/GroupWasDeleted.php | 2 +- framework/core/src/Event/GroupWasRenamed.php | 2 +- .../core/src/Event/GroupWillBeDeleted.php | 2 +- framework/core/src/Event/GroupWillBeSaved.php | 2 +- .../core/src/Event/NotificationWillBeSent.php | 2 +- framework/core/src/Event/PostWasDeleted.php | 2 +- framework/core/src/Event/PostWasHidden.php | 2 +- framework/core/src/Event/PostWasPosted.php | 2 +- framework/core/src/Event/PostWasRestored.php | 2 +- framework/core/src/Event/PostWasRevised.php | 2 +- .../core/src/Event/PostWillBeDeleted.php | 2 +- framework/core/src/Event/PostWillBeSaved.php | 2 +- .../core/src/Event/PrepareApiAttributes.php | 2 +- framework/core/src/Event/PrepareApiData.php | 2 +- .../core/src/Event/PrepareUserGroups.php | 2 +- .../Event/ScopeHiddenDiscussionVisibility.php | 2 +- .../core/src/Event/ScopeModelVisibility.php | 2 +- .../core/src/Event/ScopePostVisibility.php | 2 +- .../ScopePrivateDiscussionVisibility.php | 2 +- .../src/Event/ScopePrivatePostVisibility.php | 2 +- .../core/src/Event/UserEmailWasChanged.php | 37 ---------------- .../core/src/Event/UserPasswordWasChanged.php | 37 ---------------- .../Forum/AuthenticationResponseFactory.php | 4 +- .../Controller/AuthorizedWebAppController.php | 2 +- .../Controller/ConfirmEmailController.php | 2 +- .../Forum/Controller/DiscussionController.php | 2 +- .../src/Forum/Controller/IndexController.php | 2 +- .../src/Forum/Controller/LogInController.php | 10 ++--- .../src/Forum/Controller/LogOutController.php | 4 +- .../Controller/ResetPasswordController.php | 6 +-- .../Controller/SavePasswordController.php | 6 +-- framework/core/src/Http/AbstractServer.php | 6 +-- framework/core/src/Http/AccessToken.php | 4 +- .../Middleware/AuthenticateWithHeader.php | 2 +- .../Middleware/AuthenticateWithSession.php | 4 +- .../src/Install/Console/InstallCommand.php | 2 +- .../{Core/Access => User}/AbstractPolicy.php | 2 +- .../core/src/{Core => User}/AuthToken.php | 6 +-- .../Validator => User}/AvatarValidator.php | 4 +- .../EmailConfirmationMailer.php | 21 ++++----- .../core/src/{Core => User}/EmailToken.php | 4 +- .../Event/Activated.php} | 6 +-- .../core/src/User/Event/AvatarChanged.php | 37 ++++++++++++++++ .../Event/BioChanged.php} | 6 +-- .../Event/Deleted.php} | 6 +-- .../Event/Deleting.php} | 6 +-- .../Event/EmailChangeRequested.php} | 6 +-- .../Event/EmailChanged.php} | 6 +-- .../Event/GroupsChanged.php} | 6 +-- .../Event/LoggedIn.php} | 6 +-- .../Event/LoggedOut.php} | 6 +-- .../Event/PasswordChanged.php} | 6 +-- .../Event/Registered.php} | 6 +-- framework/core/src/User/Event/Renamed.php | 37 ++++++++++++++++ .../Event/Saving.php} | 6 +-- .../InvalidConfirmationTokenException.php | 2 +- .../Exception/PermissionDeniedException.php | 2 +- .../core/src/{Core/Access => User}/Gate.php | 2 +- framework/core/src/{Core => User}/Guest.php | 4 +- .../core/src/{Core => User}/PasswordToken.php | 2 +- .../Search}/Gambit/EmailGambit.php | 10 ++--- .../Search}/Gambit/FulltextGambit.php | 6 +-- .../Search}/Gambit/GroupGambit.php | 4 +- .../User => User/Search}/UserSearch.php | 2 +- .../User => User/Search}/UserSearcher.php | 7 +-- framework/core/src/{Core => User}/User.php | 43 ++++++++++--------- .../Listener => User}/UserMetadataUpdater.php | 4 +- .../src/{Core/Access => User}/UserPolicy.php | 4 +- .../Repository => User}/UserRepository.php | 3 +- .../Validator => User}/UserValidator.php | 4 +- ...dConfirmationTokenExceptionHandlerTest.php | 2 +- .../PermissionDeniedExceptionHandlerTest.php | 2 +- 163 files changed, 405 insertions(+), 394 deletions(-) delete mode 100644 framework/core/src/Event/UserEmailWasChanged.php delete mode 100644 framework/core/src/Event/UserPasswordWasChanged.php rename framework/core/src/{Core/Access => User}/AbstractPolicy.php (98%) rename framework/core/src/{Core => User}/AuthToken.php (92%) rename framework/core/src/{Core/Validator => User}/AvatarValidator.php (86%) rename framework/core/src/{Core/Listener => User}/EmailConfirmationMailer.php (82%) rename framework/core/src/{Core => User}/EmailToken.php (95%) rename framework/core/src/{Event/UserWasDeleted.php => User/Event/Activated.php} (88%) create mode 100644 framework/core/src/User/Event/AvatarChanged.php rename framework/core/src/{Event/UserWasActivated.php => User/Event/BioChanged.php} (88%) rename framework/core/src/{Event/UserWasRenamed.php => User/Event/Deleted.php} (88%) rename framework/core/src/{Event/UserWillBeDeleted.php => User/Event/Deleting.php} (92%) rename framework/core/src/{Event/UserEmailChangeWasRequested.php => User/Event/EmailChangeRequested.php} (89%) rename framework/core/src/{Event/UserBioWasChanged.php => User/Event/EmailChanged.php} (88%) rename framework/core/src/{Event/UserGroupsWereChanged.php => User/Event/GroupsChanged.php} (91%) rename framework/core/src/{Event/UserLoggedIn.php => User/Event/LoggedIn.php} (86%) rename framework/core/src/{Event/UserLoggedOut.php => User/Event/LoggedOut.php} (83%) rename framework/core/src/{Event/UserAvatarWasChanged.php => User/Event/PasswordChanged.php} (88%) rename framework/core/src/{Event/UserWasRegistered.php => User/Event/Registered.php} (88%) create mode 100644 framework/core/src/User/Event/Renamed.php rename framework/core/src/{Event/UserWillBeSaved.php => User/Event/Saving.php} (93%) rename framework/core/src/{Core => User}/Exception/InvalidConfirmationTokenException.php (90%) rename framework/core/src/{Core => User}/Exception/PermissionDeniedException.php (93%) rename framework/core/src/{Core/Access => User}/Gate.php (99%) rename framework/core/src/{Core => User}/Guest.php (94%) rename framework/core/src/{Core => User}/PasswordToken.php (98%) rename framework/core/src/{Core/Search/User => User/Search}/Gambit/EmailGambit.php (85%) rename framework/core/src/{Core/Search/User => User/Search}/Gambit/FulltextGambit.php (87%) rename framework/core/src/{Core/Search/User => User/Search}/Gambit/GroupGambit.php (95%) rename framework/core/src/{Core/Search/User => User/Search}/UserSearch.php (89%) rename framework/core/src/{Core/Search/User => User/Search}/UserSearcher.php (93%) rename framework/core/src/{Core => User}/User.php (94%) rename framework/core/src/{Core/Listener => User}/UserMetadataUpdater.php (97%) rename framework/core/src/{Core/Access => User}/UserPolicy.php (94%) rename framework/core/src/{Core/Repository => User}/UserRepository.php (98%) rename framework/core/src/{Core/Validator => User}/UserValidator.php (95%) 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/ForgotPasswordController.php b/framework/core/src/Api/Controller/ForgotPasswordController.php index 72c7ee759..5516c6d47 100644 --- a/framework/core/src/Api/Controller/ForgotPasswordController.php +++ b/framework/core/src/Api/Controller/ForgotPasswordController.php @@ -12,7 +12,7 @@ namespace Flarum\Api\Controller; use Flarum\Core\Command\RequestPasswordReset; -use Flarum\Core\Repository\UserRepository; +use Flarum\User\UserRepository; use Flarum\Http\Controller\ControllerInterface; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; @@ -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/ListNotificationsController.php b/framework/core/src/Api/Controller/ListNotificationsController.php index dd7303efa..c1681d645 100644 --- a/framework/core/src/Api/Controller/ListNotificationsController.php +++ b/framework/core/src/Api/Controller/ListNotificationsController.php @@ -12,7 +12,7 @@ namespace Flarum\Api\Controller; use Flarum\Core\Discussion; -use Flarum\Core\Exception\PermissionDeniedException; +use Flarum\User\Exception\PermissionDeniedException; use Flarum\Core\Repository\NotificationRepository; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; diff --git a/framework/core/src/Api/Controller/ListUsersController.php b/framework/core/src/Api/Controller/ListUsersController.php index eb42a97db..7d1f6526f 100644 --- a/framework/core/src/Api/Controller/ListUsersController.php +++ b/framework/core/src/Api/Controller/ListUsersController.php @@ -12,9 +12,9 @@ namespace Flarum\Api\Controller; use Flarum\Api\UrlGenerator; -use Flarum\Core\Exception\PermissionDeniedException; +use Flarum\User\Exception\PermissionDeniedException; use Flarum\Core\Search\SearchCriteria; -use Flarum\Core\Search\User\UserSearcher; +use Flarum\Core\User\Search\UserSearcher; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; diff --git a/framework/core/src/Api/Controller/SendConfirmationEmailController.php b/framework/core/src/Api/Controller/SendConfirmationEmailController.php index 3f870f160..02c22b020 100644 --- a/framework/core/src/Api/Controller/SendConfirmationEmailController.php +++ b/framework/core/src/Api/Controller/SendConfirmationEmailController.php @@ -12,8 +12,8 @@ namespace Flarum\Api\Controller; use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\EmailToken; -use Flarum\Core\Exception\PermissionDeniedException; +use Flarum\User\EmailToken; +use Flarum\User\Exception\PermissionDeniedException; use Flarum\Forum\UrlGenerator; use Flarum\Http\Controller\ControllerInterface; use Flarum\Settings\SettingsRepositoryInterface; diff --git a/framework/core/src/Api/Controller/ShowDiscussionController.php b/framework/core/src/Api/Controller/ShowDiscussionController.php index 58417fae4..d3417ff8c 100644 --- a/framework/core/src/Api/Controller/ShowDiscussionController.php +++ b/framework/core/src/Api/Controller/ShowDiscussionController.php @@ -14,7 +14,7 @@ namespace Flarum\Api\Controller; use Flarum\Core\Discussion; use Flarum\Core\Repository\DiscussionRepository; use Flarum\Core\Repository\PostRepository; -use Flarum\Core\User; +use Flarum\User\User; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; diff --git a/framework/core/src/Api/Controller/ShowUserController.php b/framework/core/src/Api/Controller/ShowUserController.php index 2879a3c8b..f61d3a1b6 100644 --- a/framework/core/src/Api/Controller/ShowUserController.php +++ b/framework/core/src/Api/Controller/ShowUserController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Repository\UserRepository; +use Flarum\User\UserRepository; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; @@ -28,12 +28,12 @@ class ShowUserController extends AbstractShowController 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..376e48747 100644 --- a/framework/core/src/Api/Controller/TokenController.php +++ b/framework/core/src/Api/Controller/TokenController.php @@ -11,8 +11,8 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\Repository\UserRepository; +use Flarum\User\Exception\PermissionDeniedException; +use Flarum\User\UserRepository; use Flarum\Http\AccessToken; use Flarum\Http\Controller\ControllerInterface; use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher; @@ -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/UpdateUserController.php b/framework/core/src/Api/Controller/UpdateUserController.php index 78c009012..818e4d941 100644 --- a/framework/core/src/Api/Controller/UpdateUserController.php +++ b/framework/core/src/Api/Controller/UpdateUserController.php @@ -12,7 +12,7 @@ namespace Flarum\Api\Controller; use Flarum\Core\Command\EditUser; -use Flarum\Core\Exception\PermissionDeniedException; +use Flarum\User\Exception\PermissionDeniedException; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; diff --git a/framework/core/src/Api/ExceptionHandler/InvalidConfirmationTokenExceptionHandler.php b/framework/core/src/Api/ExceptionHandler/InvalidConfirmationTokenExceptionHandler.php index 7c2465dce..541b620f7 100644 --- a/framework/core/src/Api/ExceptionHandler/InvalidConfirmationTokenExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/InvalidConfirmationTokenExceptionHandler.php @@ -12,7 +12,7 @@ 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/ExceptionHandler/PermissionDeniedExceptionHandler.php b/framework/core/src/Api/ExceptionHandler/PermissionDeniedExceptionHandler.php index 059c9369d..a4b4f9d53 100644 --- a/framework/core/src/Api/ExceptionHandler/PermissionDeniedExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/PermissionDeniedExceptionHandler.php @@ -12,7 +12,7 @@ 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/Serializer/AbstractSerializer.php b/framework/core/src/Api/Serializer/AbstractSerializer.php index 3f7b245e2..a11c9e28a 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\Event\GetApiRelationship; use Flarum\Event\PrepareApiAttributes; +use Flarum\User\User; use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Events\Dispatcher; use InvalidArgumentException; diff --git a/framework/core/src/Api/Serializer/BasicUserSerializer.php b/framework/core/src/Api/Serializer/BasicUserSerializer.php index 1d854c330..91348e471 100644 --- a/framework/core/src/Api/Serializer/BasicUserSerializer.php +++ b/framework/core/src/Api/Serializer/BasicUserSerializer.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Serializer; -use Flarum\Core\User; +use Flarum\User\User; use InvalidArgumentException; class BasicUserSerializer extends AbstractSerializer diff --git a/framework/core/src/Api/Serializer/DiscussionSerializer.php b/framework/core/src/Api/Serializer/DiscussionSerializer.php index e26f8929b..96704df22 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\User\Gate; use Flarum\Core\Discussion; 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/PostSerializer.php b/framework/core/src/Api/Serializer/PostSerializer.php index bb584dd3e..e385b3533 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\User\Gate; use Flarum\Core\Post\CommentPost; 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) { diff --git a/framework/core/src/Api/Serializer/UserSerializer.php b/framework/core/src/Api/Serializer/UserSerializer.php index 7bf6f62b2..b39801843 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 BasicUserSerializer { /** - * @var Gate + * @var \Flarum\User\Gate */ protected $gate; diff --git a/framework/core/src/Core/Access/AssertPermissionTrait.php b/framework/core/src/Core/Access/AssertPermissionTrait.php index cb2d9aff3..647ca9fac 100644 --- a/framework/core/src/Core/Access/AssertPermissionTrait.php +++ b/framework/core/src/Core/Access/AssertPermissionTrait.php @@ -11,8 +11,8 @@ namespace Flarum\Core\Access; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\User; +use Flarum\User\Exception\PermissionDeniedException; +use Flarum\User\User; trait AssertPermissionTrait { @@ -40,7 +40,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/Access/DiscussionPolicy.php b/framework/core/src/Core/Access/DiscussionPolicy.php index 3abefa824..50f00a387 100644 --- a/framework/core/src/Core/Access/DiscussionPolicy.php +++ b/framework/core/src/Core/Access/DiscussionPolicy.php @@ -13,10 +13,12 @@ namespace Flarum\Core\Access; 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; diff --git a/framework/core/src/Core/Access/GroupPolicy.php b/framework/core/src/Core/Access/GroupPolicy.php index 097077335..ff9861a07 100644 --- a/framework/core/src/Core/Access/GroupPolicy.php +++ b/framework/core/src/Core/Access/GroupPolicy.php @@ -12,7 +12,8 @@ namespace Flarum\Core\Access; 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/Access/PostPolicy.php b/framework/core/src/Core/Access/PostPolicy.php index afc0addb5..9e6f5829b 100644 --- a/framework/core/src/Core/Access/PostPolicy.php +++ b/framework/core/src/Core/Access/PostPolicy.php @@ -13,10 +13,11 @@ namespace Flarum\Core\Access; 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 diff --git a/framework/core/src/Core/Command/ConfirmEmailHandler.php b/framework/core/src/Core/Command/ConfirmEmailHandler.php index 5ee4d5190..f8415792d 100644 --- a/framework/core/src/Core/Command/ConfirmEmailHandler.php +++ b/framework/core/src/Core/Command/ConfirmEmailHandler.php @@ -11,8 +11,8 @@ namespace Flarum\Core\Command; -use Flarum\Core\EmailToken; -use Flarum\Core\Repository\UserRepository; +use Flarum\User\EmailToken; +use Flarum\User\UserRepository; use Flarum\Core\Support\DispatchEventsTrait; use Illuminate\Contracts\Events\Dispatcher; @@ -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/CreateGroup.php b/framework/core/src/Core/Command/CreateGroup.php index 9ed912ce7..e67eefea6 100644 --- a/framework/core/src/Core/Command/CreateGroup.php +++ b/framework/core/src/Core/Command/CreateGroup.php @@ -11,7 +11,7 @@ namespace Flarum\Core\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/Core/Command/CreateGroupHandler.php index fce5fd598..54d8c3d8c 100644 --- a/framework/core/src/Core/Command/CreateGroupHandler.php +++ b/framework/core/src/Core/Command/CreateGroupHandler.php @@ -12,7 +12,7 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Exception\PermissionDeniedException; +use Flarum\User\Exception\PermissionDeniedException; use Flarum\Core\Group; use Flarum\Core\Support\DispatchEventsTrait; use Flarum\Core\Validator\GroupValidator; @@ -42,7 +42,7 @@ class CreateGroupHandler /** * @param CreateGroup $command * @return Group - * @throws PermissionDeniedException + * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(CreateGroup $command) { diff --git a/framework/core/src/Core/Command/DeleteAvatar.php b/framework/core/src/Core/Command/DeleteAvatar.php index 9503d00e5..a8f757c14 100644 --- a/framework/core/src/Core/Command/DeleteAvatar.php +++ b/framework/core/src/Core/Command/DeleteAvatar.php @@ -11,7 +11,7 @@ namespace Flarum\Core\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/Core/Command/DeleteAvatarHandler.php index 8efd972c7..aabbe4ddc 100644 --- a/framework/core/src/Core/Command/DeleteAvatarHandler.php +++ b/framework/core/src/Core/Command/DeleteAvatarHandler.php @@ -12,8 +12,8 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\Repository\UserRepository; +use Flarum\User\Exception\PermissionDeniedException; +use Flarum\User\UserRepository; use Flarum\Core\Support\DispatchEventsTrait; use Flarum\Event\AvatarWillBeDeleted; use Illuminate\Contracts\Events\Dispatcher; @@ -48,8 +48,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) { diff --git a/framework/core/src/Core/Command/DeleteDiscussion.php b/framework/core/src/Core/Command/DeleteDiscussion.php index 550ae5e17..3c4d1219b 100644 --- a/framework/core/src/Core/Command/DeleteDiscussion.php +++ b/framework/core/src/Core/Command/DeleteDiscussion.php @@ -11,7 +11,7 @@ namespace Flarum\Core\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/Core/Command/DeleteDiscussionHandler.php index 5f383f60d..a02e4609b 100644 --- a/framework/core/src/Core/Command/DeleteDiscussionHandler.php +++ b/framework/core/src/Core/Command/DeleteDiscussionHandler.php @@ -12,7 +12,7 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Exception\PermissionDeniedException; +use Flarum\User\Exception\PermissionDeniedException; use Flarum\Core\Repository\DiscussionRepository; use Flarum\Core\Support\DispatchEventsTrait; use Flarum\Event\DiscussionWillBeDeleted; diff --git a/framework/core/src/Core/Command/DeleteGroup.php b/framework/core/src/Core/Command/DeleteGroup.php index 2f9c6a574..b57bc7c33 100644 --- a/framework/core/src/Core/Command/DeleteGroup.php +++ b/framework/core/src/Core/Command/DeleteGroup.php @@ -11,7 +11,7 @@ namespace Flarum\Core\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/Core/Command/DeleteGroupHandler.php index 7592eb97b..ed849a5be 100644 --- a/framework/core/src/Core/Command/DeleteGroupHandler.php +++ b/framework/core/src/Core/Command/DeleteGroupHandler.php @@ -12,7 +12,7 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Exception\PermissionDeniedException; +use Flarum\User\Exception\PermissionDeniedException; use Flarum\Core\Repository\GroupRepository; use Flarum\Core\Support\DispatchEventsTrait; use Flarum\Event\GroupWillBeDeleted; diff --git a/framework/core/src/Core/Command/DeletePost.php b/framework/core/src/Core/Command/DeletePost.php index 3e363e245..e2c2e897b 100644 --- a/framework/core/src/Core/Command/DeletePost.php +++ b/framework/core/src/Core/Command/DeletePost.php @@ -11,7 +11,7 @@ namespace Flarum\Core\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/Core/Command/DeletePostHandler.php index a5010cf6d..e7697e622 100644 --- a/framework/core/src/Core/Command/DeletePostHandler.php +++ b/framework/core/src/Core/Command/DeletePostHandler.php @@ -12,7 +12,7 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Exception\PermissionDeniedException; +use Flarum\User\Exception\PermissionDeniedException; use Flarum\Core\Repository\PostRepository; use Flarum\Core\Support\DispatchEventsTrait; use Flarum\Event\PostWillBeDeleted; @@ -41,7 +41,7 @@ class DeletePostHandler /** * @param DeletePost $command * @return \Flarum\Core\Post - * @throws PermissionDeniedException + * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(DeletePost $command) { diff --git a/framework/core/src/Core/Command/DeleteUser.php b/framework/core/src/Core/Command/DeleteUser.php index 16cd44cf9..2aa0f3edb 100644 --- a/framework/core/src/Core/Command/DeleteUser.php +++ b/framework/core/src/Core/Command/DeleteUser.php @@ -11,7 +11,7 @@ namespace Flarum\Core\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/Core/Command/DeleteUserHandler.php index a4058465d..e4503a53d 100644 --- a/framework/core/src/Core/Command/DeleteUserHandler.php +++ b/framework/core/src/Core/Command/DeleteUserHandler.php @@ -12,10 +12,10 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\Repository\UserRepository; +use Flarum\User\Exception\PermissionDeniedException; +use Flarum\User\UserRepository; use Flarum\Core\Support\DispatchEventsTrait; -use Flarum\Event\UserWillBeDeleted; +use Flarum\User\Event\Deleting; 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/EditDiscussion.php b/framework/core/src/Core/Command/EditDiscussion.php index 23cb5e707..4ae77a276 100644 --- a/framework/core/src/Core/Command/EditDiscussion.php +++ b/framework/core/src/Core/Command/EditDiscussion.php @@ -11,7 +11,7 @@ namespace Flarum\Core\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/Core/Command/EditDiscussionHandler.php index 151f66d4f..b8866bf1f 100644 --- a/framework/core/src/Core/Command/EditDiscussionHandler.php +++ b/framework/core/src/Core/Command/EditDiscussionHandler.php @@ -12,7 +12,7 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Exception\PermissionDeniedException; +use Flarum\User\Exception\PermissionDeniedException; use Flarum\Core\Repository\DiscussionRepository; use Flarum\Core\Support\DispatchEventsTrait; use Flarum\Core\Validator\DiscussionValidator; @@ -49,7 +49,7 @@ class EditDiscussionHandler /** * @param EditDiscussion $command * @return \Flarum\Core\Discussion - * @throws PermissionDeniedException + * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(EditDiscussion $command) { diff --git a/framework/core/src/Core/Command/EditGroup.php b/framework/core/src/Core/Command/EditGroup.php index 233843a8c..f05dc26cd 100644 --- a/framework/core/src/Core/Command/EditGroup.php +++ b/framework/core/src/Core/Command/EditGroup.php @@ -11,7 +11,7 @@ namespace Flarum\Core\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/Core/Command/EditGroupHandler.php index 0f2ad59af..6d1d8ad4f 100644 --- a/framework/core/src/Core/Command/EditGroupHandler.php +++ b/framework/core/src/Core/Command/EditGroupHandler.php @@ -12,7 +12,7 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Exception\PermissionDeniedException; +use Flarum\User\Exception\PermissionDeniedException; use Flarum\Core\Group; use Flarum\Core\Repository\GroupRepository; use Flarum\Core\Support\DispatchEventsTrait; diff --git a/framework/core/src/Core/Command/EditPost.php b/framework/core/src/Core/Command/EditPost.php index 6a576a130..25390c890 100644 --- a/framework/core/src/Core/Command/EditPost.php +++ b/framework/core/src/Core/Command/EditPost.php @@ -11,7 +11,7 @@ namespace Flarum\Core\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/Core/Command/EditPostHandler.php index f49e4443a..32e607b5b 100644 --- a/framework/core/src/Core/Command/EditPostHandler.php +++ b/framework/core/src/Core/Command/EditPostHandler.php @@ -49,7 +49,7 @@ class EditPostHandler /** * @param EditPost $command * @return \Flarum\Core\Post - * @throws \Flarum\Core\Exception\PermissionDeniedException + * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(EditPost $command) { diff --git a/framework/core/src/Core/Command/EditUser.php b/framework/core/src/Core/Command/EditUser.php index 200fad5cb..fa758483f 100644 --- a/framework/core/src/Core/Command/EditUser.php +++ b/framework/core/src/Core/Command/EditUser.php @@ -11,7 +11,7 @@ namespace Flarum\Core\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/Core/Command/EditUserHandler.php index d42acdfc9..4ba4a4bff 100644 --- a/framework/core/src/Core/Command/EditUserHandler.php +++ b/framework/core/src/Core/Command/EditUserHandler.php @@ -12,12 +12,12 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Repository\UserRepository; +use Flarum\User\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\User\User; +use Flarum\User\UserValidator; +use Flarum\User\Event\GroupsChanged; +use Flarum\User\Event\Saving; use Illuminate\Contracts\Events\Dispatcher; class EditUserHandler @@ -26,7 +26,7 @@ class EditUserHandler use AssertPermissionTrait; /** - * @var UserRepository + * @var \Flarum\User\UserRepository */ protected $users; @@ -37,7 +37,7 @@ class EditUserHandler /** * @param Dispatcher $events - * @param UserRepository $users + * @param \Flarum\User\UserRepository $users * @param UserValidator $validator */ public function __construct(Dispatcher $events, UserRepository $users, UserValidator $validator) @@ -50,7 +50,7 @@ class EditUserHandler /** * @param EditUser $command * @return User - * @throws \Flarum\Core\Exception\PermissionDeniedException + * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(EditUser $command) { @@ -127,7 +127,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) { @@ -136,7 +136,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/PostReply.php b/framework/core/src/Core/Command/PostReply.php index a9518f00e..4877b3045 100644 --- a/framework/core/src/Core/Command/PostReply.php +++ b/framework/core/src/Core/Command/PostReply.php @@ -11,7 +11,7 @@ namespace Flarum\Core\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/Core/Command/PostReplyHandler.php index fb84877a9..06837011b 100644 --- a/framework/core/src/Core/Command/PostReplyHandler.php +++ b/framework/core/src/Core/Command/PostReplyHandler.php @@ -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) { diff --git a/framework/core/src/Core/Command/ReadAllNotifications.php b/framework/core/src/Core/Command/ReadAllNotifications.php index bbf6b2252..d231153ce 100644 --- a/framework/core/src/Core/Command/ReadAllNotifications.php +++ b/framework/core/src/Core/Command/ReadAllNotifications.php @@ -11,7 +11,7 @@ namespace Flarum\Core\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/Core/Command/ReadAllNotificationsHandler.php index 56f04f217..023568f9b 100644 --- a/framework/core/src/Core/Command/ReadAllNotificationsHandler.php +++ b/framework/core/src/Core/Command/ReadAllNotificationsHandler.php @@ -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/ReadDiscussion.php b/framework/core/src/Core/Command/ReadDiscussion.php index 00bb1a1db..4a0c8ebd4 100644 --- a/framework/core/src/Core/Command/ReadDiscussion.php +++ b/framework/core/src/Core/Command/ReadDiscussion.php @@ -11,7 +11,7 @@ namespace Flarum\Core\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/Core/Command/ReadDiscussionHandler.php index ed7a2d21b..9630100a1 100644 --- a/framework/core/src/Core/Command/ReadDiscussionHandler.php +++ b/framework/core/src/Core/Command/ReadDiscussionHandler.php @@ -40,7 +40,7 @@ class ReadDiscussionHandler /** * @param ReadDiscussion $command * @return \Flarum\Core\DiscussionState - * @throws \Flarum\Core\Exception\PermissionDeniedException + * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(ReadDiscussion $command) { diff --git a/framework/core/src/Core/Command/ReadNotification.php b/framework/core/src/Core/Command/ReadNotification.php index bbeddee96..f525299b7 100644 --- a/framework/core/src/Core/Command/ReadNotification.php +++ b/framework/core/src/Core/Command/ReadNotification.php @@ -11,7 +11,7 @@ namespace Flarum\Core\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/Core/Command/ReadNotificationHandler.php index 7adbf6039..b7da93198 100644 --- a/framework/core/src/Core/Command/ReadNotificationHandler.php +++ b/framework/core/src/Core/Command/ReadNotificationHandler.php @@ -21,7 +21,7 @@ class ReadNotificationHandler /** * @param ReadNotification $command * @return \Flarum\Core\Notification - * @throws \Flarum\Core\Exception\PermissionDeniedException + * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(ReadNotification $command) { diff --git a/framework/core/src/Core/Command/RegisterUser.php b/framework/core/src/Core/Command/RegisterUser.php index 57230324f..1d9a32b70 100644 --- a/framework/core/src/Core/Command/RegisterUser.php +++ b/framework/core/src/Core/Command/RegisterUser.php @@ -11,7 +11,7 @@ namespace Flarum\Core\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/Core/Command/RegisterUserHandler.php index c7daf38fa..2e3a1b158 100644 --- a/framework/core/src/Core/Command/RegisterUserHandler.php +++ b/framework/core/src/Core/Command/RegisterUserHandler.php @@ -13,12 +13,12 @@ namespace Flarum\Core\Command; use Exception; use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\AuthToken; -use Flarum\Core\Exception\PermissionDeniedException; +use Flarum\User\AuthToken; +use Flarum\User\Exception\PermissionDeniedException; use Flarum\Core\Support\DispatchEventsTrait; -use Flarum\Core\User; -use Flarum\Core\Validator\UserValidator; -use Flarum\Event\UserWillBeSaved; +use Flarum\User\User; +use Flarum\User\UserValidator; +use Flarum\User\Event\Saving; use Flarum\Foundation\Application; use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Events\Dispatcher; @@ -83,7 +83,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 */ @@ -131,7 +131,7 @@ class RegisterUserHandler } $this->events->fire( - new UserWillBeSaved($user, $actor, $data) + new Saving($user, $actor, $data) ); $this->validator->assertValid(array_merge($user->getAttributes(), compact('password'))); diff --git a/framework/core/src/Core/Command/RequestPasswordResetHandler.php b/framework/core/src/Core/Command/RequestPasswordResetHandler.php index fb484fbda..4647bc004 100644 --- a/framework/core/src/Core/Command/RequestPasswordResetHandler.php +++ b/framework/core/src/Core/Command/RequestPasswordResetHandler.php @@ -12,8 +12,8 @@ namespace Flarum\Core\Command; use Flarum\Core; -use Flarum\Core\PasswordToken; -use Flarum\Core\Repository\UserRepository; +use Flarum\User\PasswordToken; +use Flarum\User\UserRepository; use Flarum\Forum\UrlGenerator; use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Mail\Mailer; @@ -56,7 +56,7 @@ class RequestPasswordResetHandler protected $validatorFactory; /** - * @param UserRepository $users + * @param \Flarum\User\UserRepository $users * @param SettingsRepositoryInterface $settings * @param Mailer $mailer * @param UrlGenerator $url @@ -81,7 +81,7 @@ class RequestPasswordResetHandler /** * @param RequestPasswordReset $command - * @return \Flarum\Core\User + * @return \Flarum\User\User * @throws ModelNotFoundException */ public function handle(RequestPasswordReset $command) diff --git a/framework/core/src/Core/Command/StartDiscussion.php b/framework/core/src/Core/Command/StartDiscussion.php index 1840f9c0c..9bc0cab10 100644 --- a/framework/core/src/Core/Command/StartDiscussion.php +++ b/framework/core/src/Core/Command/StartDiscussion.php @@ -11,7 +11,7 @@ namespace Flarum\Core\Command; -use Flarum\Core\User; +use Flarum\User\User; class StartDiscussion { diff --git a/framework/core/src/Core/Command/UploadAvatar.php b/framework/core/src/Core/Command/UploadAvatar.php index 988ecc26d..ac34220e5 100644 --- a/framework/core/src/Core/Command/UploadAvatar.php +++ b/framework/core/src/Core/Command/UploadAvatar.php @@ -11,7 +11,7 @@ namespace Flarum\Core\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/Core/Command/UploadAvatarHandler.php index de451a074..61fa05601 100644 --- a/framework/core/src/Core/Command/UploadAvatarHandler.php +++ b/framework/core/src/Core/Command/UploadAvatarHandler.php @@ -13,9 +13,9 @@ namespace Flarum\Core\Command; use Exception; use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Repository\UserRepository; +use Flarum\User\UserRepository; use Flarum\Core\Support\DispatchEventsTrait; -use Flarum\Core\Validator\AvatarValidator; +use Flarum\User\AvatarValidator; use Flarum\Event\AvatarWillBeSaved; use Flarum\Foundation\Application; use Illuminate\Contracts\Events\Dispatcher; @@ -33,7 +33,7 @@ class UploadAvatarHandler use AssertPermissionTrait; /** - * @var UserRepository + * @var \Flarum\User\UserRepository */ protected $users; @@ -48,7 +48,7 @@ class UploadAvatarHandler protected $app; /** - * @var AvatarValidator + * @var \Flarum\User\AvatarValidator */ protected $validator; @@ -57,7 +57,7 @@ class UploadAvatarHandler * @param UserRepository $users * @param FilesystemInterface $uploadDir * @param Application $app - * @param AvatarValidator $validator + * @param \Flarum\User\AvatarValidator $validator */ public function __construct(Dispatcher $events, UserRepository $users, FilesystemInterface $uploadDir, Application $app, AvatarValidator $validator) { @@ -70,8 +70,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) { diff --git a/framework/core/src/Core/CoreServiceProvider.php b/framework/core/src/Core/CoreServiceProvider.php index 551cdcfda..d697aba1c 100644 --- a/framework/core/src/Core/CoreServiceProvider.php +++ b/framework/core/src/Core/CoreServiceProvider.php @@ -11,12 +11,13 @@ namespace Flarum\Core; -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 Flarum\User\Gate; +use Flarum\User\User; use Illuminate\Contracts\Container\Container; use RuntimeException; @@ -34,7 +35,7 @@ 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', 'Flarum\User\Gate'); $this->registerAvatarsFilesystem(); @@ -106,15 +107,15 @@ class CoreServiceProvider extends AbstractServiceProvider $events->subscribe('Flarum\Core\Listener\SelfDemotionGuard'); $events->subscribe('Flarum\Core\Listener\DiscussionMetadataUpdater'); - $events->subscribe('Flarum\Core\Listener\UserMetadataUpdater'); + $events->subscribe('Flarum\User\UserMetadataUpdater'); $events->subscribe('Flarum\Core\Listener\ExtensionValidator'); - $events->subscribe('Flarum\Core\Listener\EmailConfirmationMailer'); + $events->subscribe('Flarum\User\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('Flarum\User\UserPolicy'); $events->listen(ConfigureUserPreferences::class, [$this, 'configureUserPreferences']); } diff --git a/framework/core/src/Core/Discussion.php b/framework/core/src/Core/Discussion.php index 2d510ede5..39c97bf6d 100644 --- a/framework/core/src/Core/Discussion.php +++ b/framework/core/src/Core/Discussion.php @@ -22,6 +22,8 @@ use Flarum\Event\DiscussionWasRestored; use Flarum\Event\DiscussionWasStarted; use Flarum\Event\PostWasDeleted; use Flarum\Event\ScopePostVisibility; +use Flarum\User\Guest; +use Flarum\User\User; use Flarum\Util\Str; /** @@ -363,7 +365,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'); } /** @@ -383,7 +385,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 +395,7 @@ class Discussion extends AbstractModel */ public function readers() { - return $this->belongsToMany('Flarum\Core\User', 'users_discussions'); + return $this->belongsToMany('Flarum\User\User', 'users_discussions'); } /** diff --git a/framework/core/src/Core/DiscussionState.php b/framework/core/src/Core/DiscussionState.php index 2208a8ff4..e32e120b4 100644 --- a/framework/core/src/Core/DiscussionState.php +++ b/framework/core/src/Core/DiscussionState.php @@ -28,7 +28,7 @@ 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 { @@ -80,7 +80,7 @@ class DiscussionState extends AbstractModel */ public function user() { - return $this->belongsTo('Flarum\Core\User', 'user_id'); + return $this->belongsTo('Flarum\User\User', 'user_id'); } /** diff --git a/framework/core/src/Core/Group.php b/framework/core/src/Core/Group.php index db081ffe5..eb05daa5c 100755 --- a/framework/core/src/Core/Group.php +++ b/framework/core/src/Core/Group.php @@ -120,7 +120,7 @@ class Group extends AbstractModel */ public function users() { - return $this->belongsToMany('Flarum\Core\User', 'users_groups'); + return $this->belongsToMany('Flarum\User\User', 'users_groups'); } /** diff --git a/framework/core/src/Core/Notification.php b/framework/core/src/Core/Notification.php index 78b2dbf98..0d429998b 100644 --- a/framework/core/src/Core/Notification.php +++ b/framework/core/src/Core/Notification.php @@ -36,8 +36,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 @@ -113,7 +113,7 @@ class Notification extends AbstractModel */ public function user() { - return $this->belongsTo('Flarum\Core\User', 'user_id'); + return $this->belongsTo('Flarum\User\User', 'user_id'); } /** @@ -123,7 +123,7 @@ class Notification extends AbstractModel */ public function sender() { - return $this->belongsTo('Flarum\Core\User', 'sender_id'); + return $this->belongsTo('Flarum\User\User', 'sender_id'); } /** diff --git a/framework/core/src/Core/Notification/BlueprintInterface.php b/framework/core/src/Core/Notification/BlueprintInterface.php index 93f33f8c4..67bcc31ff 100644 --- a/framework/core/src/Core/Notification/BlueprintInterface.php +++ b/framework/core/src/Core/Notification/BlueprintInterface.php @@ -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/NotificationMailer.php b/framework/core/src/Core/Notification/NotificationMailer.php index 691e3e7d6..327f0252e 100644 --- a/framework/core/src/Core/Notification/NotificationMailer.php +++ b/framework/core/src/Core/Notification/NotificationMailer.php @@ -11,7 +11,7 @@ namespace Flarum\Core\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/Notification/NotificationServiceProvider.php b/framework/core/src/Core/Notification/NotificationServiceProvider.php index 54a9b0dd1..d8cf09474 100644 --- a/framework/core/src/Core/Notification/NotificationServiceProvider.php +++ b/framework/core/src/Core/Notification/NotificationServiceProvider.php @@ -12,9 +12,9 @@ namespace Flarum\Core\Notification; use Flarum\Core\Notification; -use Flarum\Core\User; use Flarum\Event\ConfigureNotificationTypes; use Flarum\Foundation\AbstractServiceProvider; +use Flarum\User\User; use ReflectionClass; class NotificationServiceProvider extends AbstractServiceProvider diff --git a/framework/core/src/Core/Notification/NotificationSyncer.php b/framework/core/src/Core/Notification/NotificationSyncer.php index 5b56ad9d5..aab276b5b 100644 --- a/framework/core/src/Core/Notification/NotificationSyncer.php +++ b/framework/core/src/Core/Notification/NotificationSyncer.php @@ -14,8 +14,8 @@ namespace Flarum\Core\Notification; use Carbon\Carbon; use Flarum\Core\Notification; use Flarum\Core\Repository\NotificationRepository; -use Flarum\Core\User; use Flarum\Event\NotificationWillBeSent; +use Flarum\User\User; /** * The Notification Syncer commits notification blueprints to the database, and diff --git a/framework/core/src/Core/Post.php b/framework/core/src/Core/Post.php index 6d4ad5620..f85563965 100755 --- a/framework/core/src/Core/Post.php +++ b/framework/core/src/Core/Post.php @@ -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/Post/CommentPost.php b/framework/core/src/Core/Post/CommentPost.php index 492088552..a8016cbb2 100755 --- a/framework/core/src/Core/Post/CommentPost.php +++ b/framework/core/src/Core/Post/CommentPost.php @@ -12,12 +12,12 @@ namespace Flarum\Core\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\User\User; /** * A standard comment in a discussion. diff --git a/framework/core/src/Core/Post/Floodgate.php b/framework/core/src/Core/Post/Floodgate.php index ff735cb5a..a62811fb1 100644 --- a/framework/core/src/Core/Post/Floodgate.php +++ b/framework/core/src/Core/Post/Floodgate.php @@ -14,7 +14,7 @@ namespace Flarum\Core\Post; use DateTime; use Flarum\Core\Exception\FloodingException; use Flarum\Core\Post; -use Flarum\Core\User; +use Flarum\User\User; class Floodgate { diff --git a/framework/core/src/Core/Repository/DiscussionRepository.php b/framework/core/src/Core/Repository/DiscussionRepository.php index f76af650e..add4f2b30 100644 --- a/framework/core/src/Core/Repository/DiscussionRepository.php +++ b/framework/core/src/Core/Repository/DiscussionRepository.php @@ -12,7 +12,7 @@ namespace Flarum\Core\Repository; use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Query\Expression; diff --git a/framework/core/src/Core/Repository/GroupRepository.php b/framework/core/src/Core/Repository/GroupRepository.php index 658c3739b..f6cfe3d82 100644 --- a/framework/core/src/Core/Repository/GroupRepository.php +++ b/framework/core/src/Core/Repository/GroupRepository.php @@ -12,7 +12,7 @@ namespace Flarum\Core\Repository; use Flarum\Core\Group; -use Flarum\Core\User; +use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; class GroupRepository diff --git a/framework/core/src/Core/Repository/NotificationRepository.php b/framework/core/src/Core/Repository/NotificationRepository.php index 3d1e5f6a0..1b9fe63fb 100644 --- a/framework/core/src/Core/Repository/NotificationRepository.php +++ b/framework/core/src/Core/Repository/NotificationRepository.php @@ -12,7 +12,7 @@ namespace Flarum\Core\Repository; use Flarum\Core\Notification; -use Flarum\Core\User; +use Flarum\User\User; class NotificationRepository { diff --git a/framework/core/src/Core/Repository/PostRepository.php b/framework/core/src/Core/Repository/PostRepository.php index 7ce6b0906..df296e358 100644 --- a/framework/core/src/Core/Repository/PostRepository.php +++ b/framework/core/src/Core/Repository/PostRepository.php @@ -13,8 +13,8 @@ namespace Flarum\Core\Repository; use Flarum\Core\Discussion; use Flarum\Core\Post; -use Flarum\Core\User; use Flarum\Event\ScopePostVisibility; +use Flarum\User\User; use Illuminate\Database\Eloquent\ModelNotFoundException; class PostRepository @@ -34,7 +34,7 @@ class PostRepository * user, or throw an exception. * * @param int $id - * @param \Flarum\Core\User $actor + * @param \Flarum\User\User $actor * @return \Flarum\Core\Post * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException @@ -55,7 +55,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 @@ -81,7 +81,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) @@ -122,7 +122,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/Core/Search/AbstractSearch.php b/framework/core/src/Core/Search/AbstractSearch.php index 581afdf95..c4f54250d 100644 --- a/framework/core/src/Core/Search/AbstractSearch.php +++ b/framework/core/src/Core/Search/AbstractSearch.php @@ -11,7 +11,7 @@ namespace Flarum\Core\Search; -use Flarum\Core\User; +use Flarum\User\User; use Illuminate\Database\Query\Builder; /** diff --git a/framework/core/src/Core/Search/Discussion/Gambit/AuthorGambit.php b/framework/core/src/Core/Search/Discussion/Gambit/AuthorGambit.php index 914fb6684..d1336efec 100644 --- a/framework/core/src/Core/Search/Discussion/Gambit/AuthorGambit.php +++ b/framework/core/src/Core/Search/Discussion/Gambit/AuthorGambit.php @@ -11,7 +11,7 @@ namespace Flarum\Core\Search\Discussion\Gambit; -use Flarum\Core\Repository\UserRepository; +use Flarum\User\UserRepository; use Flarum\Core\Search\AbstractRegexGambit; use Flarum\Core\Search\AbstractSearch; use Flarum\Core\Search\Discussion\DiscussionSearch; @@ -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/SearchCriteria.php b/framework/core/src/Core/Search/SearchCriteria.php index 2bacfb2c3..567155d8b 100644 --- a/framework/core/src/Core/Search/SearchCriteria.php +++ b/framework/core/src/Core/Search/SearchCriteria.php @@ -11,7 +11,7 @@ namespace Flarum\Core\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/SearchServiceProvider.php b/framework/core/src/Core/Search/SearchServiceProvider.php index 3f5a80065..82172abb4 100644 --- a/framework/core/src/Core/Search/SearchServiceProvider.php +++ b/framework/core/src/Core/Search/SearchServiceProvider.php @@ -37,14 +37,14 @@ class SearchServiceProvider extends AbstractServiceProvider public function registerUserGambits() { - $this->app->when('Flarum\Core\Search\User\UserSearcher') + $this->app->when('Flarum\Core\User\Search\UserSearcher') ->needs('Flarum\Core\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\Core\User\Search\Gambit\FulltextGambit'); + $gambits->add('Flarum\Core\User\Search\Gambit\EmailGambit'); + $gambits->add('Flarum\Core\User\Search\Gambit\GroupGambit'); $app->make('events')->fire( new ConfigureUserGambits($gambits) diff --git a/framework/core/src/Core/Support/DispatchEventsTrait.php b/framework/core/src/Core/Support/DispatchEventsTrait.php index 39266d1bc..c145a8c3d 100644 --- a/framework/core/src/Core/Support/DispatchEventsTrait.php +++ b/framework/core/src/Core/Support/DispatchEventsTrait.php @@ -11,7 +11,7 @@ namespace Flarum\Core\Support; -use Flarum\Core\User; +use Flarum\User\User; use Illuminate\Contracts\Events\Dispatcher; trait DispatchEventsTrait diff --git a/framework/core/src/Database/ScopeVisibilityTrait.php b/framework/core/src/Database/ScopeVisibilityTrait.php index 0cfe43fc3..276f6a39d 100644 --- a/framework/core/src/Database/ScopeVisibilityTrait.php +++ b/framework/core/src/Database/ScopeVisibilityTrait.php @@ -11,7 +11,7 @@ namespace Flarum\Database; -use Flarum\Core\User; +use Flarum\User\User; use Flarum\Event\ScopeModelVisibility; use Illuminate\Database\Eloquent\Builder; diff --git a/framework/core/src/Event/AvatarWillBeDeleted.php b/framework/core/src/Event/AvatarWillBeDeleted.php index 9828fa674..df862684a 100644 --- a/framework/core/src/Event/AvatarWillBeDeleted.php +++ b/framework/core/src/Event/AvatarWillBeDeleted.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Core\User; +use Flarum\User\User; class AvatarWillBeDeleted { diff --git a/framework/core/src/Event/AvatarWillBeSaved.php b/framework/core/src/Event/AvatarWillBeSaved.php index f4e52bb65..3737bb350 100644 --- a/framework/core/src/Event/AvatarWillBeSaved.php +++ b/framework/core/src/Event/AvatarWillBeSaved.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Core\User; +use Flarum\User\User; class AvatarWillBeSaved { diff --git a/framework/core/src/Event/CheckUserPassword.php b/framework/core/src/Event/CheckUserPassword.php index ee86252c6..fa9ef2277 100644 --- a/framework/core/src/Event/CheckUserPassword.php +++ b/framework/core/src/Event/CheckUserPassword.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Core\User; +use Flarum\User\User; class CheckUserPassword { 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/ConfigureUserSearch.php b/framework/core/src/Event/ConfigureUserSearch.php index fec2e6820..d32670705 100644 --- a/framework/core/src/Event/ConfigureUserSearch.php +++ b/framework/core/src/Event/ConfigureUserSearch.php @@ -12,12 +12,12 @@ namespace Flarum\Event; use Flarum\Core\Search\SearchCriteria; -use Flarum\Core\Search\User\UserSearch; +use Flarum\Core\User\Search\UserSearch; class ConfigureUserSearch { /** - * @var UserSearch + * @var \Flarum\Core\User\Search\UserSearch */ public $search; diff --git a/framework/core/src/Event/DiscussionWasDeleted.php b/framework/core/src/Event/DiscussionWasDeleted.php index 62dee388c..f57193918 100644 --- a/framework/core/src/Event/DiscussionWasDeleted.php +++ b/framework/core/src/Event/DiscussionWasDeleted.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\User\User; class DiscussionWasDeleted { diff --git a/framework/core/src/Event/DiscussionWasHidden.php b/framework/core/src/Event/DiscussionWasHidden.php index bcd6cc93b..b99b3e03b 100644 --- a/framework/core/src/Event/DiscussionWasHidden.php +++ b/framework/core/src/Event/DiscussionWasHidden.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\User\User; class DiscussionWasHidden { diff --git a/framework/core/src/Event/DiscussionWasRenamed.php b/framework/core/src/Event/DiscussionWasRenamed.php index c17656396..7d71a20ed 100644 --- a/framework/core/src/Event/DiscussionWasRenamed.php +++ b/framework/core/src/Event/DiscussionWasRenamed.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\User\User; class DiscussionWasRenamed { diff --git a/framework/core/src/Event/DiscussionWasRestored.php b/framework/core/src/Event/DiscussionWasRestored.php index b9ead6384..22135b6ee 100644 --- a/framework/core/src/Event/DiscussionWasRestored.php +++ b/framework/core/src/Event/DiscussionWasRestored.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\User\User; class DiscussionWasRestored { diff --git a/framework/core/src/Event/DiscussionWasStarted.php b/framework/core/src/Event/DiscussionWasStarted.php index 7a83e9f6f..b35ed7851 100644 --- a/framework/core/src/Event/DiscussionWasStarted.php +++ b/framework/core/src/Event/DiscussionWasStarted.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\User\User; class DiscussionWasStarted { diff --git a/framework/core/src/Event/DiscussionWillBeDeleted.php b/framework/core/src/Event/DiscussionWillBeDeleted.php index 6508d1591..d70e399fe 100644 --- a/framework/core/src/Event/DiscussionWillBeDeleted.php +++ b/framework/core/src/Event/DiscussionWillBeDeleted.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\User\User; class DiscussionWillBeDeleted { diff --git a/framework/core/src/Event/DiscussionWillBeSaved.php b/framework/core/src/Event/DiscussionWillBeSaved.php index 6a1d31f36..3d15ff4cc 100644 --- a/framework/core/src/Event/DiscussionWillBeSaved.php +++ b/framework/core/src/Event/DiscussionWillBeSaved.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\User\User; class DiscussionWillBeSaved { 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/GroupWasCreated.php b/framework/core/src/Event/GroupWasCreated.php index a4e5f7536..2e4962809 100644 --- a/framework/core/src/Event/GroupWasCreated.php +++ b/framework/core/src/Event/GroupWasCreated.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Group; -use Flarum\Core\User; +use Flarum\User\User; class GroupWasCreated { diff --git a/framework/core/src/Event/GroupWasDeleted.php b/framework/core/src/Event/GroupWasDeleted.php index 21600c175..1d2290b7b 100644 --- a/framework/core/src/Event/GroupWasDeleted.php +++ b/framework/core/src/Event/GroupWasDeleted.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Group; -use Flarum\Core\User; +use Flarum\User\User; class GroupWasDeleted { diff --git a/framework/core/src/Event/GroupWasRenamed.php b/framework/core/src/Event/GroupWasRenamed.php index 30034f2be..ded05ce98 100644 --- a/framework/core/src/Event/GroupWasRenamed.php +++ b/framework/core/src/Event/GroupWasRenamed.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Group; -use Flarum\Core\User; +use Flarum\User\User; class GroupWasRenamed { diff --git a/framework/core/src/Event/GroupWillBeDeleted.php b/framework/core/src/Event/GroupWillBeDeleted.php index 3b8955a83..ac0d5b406 100644 --- a/framework/core/src/Event/GroupWillBeDeleted.php +++ b/framework/core/src/Event/GroupWillBeDeleted.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Group; -use Flarum\Core\User; +use Flarum\User\User; class GroupWillBeDeleted { diff --git a/framework/core/src/Event/GroupWillBeSaved.php b/framework/core/src/Event/GroupWillBeSaved.php index 51df92592..feeaac887 100644 --- a/framework/core/src/Event/GroupWillBeSaved.php +++ b/framework/core/src/Event/GroupWillBeSaved.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Group; -use Flarum\Core\User; +use Flarum\User\User; class GroupWillBeSaved { diff --git a/framework/core/src/Event/NotificationWillBeSent.php b/framework/core/src/Event/NotificationWillBeSent.php index fc428ae40..12a90ea9d 100644 --- a/framework/core/src/Event/NotificationWillBeSent.php +++ b/framework/core/src/Event/NotificationWillBeSent.php @@ -31,7 +31,7 @@ class NotificationWillBeSent /** * @param BlueprintInterface $blueprint - * @param \Flarum\Core\User[] $users + * @param \Flarum\User\User[] $users */ public function __construct(BlueprintInterface $blueprint, array &$users) { diff --git a/framework/core/src/Event/PostWasDeleted.php b/framework/core/src/Event/PostWasDeleted.php index 994ef0915..c98fdb373 100644 --- a/framework/core/src/Event/PostWasDeleted.php +++ b/framework/core/src/Event/PostWasDeleted.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Post; -use Flarum\Core\User; +use Flarum\User\User; class PostWasDeleted { diff --git a/framework/core/src/Event/PostWasHidden.php b/framework/core/src/Event/PostWasHidden.php index 4c7841c90..e41a6a7b3 100644 --- a/framework/core/src/Event/PostWasHidden.php +++ b/framework/core/src/Event/PostWasHidden.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Post\CommentPost; -use Flarum\Core\User; +use Flarum\User\User; class PostWasHidden { diff --git a/framework/core/src/Event/PostWasPosted.php b/framework/core/src/Event/PostWasPosted.php index 5b944778a..e59bcc0dc 100644 --- a/framework/core/src/Event/PostWasPosted.php +++ b/framework/core/src/Event/PostWasPosted.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Post; -use Flarum\Core\User; +use Flarum\User\User; class PostWasPosted { diff --git a/framework/core/src/Event/PostWasRestored.php b/framework/core/src/Event/PostWasRestored.php index bfc9fc801..581a6b601 100644 --- a/framework/core/src/Event/PostWasRestored.php +++ b/framework/core/src/Event/PostWasRestored.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Post\CommentPost; -use Flarum\Core\User; +use Flarum\User\User; class PostWasRestored { diff --git a/framework/core/src/Event/PostWasRevised.php b/framework/core/src/Event/PostWasRevised.php index cbffc9322..ddfd2afa0 100644 --- a/framework/core/src/Event/PostWasRevised.php +++ b/framework/core/src/Event/PostWasRevised.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Post\CommentPost; -use Flarum\Core\User; +use Flarum\User\User; class PostWasRevised { diff --git a/framework/core/src/Event/PostWillBeDeleted.php b/framework/core/src/Event/PostWillBeDeleted.php index f2875a54f..d5b32cae6 100644 --- a/framework/core/src/Event/PostWillBeDeleted.php +++ b/framework/core/src/Event/PostWillBeDeleted.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Post; -use Flarum\Core\User; +use Flarum\User\User; class PostWillBeDeleted { diff --git a/framework/core/src/Event/PostWillBeSaved.php b/framework/core/src/Event/PostWillBeSaved.php index 0dfb282c7..fb1736ab0 100644 --- a/framework/core/src/Event/PostWillBeSaved.php +++ b/framework/core/src/Event/PostWillBeSaved.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Post; -use Flarum\Core\User; +use Flarum\User\User; class PostWillBeSaved { diff --git a/framework/core/src/Event/PrepareApiAttributes.php b/framework/core/src/Event/PrepareApiAttributes.php index 533bef507..c97ad794e 100644 --- a/framework/core/src/Event/PrepareApiAttributes.php +++ b/framework/core/src/Event/PrepareApiAttributes.php @@ -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/PrepareApiData.php b/framework/core/src/Event/PrepareApiData.php index c39f0894f..6d9b8f547 100644 --- a/framework/core/src/Event/PrepareApiData.php +++ b/framework/core/src/Event/PrepareApiData.php @@ -38,7 +38,7 @@ class PrepareApiData public $document; /** - * @var \Flarum\Core\User + * @var \Flarum\User\User */ public $actor; 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..16c488903 100644 --- a/framework/core/src/Event/ScopePostVisibility.php +++ b/framework/core/src/Event/ScopePostVisibility.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; /** 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..1339e5f27 100644 --- a/framework/core/src/Event/ScopePrivatePostVisibility.php +++ b/framework/core/src/Event/ScopePrivatePostVisibility.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Core\Discussion; -use Flarum\Core\User; +use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; /** 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 @@ -<?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\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 @@ -<?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\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/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 05a5baf96..7f1a4890c 100644 --- a/framework/core/src/Forum/Controller/AuthorizedWebAppController.php +++ b/framework/core/src/Forum/Controller/AuthorizedWebAppController.php @@ -11,7 +11,7 @@ namespace Flarum\Forum\Controller; -use Flarum\Core\Exception\PermissionDeniedException; +use Flarum\User\Exception\PermissionDeniedException; use Psr\Http\Message\ServerRequestInterface as Request; class AuthorizedWebAppController extends FrontendController diff --git a/framework/core/src/Forum/Controller/ConfirmEmailController.php b/framework/core/src/Forum/Controller/ConfirmEmailController.php index 64727c693..0284674ed 100644 --- a/framework/core/src/Forum/Controller/ConfirmEmailController.php +++ b/framework/core/src/Forum/Controller/ConfirmEmailController.php @@ -12,7 +12,7 @@ namespace Flarum\Forum\Controller; use Flarum\Core\Command\ConfirmEmail; -use Flarum\Core\Exception\InvalidConfirmationTokenException; +use Flarum\User\Exception\InvalidConfirmationTokenException; use Flarum\Foundation\Application; use Flarum\Http\Controller\ControllerInterface; use Flarum\Http\SessionAuthenticator; diff --git a/framework/core/src/Forum/Controller/DiscussionController.php b/framework/core/src/Forum/Controller/DiscussionController.php index f12b1092e..4b60ecc84 100644 --- a/framework/core/src/Forum/Controller/DiscussionController.php +++ b/framework/core/src/Forum/Controller/DiscussionController.php @@ -12,10 +12,10 @@ namespace Flarum\Forum\Controller; use Flarum\Api\Client; -use Flarum\Core\User; use Flarum\Forum\UrlGenerator; use Flarum\Forum\Frontend; use Flarum\Http\Exception\RouteNotFoundException; +use Flarum\User\User; use Illuminate\Contracts\Events\Dispatcher; use Psr\Http\Message\ServerRequestInterface as Request; diff --git a/framework/core/src/Forum/Controller/IndexController.php b/framework/core/src/Forum/Controller/IndexController.php index 8deeb7867..278710aab 100644 --- a/framework/core/src/Forum/Controller/IndexController.php +++ b/framework/core/src/Forum/Controller/IndexController.php @@ -12,7 +12,7 @@ namespace Flarum\Forum\Controller; use Flarum\Api\Client as ApiClient; -use Flarum\Core\User; +use Flarum\User\User; use Flarum\Forum\Frontend; use Illuminate\Contracts\Events\Dispatcher; use Psr\Http\Message\ServerRequestInterface as Request; diff --git a/framework/core/src/Forum/Controller/LogInController.php b/framework/core/src/Forum/Controller/LogInController.php index f131150f9..5cabd47dd 100644 --- a/framework/core/src/Forum/Controller/LogInController.php +++ b/framework/core/src/Forum/Controller/LogInController.php @@ -13,8 +13,8 @@ namespace Flarum\Forum\Controller; use Flarum\Api\Client; use Flarum\Api\Controller\TokenController; -use Flarum\Core\Repository\UserRepository; -use Flarum\Event\UserLoggedIn; +use Flarum\User\UserRepository; +use Flarum\User\Event\LoggedIn; use Flarum\Http\AccessToken; use Flarum\Http\Controller\ControllerInterface; use Flarum\Http\Rememberer; @@ -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)); $response = $this->rememberer->remember($response, $token, ! array_get($body, 'remember')); } diff --git a/framework/core/src/Forum/Controller/LogOutController.php b/framework/core/src/Forum/Controller/LogOutController.php index 1aef40efb..c83601268 100644 --- a/framework/core/src/Forum/Controller/LogOutController.php +++ b/framework/core/src/Forum/Controller/LogOutController.php @@ -12,7 +12,7 @@ namespace Flarum\Forum\Controller; use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Event\UserLoggedOut; +use Flarum\User\Event\LoggedOut; use Flarum\Foundation\Application; use Flarum\Http\Controller\ControllerInterface; use Flarum\Http\Exception\TokenMismatchException; @@ -85,7 +85,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/ResetPasswordController.php b/framework/core/src/Forum/Controller/ResetPasswordController.php index 42a47b288..36e313a2e 100644 --- a/framework/core/src/Forum/Controller/ResetPasswordController.php +++ b/framework/core/src/Forum/Controller/ResetPasswordController.php @@ -12,8 +12,8 @@ namespace Flarum\Forum\Controller; use DateTime; -use Flarum\Core\Exception\InvalidConfirmationTokenException; -use Flarum\Core\PasswordToken; +use Flarum\User\Exception\InvalidConfirmationTokenException; +use Flarum\User\PasswordToken; use Flarum\Http\Controller\AbstractHtmlController; use Illuminate\Contracts\View\Factory; use Psr\Http\Message\ServerRequestInterface as Request; @@ -43,7 +43,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 0b36f9779..20623cf8f 100644 --- a/framework/core/src/Forum/Controller/SavePasswordController.php +++ b/framework/core/src/Forum/Controller/SavePasswordController.php @@ -11,8 +11,8 @@ namespace Flarum\Forum\Controller; -use Flarum\Core\PasswordToken; -use Flarum\Core\Validator\UserValidator; +use Flarum\User\PasswordToken; +use Flarum\User\UserValidator; use Flarum\Forum\UrlGenerator; use Flarum\Http\Controller\ControllerInterface; use Flarum\Http\SessionAuthenticator; @@ -29,7 +29,7 @@ class SavePasswordController implements ControllerInterface protected $url; /** - * @var UserValidator + * @var \Flarum\User\UserValidator */ protected $validator; diff --git a/framework/core/src/Http/AbstractServer.php b/framework/core/src/Http/AbstractServer.php index ae676755a..de6f923c2 100644 --- a/framework/core/src/Http/AbstractServer.php +++ b/framework/core/src/Http/AbstractServer.php @@ -11,9 +11,9 @@ namespace Flarum\Http; -use Flarum\Core\AuthToken; -use Flarum\Core\EmailToken; -use Flarum\Core\PasswordToken; +use Flarum\User\AuthToken; +use Flarum\User\EmailToken; +use Flarum\User\PasswordToken; use Flarum\Foundation\AbstractServer as BaseAbstractServer; use Flarum\Foundation\Application; use Psr\Http\Message\ResponseInterface; 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/Middleware/AuthenticateWithHeader.php b/framework/core/src/Http/Middleware/AuthenticateWithHeader.php index 9b34b11dc..c13313754 100644 --- a/framework/core/src/Http/Middleware/AuthenticateWithHeader.php +++ b/framework/core/src/Http/Middleware/AuthenticateWithHeader.php @@ -12,7 +12,7 @@ namespace Flarum\Http\Middleware; use Flarum\Api\ApiKey; -use Flarum\Core\User; +use Flarum\User\User; use Flarum\Http\AccessToken; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; 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/Install/Console/InstallCommand.php b/framework/core/src/Install/Console/InstallCommand.php index 1a7317830..acf67997d 100644 --- a/framework/core/src/Install/Console/InstallCommand.php +++ b/framework/core/src/Install/Console/InstallCommand.php @@ -15,7 +15,7 @@ use Exception; use Flarum\Console\AbstractCommand; use Flarum\Core\Group; use Flarum\Core\Permission; -use Flarum\Core\User; +use Flarum\User\User; use Flarum\Database\AbstractModel; use Illuminate\Contracts\Foundation\Application; use Illuminate\Filesystem\Filesystem; 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/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..dd785b72a 100644 --- a/framework/core/src/Core/AuthToken.php +++ b/framework/core/src/User/AuthToken.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\User; use DateTime; -use Flarum\Core\Exception\InvalidConfirmationTokenException; +use Flarum\User\Exception\InvalidConfirmationTokenException; use Flarum\Database\AbstractModel; /** @@ -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/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..b4adcb321 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\Core\Validator\AbstractValidator; class AvatarValidator extends AbstractValidator { diff --git a/framework/core/src/Core/Listener/EmailConfirmationMailer.php b/framework/core/src/User/EmailConfirmationMailer.php similarity index 82% rename from framework/core/src/Core/Listener/EmailConfirmationMailer.php rename to framework/core/src/User/EmailConfirmationMailer.php index 295d45d7c..b02c3f037 100755 --- a/framework/core/src/Core/Listener/EmailConfirmationMailer.php +++ b/framework/core/src/User/EmailConfirmationMailer.php @@ -9,13 +9,10 @@ * 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\User\Event\EmailChangeRequested; +use Flarum\User\Event\Registered; use Flarum\Forum\UrlGenerator; use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Events\Dispatcher; @@ -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); diff --git a/framework/core/src/Core/EmailToken.php b/framework/core/src/User/EmailToken.php similarity index 95% rename from framework/core/src/Core/EmailToken.php rename to framework/core/src/User/EmailToken.php index 257d62211..e0383f2ff 100644 --- a/framework/core/src/Core/EmailToken.php +++ b/framework/core/src/User/EmailToken.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\User; use DateTime; -use Flarum\Core\Exception\InvalidConfirmationTokenException; +use Flarum\User\Exception\InvalidConfirmationTokenException; use Flarum\Database\AbstractModel; /** diff --git a/framework/core/src/Event/UserWasDeleted.php b/framework/core/src/User/Event/Activated.php similarity index 88% rename from framework/core/src/Event/UserWasDeleted.php rename to framework/core/src/User/Event/Activated.php index 5f041b284..d4ad87dff 100644 --- a/framework/core/src/Event/UserWasDeleted.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 UserWasDeleted +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/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/UserWasRenamed.php b/framework/core/src/User/Event/Deleted.php similarity index 88% rename from framework/core/src/Event/UserWasRenamed.php rename to framework/core/src/User/Event/Deleted.php index 671e64080..0b3a574ef 100644 --- a/framework/core/src/Event/UserWasRenamed.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 UserWasRenamed +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/UserBioWasChanged.php b/framework/core/src/User/Event/EmailChanged.php similarity index 88% rename from framework/core/src/Event/UserBioWasChanged.php rename to framework/core/src/User/Event/EmailChanged.php index dfde182b0..fa1bf7759 100644 --- a/framework/core/src/Event/UserBioWasChanged.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 UserBioWasChanged +class EmailChanged { /** * @var User diff --git a/framework/core/src/Event/UserGroupsWereChanged.php b/framework/core/src/User/Event/GroupsChanged.php similarity index 91% rename from framework/core/src/Event/UserGroupsWereChanged.php rename to framework/core/src/User/Event/GroupsChanged.php index 91822f158..feb6484d7 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. 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..32d17b695 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\User\User; use Flarum\Http\AccessToken; -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/Event/UserWasRegistered.php b/framework/core/src/User/Event/Registered.php similarity index 88% rename from framework/core/src/Event/UserWasRegistered.php rename to framework/core/src/User/Event/Registered.php index 2cc82ce5b..5deedfc5d 100644 --- a/framework/core/src/Event/UserWasRegistered.php +++ b/framework/core/src/User/Event/Registered.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 Registered { /** * @var User 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/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 99% rename from framework/core/src/Core/Access/Gate.php rename to framework/core/src/User/Gate.php index f6eba5078..9a9e91a27 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; diff --git a/framework/core/src/Core/Guest.php b/framework/core/src/User/Guest.php similarity index 94% rename from framework/core/src/Core/Guest.php rename to framework/core/src/User/Guest.php index 0fbf00748..e62b8c695 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\Core\Group; class Guest extends User { diff --git a/framework/core/src/Core/PasswordToken.php b/framework/core/src/User/PasswordToken.php similarity index 98% rename from framework/core/src/Core/PasswordToken.php rename to framework/core/src/User/PasswordToken.php index 5d08e3867..190d1d27a 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; diff --git a/framework/core/src/Core/Search/User/Gambit/EmailGambit.php b/framework/core/src/User/Search/Gambit/EmailGambit.php similarity index 85% rename from framework/core/src/Core/Search/User/Gambit/EmailGambit.php rename to framework/core/src/User/Search/Gambit/EmailGambit.php index 8d14fd921..11b0b793a 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\Core\User\Search\Gambit; -use Flarum\Core\Repository\UserRepository; +use Flarum\User\UserRepository; use Flarum\Core\Search\AbstractRegexGambit; use Flarum\Core\Search\AbstractSearch; -use Flarum\Core\Search\User\UserSearch; +use Flarum\Core\User\Search\UserSearch; 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 87% rename from framework/core/src/Core/Search/User/Gambit/FulltextGambit.php rename to framework/core/src/User/Search/Gambit/FulltextGambit.php index 2f7c4c4c3..c8349d740 100644 --- a/framework/core/src/Core/Search/User/Gambit/FulltextGambit.php +++ b/framework/core/src/User/Search/Gambit/FulltextGambit.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\User\Gambit; +namespace Flarum\Core\User\Search\Gambit; -use Flarum\Core\Repository\UserRepository; +use Flarum\User\UserRepository; use Flarum\Core\Search\AbstractSearch; use Flarum\Core\Search\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 95% rename from framework/core/src/Core/Search/User/Gambit/GroupGambit.php rename to framework/core/src/User/Search/Gambit/GroupGambit.php index 4f020904d..abe1ad984 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\Core\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\Core\User\Search\UserSearch; use LogicException; class GroupGambit extends AbstractRegexGambit diff --git a/framework/core/src/Core/Search/User/UserSearch.php b/framework/core/src/User/Search/UserSearch.php similarity index 89% rename from framework/core/src/Core/Search/User/UserSearch.php rename to framework/core/src/User/Search/UserSearch.php index dc3554499..9223dbd04 100644 --- a/framework/core/src/Core/Search/User/UserSearch.php +++ b/framework/core/src/User/Search/UserSearch.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\User; +namespace Flarum\Core\User\Search; use Flarum\Core\Search\AbstractSearch; diff --git a/framework/core/src/Core/Search/User/UserSearcher.php b/framework/core/src/User/Search/UserSearcher.php similarity index 93% rename from framework/core/src/Core/Search/User/UserSearcher.php rename to framework/core/src/User/Search/UserSearcher.php index 855726dfd..0043deb1d 100644 --- a/framework/core/src/Core/Search/User/UserSearcher.php +++ b/framework/core/src/User/Search/UserSearcher.php @@ -9,9 +9,10 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\User; +namespace Flarum\Core\User\Search; -use Flarum\Core\Repository\UserRepository; +use Flarum\Core\User\Search\UserSearch; +use Flarum\User\UserRepository; use Flarum\Core\Search\ApplySearchParametersTrait; use Flarum\Core\Search\GambitManager; use Flarum\Core\Search\SearchCriteria; @@ -38,7 +39,7 @@ class UserSearcher /** * @param GambitManager $gambits - * @param UserRepository $users + * @param \Flarum\User\UserRepository $users */ public function __construct(GambitManager $gambits, UserRepository $users) { diff --git a/framework/core/src/Core/User.php b/framework/core/src/User/User.php similarity index 94% rename from framework/core/src/Core/User.php rename to framework/core/src/User/User.php index fd175c998..9e4917fc5 100755 --- a/framework/core/src/Core/User.php +++ b/framework/core/src/User/User.php @@ -9,10 +9,13 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\User; use DomainException; -use Flarum\Core\Access\Gate; +use Flarum\User\Gate; +use Flarum\Core\Group; +use Flarum\Core\Notification; +use Flarum\Core\Permission; use Flarum\Core\Support\EventGeneratorTrait; use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; @@ -20,15 +23,15 @@ use Flarum\Event\CheckUserPassword; use Flarum\Event\ConfigureUserPreferences; use Flarum\Event\PostWasDeleted; use Flarum\Event\PrepareUserGroups; -use Flarum\Event\UserAvatarWasChanged; -use Flarum\Event\UserBioWasChanged; -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\User\Event\AvatarChanged; +use Flarum\User\Event\BioChanged; +use Flarum\User\Event\EmailChangeRequested; +use Flarum\User\Event\EmailChanged; +use Flarum\User\Event\PasswordChanged; +use Flarum\User\Event\Activated; +use Flarum\User\Event\Deleted; +use Flarum\User\Event\Registered; +use Flarum\User\Event\Renamed; use Flarum\Foundation\Application; use Illuminate\Contracts\Hashing\Hasher; use Symfony\Component\HttpFoundation\Session\SessionInterface; @@ -125,7 +128,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 @@ -166,7 +169,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 +201,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 +218,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 +233,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 +249,7 @@ class User extends AbstractModel { $this->password = $password; - $this->raise(new UserPasswordWasChanged($this)); + $this->raise(new PasswordChanged($this)); return $this; } @@ -271,7 +274,7 @@ class User extends AbstractModel { $this->bio = $bio; - $this->raise(new UserBioWasChanged($this)); + $this->raise(new BioChanged($this)); return $this; } @@ -310,7 +313,7 @@ class User extends AbstractModel { $this->avatar_path = $path; - $this->raise(new UserAvatarWasChanged($this)); + $this->raise(new AvatarChanged($this)); return $this; } @@ -367,7 +370,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; diff --git a/framework/core/src/Core/Listener/UserMetadataUpdater.php b/framework/core/src/User/UserMetadataUpdater.php similarity index 97% rename from framework/core/src/Core/Listener/UserMetadataUpdater.php rename to framework/core/src/User/UserMetadataUpdater.php index 2e85c2d5c..3d5e9ad5b 100755 --- a/framework/core/src/Core/Listener/UserMetadataUpdater.php +++ b/framework/core/src/User/UserMetadataUpdater.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Listener; +namespace Flarum\User; use Flarum\Core\Discussion; use Flarum\Core\Post; @@ -69,7 +69,7 @@ class UserMetadataUpdater } /** - * @param \Flarum\Events\DiscussionWasStarted $event + * @param \Flarum\Event\DiscussionWasStarted $event */ public function whenDiscussionWasStarted(DiscussionWasStarted $event) { 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..3a52fcaf0 100644 --- a/framework/core/src/Core/Access/UserPolicy.php +++ b/framework/core/src/User/UserPolicy.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Access; +namespace Flarum\User; -use Flarum\Core\User; +use Flarum\User\AbstractPolicy; 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 98% rename from framework/core/src/Core/Repository/UserRepository.php rename to framework/core/src/User/UserRepository.php index a350f9f10..bea76c55d 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 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..79d0a08c1 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\Core\Validator\AbstractValidator; class UserValidator extends AbstractValidator { diff --git a/framework/core/tests/Flarum/Api/Handler/InvalidConfirmationTokenExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/InvalidConfirmationTokenExceptionHandlerTest.php index 6591fff1f..19b918d2c 100644 --- a/framework/core/tests/Flarum/Api/Handler/InvalidConfirmationTokenExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/InvalidConfirmationTokenExceptionHandlerTest.php @@ -13,7 +13,7 @@ namespace Tests\Flarum\Api\Handler; use Exception; use Flarum\Api\ExceptionHandler\InvalidConfirmationTokenExceptionHandler; -use Flarum\Core\Exception\InvalidConfirmationTokenException; +use Flarum\User\Exception\InvalidConfirmationTokenException; use Tests\Test\TestCase; class InvalidConfirmationTokenExceptionHandlerTest extends TestCase diff --git a/framework/core/tests/Flarum/Api/Handler/PermissionDeniedExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/PermissionDeniedExceptionHandlerTest.php index 10d52b19f..0494f6240 100644 --- a/framework/core/tests/Flarum/Api/Handler/PermissionDeniedExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/PermissionDeniedExceptionHandlerTest.php @@ -13,7 +13,7 @@ namespace Tests\Flarum\Api\Handler; use Exception; use Flarum\Api\ExceptionHandler\PermissionDeniedExceptionHandler; -use Flarum\Core\Exception\PermissionDeniedException; +use Flarum\User\Exception\PermissionDeniedException; use Tests\Test\TestCase; class PermissionDeniedExceptionHandlerTest extends TestCase From 5a6d28f8a70a3f4eb7a132b02af9ebef344d74fd Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 13:16:02 +0200 Subject: [PATCH 015/172] Move events to Flarum\Settings\Event namespace --- framework/core/src/Admin/AdminServiceProvider.php | 4 ++-- .../core/src/Admin/Controller/FrontendController.php | 4 ++-- .../core/src/Api/Controller/SetSettingsController.php | 8 ++++---- framework/core/src/Forum/ForumServiceProvider.php | 4 ++-- .../Event/Deserializing.php} | 4 ++-- .../{Event/SettingWasSet.php => Settings/Event/Saved.php} | 4 ++-- .../Event/Serializing.php} | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-) rename framework/core/src/{Event/PrepareUnserializedSettings.php => Settings/Event/Deserializing.php} (92%) rename framework/core/src/{Event/SettingWasSet.php => Settings/Event/Saved.php} (93%) rename framework/core/src/{Event/PrepareSerializedSetting.php => Settings/Event/Serializing.php} (92%) diff --git a/framework/core/src/Admin/AdminServiceProvider.php b/framework/core/src/Admin/AdminServiceProvider.php index 2cbd60a78..87e784816 100644 --- a/framework/core/src/Admin/AdminServiceProvider.php +++ b/framework/core/src/Admin/AdminServiceProvider.php @@ -13,7 +13,7 @@ namespace Flarum\Admin; use Flarum\Event\ExtensionWasDisabled; use Flarum\Event\ExtensionWasEnabled; -use Flarum\Event\SettingWasSet; +use Flarum\Settings\Event\Saved; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Http\Handler\RouteHandlerFactory; use Flarum\Http\RouteCollection; @@ -63,7 +63,7 @@ class AdminServiceProvider 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(); } diff --git a/framework/core/src/Admin/Controller/FrontendController.php b/framework/core/src/Admin/Controller/FrontendController.php index eb691f88f..d1b18d2ba 100644 --- a/framework/core/src/Admin/Controller/FrontendController.php +++ b/framework/core/src/Admin/Controller/FrontendController.php @@ -13,7 +13,7 @@ namespace Flarum\Admin\Controller; use Flarum\Admin\Frontend; use Flarum\Core\Permission; -use Flarum\Event\PrepareUnserializedSettings; +use Flarum\Settings\Event\Deserializing; use Flarum\Extension\ExtensionManager; use Flarum\Frontend\AbstractFrontendController; use Flarum\Settings\SettingsRepositoryInterface; @@ -56,7 +56,7 @@ class FrontendController extends AbstractFrontendController $settings = $this->settings->all(); $this->events->fire( - new PrepareUnserializedSettings($settings) + new Deserializing($settings) ); $view->setVariable('settings', $settings); diff --git a/framework/core/src/Api/Controller/SetSettingsController.php b/framework/core/src/Api/Controller/SetSettingsController.php index d714ab165..09f23c6eb 100644 --- a/framework/core/src/Api/Controller/SetSettingsController.php +++ b/framework/core/src/Api/Controller/SetSettingsController.php @@ -12,8 +12,8 @@ namespace Flarum\Api\Controller; use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Event\PrepareSerializedSetting; -use Flarum\Event\SettingWasSet; +use Flarum\Settings\Event\Serializing; +use Flarum\Settings\Event\Saved; use Flarum\Http\Controller\ControllerInterface; use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Events\Dispatcher; @@ -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/Forum/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index 86ef67d31..4504443b4 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -14,7 +14,7 @@ namespace Flarum\Forum; use Flarum\Event\ConfigureForumRoutes; use Flarum\Event\ExtensionWasDisabled; use Flarum\Event\ExtensionWasEnabled; -use Flarum\Event\SettingWasSet; +use Flarum\Settings\Event\Saved; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Http\Handler\RouteHandlerFactory; use Flarum\Http\RouteCollection; @@ -82,7 +82,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(); } 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. From d0b5aa2338fd706ae945cca7ce5e423d58dd4eb2 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 13:19:56 +0200 Subject: [PATCH 016/172] Flatten Flarum\Http namespace --- framework/core/src/Admin/AdminServiceProvider.php | 2 +- framework/core/src/Admin/routes.php | 2 +- framework/core/src/Api/ApiServiceProvider.php | 2 +- framework/core/src/Api/routes.php | 2 +- framework/core/src/Event/AbstractConfigureRoutes.php | 4 ++-- framework/core/src/Forum/ForumServiceProvider.php | 2 +- framework/core/src/Forum/routes.php | 2 +- .../core/src/Http/{Handler => }/ControllerRouteHandler.php | 2 +- framework/core/src/Http/{Handler => }/RouteHandlerFactory.php | 2 +- framework/core/src/Install/InstallServiceProvider.php | 2 +- framework/core/src/Update/UpdateServiceProvider.php | 2 +- 11 files changed, 12 insertions(+), 12 deletions(-) rename framework/core/src/Http/{Handler => }/ControllerRouteHandler.php (98%) rename framework/core/src/Http/{Handler => }/RouteHandlerFactory.php (95%) diff --git a/framework/core/src/Admin/AdminServiceProvider.php b/framework/core/src/Admin/AdminServiceProvider.php index 87e784816..8d9b0cda1 100644 --- a/framework/core/src/Admin/AdminServiceProvider.php +++ b/framework/core/src/Admin/AdminServiceProvider.php @@ -15,7 +15,7 @@ use Flarum\Event\ExtensionWasDisabled; use Flarum\Event\ExtensionWasEnabled; use Flarum\Settings\Event\Saved; use Flarum\Foundation\AbstractServiceProvider; -use Flarum\Http\Handler\RouteHandlerFactory; +use Flarum\Http\RouteHandlerFactory; use Flarum\Http\RouteCollection; class AdminServiceProvider extends AbstractServiceProvider diff --git a/framework/core/src/Admin/routes.php b/framework/core/src/Admin/routes.php index 76f1aad4a..f2a04f74b 100644 --- a/framework/core/src/Admin/routes.php +++ b/framework/core/src/Admin/routes.php @@ -10,7 +10,7 @@ */ use Flarum\Admin\Controller; -use Flarum\Http\Handler\RouteHandlerFactory; +use Flarum\Http\RouteHandlerFactory; use Flarum\Http\RouteCollection; return function (RouteCollection $map, RouteHandlerFactory $route) { diff --git a/framework/core/src/Api/ApiServiceProvider.php b/framework/core/src/Api/ApiServiceProvider.php index 24020af42..8e524324f 100644 --- a/framework/core/src/Api/ApiServiceProvider.php +++ b/framework/core/src/Api/ApiServiceProvider.php @@ -17,7 +17,7 @@ use Flarum\Api\Serializer\NotificationSerializer; use Flarum\Event\ConfigureApiRoutes; use Flarum\Event\ConfigureNotificationTypes; use Flarum\Foundation\AbstractServiceProvider; -use Flarum\Http\Handler\RouteHandlerFactory; +use Flarum\Http\RouteHandlerFactory; use Flarum\Http\RouteCollection; use Tobscure\JsonApi\ErrorHandler; use Tobscure\JsonApi\Exception\Handler\FallbackExceptionHandler; diff --git a/framework/core/src/Api/routes.php b/framework/core/src/Api/routes.php index 0203b6131..f394141a7 100644 --- a/framework/core/src/Api/routes.php +++ b/framework/core/src/Api/routes.php @@ -10,7 +10,7 @@ */ use Flarum\Api\Controller; -use Flarum\Http\Handler\RouteHandlerFactory; +use Flarum\Http\RouteHandlerFactory; use Flarum\Http\RouteCollection; return function (RouteCollection $map, RouteHandlerFactory $route) { diff --git a/framework/core/src/Event/AbstractConfigureRoutes.php b/framework/core/src/Event/AbstractConfigureRoutes.php index fbd8d175c..fec628648 100644 --- a/framework/core/src/Event/AbstractConfigureRoutes.php +++ b/framework/core/src/Event/AbstractConfigureRoutes.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Http\Handler\RouteHandlerFactory; +use Flarum\Http\RouteHandlerFactory; use Flarum\Http\RouteCollection; 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) { diff --git a/framework/core/src/Forum/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index 4504443b4..69e684c22 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -16,7 +16,7 @@ use Flarum\Event\ExtensionWasDisabled; use Flarum\Event\ExtensionWasEnabled; use Flarum\Settings\Event\Saved; use Flarum\Foundation\AbstractServiceProvider; -use Flarum\Http\Handler\RouteHandlerFactory; +use Flarum\Http\RouteHandlerFactory; use Flarum\Http\RouteCollection; class ForumServiceProvider extends AbstractServiceProvider diff --git a/framework/core/src/Forum/routes.php b/framework/core/src/Forum/routes.php index 96e26dc3a..028fe37dd 100644 --- a/framework/core/src/Forum/routes.php +++ b/framework/core/src/Forum/routes.php @@ -10,7 +10,7 @@ */ use Flarum\Forum\Controller; -use Flarum\Http\Handler\RouteHandlerFactory; +use Flarum\Http\RouteHandlerFactory; use Flarum\Http\RouteCollection; return function (RouteCollection $map, RouteHandlerFactory $route) { 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/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/Install/InstallServiceProvider.php b/framework/core/src/Install/InstallServiceProvider.php index e796f3895..26c089c06 100644 --- a/framework/core/src/Install/InstallServiceProvider.php +++ b/framework/core/src/Install/InstallServiceProvider.php @@ -12,7 +12,7 @@ namespace Flarum\Install; use Flarum\Foundation\AbstractServiceProvider; -use Flarum\Http\Handler\RouteHandlerFactory; +use Flarum\Http\RouteHandlerFactory; use Flarum\Http\RouteCollection; use Flarum\Install\Prerequisite\Composite; use Flarum\Install\Prerequisite\PhpExtensions; diff --git a/framework/core/src/Update/UpdateServiceProvider.php b/framework/core/src/Update/UpdateServiceProvider.php index 17b225f35..f45364230 100644 --- a/framework/core/src/Update/UpdateServiceProvider.php +++ b/framework/core/src/Update/UpdateServiceProvider.php @@ -12,7 +12,7 @@ namespace Flarum\Update; use Flarum\Foundation\AbstractServiceProvider; -use Flarum\Http\Handler\RouteHandlerFactory; +use Flarum\Http\RouteHandlerFactory; use Flarum\Http\RouteCollection; class UpdateServiceProvider extends AbstractServiceProvider From d851699c970bcfe9d64691c8a1fd00bcb222a3ec Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 13:25:49 +0200 Subject: [PATCH 017/172] Finalize Flarum\Foundation namespace --- .../ExceptionHandler/ValidationExceptionHandler.php | 2 +- .../core/src/Core/Command/ConfirmEmailHandler.php | 4 ++-- framework/core/src/Core/Command/CreateGroupHandler.php | 4 ++-- .../core/src/Core/Command/DeleteAvatarHandler.php | 4 ++-- .../core/src/Core/Command/DeleteDiscussionHandler.php | 4 ++-- framework/core/src/Core/Command/DeleteGroupHandler.php | 4 ++-- framework/core/src/Core/Command/DeletePostHandler.php | 4 ++-- framework/core/src/Core/Command/DeleteUserHandler.php | 4 ++-- .../core/src/Core/Command/EditDiscussionHandler.php | 4 ++-- framework/core/src/Core/Command/EditGroupHandler.php | 4 ++-- framework/core/src/Core/Command/EditPostHandler.php | 4 ++-- framework/core/src/Core/Command/EditUserHandler.php | 4 ++-- framework/core/src/Core/Command/PostReplyHandler.php | 4 ++-- .../core/src/Core/Command/ReadDiscussionHandler.php | 4 ++-- .../core/src/Core/Command/RegisterUserHandler.php | 4 ++-- .../core/src/Core/Command/StartDiscussionHandler.php | 4 ++-- .../core/src/Core/Command/UploadAvatarHandler.php | 4 ++-- framework/core/src/Core/Discussion.php | 4 ++-- framework/core/src/Core/DiscussionState.php | 4 ++-- framework/core/src/Core/Group.php | 4 ++-- framework/core/src/Core/Post.php | 4 ++-- .../core/src/Core/Validator/DiscussionValidator.php | 2 ++ framework/core/src/Core/Validator/GroupValidator.php | 2 ++ framework/core/src/Core/Validator/PostValidator.php | 2 ++ .../Validator => Foundation}/AbstractValidator.php | 6 +++--- .../Support => Foundation}/DispatchEventsTrait.php | 2 +- .../Event/Validating.php} | 10 +++++----- .../Support => Foundation}/EventGeneratorTrait.php | 2 +- .../Exception => Foundation}/ValidationException.php | 2 +- framework/core/src/User/AvatarValidator.php | 2 +- framework/core/src/User/User.php | 4 ++-- framework/core/src/User/UserValidator.php | 2 +- .../Api/Handler/ValidationExceptionHandlerTest.php | 2 +- 33 files changed, 63 insertions(+), 57 deletions(-) rename framework/core/src/{Core/Validator => Foundation}/AbstractValidator.php (94%) rename framework/core/src/{Core/Support => Foundation}/DispatchEventsTrait.php (95%) rename framework/core/src/{Event/ConfigureValidator.php => Foundation/Event/Validating.php} (78%) rename framework/core/src/{Core/Support => Foundation}/EventGeneratorTrait.php (95%) rename framework/core/src/{Core/Exception => Foundation}/ValidationException.php (96%) diff --git a/framework/core/src/Api/ExceptionHandler/ValidationExceptionHandler.php b/framework/core/src/Api/ExceptionHandler/ValidationExceptionHandler.php index 9a1f77ec1..f36b253fd 100644 --- a/framework/core/src/Api/ExceptionHandler/ValidationExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/ValidationExceptionHandler.php @@ -12,7 +12,7 @@ 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/Core/Command/ConfirmEmailHandler.php b/framework/core/src/Core/Command/ConfirmEmailHandler.php index f8415792d..b657f1972 100644 --- a/framework/core/src/Core/Command/ConfirmEmailHandler.php +++ b/framework/core/src/Core/Command/ConfirmEmailHandler.php @@ -13,12 +13,12 @@ namespace Flarum\Core\Command; use Flarum\User\EmailToken; use Flarum\User\UserRepository; -use Flarum\Core\Support\DispatchEventsTrait; +use Flarum\Foundation\DispatchEventsTrait; use Illuminate\Contracts\Events\Dispatcher; class ConfirmEmailHandler { - use DispatchEventsTrait; + use Flarum\Foundation\DispatchEventsTrait; /** * @var \Flarum\User\UserRepository diff --git a/framework/core/src/Core/Command/CreateGroupHandler.php b/framework/core/src/Core/Command/CreateGroupHandler.php index 54d8c3d8c..6c3be8830 100644 --- a/framework/core/src/Core/Command/CreateGroupHandler.php +++ b/framework/core/src/Core/Command/CreateGroupHandler.php @@ -14,14 +14,14 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; use Flarum\Core\Group; -use Flarum\Core\Support\DispatchEventsTrait; +use Flarum\Foundation\DispatchEventsTrait; use Flarum\Core\Validator\GroupValidator; use Flarum\Event\GroupWillBeSaved; use Illuminate\Contracts\Events\Dispatcher; class CreateGroupHandler { - use DispatchEventsTrait; + use Flarum\Foundation\DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/DeleteAvatarHandler.php b/framework/core/src/Core/Command/DeleteAvatarHandler.php index aabbe4ddc..00961f741 100644 --- a/framework/core/src/Core/Command/DeleteAvatarHandler.php +++ b/framework/core/src/Core/Command/DeleteAvatarHandler.php @@ -14,14 +14,14 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; use Flarum\User\UserRepository; -use Flarum\Core\Support\DispatchEventsTrait; +use Flarum\Foundation\DispatchEventsTrait; use Flarum\Event\AvatarWillBeDeleted; use Illuminate\Contracts\Events\Dispatcher; use League\Flysystem\FilesystemInterface; class DeleteAvatarHandler { - use DispatchEventsTrait; + use Flarum\Foundation\DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/DeleteDiscussionHandler.php b/framework/core/src/Core/Command/DeleteDiscussionHandler.php index a02e4609b..459432041 100644 --- a/framework/core/src/Core/Command/DeleteDiscussionHandler.php +++ b/framework/core/src/Core/Command/DeleteDiscussionHandler.php @@ -14,13 +14,13 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; use Flarum\Core\Repository\DiscussionRepository; -use Flarum\Core\Support\DispatchEventsTrait; +use Flarum\Foundation\DispatchEventsTrait; use Flarum\Event\DiscussionWillBeDeleted; use Illuminate\Contracts\Events\Dispatcher; class DeleteDiscussionHandler { - use DispatchEventsTrait; + use Flarum\Foundation\DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/DeleteGroupHandler.php b/framework/core/src/Core/Command/DeleteGroupHandler.php index ed849a5be..e3ee47543 100644 --- a/framework/core/src/Core/Command/DeleteGroupHandler.php +++ b/framework/core/src/Core/Command/DeleteGroupHandler.php @@ -14,13 +14,13 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; use Flarum\Core\Repository\GroupRepository; -use Flarum\Core\Support\DispatchEventsTrait; +use Flarum\Foundation\DispatchEventsTrait; use Flarum\Event\GroupWillBeDeleted; use Illuminate\Contracts\Events\Dispatcher; class DeleteGroupHandler { - use DispatchEventsTrait; + use Flarum\Foundation\DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/DeletePostHandler.php b/framework/core/src/Core/Command/DeletePostHandler.php index e7697e622..a616dbcc5 100644 --- a/framework/core/src/Core/Command/DeletePostHandler.php +++ b/framework/core/src/Core/Command/DeletePostHandler.php @@ -14,13 +14,13 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; use Flarum\Core\Repository\PostRepository; -use Flarum\Core\Support\DispatchEventsTrait; +use Flarum\Foundation\DispatchEventsTrait; use Flarum\Event\PostWillBeDeleted; use Illuminate\Contracts\Events\Dispatcher; class DeletePostHandler { - use DispatchEventsTrait; + use Flarum\Foundation\DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/DeleteUserHandler.php b/framework/core/src/Core/Command/DeleteUserHandler.php index e4503a53d..d5ed6c15f 100644 --- a/framework/core/src/Core/Command/DeleteUserHandler.php +++ b/framework/core/src/Core/Command/DeleteUserHandler.php @@ -14,13 +14,13 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; use Flarum\User\UserRepository; -use Flarum\Core\Support\DispatchEventsTrait; +use Flarum\Foundation\DispatchEventsTrait; use Flarum\User\Event\Deleting; use Illuminate\Contracts\Events\Dispatcher; class DeleteUserHandler { - use DispatchEventsTrait; + use Flarum\Foundation\DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/EditDiscussionHandler.php b/framework/core/src/Core/Command/EditDiscussionHandler.php index b8866bf1f..6f8e7bada 100644 --- a/framework/core/src/Core/Command/EditDiscussionHandler.php +++ b/framework/core/src/Core/Command/EditDiscussionHandler.php @@ -14,14 +14,14 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; use Flarum\Core\Repository\DiscussionRepository; -use Flarum\Core\Support\DispatchEventsTrait; +use Flarum\Foundation\DispatchEventsTrait; use Flarum\Core\Validator\DiscussionValidator; use Flarum\Event\DiscussionWillBeSaved; use Illuminate\Contracts\Events\Dispatcher; class EditDiscussionHandler { - use DispatchEventsTrait; + use Flarum\Foundation\DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/EditGroupHandler.php b/framework/core/src/Core/Command/EditGroupHandler.php index 6d1d8ad4f..42fe0e0a7 100644 --- a/framework/core/src/Core/Command/EditGroupHandler.php +++ b/framework/core/src/Core/Command/EditGroupHandler.php @@ -15,14 +15,14 @@ use Flarum\Core\Access\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; use Flarum\Core\Group; use Flarum\Core\Repository\GroupRepository; -use Flarum\Core\Support\DispatchEventsTrait; +use Flarum\Foundation\DispatchEventsTrait; use Flarum\Core\Validator\GroupValidator; use Flarum\Event\GroupWillBeSaved; use Illuminate\Contracts\Events\Dispatcher; class EditGroupHandler { - use DispatchEventsTrait; + use Flarum\Foundation\DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/EditPostHandler.php b/framework/core/src/Core/Command/EditPostHandler.php index 32e607b5b..65707e301 100644 --- a/framework/core/src/Core/Command/EditPostHandler.php +++ b/framework/core/src/Core/Command/EditPostHandler.php @@ -14,14 +14,14 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\Core\Post\CommentPost; use Flarum\Core\Repository\PostRepository; -use Flarum\Core\Support\DispatchEventsTrait; +use Flarum\Foundation\DispatchEventsTrait; use Flarum\Core\Validator\PostValidator; use Flarum\Event\PostWillBeSaved; use Illuminate\Contracts\Events\Dispatcher; class EditPostHandler { - use DispatchEventsTrait; + use Flarum\Foundation\DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/EditUserHandler.php b/framework/core/src/Core/Command/EditUserHandler.php index 4ba4a4bff..6071fa1ad 100644 --- a/framework/core/src/Core/Command/EditUserHandler.php +++ b/framework/core/src/Core/Command/EditUserHandler.php @@ -13,7 +13,7 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\User\UserRepository; -use Flarum\Core\Support\DispatchEventsTrait; +use Flarum\Foundation\DispatchEventsTrait; use Flarum\User\User; use Flarum\User\UserValidator; use Flarum\User\Event\GroupsChanged; @@ -22,7 +22,7 @@ use Illuminate\Contracts\Events\Dispatcher; class EditUserHandler { - use DispatchEventsTrait; + use Flarum\Foundation\DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/PostReplyHandler.php b/framework/core/src/Core/Command/PostReplyHandler.php index 06837011b..260116bca 100644 --- a/framework/core/src/Core/Command/PostReplyHandler.php +++ b/framework/core/src/Core/Command/PostReplyHandler.php @@ -16,14 +16,14 @@ 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\Foundation\DispatchEventsTrait; use Flarum\Core\Validator\PostValidator; use Flarum\Event\PostWillBeSaved; use Illuminate\Contracts\Events\Dispatcher; class PostReplyHandler { - use DispatchEventsTrait; + use Flarum\Foundation\DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/ReadDiscussionHandler.php b/framework/core/src/Core/Command/ReadDiscussionHandler.php index 9630100a1..0166b1439 100644 --- a/framework/core/src/Core/Command/ReadDiscussionHandler.php +++ b/framework/core/src/Core/Command/ReadDiscussionHandler.php @@ -13,13 +13,13 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\Core\Repository\DiscussionRepository; -use Flarum\Core\Support\DispatchEventsTrait; +use Flarum\Foundation\DispatchEventsTrait; use Flarum\Event\DiscussionStateWillBeSaved; use Illuminate\Contracts\Events\Dispatcher; class ReadDiscussionHandler { - use DispatchEventsTrait; + use Flarum\Foundation\DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/RegisterUserHandler.php b/framework/core/src/Core/Command/RegisterUserHandler.php index 2e3a1b158..2c3bdb931 100644 --- a/framework/core/src/Core/Command/RegisterUserHandler.php +++ b/framework/core/src/Core/Command/RegisterUserHandler.php @@ -15,7 +15,7 @@ use Exception; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\User\AuthToken; use Flarum\User\Exception\PermissionDeniedException; -use Flarum\Core\Support\DispatchEventsTrait; +use Flarum\Foundation\DispatchEventsTrait; use Flarum\User\User; use Flarum\User\UserValidator; use Flarum\User\Event\Saving; @@ -33,7 +33,7 @@ use League\Flysystem\MountManager; class RegisterUserHandler { - use DispatchEventsTrait; + use Flarum\Foundation\DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/StartDiscussionHandler.php b/framework/core/src/Core/Command/StartDiscussionHandler.php index fa1950259..e3f916f61 100644 --- a/framework/core/src/Core/Command/StartDiscussionHandler.php +++ b/framework/core/src/Core/Command/StartDiscussionHandler.php @@ -14,7 +14,7 @@ namespace Flarum\Core\Command; use Exception; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\Core\Discussion; -use Flarum\Core\Support\DispatchEventsTrait; +use Flarum\Foundation\DispatchEventsTrait; use Flarum\Core\Validator\DiscussionValidator; use Flarum\Event\DiscussionWillBeSaved; use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher; @@ -22,7 +22,7 @@ use Illuminate\Contracts\Events\Dispatcher as EventDispatcher; class StartDiscussionHandler { - use DispatchEventsTrait; + use Flarum\Foundation\DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/UploadAvatarHandler.php b/framework/core/src/Core/Command/UploadAvatarHandler.php index 61fa05601..791090e58 100644 --- a/framework/core/src/Core/Command/UploadAvatarHandler.php +++ b/framework/core/src/Core/Command/UploadAvatarHandler.php @@ -14,7 +14,7 @@ namespace Flarum\Core\Command; use Exception; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\User\UserRepository; -use Flarum\Core\Support\DispatchEventsTrait; +use Flarum\Foundation\DispatchEventsTrait; use Flarum\User\AvatarValidator; use Flarum\Event\AvatarWillBeSaved; use Flarum\Foundation\Application; @@ -29,7 +29,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile; class UploadAvatarHandler { - use DispatchEventsTrait; + use Flarum\Foundation\DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Discussion.php b/framework/core/src/Core/Discussion.php index 39c97bf6d..d22910469 100644 --- a/framework/core/src/Core/Discussion.php +++ b/framework/core/src/Core/Discussion.php @@ -12,7 +12,7 @@ namespace Flarum\Core; use Flarum\Core\Post\MergeableInterface; -use Flarum\Core\Support\EventGeneratorTrait; +use Flarum\Foundation\EventGeneratorTrait; use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; use Flarum\Event\DiscussionWasDeleted; @@ -55,7 +55,7 @@ use Flarum\Util\Str; */ class Discussion extends AbstractModel { - use EventGeneratorTrait; + use Flarum\Foundation\EventGeneratorTrait; use ScopeVisibilityTrait; /** diff --git a/framework/core/src/Core/DiscussionState.php b/framework/core/src/Core/DiscussionState.php index e32e120b4..39ea0e974 100644 --- a/framework/core/src/Core/DiscussionState.php +++ b/framework/core/src/Core/DiscussionState.php @@ -11,7 +11,7 @@ namespace Flarum\Core; -use Flarum\Core\Support\EventGeneratorTrait; +use Flarum\Foundation\EventGeneratorTrait; use Flarum\Database\AbstractModel; use Flarum\Event\DiscussionWasRead; use Illuminate\Database\Eloquent\Builder; @@ -32,7 +32,7 @@ use Illuminate\Database\Eloquent\Builder; */ class DiscussionState extends AbstractModel { - use EventGeneratorTrait; + use Flarum\Foundation\EventGeneratorTrait; /** * {@inheritdoc} diff --git a/framework/core/src/Core/Group.php b/framework/core/src/Core/Group.php index eb05daa5c..f25459f12 100755 --- a/framework/core/src/Core/Group.php +++ b/framework/core/src/Core/Group.php @@ -11,7 +11,7 @@ namespace Flarum\Core; -use Flarum\Core\Support\EventGeneratorTrait; +use Flarum\Foundation\EventGeneratorTrait; use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; use Flarum\Event\GroupWasCreated; @@ -29,7 +29,7 @@ use Flarum\Event\GroupWasRenamed; */ class Group extends AbstractModel { - use EventGeneratorTrait; + use Flarum\Foundation\EventGeneratorTrait; use ScopeVisibilityTrait; /** diff --git a/framework/core/src/Core/Post.php b/framework/core/src/Core/Post.php index f85563965..36d7c5124 100755 --- a/framework/core/src/Core/Post.php +++ b/framework/core/src/Core/Post.php @@ -12,7 +12,7 @@ namespace Flarum\Core; use Flarum\Core\Post\RegisteredTypesScope; -use Flarum\Core\Support\EventGeneratorTrait; +use Flarum\Foundation\EventGeneratorTrait; use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; use Flarum\Event\PostWasDeleted; @@ -39,7 +39,7 @@ use Illuminate\Database\Eloquent\Builder; */ class Post extends AbstractModel { - use EventGeneratorTrait; + use Flarum\Foundation\EventGeneratorTrait; use ScopeVisibilityTrait; /** diff --git a/framework/core/src/Core/Validator/DiscussionValidator.php b/framework/core/src/Core/Validator/DiscussionValidator.php index 7d67fd0a4..2c2a90818 100644 --- a/framework/core/src/Core/Validator/DiscussionValidator.php +++ b/framework/core/src/Core/Validator/DiscussionValidator.php @@ -11,6 +11,8 @@ namespace Flarum\Core\Validator; +use Flarum\Foundation\AbstractValidator; + class DiscussionValidator extends AbstractValidator { protected $rules = [ diff --git a/framework/core/src/Core/Validator/GroupValidator.php b/framework/core/src/Core/Validator/GroupValidator.php index a66f52dd4..506163f6f 100644 --- a/framework/core/src/Core/Validator/GroupValidator.php +++ b/framework/core/src/Core/Validator/GroupValidator.php @@ -11,6 +11,8 @@ namespace Flarum\Core\Validator; +use Flarum\Foundation\AbstractValidator; + class GroupValidator extends AbstractValidator { protected $rules = [ diff --git a/framework/core/src/Core/Validator/PostValidator.php b/framework/core/src/Core/Validator/PostValidator.php index 3fe573845..87142c9fd 100644 --- a/framework/core/src/Core/Validator/PostValidator.php +++ b/framework/core/src/Core/Validator/PostValidator.php @@ -11,6 +11,8 @@ namespace Flarum\Core\Validator; +use Flarum\Foundation\AbstractValidator; + class PostValidator extends AbstractValidator { protected $rules = [ diff --git a/framework/core/src/Core/Validator/AbstractValidator.php b/framework/core/src/Foundation/AbstractValidator.php similarity index 94% rename from framework/core/src/Core/Validator/AbstractValidator.php rename to framework/core/src/Foundation/AbstractValidator.php index e1c138ecb..ee1062af5 100644 --- a/framework/core/src/Core/Validator/AbstractValidator.php +++ b/framework/core/src/Foundation/AbstractValidator.php @@ -9,9 +9,9 @@ * 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; @@ -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/Core/Support/DispatchEventsTrait.php b/framework/core/src/Foundation/DispatchEventsTrait.php similarity index 95% rename from framework/core/src/Core/Support/DispatchEventsTrait.php rename to framework/core/src/Foundation/DispatchEventsTrait.php index c145a8c3d..081bfc64b 100644 --- a/framework/core/src/Core/Support/DispatchEventsTrait.php +++ b/framework/core/src/Foundation/DispatchEventsTrait.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Support; +namespace Flarum\Foundation; use Flarum\User\User; use Illuminate\Contracts\Events\Dispatcher; 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/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/User/AvatarValidator.php b/framework/core/src/User/AvatarValidator.php index b4adcb321..e40ca45f1 100644 --- a/framework/core/src/User/AvatarValidator.php +++ b/framework/core/src/User/AvatarValidator.php @@ -11,7 +11,7 @@ namespace Flarum\User; -use Flarum\Core\Validator\AbstractValidator; +use Flarum\Foundation\AbstractValidator; class AvatarValidator extends AbstractValidator { diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 9e4917fc5..80792e0c8 100755 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -16,7 +16,7 @@ use Flarum\User\Gate; use Flarum\Core\Group; use Flarum\Core\Notification; use Flarum\Core\Permission; -use Flarum\Core\Support\EventGeneratorTrait; +use Flarum\Foundation\EventGeneratorTrait; use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; use Flarum\Event\CheckUserPassword; @@ -56,7 +56,7 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface; */ class User extends AbstractModel { - use EventGeneratorTrait; + use Flarum\Foundation\EventGeneratorTrait; use ScopeVisibilityTrait; /** diff --git a/framework/core/src/User/UserValidator.php b/framework/core/src/User/UserValidator.php index 79d0a08c1..a994a999f 100644 --- a/framework/core/src/User/UserValidator.php +++ b/framework/core/src/User/UserValidator.php @@ -11,7 +11,7 @@ namespace Flarum\User; -use Flarum\Core\Validator\AbstractValidator; +use Flarum\Foundation\AbstractValidator; class UserValidator extends AbstractValidator { diff --git a/framework/core/tests/Flarum/Api/Handler/ValidationExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/ValidationExceptionHandlerTest.php index 2d2130cf1..d3440f52f 100644 --- a/framework/core/tests/Flarum/Api/Handler/ValidationExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/ValidationExceptionHandlerTest.php @@ -13,7 +13,7 @@ namespace Tests\Flarum\Api\Handler; use Exception; use Flarum\Api\ExceptionHandler\ValidationExceptionHandler; -use Flarum\Core\Exception\ValidationException; +use Flarum\Foundation\ValidationException; use Tests\Test\TestCase; class ValidationExceptionHandlerTest extends TestCase From 8c0459139db6265ddc2e3bf897c1c622ce54c0b7 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 13:28:22 +0200 Subject: [PATCH 018/172] Move events to Flarum\Formatter\Event namespace --- .../Event/Configuring.php} | 4 ++-- .../Event/Parsing.php} | 4 ++-- .../Event/Rendering.php} | 4 ++-- framework/core/src/Formatter/Formatter.php | 12 ++++++------ 4 files changed, 12 insertions(+), 12 deletions(-) rename framework/core/src/{Event/ConfigureFormatter.php => Formatter/Event/Configuring.php} (90%) rename framework/core/src/{Event/ConfigureFormatterParser.php => Formatter/Event/Parsing.php} (92%) rename framework/core/src/{Event/ConfigureFormatterRenderer.php => Formatter/Event/Rendering.php} (92%) 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); From aacf6f05d60ff138acde0a40429680f2c8df5c35 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 13:31:13 +0200 Subject: [PATCH 019/172] Move events to Flarum\Extension\Event namespace --- .../core/src/Admin/AdminServiceProvider.php | 8 ++--- .../src/Event/ExtensionWasUninstalled.php | 30 ------------------- .../Event/Disabled.php} | 4 +-- .../Event/Disabling.php} | 4 +-- .../Event/Enabled.php} | 4 +-- .../Event/Enabling.php} | 4 +-- .../core/src/Extension/Event/Uninstalled.php | 30 +++++++++++++++++++ .../core/src/Extension/ExtensionManager.php | 20 ++++++------- .../Formatter/FormatterServiceProvider.php | 8 ++--- .../core/src/Forum/ForumServiceProvider.php | 8 ++--- 10 files changed, 60 insertions(+), 60 deletions(-) delete mode 100644 framework/core/src/Event/ExtensionWasUninstalled.php rename framework/core/src/{Event/ExtensionWasEnabled.php => Extension/Event/Disabled.php} (90%) rename framework/core/src/{Event/ExtensionWasDisabled.php => Extension/Event/Disabling.php} (90%) rename framework/core/src/{Event/ExtensionWillBeEnabled.php => Extension/Event/Enabled.php} (90%) rename framework/core/src/{Event/ExtensionWillBeDisabled.php => Extension/Event/Enabling.php} (89%) create mode 100644 framework/core/src/Extension/Event/Uninstalled.php diff --git a/framework/core/src/Admin/AdminServiceProvider.php b/framework/core/src/Admin/AdminServiceProvider.php index 8d9b0cda1..f394637e2 100644 --- a/framework/core/src/Admin/AdminServiceProvider.php +++ b/framework/core/src/Admin/AdminServiceProvider.php @@ -11,8 +11,8 @@ namespace Flarum\Admin; -use Flarum\Event\ExtensionWasDisabled; -use Flarum\Event\ExtensionWasEnabled; +use Flarum\Extension\Event\Disabled; +use Flarum\Extension\Event\Enabled; use Flarum\Settings\Event\Saved; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Http\RouteHandlerFactory; @@ -74,8 +74,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() 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 @@ -<?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\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/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 @@ +<?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\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..724250aec 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\Enabled; +use Flarum\Extension\Event\Uninstalled; +use Flarum\Extension\Event\Disabling; +use Flarum\Extension\Event\Enabling; 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/Formatter/FormatterServiceProvider.php b/framework/core/src/Formatter/FormatterServiceProvider.php index 60f43bc8f..de07468dd 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']); } /** diff --git a/framework/core/src/Forum/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index 69e684c22..8b96164a6 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -12,8 +12,8 @@ namespace Flarum\Forum; use Flarum\Event\ConfigureForumRoutes; -use Flarum\Event\ExtensionWasDisabled; -use Flarum\Event\ExtensionWasEnabled; +use Flarum\Extension\Event\Disabled; +use Flarum\Extension\Event\Enabled; use Flarum\Settings\Event\Saved; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Http\RouteHandlerFactory; @@ -93,8 +93,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() From 02a5b65d0862314ad2e01fdf3aa52cdc2c3bb4ea Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 13:33:42 +0200 Subject: [PATCH 020/172] Fix trait imports --- framework/core/src/Core/Discussion.php | 2 +- framework/core/src/Core/DiscussionState.php | 2 +- framework/core/src/Core/Group.php | 2 +- framework/core/src/Core/Post.php | 2 +- framework/core/src/User/User.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/framework/core/src/Core/Discussion.php b/framework/core/src/Core/Discussion.php index d22910469..f81ade832 100644 --- a/framework/core/src/Core/Discussion.php +++ b/framework/core/src/Core/Discussion.php @@ -55,7 +55,7 @@ use Flarum\Util\Str; */ class Discussion extends AbstractModel { - use Flarum\Foundation\EventGeneratorTrait; + use EventGeneratorTrait; use ScopeVisibilityTrait; /** diff --git a/framework/core/src/Core/DiscussionState.php b/framework/core/src/Core/DiscussionState.php index 39ea0e974..15b2e2142 100644 --- a/framework/core/src/Core/DiscussionState.php +++ b/framework/core/src/Core/DiscussionState.php @@ -32,7 +32,7 @@ use Illuminate\Database\Eloquent\Builder; */ class DiscussionState extends AbstractModel { - use Flarum\Foundation\EventGeneratorTrait; + use EventGeneratorTrait; /** * {@inheritdoc} diff --git a/framework/core/src/Core/Group.php b/framework/core/src/Core/Group.php index f25459f12..53d4da36f 100755 --- a/framework/core/src/Core/Group.php +++ b/framework/core/src/Core/Group.php @@ -29,7 +29,7 @@ use Flarum\Event\GroupWasRenamed; */ class Group extends AbstractModel { - use Flarum\Foundation\EventGeneratorTrait; + use EventGeneratorTrait; use ScopeVisibilityTrait; /** diff --git a/framework/core/src/Core/Post.php b/framework/core/src/Core/Post.php index 36d7c5124..bb5f0e731 100755 --- a/framework/core/src/Core/Post.php +++ b/framework/core/src/Core/Post.php @@ -39,7 +39,7 @@ use Illuminate\Database\Eloquent\Builder; */ class Post extends AbstractModel { - use Flarum\Foundation\EventGeneratorTrait; + use EventGeneratorTrait; use ScopeVisibilityTrait; /** diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 80792e0c8..9849b2d88 100755 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -56,7 +56,7 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface; */ class User extends AbstractModel { - use Flarum\Foundation\EventGeneratorTrait; + use EventGeneratorTrait; use ScopeVisibilityTrait; /** From aaa04e2e1392234cd909ef7b723f00d41da012a1 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 13:43:33 +0200 Subject: [PATCH 021/172] Extract new Flarum\Post namespace --- .../Controller/CreateDiscussionController.php | 2 +- .../Api/Controller/CreatePostController.php | 6 ++-- .../Api/Controller/ListPostsController.php | 6 ++-- .../Controller/ShowDiscussionController.php | 4 +-- .../src/Api/Controller/ShowPostController.php | 6 ++-- .../FloodingExceptionHandler.php | 2 +- .../Api/Serializer/BasicPostSerializer.php | 2 +- .../src/Api/Serializer/PostSerializer.php | 2 +- .../src/Core/Command/DeletePostHandler.php | 10 +++--- .../core/src/Core/Command/EditPostHandler.php | 16 ++++----- .../src/Core/Command/PostReplyHandler.php | 10 +++--- .../core/src/Core/CoreServiceProvider.php | 9 ++--- framework/core/src/Core/Discussion.php | 15 ++++---- .../Listener/DiscussionMetadataUpdater.php | 34 +++++++++---------- .../Listener/DiscussionRenamedNotifier.php | 2 +- .../DiscussionRenamedBlueprint.php | 4 +-- .../Search/Discussion/DiscussionSearcher.php | 2 +- .../src/{Core => }/Post/AbstractEventPost.php | 4 +-- .../core/src/{Core => }/Post/CommentPost.php | 19 +++++------ .../{Core => }/Post/DiscussionRenamedPost.php | 4 +-- .../Event/Deleted.php} | 10 +++--- .../Event/Deleting.php} | 10 +++--- .../Event/Hidden.php} | 6 ++-- .../Event/Posted.php} | 10 +++--- .../Event/Restored.php} | 10 +++--- .../Event/Revised.php} | 10 +++--- .../Event/Saving.php} | 10 +++--- .../Exception/FloodingException.php | 2 +- .../core/src/{Core => }/Post/Floodgate.php | 7 ++-- .../{Core => }/Post/MergeableInterface.php | 6 ++-- framework/core/src/{Core => Post}/Post.php | 8 ++--- .../src/{Core/Access => Post}/PostPolicy.php | 5 ++- .../Repository => Post}/PostRepository.php | 3 +- .../Validator => Post}/PostValidator.php | 2 +- .../{Core => }/Post/RegisteredTypesScope.php | 2 +- framework/core/src/User/User.php | 6 ++-- .../core/src/User/UserMetadataUpdater.php | 32 ++++++++--------- .../Handler/FloodingExceptionHandlerTest.php | 2 +- 38 files changed, 146 insertions(+), 154 deletions(-) rename framework/core/src/{Core => }/Post/AbstractEventPost.php (93%) rename framework/core/src/{Core => }/Post/CommentPost.php (90%) rename framework/core/src/{Core => }/Post/DiscussionRenamedPost.php (97%) rename framework/core/src/{Event/PostWasPosted.php => Post/Event/Deleted.php} (78%) rename framework/core/src/{Event/PostWillBeDeleted.php => Post/Event/Deleting.php} (85%) rename framework/core/src/{Event/PostWasHidden.php => Post/Event/Hidden.php} (87%) rename framework/core/src/{Event/PostWasDeleted.php => Post/Event/Posted.php} (78%) rename framework/core/src/{Event/PostWasRestored.php => Post/Event/Restored.php} (76%) rename framework/core/src/{Event/PostWasRevised.php => Post/Event/Revised.php} (76%) rename framework/core/src/{Event/PostWillBeSaved.php => Post/Event/Saving.php} (85%) rename framework/core/src/{Core => Post}/Exception/FloodingException.php (89%) rename framework/core/src/{Core => }/Post/Floodgate.php (84%) rename framework/core/src/{Core => }/Post/MergeableInterface.php (91%) rename framework/core/src/{Core => Post}/Post.php (97%) rename framework/core/src/{Core/Access => Post}/PostPolicy.php (97%) rename framework/core/src/{Core/Repository => Post}/PostRepository.php (98%) rename framework/core/src/{Core/Validator => Post}/PostValidator.php (92%) rename framework/core/src/{Core => }/Post/RegisteredTypesScope.php (98%) diff --git a/framework/core/src/Api/Controller/CreateDiscussionController.php b/framework/core/src/Api/Controller/CreateDiscussionController.php index 6c3c005e7..ab6eb9cde 100644 --- a/framework/core/src/Api/Controller/CreateDiscussionController.php +++ b/framework/core/src/Api/Controller/CreateDiscussionController.php @@ -13,7 +13,7 @@ namespace Flarum\Api\Controller; use Flarum\Core\Command\ReadDiscussion; use Flarum\Core\Command\StartDiscussion; -use Flarum\Core\Post\Floodgate; +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/CreatePostController.php b/framework/core/src/Api/Controller/CreatePostController.php index 16ba2a679..a268b7d21 100644 --- a/framework/core/src/Api/Controller/CreatePostController.php +++ b/framework/core/src/Api/Controller/CreatePostController.php @@ -13,7 +13,7 @@ namespace Flarum\Api\Controller; use Flarum\Core\Command\PostReply; use Flarum\Core\Command\ReadDiscussion; -use Flarum\Core\Post\Floodgate; +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) { diff --git a/framework/core/src/Api/Controller/ListPostsController.php b/framework/core/src/Api/Controller/ListPostsController.php index c50490d07..071dbc41d 100644 --- a/framework/core/src/Api/Controller/ListPostsController.php +++ b/framework/core/src/Api/Controller/ListPostsController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Repository\PostRepository; +use Flarum\Post\PostRepository; use Flarum\Event\ConfigurePostsQuery; use Illuminate\Database\Eloquent\Builder; use Psr\Http\Message\ServerRequestInterface; @@ -42,12 +42,12 @@ class ListPostsController extends AbstractListController 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) { diff --git a/framework/core/src/Api/Controller/ShowDiscussionController.php b/framework/core/src/Api/Controller/ShowDiscussionController.php index d3417ff8c..171ddc8e4 100644 --- a/framework/core/src/Api/Controller/ShowDiscussionController.php +++ b/framework/core/src/Api/Controller/ShowDiscussionController.php @@ -13,7 +13,7 @@ namespace Flarum\Api\Controller; use Flarum\Core\Discussion; use Flarum\Core\Repository\DiscussionRepository; -use Flarum\Core\Repository\PostRepository; +use Flarum\Post\PostRepository; use Flarum\User\User; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; @@ -59,7 +59,7 @@ class ShowDiscussionController extends AbstractShowController /** * @param \Flarum\Core\Repository\DiscussionRepository $discussions - * @param \Flarum\Core\Repository\PostRepository $posts + * @param \Flarum\Post\PostRepository $posts */ public function __construct(DiscussionRepository $discussions, PostRepository $posts) { diff --git a/framework/core/src/Api/Controller/ShowPostController.php b/framework/core/src/Api/Controller/ShowPostController.php index 25e2f0e79..49a5f2dec 100644 --- a/framework/core/src/Api/Controller/ShowPostController.php +++ b/framework/core/src/Api/Controller/ShowPostController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Repository\PostRepository; +use Flarum\Post\PostRepository; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; @@ -34,12 +34,12 @@ class ShowPostController extends AbstractShowController ]; /** - * @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/ExceptionHandler/FloodingExceptionHandler.php b/framework/core/src/Api/ExceptionHandler/FloodingExceptionHandler.php index 53b6de082..0a55870dc 100644 --- a/framework/core/src/Api/ExceptionHandler/FloodingExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/FloodingExceptionHandler.php @@ -12,7 +12,7 @@ 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/Serializer/BasicPostSerializer.php b/framework/core/src/Api/Serializer/BasicPostSerializer.php index 2988a6343..2e0a75951 100644 --- a/framework/core/src/Api/Serializer/BasicPostSerializer.php +++ b/framework/core/src/Api/Serializer/BasicPostSerializer.php @@ -12,7 +12,7 @@ namespace Flarum\Api\Serializer; use Flarum\Core\Post; -use Flarum\Core\Post\CommentPost; +use Flarum\Post\CommentPost; use InvalidArgumentException; class BasicPostSerializer extends AbstractSerializer diff --git a/framework/core/src/Api/Serializer/PostSerializer.php b/framework/core/src/Api/Serializer/PostSerializer.php index e385b3533..9f22c5704 100644 --- a/framework/core/src/Api/Serializer/PostSerializer.php +++ b/framework/core/src/Api/Serializer/PostSerializer.php @@ -12,7 +12,7 @@ namespace Flarum\Api\Serializer; use Flarum\User\Gate; -use Flarum\Core\Post\CommentPost; +use Flarum\Post\CommentPost; class PostSerializer extends BasicPostSerializer { diff --git a/framework/core/src/Core/Command/DeletePostHandler.php b/framework/core/src/Core/Command/DeletePostHandler.php index a616dbcc5..176aa5d3f 100644 --- a/framework/core/src/Core/Command/DeletePostHandler.php +++ b/framework/core/src/Core/Command/DeletePostHandler.php @@ -13,9 +13,9 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; -use Flarum\Core\Repository\PostRepository; +use Flarum\Post\PostRepository; use Flarum\Foundation\DispatchEventsTrait; -use Flarum\Event\PostWillBeDeleted; +use Flarum\Post\Event\Deleting; use Illuminate\Contracts\Events\Dispatcher; class DeletePostHandler @@ -24,13 +24,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) { @@ -52,7 +52,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/EditPostHandler.php b/framework/core/src/Core/Command/EditPostHandler.php index 65707e301..af0a52a45 100644 --- a/framework/core/src/Core/Command/EditPostHandler.php +++ b/framework/core/src/Core/Command/EditPostHandler.php @@ -12,11 +12,11 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Post\CommentPost; -use Flarum\Core\Repository\PostRepository; +use Flarum\Post\CommentPost; +use Flarum\Post\PostRepository; use Flarum\Foundation\DispatchEventsTrait; -use Flarum\Core\Validator\PostValidator; -use Flarum\Event\PostWillBeSaved; +use Flarum\Post\PostValidator; +use Flarum\Post\Event\Saving; 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) { @@ -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/PostReplyHandler.php b/framework/core/src/Core/Command/PostReplyHandler.php index 260116bca..a6b327b6d 100644 --- a/framework/core/src/Core/Command/PostReplyHandler.php +++ b/framework/core/src/Core/Command/PostReplyHandler.php @@ -14,11 +14,11 @@ namespace Flarum\Core\Command; use DateTime; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\Core\Notification\NotificationSyncer; -use Flarum\Core\Post\CommentPost; +use Flarum\Post\CommentPost; use Flarum\Core\Repository\DiscussionRepository; use Flarum\Foundation\DispatchEventsTrait; -use Flarum\Core\Validator\PostValidator; -use Flarum\Event\PostWillBeSaved; +use Flarum\Post\PostValidator; +use Flarum\Post\Event\Saving; use Illuminate\Contracts\Events\Dispatcher; class PostReplyHandler @@ -37,7 +37,7 @@ class PostReplyHandler protected $notifications; /** - * @var PostValidator + * @var \Flarum\Post\PostValidator */ protected $validator; @@ -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/CoreServiceProvider.php b/framework/core/src/Core/CoreServiceProvider.php index d697aba1c..c3234f488 100644 --- a/framework/core/src/Core/CoreServiceProvider.php +++ b/framework/core/src/Core/CoreServiceProvider.php @@ -11,11 +11,12 @@ namespace Flarum\Core; -use Flarum\Core\Post\CommentPost; +use Flarum\Post\CommentPost; use Flarum\Event\ConfigurePostTypes; use Flarum\Event\ConfigureUserPreferences; use Flarum\Event\GetPermission; use Flarum\Foundation\AbstractServiceProvider; +use Flarum\Post\Post; use Flarum\User\Gate; use Flarum\User\User; use Illuminate\Contracts\Container\Container; @@ -114,7 +115,7 @@ class CoreServiceProvider extends AbstractServiceProvider $events->subscribe('Flarum\Core\Access\DiscussionPolicy'); $events->subscribe('Flarum\Core\Access\GroupPolicy'); - $events->subscribe('Flarum\Core\Access\PostPolicy'); + $events->subscribe('Flarum\Post\PostPolicy'); $events->subscribe('Flarum\User\UserPolicy'); $events->listen(ConfigureUserPreferences::class, [$this, 'configureUserPreferences']); @@ -123,8 +124,8 @@ class CoreServiceProvider extends AbstractServiceProvider public function registerPostTypes() { $models = [ - 'Flarum\Core\Post\CommentPost', - 'Flarum\Core\Post\DiscussionRenamedPost' + 'Flarum\Post\Post\CommentPost', + 'Flarum\Post\Post\DiscussionRenamedPost' ]; $this->app->make('events')->fire( diff --git a/framework/core/src/Core/Discussion.php b/framework/core/src/Core/Discussion.php index f81ade832..d185e8440 100644 --- a/framework/core/src/Core/Discussion.php +++ b/framework/core/src/Core/Discussion.php @@ -11,7 +11,7 @@ namespace Flarum\Core; -use Flarum\Core\Post\MergeableInterface; +use Flarum\Post\MergeableInterface; use Flarum\Foundation\EventGeneratorTrait; use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; @@ -20,8 +20,9 @@ use Flarum\Event\DiscussionWasHidden; use Flarum\Event\DiscussionWasRenamed; use Flarum\Event\DiscussionWasRestored; use Flarum\Event\DiscussionWasStarted; -use Flarum\Event\PostWasDeleted; +use Flarum\Post\Event\Deleted; use Flarum\Event\ScopePostVisibility; +use Flarum\Post\Post; use Flarum\User\Guest; use Flarum\User\User; use Flarum\Util\Str; @@ -109,7 +110,7 @@ class Discussion extends AbstractModel $posts = $discussion->posts()->allTypes(); foreach ($posts->get() as $post) { - $discussion->raise(new PostWasDeleted($post)); + $discussion->raise(new Deleted($post)); } $posts->delete(); @@ -272,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. @@ -303,7 +304,7 @@ class Discussion extends AbstractModel */ public function posts() { - return $this->hasMany('Flarum\Core\Post'); + return $this->hasMany('Flarum\Post\Post'); } /** @@ -355,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'); } /** @@ -375,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'); } /** diff --git a/framework/core/src/Core/Listener/DiscussionMetadataUpdater.php b/framework/core/src/Core/Listener/DiscussionMetadataUpdater.php index b715e08ae..ea05dba72 100755 --- a/framework/core/src/Core/Listener/DiscussionMetadataUpdater.php +++ b/framework/core/src/Core/Listener/DiscussionMetadataUpdater.php @@ -11,11 +11,11 @@ namespace Flarum\Core\Listener; -use Flarum\Core\Post; -use Flarum\Event\PostWasDeleted; -use Flarum\Event\PostWasHidden; -use Flarum\Event\PostWasPosted; -use Flarum\Event\PostWasRestored; +use Flarum\Post\Post; +use Flarum\Post\Event\Deleted; +use Flarum\Post\Event\Hidden; +use Flarum\Post\Event\Posted; +use Flarum\Post\Event\Restored; 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/Listener/DiscussionRenamedNotifier.php b/framework/core/src/Core/Listener/DiscussionRenamedNotifier.php index 61d212d20..1357b1948 100755 --- a/framework/core/src/Core/Listener/DiscussionRenamedNotifier.php +++ b/framework/core/src/Core/Listener/DiscussionRenamedNotifier.php @@ -13,7 +13,7 @@ namespace Flarum\Core\Listener; use Flarum\Core\Notification\DiscussionRenamedBlueprint; use Flarum\Core\Notification\NotificationSyncer; -use Flarum\Core\Post\DiscussionRenamedPost; +use Flarum\Post\DiscussionRenamedPost; use Flarum\Event\DiscussionWasRenamed; use Illuminate\Contracts\Events\Dispatcher; diff --git a/framework/core/src/Core/Notification/DiscussionRenamedBlueprint.php b/framework/core/src/Core/Notification/DiscussionRenamedBlueprint.php index 5a19d8c7b..b47cac1f9 100644 --- a/framework/core/src/Core/Notification/DiscussionRenamedBlueprint.php +++ b/framework/core/src/Core/Notification/DiscussionRenamedBlueprint.php @@ -11,12 +11,12 @@ namespace Flarum\Core\Notification; -use Flarum\Core\Post\DiscussionRenamedPost; +use Flarum\Post\DiscussionRenamedPost; class DiscussionRenamedBlueprint implements BlueprintInterface { /** - * @var DiscussionRenamedPost + * @var \Flarum\Post\DiscussionRenamedPost */ protected $post; diff --git a/framework/core/src/Core/Search/Discussion/DiscussionSearcher.php b/framework/core/src/Core/Search/Discussion/DiscussionSearcher.php index b85df3f52..f606d99c2 100644 --- a/framework/core/src/Core/Search/Discussion/DiscussionSearcher.php +++ b/framework/core/src/Core/Search/Discussion/DiscussionSearcher.php @@ -13,7 +13,7 @@ namespace Flarum\Core\Search\Discussion; use Flarum\Core\Discussion; use Flarum\Core\Repository\DiscussionRepository; -use Flarum\Core\Repository\PostRepository; +use Flarum\Post\PostRepository; use Flarum\Core\Search\ApplySearchParametersTrait; use Flarum\Core\Search\GambitManager; use Flarum\Core\Search\SearchCriteria; 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/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 a8016cbb2..e42403b7e 100755 --- a/framework/core/src/Core/Post/CommentPost.php +++ b/framework/core/src/Post/CommentPost.php @@ -9,13 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Post; +namespace Flarum\Post; -use Flarum\Core\Post; -use Flarum\Event\PostWasHidden; -use Flarum\Event\PostWasPosted; -use Flarum\Event\PostWasRestored; -use Flarum\Event\PostWasRevised; +use Flarum\Post\Event\Hidden; +use Flarum\Post\Event\Posted; +use Flarum\Post\Event\Restored; +use Flarum\Post\Event\Revised; use Flarum\Formatter\Formatter; use Flarum\User\User; @@ -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 78% rename from framework/core/src/Event/PostWasPosted.php rename to framework/core/src/Post/Event/Deleted.php index e59bcc0dc..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\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 85% rename from framework/core/src/Event/PostWillBeDeleted.php rename to framework/core/src/Post/Event/Deleting.php index d5b32cae6..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\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 87% rename from framework/core/src/Event/PostWasHidden.php rename to framework/core/src/Post/Event/Hidden.php index e41a6a7b3..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\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 78% rename from framework/core/src/Event/PostWasDeleted.php rename to framework/core/src/Post/Event/Posted.php index c98fdb373..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\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 76% rename from framework/core/src/Event/PostWasRestored.php rename to framework/core/src/Post/Event/Restored.php index 581a6b601..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\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 76% rename from framework/core/src/Event/PostWasRevised.php rename to framework/core/src/Post/Event/Revised.php index ddfd2afa0..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\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 85% rename from framework/core/src/Event/PostWillBeSaved.php rename to framework/core/src/Post/Event/Saving.php index fb1736ab0..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\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 84% rename from framework/core/src/Core/Post/Floodgate.php rename to framework/core/src/Post/Floodgate.php index a62811fb1..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\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 97% rename from framework/core/src/Core/Post.php rename to framework/core/src/Post/Post.php index bb5f0e731..ab081b6a6 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\User; use Flarum\Foundation\EventGeneratorTrait; use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; -use Flarum\Event\PostWasDeleted; +use Flarum\Post\Event\Deleted; use Illuminate\Database\Eloquent\Builder; /** @@ -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); diff --git a/framework/core/src/Core/Access/PostPolicy.php b/framework/core/src/Post/PostPolicy.php similarity index 97% rename from framework/core/src/Core/Access/PostPolicy.php rename to framework/core/src/Post/PostPolicy.php index 9e6f5829b..bc63b7ebc 100644 --- a/framework/core/src/Core/Access/PostPolicy.php +++ b/framework/core/src/Post/PostPolicy.php @@ -9,10 +9,9 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Access; +namespace Flarum\Post; use Carbon\Carbon; -use Flarum\Core\Post; use Flarum\Event\ScopePostVisibility; use Flarum\Event\ScopePrivatePostVisibility; use Flarum\Settings\SettingsRepositoryInterface; @@ -58,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 98% rename from framework/core/src/Core/Repository/PostRepository.php rename to framework/core/src/Post/PostRepository.php index df296e358..b9560be91 100644 --- a/framework/core/src/Core/Repository/PostRepository.php +++ b/framework/core/src/Post/PostRepository.php @@ -9,10 +9,9 @@ * 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\Event\ScopePostVisibility; use Flarum\User\User; use Illuminate\Database\Eloquent\ModelNotFoundException; diff --git a/framework/core/src/Core/Validator/PostValidator.php b/framework/core/src/Post/PostValidator.php similarity index 92% rename from framework/core/src/Core/Validator/PostValidator.php rename to framework/core/src/Post/PostValidator.php index 87142c9fd..0306b592f 100644 --- a/framework/core/src/Core/Validator/PostValidator.php +++ b/framework/core/src/Post/PostValidator.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Validator; +namespace Flarum\Post; use Flarum\Foundation\AbstractValidator; diff --git a/framework/core/src/Core/Post/RegisteredTypesScope.php b/framework/core/src/Post/RegisteredTypesScope.php similarity index 98% rename from framework/core/src/Core/Post/RegisteredTypesScope.php rename to framework/core/src/Post/RegisteredTypesScope.php index 35dd977e8..e18945259 100644 --- a/framework/core/src/Core/Post/RegisteredTypesScope.php +++ b/framework/core/src/Post/RegisteredTypesScope.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Post; +namespace Flarum\Post; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 9849b2d88..dfb81d60d 100755 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -21,7 +21,7 @@ use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; use Flarum\Event\CheckUserPassword; use Flarum\Event\ConfigureUserPreferences; -use Flarum\Event\PostWasDeleted; +use Flarum\Post\Event\Deleted; use Flarum\Event\PrepareUserGroups; use Flarum\User\Event\AvatarChanged; use Flarum\User\Event\BioChanged; @@ -136,7 +136,7 @@ class User extends AbstractModel $posts = $user->posts()->allTypes(); foreach ($posts->get() as $post) { - $user->raise(new PostWasDeleted($post)); + $user->raise(new Deleted($post)); } $posts->delete(); @@ -603,7 +603,7 @@ class User extends AbstractModel */ public function posts() { - return $this->hasMany('Flarum\Core\Post'); + return $this->hasMany('Flarum\Post\Post'); } /** diff --git a/framework/core/src/User/UserMetadataUpdater.php b/framework/core/src/User/UserMetadataUpdater.php index 3d5e9ad5b..3e8af5404 100755 --- a/framework/core/src/User/UserMetadataUpdater.php +++ b/framework/core/src/User/UserMetadataUpdater.php @@ -15,10 +15,10 @@ 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\Post\Event\Deleted; +use Flarum\Post\Event\Hidden; +use Flarum\Post\Event\Posted; +use Flarum\Post\Event\Restored; use Illuminate\Contracts\Events\Dispatcher; class UserMetadataUpdater @@ -28,42 +28,42 @@ 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(Posted::class, [$this, 'whenPostWasPosted']); + $events->listen(Deleted::class, [$this, 'whenPostWasDeleted']); + $events->listen(Hidden::class, [$this, 'whenPostWasHidden']); + $events->listen(Restored::class, [$this, 'whenPostWasRestored']); $events->listen(DiscussionWasStarted::class, [$this, 'whenDiscussionWasStarted']); $events->listen(DiscussionWasDeleted::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(Deleted $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); } diff --git a/framework/core/tests/Flarum/Api/Handler/FloodingExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/FloodingExceptionHandlerTest.php index 6a70a96bc..3abfbeade 100644 --- a/framework/core/tests/Flarum/Api/Handler/FloodingExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/FloodingExceptionHandlerTest.php @@ -13,7 +13,7 @@ namespace Tests\Flarum\Api\Handler; use Exception; use Flarum\Api\ExceptionHandler\FloodingExceptionHandler; -use Flarum\Core\Exception\FloodingException; +use Flarum\Post\Exception\FloodingException; use Tests\Test\TestCase; class FloodingExceptionHandlerTest extends TestCase From 3c76ed57862ef6bc111392c84a99938b612707c8 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 13:48:04 +0200 Subject: [PATCH 022/172] Extract new Flarum\Discussion namespace --- .../Controller/ListDiscussionsController.php | 2 +- .../ListNotificationsController.php | 2 +- .../Controller/ShowDiscussionController.php | 8 +++---- .../Serializer/BasicDiscussionSerializer.php | 2 +- .../Api/Serializer/DiscussionSerializer.php | 2 +- .../Core/Command/DeleteDiscussionHandler.php | 10 ++++---- .../Core/Command/EditDiscussionHandler.php | 10 ++++---- .../src/Core/Command/PostReplyHandler.php | 2 +- .../Core/Command/ReadDiscussionHandler.php | 6 ++--- .../Core/Command/StartDiscussionHandler.php | 12 +++++----- .../core/src/Core/CoreServiceProvider.php | 6 ++--- framework/core/src/Core/DiscussionState.php | 7 +++--- framework/core/src/Core/Notification.php | 2 +- .../DiscussionRenamedBlueprint.php | 2 +- .../src/Core/Search/SearchServiceProvider.php | 16 ++++++------- .../src/{Core => Discussion}/Discussion.php | 23 ++++++++++--------- .../DiscussionMetadataUpdater.php | 2 +- .../DiscussionPolicy.php | 8 +++---- .../DiscussionRenamedNotifier.php | 10 ++++---- .../DiscussionRepository.php | 5 ++-- .../DiscussionValidator.php | 2 +- .../Event/Deleted.php} | 10 ++++---- .../Event/Deleting.php} | 6 ++--- .../Event/Hidden.php} | 10 ++++---- .../Event/Renamed.php} | 8 +++---- .../Event/Restored.php} | 10 ++++---- .../Event/Saving.php} | 10 ++++---- .../Event/Started.php} | 10 ++++---- .../Event/UserDataSaving.php} | 4 ++-- .../Event/UserRead.php} | 4 ++-- .../Search}/DiscussionSearch.php | 2 +- .../Search}/DiscussionSearcher.php | 7 +++--- .../Search}/Fulltext/DriverInterface.php | 2 +- .../Search}/Fulltext/MySqlFulltextDriver.php | 2 +- .../Search}/Gambit/AuthorGambit.php | 4 ++-- .../Search}/Gambit/CreatedGambit.php | 4 ++-- .../Search}/Gambit/FulltextGambit.php | 10 ++++---- .../Search}/Gambit/HiddenGambit.php | 4 ++-- .../Search}/Gambit/UnreadGambit.php | 10 ++++---- .../src/Event/ConfigureDiscussionSearch.php | 2 +- .../core/src/Event/ScopePostVisibility.php | 4 ++-- .../src/Event/ScopePrivatePostVisibility.php | 6 ++--- framework/core/src/Post/Post.php | 4 ++-- framework/core/src/Post/PostRepository.php | 2 +- framework/core/src/User/User.php | 2 +- .../core/src/User/UserMetadataUpdater.php | 20 ++++++++-------- 46 files changed, 149 insertions(+), 147 deletions(-) rename framework/core/src/{Core => Discussion}/Discussion.php (95%) rename framework/core/src/{Core/Listener => Discussion}/DiscussionMetadataUpdater.php (98%) rename framework/core/src/{Core/Access => Discussion}/DiscussionPolicy.php (94%) rename framework/core/src/{Core/Listener => Discussion}/DiscussionRenamedNotifier.php (83%) rename framework/core/src/{Core/Repository => Discussion}/DiscussionRepository.php (94%) rename framework/core/src/{Core/Validator => Discussion}/DiscussionValidator.php (93%) rename framework/core/src/{Event/DiscussionWasDeleted.php => Discussion/Event/Deleted.php} (75%) rename framework/core/src/{Event/DiscussionWillBeDeleted.php => Discussion/Event/Deleting.php} (91%) rename framework/core/src/{Event/DiscussionWasStarted.php => Discussion/Event/Hidden.php} (75%) rename framework/core/src/{Event/DiscussionWasRenamed.php => Discussion/Event/Renamed.php} (83%) rename framework/core/src/{Event/DiscussionWasRestored.php => Discussion/Event/Restored.php} (75%) rename framework/core/src/{Event/DiscussionWillBeSaved.php => Discussion/Event/Saving.php} (82%) rename framework/core/src/{Event/DiscussionWasHidden.php => Discussion/Event/Started.php} (75%) rename framework/core/src/{Event/DiscussionStateWillBeSaved.php => Discussion/Event/UserDataSaving.php} (89%) rename framework/core/src/{Event/DiscussionWasRead.php => Discussion/Event/UserRead.php} (90%) rename framework/core/src/{Core/Search/Discussion => Discussion/Search}/DiscussionSearch.php (96%) rename framework/core/src/{Core/Search/Discussion => Discussion/Search}/DiscussionSearcher.php (96%) rename framework/core/src/{Core/Search/Discussion => Discussion/Search}/Fulltext/DriverInterface.php (90%) rename framework/core/src/{Core/Search/Discussion => Discussion/Search}/Fulltext/MySqlFulltextDriver.php (94%) rename framework/core/src/{Core/Search/Discussion => Discussion/Search}/Gambit/AuthorGambit.php (93%) rename framework/core/src/{Core/Search/Discussion => Discussion/Search}/Gambit/CreatedGambit.php (93%) rename framework/core/src/{Core/Search/Discussion => Discussion/Search}/Gambit/FulltextGambit.php (79%) rename framework/core/src/{Core/Search/Discussion => Discussion/Search}/Gambit/HiddenGambit.php (91%) rename framework/core/src/{Core/Search/Discussion => Discussion/Search}/Gambit/UnreadGambit.php (85%) diff --git a/framework/core/src/Api/Controller/ListDiscussionsController.php b/framework/core/src/Api/Controller/ListDiscussionsController.php index c39d2d6a4..a1acdb651 100644 --- a/framework/core/src/Api/Controller/ListDiscussionsController.php +++ b/framework/core/src/Api/Controller/ListDiscussionsController.php @@ -12,7 +12,7 @@ namespace Flarum\Api\Controller; use Flarum\Api\UrlGenerator; -use Flarum\Core\Search\Discussion\DiscussionSearcher; +use Flarum\Discussion\Search\DiscussionSearcher; use Flarum\Core\Search\SearchCriteria; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; diff --git a/framework/core/src/Api/Controller/ListNotificationsController.php b/framework/core/src/Api/Controller/ListNotificationsController.php index c1681d645..c167498fe 100644 --- a/framework/core/src/Api/Controller/ListNotificationsController.php +++ b/framework/core/src/Api/Controller/ListNotificationsController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Discussion; +use Flarum\Discussion\Discussion; use Flarum\User\Exception\PermissionDeniedException; use Flarum\Core\Repository\NotificationRepository; use Psr\Http\Message\ServerRequestInterface; diff --git a/framework/core/src/Api/Controller/ShowDiscussionController.php b/framework/core/src/Api/Controller/ShowDiscussionController.php index 171ddc8e4..4ee73d225 100644 --- a/framework/core/src/Api/Controller/ShowDiscussionController.php +++ b/framework/core/src/Api/Controller/ShowDiscussionController.php @@ -11,8 +11,8 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Discussion; -use Flarum\Core\Repository\DiscussionRepository; +use Flarum\Discussion\Discussion; +use Flarum\Discussion\DiscussionRepository; use Flarum\Post\PostRepository; use Flarum\User\User; use Psr\Http\Message\ServerRequestInterface; @@ -21,7 +21,7 @@ use Tobscure\JsonApi\Document; class ShowDiscussionController extends AbstractShowController { /** - * @var DiscussionRepository + * @var \Flarum\Discussion\DiscussionRepository */ protected $discussions; @@ -58,7 +58,7 @@ class ShowDiscussionController extends AbstractShowController ]; /** - * @param \Flarum\Core\Repository\DiscussionRepository $discussions + * @param \Flarum\Discussion\DiscussionRepository $discussions * @param \Flarum\Post\PostRepository $posts */ public function __construct(DiscussionRepository $discussions, PostRepository $posts) diff --git a/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php b/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php index 1fb175601..a82c9c7b7 100644 --- a/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php +++ b/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Serializer; -use Flarum\Core\Discussion; +use Flarum\Discussion\Discussion; use InvalidArgumentException; class BasicDiscussionSerializer extends AbstractSerializer diff --git a/framework/core/src/Api/Serializer/DiscussionSerializer.php b/framework/core/src/Api/Serializer/DiscussionSerializer.php index 96704df22..17c43e970 100644 --- a/framework/core/src/Api/Serializer/DiscussionSerializer.php +++ b/framework/core/src/Api/Serializer/DiscussionSerializer.php @@ -12,7 +12,7 @@ namespace Flarum\Api\Serializer; use Flarum\User\Gate; -use Flarum\Core\Discussion; +use Flarum\Discussion\Discussion; class DiscussionSerializer extends BasicDiscussionSerializer { diff --git a/framework/core/src/Core/Command/DeleteDiscussionHandler.php b/framework/core/src/Core/Command/DeleteDiscussionHandler.php index 459432041..4665db213 100644 --- a/framework/core/src/Core/Command/DeleteDiscussionHandler.php +++ b/framework/core/src/Core/Command/DeleteDiscussionHandler.php @@ -13,9 +13,9 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; -use Flarum\Core\Repository\DiscussionRepository; +use Flarum\Discussion\DiscussionRepository; use Flarum\Foundation\DispatchEventsTrait; -use Flarum\Event\DiscussionWillBeDeleted; +use Flarum\Discussion\Event\Deleting; 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/EditDiscussionHandler.php b/framework/core/src/Core/Command/EditDiscussionHandler.php index 6f8e7bada..bce27933e 100644 --- a/framework/core/src/Core/Command/EditDiscussionHandler.php +++ b/framework/core/src/Core/Command/EditDiscussionHandler.php @@ -13,10 +13,10 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; -use Flarum\Core\Repository\DiscussionRepository; +use Flarum\Discussion\DiscussionRepository; use Flarum\Foundation\DispatchEventsTrait; -use Flarum\Core\Validator\DiscussionValidator; -use Flarum\Event\DiscussionWillBeSaved; +use Flarum\Discussion\DiscussionValidator; +use Flarum\Discussion\Event\Saving; use Illuminate\Contracts\Events\Dispatcher; class EditDiscussionHandler @@ -48,7 +48,7 @@ class EditDiscussionHandler /** * @param EditDiscussion $command - * @return \Flarum\Core\Discussion + * @return \Flarum\Discussion\Discussion * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(EditDiscussion $command) @@ -76,7 +76,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/PostReplyHandler.php b/framework/core/src/Core/Command/PostReplyHandler.php index a6b327b6d..cb51c4fda 100644 --- a/framework/core/src/Core/Command/PostReplyHandler.php +++ b/framework/core/src/Core/Command/PostReplyHandler.php @@ -15,7 +15,7 @@ use DateTime; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\Core\Notification\NotificationSyncer; use Flarum\Post\CommentPost; -use Flarum\Core\Repository\DiscussionRepository; +use Flarum\Discussion\DiscussionRepository; use Flarum\Foundation\DispatchEventsTrait; use Flarum\Post\PostValidator; use Flarum\Post\Event\Saving; diff --git a/framework/core/src/Core/Command/ReadDiscussionHandler.php b/framework/core/src/Core/Command/ReadDiscussionHandler.php index 0166b1439..42e4722ea 100644 --- a/framework/core/src/Core/Command/ReadDiscussionHandler.php +++ b/framework/core/src/Core/Command/ReadDiscussionHandler.php @@ -12,9 +12,9 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Repository\DiscussionRepository; +use Flarum\Discussion\DiscussionRepository; use Flarum\Foundation\DispatchEventsTrait; -use Flarum\Event\DiscussionStateWillBeSaved; +use Flarum\Discussion\Event\UserDataSaving; use Illuminate\Contracts\Events\Dispatcher; class ReadDiscussionHandler @@ -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/StartDiscussionHandler.php b/framework/core/src/Core/Command/StartDiscussionHandler.php index e3f916f61..bad252625 100644 --- a/framework/core/src/Core/Command/StartDiscussionHandler.php +++ b/framework/core/src/Core/Command/StartDiscussionHandler.php @@ -13,10 +13,10 @@ namespace Flarum\Core\Command; use Exception; use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Discussion; +use Flarum\Discussion\Discussion; use Flarum\Foundation\DispatchEventsTrait; -use Flarum\Core\Validator\DiscussionValidator; -use Flarum\Event\DiscussionWillBeSaved; +use Flarum\Discussion\DiscussionValidator; +use Flarum\Discussion\Event\Saving; use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher; use Illuminate\Contracts\Events\Dispatcher as EventDispatcher; @@ -31,14 +31,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 +70,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/CoreServiceProvider.php b/framework/core/src/Core/CoreServiceProvider.php index c3234f488..106201d86 100644 --- a/framework/core/src/Core/CoreServiceProvider.php +++ b/framework/core/src/Core/CoreServiceProvider.php @@ -107,13 +107,13 @@ class CoreServiceProvider extends AbstractServiceProvider $events = $this->app->make('events'); $events->subscribe('Flarum\Core\Listener\SelfDemotionGuard'); - $events->subscribe('Flarum\Core\Listener\DiscussionMetadataUpdater'); + $events->subscribe('Flarum\Discussion\DiscussionMetadataUpdater'); $events->subscribe('Flarum\User\UserMetadataUpdater'); $events->subscribe('Flarum\Core\Listener\ExtensionValidator'); $events->subscribe('Flarum\User\EmailConfirmationMailer'); - $events->subscribe('Flarum\Core\Listener\DiscussionRenamedNotifier'); + $events->subscribe('Flarum\Discussion\DiscussionRenamedNotifier'); - $events->subscribe('Flarum\Core\Access\DiscussionPolicy'); + $events->subscribe('Flarum\Discussion\DiscussionPolicy'); $events->subscribe('Flarum\Core\Access\GroupPolicy'); $events->subscribe('Flarum\Post\PostPolicy'); $events->subscribe('Flarum\User\UserPolicy'); diff --git a/framework/core/src/Core/DiscussionState.php b/framework/core/src/Core/DiscussionState.php index 15b2e2142..be5e246fc 100644 --- a/framework/core/src/Core/DiscussionState.php +++ b/framework/core/src/Core/DiscussionState.php @@ -11,9 +11,10 @@ namespace Flarum\Core; +use Flarum\Discussion\Discussion; use Flarum\Foundation\EventGeneratorTrait; use Flarum\Database\AbstractModel; -use Flarum\Event\DiscussionWasRead; +use Flarum\Discussion\Event\UserRead; use Illuminate\Database\Eloquent\Builder; /** @@ -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('Flarum\Discussion\Discussion', 'discussion_id'); } /** diff --git a/framework/core/src/Core/Notification.php b/framework/core/src/Core/Notification.php index 0d429998b..4429cc4b3 100644 --- a/framework/core/src/Core/Notification.php +++ b/framework/core/src/Core/Notification.php @@ -56,7 +56,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 */ diff --git a/framework/core/src/Core/Notification/DiscussionRenamedBlueprint.php b/framework/core/src/Core/Notification/DiscussionRenamedBlueprint.php index b47cac1f9..b642d82b9 100644 --- a/framework/core/src/Core/Notification/DiscussionRenamedBlueprint.php +++ b/framework/core/src/Core/Notification/DiscussionRenamedBlueprint.php @@ -65,6 +65,6 @@ class DiscussionRenamedBlueprint implements BlueprintInterface */ public static function getSubjectModel() { - return 'Flarum\Core\Discussion'; + return 'Flarum\Discussion\Discussion'; } } diff --git a/framework/core/src/Core/Search/SearchServiceProvider.php b/framework/core/src/Core/Search/SearchServiceProvider.php index 82172abb4..554a6bd7b 100644 --- a/framework/core/src/Core/Search/SearchServiceProvider.php +++ b/framework/core/src/Core/Search/SearchServiceProvider.php @@ -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(); @@ -56,16 +56,16 @@ class SearchServiceProvider extends AbstractServiceProvider public function registerDiscussionGambits() { - $this->app->when('Flarum\Core\Search\Discussion\DiscussionSearcher') + $this->app->when('Flarum\Discussion\Search\DiscussionSearcher') ->needs('Flarum\Core\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/Core/Discussion.php b/framework/core/src/Discussion/Discussion.php similarity index 95% rename from framework/core/src/Core/Discussion.php rename to framework/core/src/Discussion/Discussion.php index d185e8440..34122fd90 100644 --- a/framework/core/src/Core/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -9,17 +9,18 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\Discussion; +use Flarum\Core\DiscussionState; use Flarum\Post\MergeableInterface; use Flarum\Foundation\EventGeneratorTrait; use Flarum\Database\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\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\Post\Event\Deleted; use Flarum\Event\ScopePostVisibility; use Flarum\Post\Post; @@ -102,7 +103,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 @@ -138,7 +139,7 @@ class Discussion extends AbstractModel $discussion->setRelation('startUser', $user); - $discussion->raise(new DiscussionWasStarted($discussion)); + $discussion->raise(new Started($discussion)); return $discussion; } @@ -155,7 +156,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; @@ -173,7 +174,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; @@ -190,7 +191,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; diff --git a/framework/core/src/Core/Listener/DiscussionMetadataUpdater.php b/framework/core/src/Discussion/DiscussionMetadataUpdater.php similarity index 98% rename from framework/core/src/Core/Listener/DiscussionMetadataUpdater.php rename to framework/core/src/Discussion/DiscussionMetadataUpdater.php index ea05dba72..123d8d8c0 100755 --- a/framework/core/src/Core/Listener/DiscussionMetadataUpdater.php +++ b/framework/core/src/Discussion/DiscussionMetadataUpdater.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Listener; +namespace Flarum\Discussion; use Flarum\Post\Post; use Flarum\Post\Event\Deleted; diff --git a/framework/core/src/Core/Access/DiscussionPolicy.php b/framework/core/src/Discussion/DiscussionPolicy.php similarity index 94% rename from framework/core/src/Core/Access/DiscussionPolicy.php rename to framework/core/src/Discussion/DiscussionPolicy.php index 50f00a387..b43345727 100644 --- a/framework/core/src/Core/Access/DiscussionPolicy.php +++ b/framework/core/src/Discussion/DiscussionPolicy.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Access; +namespace Flarum\Discussion; use Carbon\Carbon; -use Flarum\Core\Discussion; +use Flarum\Discussion\Discussion; use Flarum\Event\ScopeHiddenDiscussionVisibility; use Flarum\Event\ScopePrivateDiscussionVisibility; use Flarum\Settings\SettingsRepositoryInterface; @@ -100,7 +100,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) @@ -118,7 +118,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/DiscussionRenamedNotifier.php similarity index 83% rename from framework/core/src/Core/Listener/DiscussionRenamedNotifier.php rename to framework/core/src/Discussion/DiscussionRenamedNotifier.php index 1357b1948..2cd8bdc9c 100755 --- a/framework/core/src/Core/Listener/DiscussionRenamedNotifier.php +++ b/framework/core/src/Discussion/DiscussionRenamedNotifier.php @@ -9,12 +9,12 @@ * 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\Post\DiscussionRenamedPost; -use Flarum\Event\DiscussionWasRenamed; +use Flarum\Discussion\Event\Renamed; use Illuminate\Contracts\Events\Dispatcher; class DiscussionRenamedNotifier @@ -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 94% rename from framework/core/src/Core/Repository/DiscussionRepository.php rename to framework/core/src/Discussion/DiscussionRepository.php index add4f2b30..11c64664a 100644 --- a/framework/core/src/Core/Repository/DiscussionRepository.php +++ b/framework/core/src/Discussion/DiscussionRepository.php @@ -9,9 +9,8 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Repository; +namespace Flarum\Discussion; -use Flarum\Core\Discussion; 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) { diff --git a/framework/core/src/Core/Validator/DiscussionValidator.php b/framework/core/src/Discussion/DiscussionValidator.php similarity index 93% rename from framework/core/src/Core/Validator/DiscussionValidator.php rename to framework/core/src/Discussion/DiscussionValidator.php index 2c2a90818..1511cd55d 100644 --- a/framework/core/src/Core/Validator/DiscussionValidator.php +++ b/framework/core/src/Discussion/DiscussionValidator.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Validator; +namespace Flarum\Discussion; use Flarum\Foundation\AbstractValidator; diff --git a/framework/core/src/Event/DiscussionWasDeleted.php b/framework/core/src/Discussion/Event/Deleted.php similarity index 75% rename from framework/core/src/Event/DiscussionWasDeleted.php rename to framework/core/src/Discussion/Event/Deleted.php index f57193918..d4b21bf87 100644 --- a/framework/core/src/Event/DiscussionWasDeleted.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\Discussion\Discussion; use Flarum\User\User; -class DiscussionWasDeleted +class Deleted { /** - * @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/DiscussionWillBeDeleted.php b/framework/core/src/Discussion/Event/Deleting.php similarity index 91% rename from framework/core/src/Event/DiscussionWillBeDeleted.php rename to framework/core/src/Discussion/Event/Deleting.php index d70e399fe..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\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/DiscussionWasStarted.php b/framework/core/src/Discussion/Event/Hidden.php similarity index 75% rename from framework/core/src/Event/DiscussionWasStarted.php rename to framework/core/src/Discussion/Event/Hidden.php index b35ed7851..6a2095a74 100644 --- a/framework/core/src/Event/DiscussionWasStarted.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\Discussion\Discussion; use Flarum\User\User; -class DiscussionWasStarted +class Hidden { /** - * @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/DiscussionWasRenamed.php b/framework/core/src/Discussion/Event/Renamed.php similarity index 83% rename from framework/core/src/Event/DiscussionWasRenamed.php rename to framework/core/src/Discussion/Event/Renamed.php index 7d71a20ed..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\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/DiscussionWasRestored.php b/framework/core/src/Discussion/Event/Restored.php similarity index 75% rename from framework/core/src/Event/DiscussionWasRestored.php rename to framework/core/src/Discussion/Event/Restored.php index 22135b6ee..eb276e755 100644 --- a/framework/core/src/Event/DiscussionWasRestored.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\Discussion\Discussion; use Flarum\User\User; -class DiscussionWasRestored +class Restored { /** - * @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/DiscussionWillBeSaved.php b/framework/core/src/Discussion/Event/Saving.php similarity index 82% rename from framework/core/src/Event/DiscussionWillBeSaved.php rename to framework/core/src/Discussion/Event/Saving.php index 3d15ff4cc..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\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/DiscussionWasHidden.php b/framework/core/src/Discussion/Event/Started.php similarity index 75% rename from framework/core/src/Event/DiscussionWasHidden.php rename to framework/core/src/Discussion/Event/Started.php index b99b3e03b..ddb640662 100644 --- a/framework/core/src/Event/DiscussionWasHidden.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\Discussion\Discussion; use Flarum\User\User; -class DiscussionWasHidden +class Started { /** - * @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/DiscussionStateWillBeSaved.php b/framework/core/src/Discussion/Event/UserDataSaving.php similarity index 89% rename from framework/core/src/Event/DiscussionStateWillBeSaved.php rename to framework/core/src/Discussion/Event/UserDataSaving.php index 05ddd45cc..1574b44b6 100644 --- a/framework/core/src/Event/DiscussionStateWillBeSaved.php +++ b/framework/core/src/Discussion/Event/UserDataSaving.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Discussion\Event; use Flarum\Core\DiscussionState; -class DiscussionStateWillBeSaved +class UserDataSaving { /** * @var DiscussionState diff --git a/framework/core/src/Event/DiscussionWasRead.php b/framework/core/src/Discussion/Event/UserRead.php similarity index 90% rename from framework/core/src/Event/DiscussionWasRead.php rename to framework/core/src/Discussion/Event/UserRead.php index cf8936310..8baf3fc31 100644 --- a/framework/core/src/Event/DiscussionWasRead.php +++ b/framework/core/src/Discussion/Event/UserRead.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Discussion\Event; use Flarum\Core\DiscussionState; -class DiscussionWasRead +class UserRead { /** * @var DiscussionState diff --git a/framework/core/src/Core/Search/Discussion/DiscussionSearch.php b/framework/core/src/Discussion/Search/DiscussionSearch.php similarity index 96% rename from framework/core/src/Core/Search/Discussion/DiscussionSearch.php rename to framework/core/src/Discussion/Search/DiscussionSearch.php index 8b1324cf8..bde618ef1 100644 --- a/framework/core/src/Core/Search/Discussion/DiscussionSearch.php +++ b/framework/core/src/Discussion/Search/DiscussionSearch.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\Discussion; +namespace Flarum\Discussion\Search; use Flarum\Core\Search\AbstractSearch; diff --git a/framework/core/src/Core/Search/Discussion/DiscussionSearcher.php b/framework/core/src/Discussion/Search/DiscussionSearcher.php similarity index 96% rename from framework/core/src/Core/Search/Discussion/DiscussionSearcher.php rename to framework/core/src/Discussion/Search/DiscussionSearcher.php index f606d99c2..aacce651d 100644 --- a/framework/core/src/Core/Search/Discussion/DiscussionSearcher.php +++ b/framework/core/src/Discussion/Search/DiscussionSearcher.php @@ -9,10 +9,11 @@ * 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\Discussion\Discussion; +use Flarum\Discussion\DiscussionRepository; +use Flarum\Discussion\Search\DiscussionSearch; use Flarum\Post\PostRepository; use Flarum\Core\Search\ApplySearchParametersTrait; use Flarum\Core\Search\GambitManager; 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 94% rename from framework/core/src/Core/Search/Discussion/Fulltext/MySqlFulltextDriver.php rename to framework/core/src/Discussion/Search/Fulltext/MySqlFulltextDriver.php index 402fefc4c..8c71066d6 100644 --- a/framework/core/src/Core/Search/Discussion/Fulltext/MySqlFulltextDriver.php +++ b/framework/core/src/Discussion/Search/Fulltext/MySqlFulltextDriver.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search\Discussion\Fulltext; +namespace Flarum\Discussion\Search\Fulltext; use Flarum\Core\Post; diff --git a/framework/core/src/Core/Search/Discussion/Gambit/AuthorGambit.php b/framework/core/src/Discussion/Search/Gambit/AuthorGambit.php similarity index 93% rename from framework/core/src/Core/Search/Discussion/Gambit/AuthorGambit.php rename to framework/core/src/Discussion/Search/Gambit/AuthorGambit.php index d1336efec..10492e981 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\User\UserRepository; use Flarum\Core\Search\AbstractRegexGambit; use Flarum\Core\Search\AbstractSearch; -use Flarum\Core\Search\Discussion\DiscussionSearch; +use Flarum\Discussion\Search\DiscussionSearch; use LogicException; class AuthorGambit extends AbstractRegexGambit diff --git a/framework/core/src/Core/Search/Discussion/Gambit/CreatedGambit.php b/framework/core/src/Discussion/Search/Gambit/CreatedGambit.php similarity index 93% rename from framework/core/src/Core/Search/Discussion/Gambit/CreatedGambit.php rename to framework/core/src/Discussion/Search/Gambit/CreatedGambit.php index e47bedfc4..244930d45 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 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 79% rename from framework/core/src/Core/Search/Discussion/Gambit/FulltextGambit.php rename to framework/core/src/Discussion/Search/Gambit/FulltextGambit.php index 6531ba915..f28ccf412 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\Discussion\Search\DiscussionSearch; +use Flarum\Discussion\Search\Fulltext\DriverInterface; use Flarum\Core\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 91% rename from framework/core/src/Core/Search/Discussion/Gambit/HiddenGambit.php rename to framework/core/src/Discussion/Search/Gambit/HiddenGambit.php index c27bf457a..99c544741 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 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 85% rename from framework/core/src/Core/Search/Discussion/Gambit/UnreadGambit.php rename to framework/core/src/Discussion/Search/Gambit/UnreadGambit.php index 9c7890095..29f3b2f10 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\Discussion\DiscussionRepository; use Flarum\Core\Search\AbstractRegexGambit; use Flarum\Core\Search\AbstractSearch; -use Flarum\Core\Search\Discussion\DiscussionSearch; +use Flarum\Discussion\Search\DiscussionSearch; 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/Event/ConfigureDiscussionSearch.php b/framework/core/src/Event/ConfigureDiscussionSearch.php index 90ff9b1a0..f86d29fea 100644 --- a/framework/core/src/Event/ConfigureDiscussionSearch.php +++ b/framework/core/src/Event/ConfigureDiscussionSearch.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Core\Search\Discussion\DiscussionSearch; +use Flarum\Discussion\Search\DiscussionSearch; use Flarum\Core\Search\SearchCriteria; class ConfigureDiscussionSearch diff --git a/framework/core/src/Event/ScopePostVisibility.php b/framework/core/src/Event/ScopePostVisibility.php index 16c488903..d8d2304e2 100644 --- a/framework/core/src/Event/ScopePostVisibility.php +++ b/framework/core/src/Event/ScopePostVisibility.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Core\Discussion; +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/ScopePrivatePostVisibility.php b/framework/core/src/Event/ScopePrivatePostVisibility.php index 1339e5f27..bb84cda39 100644 --- a/framework/core/src/Event/ScopePrivatePostVisibility.php +++ b/framework/core/src/Event/ScopePrivatePostVisibility.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Core\Discussion; +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/Post/Post.php b/framework/core/src/Post/Post.php index ab081b6a6..468a708fb 100755 --- a/framework/core/src/Post/Post.php +++ b/framework/core/src/Post/Post.php @@ -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 @@ -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'); } /** diff --git a/framework/core/src/Post/PostRepository.php b/framework/core/src/Post/PostRepository.php index b9560be91..a43ce300c 100644 --- a/framework/core/src/Post/PostRepository.php +++ b/framework/core/src/Post/PostRepository.php @@ -11,7 +11,7 @@ namespace Flarum\Post; -use Flarum\Core\Discussion; +use Flarum\Discussion\Discussion; use Flarum\Event\ScopePostVisibility; use Flarum\User\User; use Illuminate\Database\Eloquent\ModelNotFoundException; diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index dfb81d60d..f85470449 100755 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -613,7 +613,7 @@ class User extends AbstractModel */ public function read() { - return $this->belongsToMany('Flarum\Core\Discussion', 'users_discussions'); + return $this->belongsToMany('Flarum\Discussion\Discussion', 'users_discussions'); } /** diff --git a/framework/core/src/User/UserMetadataUpdater.php b/framework/core/src/User/UserMetadataUpdater.php index 3e8af5404..3cf33979a 100755 --- a/framework/core/src/User/UserMetadataUpdater.php +++ b/framework/core/src/User/UserMetadataUpdater.php @@ -11,10 +11,10 @@ namespace Flarum\User; -use Flarum\Core\Discussion; +use Flarum\Discussion\Discussion; use Flarum\Core\Post; -use Flarum\Event\DiscussionWasDeleted; -use Flarum\Event\DiscussionWasStarted; +use Flarum\Discussion\Event\Deleted; +use Flarum\Discussion\Event\Started; use Flarum\Post\Event\Deleted; use Flarum\Post\Event\Hidden; use Flarum\Post\Event\Posted; @@ -32,8 +32,8 @@ class UserMetadataUpdater $events->listen(Deleted::class, [$this, 'whenPostWasDeleted']); $events->listen(Hidden::class, [$this, 'whenPostWasHidden']); $events->listen(Restored::class, [$this, 'whenPostWasRestored']); - $events->listen(DiscussionWasStarted::class, [$this, 'whenDiscussionWasStarted']); - $events->listen(DiscussionWasDeleted::class, [$this, 'whenDiscussionWasDeleted']); + $events->listen(Started::class, [$this, 'whenDiscussionWasStarted']); + $events->listen(Deleted::class, [$this, 'whenDiscussionWasDeleted']); } /** @@ -69,17 +69,17 @@ class UserMetadataUpdater } /** - * @param \Flarum\Event\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(Deleted $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) From 23c9acdf44d6dfddb74fb4b966e8de13135e10ca Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 13:59:50 +0200 Subject: [PATCH 023/172] Extract Flarum\Search namespace --- .../Controller/ListDiscussionsController.php | 2 +- .../Api/Controller/ListUsersController.php | 2 +- .../core/src/Core/CoreServiceProvider.php | 2 +- .../Discussion/Search/DiscussionSearch.php | 2 +- .../Discussion/Search/DiscussionSearcher.php | 20 +++++++++---------- .../Discussion/Search/Gambit/AuthorGambit.php | 4 ++-- .../Search/Gambit/CreatedGambit.php | 4 ++-- .../Search/Gambit/FulltextGambit.php | 4 ++-- .../Discussion/Search/Gambit/HiddenGambit.php | 4 ++-- .../Discussion/Search/Gambit/UnreadGambit.php | 4 ++-- .../src/Event/AbstractConfigureGambits.php | 4 ++-- .../src/Event/ConfigureDiscussionSearch.php | 6 +++--- .../core/src/Event/ConfigureUserSearch.php | 2 +- .../{Core => }/Search/AbstractRegexGambit.php | 2 +- .../src/{Core => }/Search/AbstractSearch.php | 2 +- .../Search/ApplySearchParametersTrait.php | 2 +- .../src/{Core => }/Search/GambitInterface.php | 2 +- .../src/{Core => }/Search/GambitManager.php | 2 +- .../src/{Core => }/Search/SearchCriteria.php | 2 +- .../src/{Core => }/Search/SearchResults.php | 2 +- .../Search/SearchServiceProvider.php | 6 +++--- .../src/User/Search/Gambit/EmailGambit.php | 4 ++-- .../src/User/Search/Gambit/FulltextGambit.php | 4 ++-- .../src/User/Search/Gambit/GroupGambit.php | 4 ++-- framework/core/src/User/Search/UserSearch.php | 2 +- .../core/src/User/Search/UserSearcher.php | 20 +++++++++---------- 26 files changed, 57 insertions(+), 57 deletions(-) rename framework/core/src/{Core => }/Search/AbstractRegexGambit.php (97%) rename framework/core/src/{Core => }/Search/AbstractSearch.php (98%) rename framework/core/src/{Core => }/Search/ApplySearchParametersTrait.php (97%) rename framework/core/src/{Core => }/Search/GambitInterface.php (95%) rename framework/core/src/{Core => }/Search/GambitManager.php (99%) rename framework/core/src/{Core => }/Search/SearchCriteria.php (97%) rename framework/core/src/{Core => }/Search/SearchResults.php (96%) rename framework/core/src/{Core => }/Search/SearchServiceProvider.php (94%) diff --git a/framework/core/src/Api/Controller/ListDiscussionsController.php b/framework/core/src/Api/Controller/ListDiscussionsController.php index a1acdb651..d69e07de6 100644 --- a/framework/core/src/Api/Controller/ListDiscussionsController.php +++ b/framework/core/src/Api/Controller/ListDiscussionsController.php @@ -13,7 +13,7 @@ namespace Flarum\Api\Controller; use Flarum\Api\UrlGenerator; use Flarum\Discussion\Search\DiscussionSearcher; -use Flarum\Core\Search\SearchCriteria; +use Flarum\Search\SearchCriteria; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; diff --git a/framework/core/src/Api/Controller/ListUsersController.php b/framework/core/src/Api/Controller/ListUsersController.php index 7d1f6526f..1dadbb103 100644 --- a/framework/core/src/Api/Controller/ListUsersController.php +++ b/framework/core/src/Api/Controller/ListUsersController.php @@ -13,7 +13,7 @@ namespace Flarum\Api\Controller; use Flarum\Api\UrlGenerator; use Flarum\User\Exception\PermissionDeniedException; -use Flarum\Core\Search\SearchCriteria; +use Flarum\Search\SearchCriteria; use Flarum\Core\User\Search\UserSearcher; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; diff --git a/framework/core/src/Core/CoreServiceProvider.php b/framework/core/src/Core/CoreServiceProvider.php index 106201d86..088733ce8 100644 --- a/framework/core/src/Core/CoreServiceProvider.php +++ b/framework/core/src/Core/CoreServiceProvider.php @@ -41,7 +41,7 @@ class CoreServiceProvider extends AbstractServiceProvider $this->registerAvatarsFilesystem(); $this->app->register('Flarum\Core\Notification\NotificationServiceProvider'); - $this->app->register('Flarum\Core\Search\SearchServiceProvider'); + $this->app->register('Flarum\Search\SearchServiceProvider'); $this->app->register('Flarum\Formatter\FormatterServiceProvider'); } diff --git a/framework/core/src/Discussion/Search/DiscussionSearch.php b/framework/core/src/Discussion/Search/DiscussionSearch.php index bde618ef1..8cb886e29 100644 --- a/framework/core/src/Discussion/Search/DiscussionSearch.php +++ b/framework/core/src/Discussion/Search/DiscussionSearch.php @@ -11,7 +11,7 @@ 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/Discussion/Search/DiscussionSearcher.php b/framework/core/src/Discussion/Search/DiscussionSearcher.php index aacce651d..81ac2803a 100644 --- a/framework/core/src/Discussion/Search/DiscussionSearcher.php +++ b/framework/core/src/Discussion/Search/DiscussionSearcher.php @@ -15,10 +15,10 @@ use Flarum\Discussion\Discussion; use Flarum\Discussion\DiscussionRepository; use Flarum\Discussion\Search\DiscussionSearch; use Flarum\Post\PostRepository; -use Flarum\Core\Search\ApplySearchParametersTrait; -use Flarum\Core\Search\GambitManager; -use Flarum\Core\Search\SearchCriteria; -use Flarum\Core\Search\SearchResults; +use Flarum\Search\ApplySearchParametersTrait; +use Flarum\Search\GambitManager; +use Flarum\Search\SearchCriteria; +use Flarum\Search\SearchResults; use Flarum\Event\ConfigureDiscussionSearch; use Illuminate\Database\Eloquent\Collection; @@ -31,7 +31,7 @@ class DiscussionSearcher use ApplySearchParametersTrait; /** - * @var GambitManager + * @var \Flarum\Search\GambitManager */ protected $gambits; @@ -46,7 +46,7 @@ class DiscussionSearcher protected $posts; /** - * @param GambitManager $gambits + * @param \Flarum\Search\GambitManager $gambits * @param DiscussionRepository $discussions * @param PostRepository $posts */ @@ -61,13 +61,13 @@ class DiscussionSearcher } /** - * @param SearchCriteria $criteria + * @param \Flarum\Search\SearchCriteria $criteria * @param int|null $limit * @param int $offset * @param array $load An array of relationships to load on the results. - * @return SearchResults + * @return \Flarum\Search\SearchResults */ - public function search(SearchCriteria $criteria, $limit = null, $offset = 0, array $load = []) + public function search(\Flarum\Search\SearchCriteria $criteria, $limit = null, $offset = 0, array $load = []) { $actor = $criteria->actor; @@ -110,7 +110,7 @@ class DiscussionSearcher Discussion::setStateUser($actor); $discussions->load($load); - return new SearchResults($discussions, $areMoreResults); + return new \Flarum\Search\SearchResults($discussions, $areMoreResults); } /** diff --git a/framework/core/src/Discussion/Search/Gambit/AuthorGambit.php b/framework/core/src/Discussion/Search/Gambit/AuthorGambit.php index 10492e981..15e425512 100644 --- a/framework/core/src/Discussion/Search/Gambit/AuthorGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/AuthorGambit.php @@ -12,8 +12,8 @@ namespace Flarum\Discussion\Search\Gambit; use Flarum\User\UserRepository; -use Flarum\Core\Search\AbstractRegexGambit; -use Flarum\Core\Search\AbstractSearch; +use Flarum\Search\AbstractRegexGambit; +use Flarum\Search\AbstractSearch; use Flarum\Discussion\Search\DiscussionSearch; use LogicException; diff --git a/framework/core/src/Discussion/Search/Gambit/CreatedGambit.php b/framework/core/src/Discussion/Search/Gambit/CreatedGambit.php index 244930d45..0b38fec35 100644 --- a/framework/core/src/Discussion/Search/Gambit/CreatedGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/CreatedGambit.php @@ -11,8 +11,8 @@ namespace Flarum\Discussion\Search\Gambit; -use Flarum\Core\Search\AbstractRegexGambit; -use Flarum\Core\Search\AbstractSearch; +use Flarum\Search\AbstractRegexGambit; +use Flarum\Search\AbstractSearch; use Flarum\Discussion\Search\DiscussionSearch; use LogicException; diff --git a/framework/core/src/Discussion/Search/Gambit/FulltextGambit.php b/framework/core/src/Discussion/Search/Gambit/FulltextGambit.php index f28ccf412..da54f358f 100644 --- a/framework/core/src/Discussion/Search/Gambit/FulltextGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/FulltextGambit.php @@ -11,10 +11,10 @@ namespace Flarum\Discussion\Search\Gambit; -use Flarum\Core\Search\AbstractSearch; +use Flarum\Search\AbstractSearch; use Flarum\Discussion\Search\DiscussionSearch; use Flarum\Discussion\Search\Fulltext\DriverInterface; -use Flarum\Core\Search\GambitInterface; +use Flarum\Search\GambitInterface; use LogicException; class FulltextGambit implements GambitInterface diff --git a/framework/core/src/Discussion/Search/Gambit/HiddenGambit.php b/framework/core/src/Discussion/Search/Gambit/HiddenGambit.php index 99c544741..9bd1c7b24 100644 --- a/framework/core/src/Discussion/Search/Gambit/HiddenGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/HiddenGambit.php @@ -11,8 +11,8 @@ namespace Flarum\Discussion\Search\Gambit; -use Flarum\Core\Search\AbstractRegexGambit; -use Flarum\Core\Search\AbstractSearch; +use Flarum\Search\AbstractRegexGambit; +use Flarum\Search\AbstractSearch; use Flarum\Discussion\Search\DiscussionSearch; use LogicException; diff --git a/framework/core/src/Discussion/Search/Gambit/UnreadGambit.php b/framework/core/src/Discussion/Search/Gambit/UnreadGambit.php index 29f3b2f10..87eb7cfe2 100644 --- a/framework/core/src/Discussion/Search/Gambit/UnreadGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/UnreadGambit.php @@ -12,8 +12,8 @@ namespace Flarum\Discussion\Search\Gambit; use Flarum\Discussion\DiscussionRepository; -use Flarum\Core\Search\AbstractRegexGambit; -use Flarum\Core\Search\AbstractSearch; +use Flarum\Search\AbstractRegexGambit; +use Flarum\Search\AbstractSearch; use Flarum\Discussion\Search\DiscussionSearch; use LogicException; 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/ConfigureDiscussionSearch.php b/framework/core/src/Event/ConfigureDiscussionSearch.php index f86d29fea..2b126046e 100644 --- a/framework/core/src/Event/ConfigureDiscussionSearch.php +++ b/framework/core/src/Event/ConfigureDiscussionSearch.php @@ -12,7 +12,7 @@ namespace Flarum\Event; use Flarum\Discussion\Search\DiscussionSearch; -use Flarum\Core\Search\SearchCriteria; +use Flarum\Search\SearchCriteria; class ConfigureDiscussionSearch { @@ -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/ConfigureUserSearch.php b/framework/core/src/Event/ConfigureUserSearch.php index d32670705..309f60c10 100644 --- a/framework/core/src/Event/ConfigureUserSearch.php +++ b/framework/core/src/Event/ConfigureUserSearch.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Core\Search\SearchCriteria; +use Flarum\Search\SearchCriteria; use Flarum\Core\User\Search\UserSearch; class ConfigureUserSearch 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 98% rename from framework/core/src/Core/Search/AbstractSearch.php rename to framework/core/src/Search/AbstractSearch.php index c4f54250d..23e7c4b78 100644 --- a/framework/core/src/Core/Search/AbstractSearch.php +++ b/framework/core/src/Search/AbstractSearch.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search; +namespace Flarum\Search; 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 97% rename from framework/core/src/Core/Search/SearchCriteria.php rename to framework/core/src/Search/SearchCriteria.php index 567155d8b..be5d598b0 100644 --- a/framework/core/src/Core/Search/SearchCriteria.php +++ b/framework/core/src/Search/SearchCriteria.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Search; +namespace Flarum\Search; use Flarum\User\User; 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 94% rename from framework/core/src/Core/Search/SearchServiceProvider.php rename to framework/core/src/Search/SearchServiceProvider.php index 554a6bd7b..9b2ded54b 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; @@ -38,7 +38,7 @@ class SearchServiceProvider extends AbstractServiceProvider public function registerUserGambits() { $this->app->when('Flarum\Core\User\Search\UserSearcher') - ->needs('Flarum\Core\Search\GambitManager') + ->needs('Flarum\Search\GambitManager') ->give(function (Container $app) { $gambits = new GambitManager($app); @@ -57,7 +57,7 @@ class SearchServiceProvider extends AbstractServiceProvider public function registerDiscussionGambits() { $this->app->when('Flarum\Discussion\Search\DiscussionSearcher') - ->needs('Flarum\Core\Search\GambitManager') + ->needs('Flarum\Search\GambitManager') ->give(function (Container $app) { $gambits = new GambitManager($app); diff --git a/framework/core/src/User/Search/Gambit/EmailGambit.php b/framework/core/src/User/Search/Gambit/EmailGambit.php index 11b0b793a..3d12c02ed 100644 --- a/framework/core/src/User/Search/Gambit/EmailGambit.php +++ b/framework/core/src/User/Search/Gambit/EmailGambit.php @@ -12,8 +12,8 @@ namespace Flarum\Core\User\Search\Gambit; use Flarum\User\UserRepository; -use Flarum\Core\Search\AbstractRegexGambit; -use Flarum\Core\Search\AbstractSearch; +use Flarum\Search\AbstractRegexGambit; +use Flarum\Search\AbstractSearch; use Flarum\Core\User\Search\UserSearch; use LogicException; diff --git a/framework/core/src/User/Search/Gambit/FulltextGambit.php b/framework/core/src/User/Search/Gambit/FulltextGambit.php index c8349d740..0d2c02baa 100644 --- a/framework/core/src/User/Search/Gambit/FulltextGambit.php +++ b/framework/core/src/User/Search/Gambit/FulltextGambit.php @@ -12,8 +12,8 @@ namespace Flarum\Core\User\Search\Gambit; use Flarum\User\UserRepository; -use Flarum\Core\Search\AbstractSearch; -use Flarum\Core\Search\GambitInterface; +use Flarum\Search\AbstractSearch; +use Flarum\Search\GambitInterface; class FulltextGambit implements GambitInterface { diff --git a/framework/core/src/User/Search/Gambit/GroupGambit.php b/framework/core/src/User/Search/Gambit/GroupGambit.php index abe1ad984..b8c627bde 100644 --- a/framework/core/src/User/Search/Gambit/GroupGambit.php +++ b/framework/core/src/User/Search/Gambit/GroupGambit.php @@ -12,8 +12,8 @@ namespace Flarum\Core\User\Search\Gambit; use Flarum\Core\Repository\GroupRepository; -use Flarum\Core\Search\AbstractRegexGambit; -use Flarum\Core\Search\AbstractSearch; +use Flarum\Search\AbstractRegexGambit; +use Flarum\Search\AbstractSearch; use Flarum\Core\User\Search\UserSearch; use LogicException; diff --git a/framework/core/src/User/Search/UserSearch.php b/framework/core/src/User/Search/UserSearch.php index 9223dbd04..d26620f5e 100644 --- a/framework/core/src/User/Search/UserSearch.php +++ b/framework/core/src/User/Search/UserSearch.php @@ -11,7 +11,7 @@ namespace Flarum\Core\User\Search; -use Flarum\Core\Search\AbstractSearch; +use Flarum\Search\AbstractSearch; class UserSearch extends AbstractSearch { diff --git a/framework/core/src/User/Search/UserSearcher.php b/framework/core/src/User/Search/UserSearcher.php index 0043deb1d..13b0838aa 100644 --- a/framework/core/src/User/Search/UserSearcher.php +++ b/framework/core/src/User/Search/UserSearcher.php @@ -13,10 +13,10 @@ namespace Flarum\Core\User\Search; use Flarum\Core\User\Search\UserSearch; use Flarum\User\UserRepository; -use Flarum\Core\Search\ApplySearchParametersTrait; -use Flarum\Core\Search\GambitManager; -use Flarum\Core\Search\SearchCriteria; -use Flarum\Core\Search\SearchResults; +use Flarum\Search\ApplySearchParametersTrait; +use Flarum\Search\GambitManager; +use Flarum\Search\SearchCriteria; +use Flarum\Search\SearchResults; use Flarum\Event\ConfigureUserSearch; /** @@ -28,7 +28,7 @@ class UserSearcher use ApplySearchParametersTrait; /** - * @var GambitManager + * @var \Flarum\Search\GambitManager */ protected $gambits; @@ -38,10 +38,10 @@ class UserSearcher protected $users; /** - * @param GambitManager $gambits + * @param \Flarum\Search\GambitManager $gambits * @param \Flarum\User\UserRepository $users */ - public function __construct(GambitManager $gambits, UserRepository $users) + public function __construct(\Flarum\Search\GambitManager $gambits, UserRepository $users) { $this->gambits = $gambits; $this->users = $users; @@ -52,9 +52,9 @@ class UserSearcher * @param int|null $limit * @param int $offset * @param array $load An array of relationships to load on the results. - * @return SearchResults + * @return \Flarum\Search\SearchResults */ - public function search(SearchCriteria $criteria, $limit = null, $offset = 0, array $load = []) + public function search(\Flarum\Search\SearchCriteria $criteria, $limit = null, $offset = 0, array $load = []) { $actor = $criteria->actor; @@ -83,6 +83,6 @@ class UserSearcher $users->load($load); - return new SearchResults($users, $areMoreResults); + return new \Flarum\Search\SearchResults($users, $areMoreResults); } } From eb8c38af334d612013d6ac6871e98268e5a3b3f9 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 14:05:00 +0200 Subject: [PATCH 024/172] Extract Flarum\Group namespace --- .../src/Admin/Controller/FrontendController.php | 2 +- .../src/Api/Controller/ListGroupsController.php | 2 +- .../Api/Controller/SetPermissionController.php | 2 +- .../src/Api/Controller/ShowForumController.php | 2 +- .../core/src/Api/Serializer/GroupSerializer.php | 2 +- .../core/src/Core/Command/CreateGroupHandler.php | 14 +++++++------- .../core/src/Core/Command/DeleteGroupHandler.php | 8 ++++---- .../core/src/Core/Command/EditGroupHandler.php | 12 ++++++------ framework/core/src/Core/CoreServiceProvider.php | 2 +- .../Event/Created.php} | 8 ++++---- .../Event/Deleted.php} | 10 +++++----- .../Event/Deleting.php} | 6 +++--- .../Event/Renamed.php} | 10 +++++----- .../Event/Saving.php} | 8 ++++---- framework/core/src/{Core => Group}/Group.php | 16 ++++++++-------- .../src/{Core/Access => Group}/GroupPolicy.php | 3 +-- .../Repository => Group}/GroupRepository.php | 5 ++--- .../{Core/Validator => Group}/GroupValidator.php | 2 +- .../core/src/{Core => Group}/Permission.php | 4 ++-- .../core/src/Install/Console/InstallCommand.php | 4 ++-- framework/core/src/User/Event/GroupsChanged.php | 4 ++-- framework/core/src/User/Guest.php | 4 ++-- .../core/src/User/Search/Gambit/GroupGambit.php | 4 ++-- framework/core/src/User/User.php | 6 +++--- 24 files changed, 69 insertions(+), 71 deletions(-) rename framework/core/src/{Event/GroupWasCreated.php => Group/Event/Created.php} (84%) rename framework/core/src/{Event/GroupWasDeleted.php => Group/Event/Deleted.php} (78%) rename framework/core/src/{Event/GroupWillBeDeleted.php => Group/Event/Deleting.php} (92%) rename framework/core/src/{Event/GroupWasRenamed.php => Group/Event/Renamed.php} (78%) rename framework/core/src/{Event/GroupWillBeSaved.php => Group/Event/Saving.php} (90%) rename framework/core/src/{Core => Group}/Group.php (88%) rename framework/core/src/{Core/Access => Group}/GroupPolicy.php (92%) rename framework/core/src/{Core/Repository => Group}/GroupRepository.php (95%) rename framework/core/src/{Core/Validator => Group}/GroupValidator.php (92%) rename framework/core/src/{Core => Group}/Permission.php (93%) diff --git a/framework/core/src/Admin/Controller/FrontendController.php b/framework/core/src/Admin/Controller/FrontendController.php index d1b18d2ba..14258eb05 100644 --- a/framework/core/src/Admin/Controller/FrontendController.php +++ b/framework/core/src/Admin/Controller/FrontendController.php @@ -12,7 +12,7 @@ namespace Flarum\Admin\Controller; use Flarum\Admin\Frontend; -use Flarum\Core\Permission; +use Flarum\Group\Permission; use Flarum\Settings\Event\Deserializing; use Flarum\Extension\ExtensionManager; use Flarum\Frontend\AbstractFrontendController; diff --git a/framework/core/src/Api/Controller/ListGroupsController.php b/framework/core/src/Api/Controller/ListGroupsController.php index 66d734917..f02253810 100644 --- a/framework/core/src/Api/Controller/ListGroupsController.php +++ b/framework/core/src/Api/Controller/ListGroupsController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Group; +use Flarum\Group\Group; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; diff --git a/framework/core/src/Api/Controller/SetPermissionController.php b/framework/core/src/Api/Controller/SetPermissionController.php index 8eff7ccd9..edbc7cf20 100644 --- a/framework/core/src/Api/Controller/SetPermissionController.php +++ b/framework/core/src/Api/Controller/SetPermissionController.php @@ -12,7 +12,7 @@ namespace Flarum\Api\Controller; use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Core\Permission; +use Flarum\Group\Permission; use Flarum\Http\Controller\ControllerInterface; use Psr\Http\Message\ServerRequestInterface; use Zend\Diactoros\Response\EmptyResponse; diff --git a/framework/core/src/Api/Controller/ShowForumController.php b/framework/core/src/Api/Controller/ShowForumController.php index d221646e8..2dd3cd369 100644 --- a/framework/core/src/Api/Controller/ShowForumController.php +++ b/framework/core/src/Api/Controller/ShowForumController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Group; +use Flarum\Group\Group; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; diff --git a/framework/core/src/Api/Serializer/GroupSerializer.php b/framework/core/src/Api/Serializer/GroupSerializer.php index ba07e7754..7cd1eb989 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; diff --git a/framework/core/src/Core/Command/CreateGroupHandler.php b/framework/core/src/Core/Command/CreateGroupHandler.php index 6c3be8830..299cf5804 100644 --- a/framework/core/src/Core/Command/CreateGroupHandler.php +++ b/framework/core/src/Core/Command/CreateGroupHandler.php @@ -13,10 +13,10 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; -use Flarum\Core\Group; +use Flarum\Group\Group; use Flarum\Foundation\DispatchEventsTrait; -use Flarum\Core\Validator\GroupValidator; -use Flarum\Event\GroupWillBeSaved; +use Flarum\Group\GroupValidator; +use Flarum\Group\Event\Saving; use Illuminate\Contracts\Events\Dispatcher; class CreateGroupHandler @@ -25,13 +25,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,7 +41,7 @@ class CreateGroupHandler /** * @param CreateGroup $command - * @return Group + * @return \Flarum\Group\Group * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(CreateGroup $command) @@ -59,7 +59,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/DeleteGroupHandler.php b/framework/core/src/Core/Command/DeleteGroupHandler.php index e3ee47543..9755311cd 100644 --- a/framework/core/src/Core/Command/DeleteGroupHandler.php +++ b/framework/core/src/Core/Command/DeleteGroupHandler.php @@ -13,9 +13,9 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; -use Flarum\Core\Repository\GroupRepository; +use Flarum\Group\GroupRepository; use Flarum\Foundation\DispatchEventsTrait; -use Flarum\Event\GroupWillBeDeleted; +use Flarum\Group\Event\Deleting; 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/EditGroupHandler.php b/framework/core/src/Core/Command/EditGroupHandler.php index 42fe0e0a7..1425f59df 100644 --- a/framework/core/src/Core/Command/EditGroupHandler.php +++ b/framework/core/src/Core/Command/EditGroupHandler.php @@ -13,11 +13,11 @@ namespace Flarum\Core\Command; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; -use Flarum\Core\Group; -use Flarum\Core\Repository\GroupRepository; +use Flarum\Group\Group; +use Flarum\Group\GroupRepository; use Flarum\Foundation\DispatchEventsTrait; -use Flarum\Core\Validator\GroupValidator; -use Flarum\Event\GroupWillBeSaved; +use Flarum\Group\GroupValidator; +use Flarum\Group\Event\Saving; 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/Core/CoreServiceProvider.php b/framework/core/src/Core/CoreServiceProvider.php index 088733ce8..ed79cbfaf 100644 --- a/framework/core/src/Core/CoreServiceProvider.php +++ b/framework/core/src/Core/CoreServiceProvider.php @@ -114,7 +114,7 @@ class CoreServiceProvider extends AbstractServiceProvider $events->subscribe('Flarum\Discussion\DiscussionRenamedNotifier'); $events->subscribe('Flarum\Discussion\DiscussionPolicy'); - $events->subscribe('Flarum\Core\Access\GroupPolicy'); + $events->subscribe('Flarum\Group\GroupPolicy'); $events->subscribe('Flarum\Post\PostPolicy'); $events->subscribe('Flarum\User\UserPolicy'); diff --git a/framework/core/src/Event/GroupWasCreated.php b/framework/core/src/Group/Event/Created.php similarity index 84% rename from framework/core/src/Event/GroupWasCreated.php rename to framework/core/src/Group/Event/Created.php index 2e4962809..109c615d6 100644 --- a/framework/core/src/Event/GroupWasCreated.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\Group\Group; use Flarum\User\User; -class GroupWasCreated +class Created { /** - * @var Group + * @var \Flarum\Group\Group */ public $group; diff --git a/framework/core/src/Event/GroupWasDeleted.php b/framework/core/src/Group/Event/Deleted.php similarity index 78% rename from framework/core/src/Event/GroupWasDeleted.php rename to framework/core/src/Group/Event/Deleted.php index 1d2290b7b..6fbc5fbc1 100644 --- a/framework/core/src/Event/GroupWasDeleted.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\Group\Group; use Flarum\User\User; -class GroupWasDeleted +class Deleted { /** - * @var Group + * @var \Flarum\Group\Group */ public $group; @@ -27,7 +27,7 @@ class GroupWasDeleted 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 92% rename from framework/core/src/Event/GroupWillBeDeleted.php rename to framework/core/src/Group/Event/Deleting.php index ac0d5b406..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\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 78% rename from framework/core/src/Event/GroupWasRenamed.php rename to framework/core/src/Group/Event/Renamed.php index ded05ce98..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\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 90% rename from framework/core/src/Event/GroupWillBeSaved.php rename to framework/core/src/Group/Event/Saving.php index feeaac887..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\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 88% rename from framework/core/src/Core/Group.php rename to framework/core/src/Group/Group.php index 53d4da36f..dd30cbb53 100755 --- a/framework/core/src/Core/Group.php +++ b/framework/core/src/Group/Group.php @@ -9,14 +9,14 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\Group; use Flarum\Foundation\EventGeneratorTrait; use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; -use Flarum\Event\GroupWasCreated; -use Flarum\Event\GroupWasDeleted; -use Flarum\Event\GroupWasRenamed; +use Flarum\Group\Event\Created; +use Flarum\Group\Event\Deleting; +use Flarum\Group\Event\Renamed; /** * @property int $id @@ -67,7 +67,7 @@ class Group extends AbstractModel parent::boot(); static::deleted(function (Group $group) { - $group->raise(new GroupWasDeleted($group)); + $group->raise(new Deleting($group)); $group->permissions()->delete(); }); @@ -91,7 +91,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 +108,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; } @@ -130,6 +130,6 @@ class Group extends AbstractModel */ public function permissions() { - return $this->hasMany('Flarum\Core\Permission'); + return $this->hasMany('Flarum\Group\Permission'); } } diff --git a/framework/core/src/Core/Access/GroupPolicy.php b/framework/core/src/Group/GroupPolicy.php similarity index 92% rename from framework/core/src/Core/Access/GroupPolicy.php rename to framework/core/src/Group/GroupPolicy.php index ff9861a07..91af563a8 100644 --- a/framework/core/src/Core/Access/GroupPolicy.php +++ b/framework/core/src/Group/GroupPolicy.php @@ -9,9 +9,8 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Access; +namespace Flarum\Group; -use Flarum\Core\Group; use Flarum\User\AbstractPolicy; use Flarum\User\User; diff --git a/framework/core/src/Core/Repository/GroupRepository.php b/framework/core/src/Group/GroupRepository.php similarity index 95% rename from framework/core/src/Core/Repository/GroupRepository.php rename to framework/core/src/Group/GroupRepository.php index f6cfe3d82..4372fa560 100644 --- a/framework/core/src/Core/Repository/GroupRepository.php +++ b/framework/core/src/Group/GroupRepository.php @@ -9,9 +9,8 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Repository; +namespace Flarum\Group; -use Flarum\Core\Group; use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; @@ -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/Core/Validator/GroupValidator.php b/framework/core/src/Group/GroupValidator.php similarity index 92% rename from framework/core/src/Core/Validator/GroupValidator.php rename to framework/core/src/Group/GroupValidator.php index 506163f6f..58d8aee16 100644 --- a/framework/core/src/Core/Validator/GroupValidator.php +++ b/framework/core/src/Group/GroupValidator.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Validator; +namespace Flarum\Group; use Flarum\Foundation\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..0ed470e3b 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('Flarum\Group\Group', 'group_id'); } /** diff --git a/framework/core/src/Install/Console/InstallCommand.php b/framework/core/src/Install/Console/InstallCommand.php index acf67997d..ace02e89b 100644 --- a/framework/core/src/Install/Console/InstallCommand.php +++ b/framework/core/src/Install/Console/InstallCommand.php @@ -13,8 +13,8 @@ namespace Flarum\Install\Console; use Exception; use Flarum\Console\AbstractCommand; -use Flarum\Core\Group; -use Flarum\Core\Permission; +use Flarum\Group\Group; +use Flarum\Group\Permission; use Flarum\User\User; use Flarum\Database\AbstractModel; use Illuminate\Contracts\Foundation\Application; diff --git a/framework/core/src/User/Event/GroupsChanged.php b/framework/core/src/User/Event/GroupsChanged.php index feb6484d7..310d70fb7 100644 --- a/framework/core/src/User/Event/GroupsChanged.php +++ b/framework/core/src/User/Event/GroupsChanged.php @@ -23,7 +23,7 @@ class GroupsChanged public $user; /** - * @var \Flarum\Core\Group[] + * @var \Flarum\Group\Group[] */ public $oldGroups; @@ -34,7 +34,7 @@ class GroupsChanged /** * @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/User/Guest.php b/framework/core/src/User/Guest.php index e62b8c695..e7dc3f502 100755 --- a/framework/core/src/User/Guest.php +++ b/framework/core/src/User/Guest.php @@ -11,7 +11,7 @@ namespace Flarum\User; -use Flarum\Core\Group; +use Flarum\Group\Group; class Guest extends User { @@ -25,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/User/Search/Gambit/GroupGambit.php b/framework/core/src/User/Search/Gambit/GroupGambit.php index b8c627bde..317ea8232 100644 --- a/framework/core/src/User/Search/Gambit/GroupGambit.php +++ b/framework/core/src/User/Search/Gambit/GroupGambit.php @@ -11,7 +11,7 @@ namespace Flarum\Core\User\Search\Gambit; -use Flarum\Core\Repository\GroupRepository; +use Flarum\Group\GroupRepository; use Flarum\Search\AbstractRegexGambit; use Flarum\Search\AbstractSearch; use Flarum\Core\User\Search\UserSearch; @@ -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/User/User.php b/framework/core/src/User/User.php index f85470449..24a6ab8bb 100755 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -13,9 +13,9 @@ namespace Flarum\User; use DomainException; use Flarum\User\Gate; -use Flarum\Core\Group; +use Flarum\Group\Group; use Flarum\Core\Notification; -use Flarum\Core\Permission; +use Flarum\Group\Permission; use Flarum\Foundation\EventGeneratorTrait; use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; @@ -623,7 +623,7 @@ class User extends AbstractModel */ public function groups() { - return $this->belongsToMany('Flarum\Core\Group', 'users_groups'); + return $this->belongsToMany('Flarum\Group\Group', 'users_groups'); } /** From 8aab52327ea8a6d165750df7603ea697ff06cdf2 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 14:10:39 +0200 Subject: [PATCH 025/172] Fix some incorrect automated refactorings --- .../src/Api/Serializer/BasicPostSerializer.php | 4 ++-- .../core/src/Core/Command/DeletePostHandler.php | 2 +- .../core/src/Core/Command/EditPostHandler.php | 2 +- framework/core/src/Core/CoreServiceProvider.php | 4 ++-- framework/core/src/Discussion/Discussion.php | 4 ++-- .../Search/Fulltext/MySqlFulltextDriver.php | 2 +- framework/core/src/Post/PostRepository.php | 2 +- framework/core/src/User/User.php | 5 ++--- framework/core/src/User/UserMetadataUpdater.php | 14 +++++++------- 9 files changed, 19 insertions(+), 20 deletions(-) diff --git a/framework/core/src/Api/Serializer/BasicPostSerializer.php b/framework/core/src/Api/Serializer/BasicPostSerializer.php index 2e0a75951..b63b6dec6 100644 --- a/framework/core/src/Api/Serializer/BasicPostSerializer.php +++ b/framework/core/src/Api/Serializer/BasicPostSerializer.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Serializer; -use Flarum\Core\Post; +use Flarum\Post\Post; use Flarum\Post\CommentPost; use InvalidArgumentException; @@ -25,7 +25,7 @@ class BasicPostSerializer extends AbstractSerializer /** * {@inheritdoc} * - * @param \Flarum\Core\Post $post + * @param \Flarum\Post\Post $post * @throws InvalidArgumentException */ protected function getDefaultAttributes($post) diff --git a/framework/core/src/Core/Command/DeletePostHandler.php b/framework/core/src/Core/Command/DeletePostHandler.php index 176aa5d3f..541c5cb40 100644 --- a/framework/core/src/Core/Command/DeletePostHandler.php +++ b/framework/core/src/Core/Command/DeletePostHandler.php @@ -40,7 +40,7 @@ class DeletePostHandler /** * @param DeletePost $command - * @return \Flarum\Core\Post + * @return \Flarum\Post\Post * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(DeletePost $command) diff --git a/framework/core/src/Core/Command/EditPostHandler.php b/framework/core/src/Core/Command/EditPostHandler.php index af0a52a45..7bca65370 100644 --- a/framework/core/src/Core/Command/EditPostHandler.php +++ b/framework/core/src/Core/Command/EditPostHandler.php @@ -48,7 +48,7 @@ class EditPostHandler /** * @param EditPost $command - * @return \Flarum\Core\Post + * @return \Flarum\Post\Post * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(EditPost $command) diff --git a/framework/core/src/Core/CoreServiceProvider.php b/framework/core/src/Core/CoreServiceProvider.php index ed79cbfaf..82e5f6b0d 100644 --- a/framework/core/src/Core/CoreServiceProvider.php +++ b/framework/core/src/Core/CoreServiceProvider.php @@ -124,8 +124,8 @@ class CoreServiceProvider extends AbstractServiceProvider public function registerPostTypes() { $models = [ - 'Flarum\Post\Post\CommentPost', - 'Flarum\Post\Post\DiscussionRenamedPost' + 'Flarum\Post\CommentPost', + 'Flarum\Post\DiscussionRenamedPost' ]; $this->app->make('events')->fire( diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index 34122fd90..0b06f632f 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -21,7 +21,7 @@ use Flarum\Discussion\Event\Hidden; use Flarum\Discussion\Event\Renamed; use Flarum\Discussion\Event\Restored; use Flarum\Discussion\Event\Started; -use Flarum\Post\Event\Deleted; +use Flarum\Post\Event\Deleted as PostDeleted; use Flarum\Event\ScopePostVisibility; use Flarum\Post\Post; use Flarum\User\Guest; @@ -111,7 +111,7 @@ class Discussion extends AbstractModel $posts = $discussion->posts()->allTypes(); foreach ($posts->get() as $post) { - $discussion->raise(new Deleted($post)); + $discussion->raise(new PostDeleted($post)); } $posts->delete(); diff --git a/framework/core/src/Discussion/Search/Fulltext/MySqlFulltextDriver.php b/framework/core/src/Discussion/Search/Fulltext/MySqlFulltextDriver.php index 8c71066d6..0c1136297 100644 --- a/framework/core/src/Discussion/Search/Fulltext/MySqlFulltextDriver.php +++ b/framework/core/src/Discussion/Search/Fulltext/MySqlFulltextDriver.php @@ -11,7 +11,7 @@ namespace Flarum\Discussion\Search\Fulltext; -use Flarum\Core\Post; +use Flarum\Post\Post; class MySqlFulltextDriver implements DriverInterface { diff --git a/framework/core/src/Post/PostRepository.php b/framework/core/src/Post/PostRepository.php index a43ce300c..e6a38af03 100644 --- a/framework/core/src/Post/PostRepository.php +++ b/framework/core/src/Post/PostRepository.php @@ -34,7 +34,7 @@ class PostRepository * * @param int $id * @param \Flarum\User\User $actor - * @return \Flarum\Core\Post + * @return \Flarum\Post\Post * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 24a6ab8bb..70396e6ff 100755 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -12,7 +12,6 @@ namespace Flarum\User; use DomainException; -use Flarum\User\Gate; use Flarum\Group\Group; use Flarum\Core\Notification; use Flarum\Group\Permission; @@ -21,7 +20,7 @@ use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; use Flarum\Event\CheckUserPassword; use Flarum\Event\ConfigureUserPreferences; -use Flarum\Post\Event\Deleted; +use Flarum\Post\Event\Deleted as PostDeleted; use Flarum\Event\PrepareUserGroups; use Flarum\User\Event\AvatarChanged; use Flarum\User\Event\BioChanged; @@ -136,7 +135,7 @@ class User extends AbstractModel $posts = $user->posts()->allTypes(); foreach ($posts->get() as $post) { - $user->raise(new Deleted($post)); + $user->raise(new PostDeleted($post)); } $posts->delete(); diff --git a/framework/core/src/User/UserMetadataUpdater.php b/framework/core/src/User/UserMetadataUpdater.php index 3cf33979a..a690813dd 100755 --- a/framework/core/src/User/UserMetadataUpdater.php +++ b/framework/core/src/User/UserMetadataUpdater.php @@ -12,13 +12,13 @@ namespace Flarum\User; use Flarum\Discussion\Discussion; -use Flarum\Core\Post; -use Flarum\Discussion\Event\Deleted; +use Flarum\Discussion\Event\Deleted as DiscussionDeleted; use Flarum\Discussion\Event\Started; -use Flarum\Post\Event\Deleted; +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 @@ -29,11 +29,11 @@ class UserMetadataUpdater public function subscribe(Dispatcher $events) { $events->listen(Posted::class, [$this, 'whenPostWasPosted']); - $events->listen(Deleted::class, [$this, 'whenPostWasDeleted']); + $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(Deleted::class, [$this, 'whenDiscussionWasDeleted']); + $events->listen(DiscussionDeleted::class, [$this, 'whenDiscussionWasDeleted']); } /** @@ -47,7 +47,7 @@ class UserMetadataUpdater /** * @param \Flarum\Post\Event\Deleted $event */ - public function whenPostWasDeleted(Deleted $event) + public function whenPostWasDeleted(PostDeleted $event) { $this->updateCommentsCount($event->post, -1); } @@ -79,7 +79,7 @@ class UserMetadataUpdater /** * @param \Flarum\Discussion\Event\Deleted $event */ - public function whenDiscussionWasDeleted(Deleted $event) + public function whenDiscussionWasDeleted(DiscussionDeleted $event) { $this->updateDiscussionsCount($event->discussion, -1); } From b48cbde5c0baebb3690d6fb79bd770cbb6649f53 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 14:16:19 +0200 Subject: [PATCH 026/172] Move another trait out of obsolete Flarum\Core namespace --- .../core/src/Admin/Middleware/RequireAdministrateAbility.php | 2 +- .../core/src/Api/Controller/DeleteFaviconController.php | 2 +- framework/core/src/Api/Controller/DeleteLogoController.php | 2 +- .../src/Api/Controller/SendConfirmationEmailController.php | 2 +- .../core/src/Api/Controller/SetPermissionController.php | 2 +- framework/core/src/Api/Controller/SetSettingsController.php | 2 +- .../core/src/Api/Controller/UninstallExtensionController.php | 2 +- .../core/src/Api/Controller/UpdateExtensionController.php | 2 +- .../core/src/Api/Controller/UploadFaviconController.php | 2 +- framework/core/src/Api/Controller/UploadLogoController.php | 2 +- framework/core/src/Core/Command/CreateGroupHandler.php | 5 ++--- framework/core/src/Core/Command/DeleteAvatarHandler.php | 4 ++-- framework/core/src/Core/Command/DeleteDiscussionHandler.php | 4 ++-- framework/core/src/Core/Command/DeleteGroupHandler.php | 4 ++-- framework/core/src/Core/Command/DeletePostHandler.php | 4 ++-- framework/core/src/Core/Command/DeleteUserHandler.php | 4 ++-- framework/core/src/Core/Command/EditDiscussionHandler.php | 4 ++-- framework/core/src/Core/Command/EditGroupHandler.php | 4 ++-- framework/core/src/Core/Command/EditPostHandler.php | 4 ++-- framework/core/src/Core/Command/EditUserHandler.php | 4 ++-- framework/core/src/Core/Command/PostReplyHandler.php | 4 ++-- .../core/src/Core/Command/ReadAllNotificationsHandler.php | 2 +- framework/core/src/Core/Command/ReadDiscussionHandler.php | 4 ++-- framework/core/src/Core/Command/ReadNotificationHandler.php | 2 +- framework/core/src/Core/Command/RegisterUserHandler.php | 4 ++-- framework/core/src/Core/Command/StartDiscussionHandler.php | 4 ++-- framework/core/src/Core/Command/UploadAvatarHandler.php | 4 ++-- framework/core/src/Forum/Controller/LogOutController.php | 2 +- .../core/src/{Core/Access => User}/AssertPermissionTrait.php | 3 +-- 29 files changed, 44 insertions(+), 46 deletions(-) rename framework/core/src/{Core/Access => User}/AssertPermissionTrait.php (96%) 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/Api/Controller/DeleteFaviconController.php b/framework/core/src/Api/Controller/DeleteFaviconController.php index 00c38bb50..4c2807abc 100644 --- a/framework/core/src/Api/Controller/DeleteFaviconController.php +++ b/framework/core/src/Api/Controller/DeleteFaviconController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\Foundation\Application; use Flarum\Settings\SettingsRepositoryInterface; use League\Flysystem\Adapter\Local; diff --git a/framework/core/src/Api/Controller/DeleteLogoController.php b/framework/core/src/Api/Controller/DeleteLogoController.php index 4e4cc016a..532674577 100644 --- a/framework/core/src/Api/Controller/DeleteLogoController.php +++ b/framework/core/src/Api/Controller/DeleteLogoController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\Foundation\Application; use Flarum\Settings\SettingsRepositoryInterface; use League\Flysystem\Adapter\Local; diff --git a/framework/core/src/Api/Controller/SendConfirmationEmailController.php b/framework/core/src/Api/Controller/SendConfirmationEmailController.php index 02c22b020..a6314ad97 100644 --- a/framework/core/src/Api/Controller/SendConfirmationEmailController.php +++ b/framework/core/src/Api/Controller/SendConfirmationEmailController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\User\EmailToken; use Flarum\User\Exception\PermissionDeniedException; use Flarum\Forum\UrlGenerator; diff --git a/framework/core/src/Api/Controller/SetPermissionController.php b/framework/core/src/Api/Controller/SetPermissionController.php index edbc7cf20..a11dc056f 100644 --- a/framework/core/src/Api/Controller/SetPermissionController.php +++ b/framework/core/src/Api/Controller/SetPermissionController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\Group\Permission; use Flarum\Http\Controller\ControllerInterface; use Psr\Http\Message\ServerRequestInterface; diff --git a/framework/core/src/Api/Controller/SetSettingsController.php b/framework/core/src/Api/Controller/SetSettingsController.php index 09f23c6eb..b9cb59cdd 100644 --- a/framework/core/src/Api/Controller/SetSettingsController.php +++ b/framework/core/src/Api/Controller/SetSettingsController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\Settings\Event\Serializing; use Flarum\Settings\Event\Saved; use Flarum\Http\Controller\ControllerInterface; diff --git a/framework/core/src/Api/Controller/UninstallExtensionController.php b/framework/core/src/Api/Controller/UninstallExtensionController.php index 4b9b185fb..0e2f02a59 100644 --- a/framework/core/src/Api/Controller/UninstallExtensionController.php +++ b/framework/core/src/Api/Controller/UninstallExtensionController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\Extension\ExtensionManager; use Psr\Http\Message\ServerRequestInterface; diff --git a/framework/core/src/Api/Controller/UpdateExtensionController.php b/framework/core/src/Api/Controller/UpdateExtensionController.php index f9d983769..c701ae469 100644 --- a/framework/core/src/Api/Controller/UpdateExtensionController.php +++ b/framework/core/src/Api/Controller/UpdateExtensionController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\Extension\ExtensionManager; use Flarum\Http\Controller\ControllerInterface; use Psr\Http\Message\ServerRequestInterface; diff --git a/framework/core/src/Api/Controller/UploadFaviconController.php b/framework/core/src/Api/Controller/UploadFaviconController.php index 1ccd5e088..80b33abee 100644 --- a/framework/core/src/Api/Controller/UploadFaviconController.php +++ b/framework/core/src/Api/Controller/UploadFaviconController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\Foundation\Application; use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Support\Str; diff --git a/framework/core/src/Api/Controller/UploadLogoController.php b/framework/core/src/Api/Controller/UploadLogoController.php index ff49683f2..ed10a8b67 100644 --- a/framework/core/src/Api/Controller/UploadLogoController.php +++ b/framework/core/src/Api/Controller/UploadLogoController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\Foundation\Application; use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Support\Str; diff --git a/framework/core/src/Core/Command/CreateGroupHandler.php b/framework/core/src/Core/Command/CreateGroupHandler.php index 299cf5804..ee152d1ec 100644 --- a/framework/core/src/Core/Command/CreateGroupHandler.php +++ b/framework/core/src/Core/Command/CreateGroupHandler.php @@ -11,8 +11,7 @@ namespace Flarum\Core\Command; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\User\Exception\PermissionDeniedException; +use Flarum\User\AssertPermissionTrait; use Flarum\Group\Group; use Flarum\Foundation\DispatchEventsTrait; use Flarum\Group\GroupValidator; @@ -21,7 +20,7 @@ use Illuminate\Contracts\Events\Dispatcher; class CreateGroupHandler { - use Flarum\Foundation\DispatchEventsTrait; + use DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/DeleteAvatarHandler.php b/framework/core/src/Core/Command/DeleteAvatarHandler.php index 00961f741..2dfe68efd 100644 --- a/framework/core/src/Core/Command/DeleteAvatarHandler.php +++ b/framework/core/src/Core/Command/DeleteAvatarHandler.php @@ -11,7 +11,7 @@ namespace Flarum\Core\Command; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; use Flarum\User\UserRepository; use Flarum\Foundation\DispatchEventsTrait; @@ -21,7 +21,7 @@ use League\Flysystem\FilesystemInterface; class DeleteAvatarHandler { - use Flarum\Foundation\DispatchEventsTrait; + use DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/DeleteDiscussionHandler.php b/framework/core/src/Core/Command/DeleteDiscussionHandler.php index 4665db213..9643b5e96 100644 --- a/framework/core/src/Core/Command/DeleteDiscussionHandler.php +++ b/framework/core/src/Core/Command/DeleteDiscussionHandler.php @@ -11,7 +11,7 @@ namespace Flarum\Core\Command; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; use Flarum\Discussion\DiscussionRepository; use Flarum\Foundation\DispatchEventsTrait; @@ -20,7 +20,7 @@ use Illuminate\Contracts\Events\Dispatcher; class DeleteDiscussionHandler { - use Flarum\Foundation\DispatchEventsTrait; + use DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/DeleteGroupHandler.php b/framework/core/src/Core/Command/DeleteGroupHandler.php index 9755311cd..119758d1f 100644 --- a/framework/core/src/Core/Command/DeleteGroupHandler.php +++ b/framework/core/src/Core/Command/DeleteGroupHandler.php @@ -11,7 +11,7 @@ namespace Flarum\Core\Command; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; use Flarum\Group\GroupRepository; use Flarum\Foundation\DispatchEventsTrait; @@ -20,7 +20,7 @@ use Illuminate\Contracts\Events\Dispatcher; class DeleteGroupHandler { - use Flarum\Foundation\DispatchEventsTrait; + use DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/DeletePostHandler.php b/framework/core/src/Core/Command/DeletePostHandler.php index 541c5cb40..1e5301f2e 100644 --- a/framework/core/src/Core/Command/DeletePostHandler.php +++ b/framework/core/src/Core/Command/DeletePostHandler.php @@ -11,7 +11,7 @@ namespace Flarum\Core\Command; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; use Flarum\Post\PostRepository; use Flarum\Foundation\DispatchEventsTrait; @@ -20,7 +20,7 @@ use Illuminate\Contracts\Events\Dispatcher; class DeletePostHandler { - use Flarum\Foundation\DispatchEventsTrait; + use DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/DeleteUserHandler.php b/framework/core/src/Core/Command/DeleteUserHandler.php index d5ed6c15f..e2f64e482 100644 --- a/framework/core/src/Core/Command/DeleteUserHandler.php +++ b/framework/core/src/Core/Command/DeleteUserHandler.php @@ -11,7 +11,7 @@ namespace Flarum\Core\Command; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; use Flarum\User\UserRepository; use Flarum\Foundation\DispatchEventsTrait; @@ -20,7 +20,7 @@ use Illuminate\Contracts\Events\Dispatcher; class DeleteUserHandler { - use Flarum\Foundation\DispatchEventsTrait; + use DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/EditDiscussionHandler.php b/framework/core/src/Core/Command/EditDiscussionHandler.php index bce27933e..038777d3e 100644 --- a/framework/core/src/Core/Command/EditDiscussionHandler.php +++ b/framework/core/src/Core/Command/EditDiscussionHandler.php @@ -11,7 +11,7 @@ namespace Flarum\Core\Command; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; use Flarum\Discussion\DiscussionRepository; use Flarum\Foundation\DispatchEventsTrait; @@ -21,7 +21,7 @@ use Illuminate\Contracts\Events\Dispatcher; class EditDiscussionHandler { - use Flarum\Foundation\DispatchEventsTrait; + use DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/EditGroupHandler.php b/framework/core/src/Core/Command/EditGroupHandler.php index 1425f59df..c3fee99f4 100644 --- a/framework/core/src/Core/Command/EditGroupHandler.php +++ b/framework/core/src/Core/Command/EditGroupHandler.php @@ -11,7 +11,7 @@ namespace Flarum\Core\Command; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; use Flarum\Group\Group; use Flarum\Group\GroupRepository; @@ -22,7 +22,7 @@ use Illuminate\Contracts\Events\Dispatcher; class EditGroupHandler { - use Flarum\Foundation\DispatchEventsTrait; + use DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/EditPostHandler.php b/framework/core/src/Core/Command/EditPostHandler.php index 7bca65370..e2b093f9a 100644 --- a/framework/core/src/Core/Command/EditPostHandler.php +++ b/framework/core/src/Core/Command/EditPostHandler.php @@ -11,7 +11,7 @@ namespace Flarum\Core\Command; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\Post\CommentPost; use Flarum\Post\PostRepository; use Flarum\Foundation\DispatchEventsTrait; @@ -21,7 +21,7 @@ use Illuminate\Contracts\Events\Dispatcher; class EditPostHandler { - use Flarum\Foundation\DispatchEventsTrait; + use DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/EditUserHandler.php b/framework/core/src/Core/Command/EditUserHandler.php index 6071fa1ad..cb2b2b725 100644 --- a/framework/core/src/Core/Command/EditUserHandler.php +++ b/framework/core/src/Core/Command/EditUserHandler.php @@ -11,7 +11,7 @@ namespace Flarum\Core\Command; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\User\UserRepository; use Flarum\Foundation\DispatchEventsTrait; use Flarum\User\User; @@ -22,7 +22,7 @@ use Illuminate\Contracts\Events\Dispatcher; class EditUserHandler { - use Flarum\Foundation\DispatchEventsTrait; + use DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/PostReplyHandler.php b/framework/core/src/Core/Command/PostReplyHandler.php index cb51c4fda..e4b3147e7 100644 --- a/framework/core/src/Core/Command/PostReplyHandler.php +++ b/framework/core/src/Core/Command/PostReplyHandler.php @@ -12,7 +12,7 @@ namespace Flarum\Core\Command; use DateTime; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\Core\Notification\NotificationSyncer; use Flarum\Post\CommentPost; use Flarum\Discussion\DiscussionRepository; @@ -23,7 +23,7 @@ use Illuminate\Contracts\Events\Dispatcher; class PostReplyHandler { - use Flarum\Foundation\DispatchEventsTrait; + use DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/ReadAllNotificationsHandler.php b/framework/core/src/Core/Command/ReadAllNotificationsHandler.php index 023568f9b..9269ed958 100644 --- a/framework/core/src/Core/Command/ReadAllNotificationsHandler.php +++ b/framework/core/src/Core/Command/ReadAllNotificationsHandler.php @@ -11,7 +11,7 @@ namespace Flarum\Core\Command; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\Core\Repository\NotificationRepository; class ReadAllNotificationsHandler diff --git a/framework/core/src/Core/Command/ReadDiscussionHandler.php b/framework/core/src/Core/Command/ReadDiscussionHandler.php index 42e4722ea..9be64074b 100644 --- a/framework/core/src/Core/Command/ReadDiscussionHandler.php +++ b/framework/core/src/Core/Command/ReadDiscussionHandler.php @@ -11,7 +11,7 @@ namespace Flarum\Core\Command; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\Discussion\DiscussionRepository; use Flarum\Foundation\DispatchEventsTrait; use Flarum\Discussion\Event\UserDataSaving; @@ -19,7 +19,7 @@ use Illuminate\Contracts\Events\Dispatcher; class ReadDiscussionHandler { - use Flarum\Foundation\DispatchEventsTrait; + use DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/ReadNotificationHandler.php b/framework/core/src/Core/Command/ReadNotificationHandler.php index b7da93198..f70f1d6b1 100644 --- a/framework/core/src/Core/Command/ReadNotificationHandler.php +++ b/framework/core/src/Core/Command/ReadNotificationHandler.php @@ -11,7 +11,7 @@ namespace Flarum\Core\Command; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\Core\Notification; class ReadNotificationHandler diff --git a/framework/core/src/Core/Command/RegisterUserHandler.php b/framework/core/src/Core/Command/RegisterUserHandler.php index 2c3bdb931..edbf35d65 100644 --- a/framework/core/src/Core/Command/RegisterUserHandler.php +++ b/framework/core/src/Core/Command/RegisterUserHandler.php @@ -12,7 +12,7 @@ namespace Flarum\Core\Command; use Exception; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\User\AuthToken; use Flarum\User\Exception\PermissionDeniedException; use Flarum\Foundation\DispatchEventsTrait; @@ -33,7 +33,7 @@ use League\Flysystem\MountManager; class RegisterUserHandler { - use Flarum\Foundation\DispatchEventsTrait; + use DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/StartDiscussionHandler.php b/framework/core/src/Core/Command/StartDiscussionHandler.php index bad252625..7f8586031 100644 --- a/framework/core/src/Core/Command/StartDiscussionHandler.php +++ b/framework/core/src/Core/Command/StartDiscussionHandler.php @@ -12,7 +12,7 @@ namespace Flarum\Core\Command; use Exception; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\Discussion\Discussion; use Flarum\Foundation\DispatchEventsTrait; use Flarum\Discussion\DiscussionValidator; @@ -22,7 +22,7 @@ use Illuminate\Contracts\Events\Dispatcher as EventDispatcher; class StartDiscussionHandler { - use Flarum\Foundation\DispatchEventsTrait; + use DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Core/Command/UploadAvatarHandler.php b/framework/core/src/Core/Command/UploadAvatarHandler.php index 791090e58..adcf76ee3 100644 --- a/framework/core/src/Core/Command/UploadAvatarHandler.php +++ b/framework/core/src/Core/Command/UploadAvatarHandler.php @@ -12,7 +12,7 @@ namespace Flarum\Core\Command; use Exception; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\User\UserRepository; use Flarum\Foundation\DispatchEventsTrait; use Flarum\User\AvatarValidator; @@ -29,7 +29,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile; class UploadAvatarHandler { - use Flarum\Foundation\DispatchEventsTrait; + use DispatchEventsTrait; use AssertPermissionTrait; /** diff --git a/framework/core/src/Forum/Controller/LogOutController.php b/framework/core/src/Forum/Controller/LogOutController.php index c83601268..af220a6b6 100644 --- a/framework/core/src/Forum/Controller/LogOutController.php +++ b/framework/core/src/Forum/Controller/LogOutController.php @@ -11,7 +11,7 @@ namespace Flarum\Forum\Controller; -use Flarum\Core\Access\AssertPermissionTrait; +use Flarum\User\AssertPermissionTrait; use Flarum\User\Event\LoggedOut; use Flarum\Foundation\Application; use Flarum\Http\Controller\ControllerInterface; diff --git a/framework/core/src/Core/Access/AssertPermissionTrait.php b/framework/core/src/User/AssertPermissionTrait.php similarity index 96% rename from framework/core/src/Core/Access/AssertPermissionTrait.php rename to framework/core/src/User/AssertPermissionTrait.php index 647ca9fac..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\User\Exception\PermissionDeniedException; -use Flarum\User\User; trait AssertPermissionTrait { From 600f50198bfe133bf07683921817da4bae55e6b8 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 14:22:19 +0200 Subject: [PATCH 027/172] Extract Flarum\Notification namespace --- .../ListNotificationsController.php | 8 +++---- .../Api/Serializer/NotificationSerializer.php | 4 ++-- .../src/Core/Command/PostReplyHandler.php | 6 ++--- .../Command/ReadAllNotificationsHandler.php | 2 +- .../Core/Command/ReadNotificationHandler.php | 4 ++-- .../core/src/Core/CoreServiceProvider.php | 2 +- .../Discussion/DiscussionRenamedNotifier.php | 4 ++-- .../src/Event/ConfigureNotificationTypes.php | 2 +- .../Blueprint}/BlueprintInterface.php | 2 +- .../Blueprint}/DiscussionRenamedBlueprint.php | 2 +- .../Event/Sending.php} | 8 +++---- .../Notification/MailableInterface.php | 2 +- .../{Core => Notification}/Notification.php | 2 +- .../Notification/NotificationMailer.php | 2 +- .../NotificationRepository.php | 3 +-- .../NotificationServiceProvider.php | 7 +++--- .../Notification/NotificationSyncer.php | 23 +++++++++---------- framework/core/src/User/User.php | 4 ++-- 18 files changed, 42 insertions(+), 45 deletions(-) rename framework/core/src/{Core/Notification => Notification/Blueprint}/BlueprintInterface.php (96%) rename framework/core/src/{Core/Notification => Notification/Blueprint}/DiscussionRenamedBlueprint.php (96%) rename framework/core/src/{Event/NotificationWillBeSent.php => Notification/Event/Sending.php} (79%) rename framework/core/src/{Core => }/Notification/MailableInterface.php (93%) rename framework/core/src/{Core => Notification}/Notification.php (99%) rename framework/core/src/{Core => }/Notification/NotificationMailer.php (96%) rename framework/core/src/{Core/Repository => Notification}/NotificationRepository.php (96%) rename framework/core/src/{Core => }/Notification/NotificationServiceProvider.php (88%) rename framework/core/src/{Core => }/Notification/NotificationSyncer.php (89%) diff --git a/framework/core/src/Api/Controller/ListNotificationsController.php b/framework/core/src/Api/Controller/ListNotificationsController.php index c167498fe..aeca867a8 100644 --- a/framework/core/src/Api/Controller/ListNotificationsController.php +++ b/framework/core/src/Api/Controller/ListNotificationsController.php @@ -13,7 +13,7 @@ namespace Flarum\Api\Controller; use Flarum\Discussion\Discussion; use Flarum\User\Exception\PermissionDeniedException; -use Flarum\Core\Repository\NotificationRepository; +use Flarum\Notification\NotificationRepository; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; @@ -39,12 +39,12 @@ class ListNotificationsController extends AbstractListController public $limit = 10; /** - * @var \Flarum\Core\Repository\NotificationRepository + * @var \Flarum\Notification\NotificationRepository */ protected $notifications; /** - * @param \Flarum\Core\Repository\NotificationRepository $notifications + * @param \Flarum\Notification\NotificationRepository $notifications */ public function __construct(NotificationRepository $notifications) { @@ -80,7 +80,7 @@ class ListNotificationsController extends AbstractListController } /** - * @param \Flarum\Core\Notification[] $notifications + * @param \Flarum\Notification\Notification[] $notifications */ private function loadSubjectDiscussions(array $notifications) { diff --git a/framework/core/src/Api/Serializer/NotificationSerializer.php b/framework/core/src/Api/Serializer/NotificationSerializer.php index bfbd8e943..9159445a3 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) diff --git a/framework/core/src/Core/Command/PostReplyHandler.php b/framework/core/src/Core/Command/PostReplyHandler.php index e4b3147e7..2a8314a8e 100644 --- a/framework/core/src/Core/Command/PostReplyHandler.php +++ b/framework/core/src/Core/Command/PostReplyHandler.php @@ -13,7 +13,7 @@ namespace Flarum\Core\Command; use DateTime; use Flarum\User\AssertPermissionTrait; -use Flarum\Core\Notification\NotificationSyncer; +use Flarum\Notification\NotificationSyncer; use Flarum\Post\CommentPost; use Flarum\Discussion\DiscussionRepository; use Flarum\Foundation\DispatchEventsTrait; @@ -32,7 +32,7 @@ class PostReplyHandler protected $discussions; /** - * @var NotificationSyncer + * @var \Flarum\Notification\NotificationSyncer */ protected $notifications; @@ -44,7 +44,7 @@ class PostReplyHandler /** * @param Dispatcher $events * @param DiscussionRepository $discussions - * @param NotificationSyncer $notifications + * @param \Flarum\Notification\NotificationSyncer $notifications * @param PostValidator $validator */ public function __construct( diff --git a/framework/core/src/Core/Command/ReadAllNotificationsHandler.php b/framework/core/src/Core/Command/ReadAllNotificationsHandler.php index 9269ed958..7e2255fd5 100644 --- a/framework/core/src/Core/Command/ReadAllNotificationsHandler.php +++ b/framework/core/src/Core/Command/ReadAllNotificationsHandler.php @@ -12,7 +12,7 @@ namespace Flarum\Core\Command; use Flarum\User\AssertPermissionTrait; -use Flarum\Core\Repository\NotificationRepository; +use Flarum\Notification\NotificationRepository; class ReadAllNotificationsHandler { diff --git a/framework/core/src/Core/Command/ReadNotificationHandler.php b/framework/core/src/Core/Command/ReadNotificationHandler.php index f70f1d6b1..d8ed0a8fa 100644 --- a/framework/core/src/Core/Command/ReadNotificationHandler.php +++ b/framework/core/src/Core/Command/ReadNotificationHandler.php @@ -12,7 +12,7 @@ namespace Flarum\Core\Command; use Flarum\User\AssertPermissionTrait; -use Flarum\Core\Notification; +use Flarum\Notification\Notification; class ReadNotificationHandler { @@ -20,7 +20,7 @@ class ReadNotificationHandler /** * @param ReadNotification $command - * @return \Flarum\Core\Notification + * @return \Flarum\Notification\Notification * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(ReadNotification $command) diff --git a/framework/core/src/Core/CoreServiceProvider.php b/framework/core/src/Core/CoreServiceProvider.php index 82e5f6b0d..dda6e1a28 100644 --- a/framework/core/src/Core/CoreServiceProvider.php +++ b/framework/core/src/Core/CoreServiceProvider.php @@ -40,7 +40,7 @@ class CoreServiceProvider extends AbstractServiceProvider $this->registerAvatarsFilesystem(); - $this->app->register('Flarum\Core\Notification\NotificationServiceProvider'); + $this->app->register('Flarum\Notification\Notification\NotificationServiceProvider'); $this->app->register('Flarum\Search\SearchServiceProvider'); $this->app->register('Flarum\Formatter\FormatterServiceProvider'); } diff --git a/framework/core/src/Discussion/DiscussionRenamedNotifier.php b/framework/core/src/Discussion/DiscussionRenamedNotifier.php index 2cd8bdc9c..d4cc7c5e4 100755 --- a/framework/core/src/Discussion/DiscussionRenamedNotifier.php +++ b/framework/core/src/Discussion/DiscussionRenamedNotifier.php @@ -11,8 +11,8 @@ namespace Flarum\Discussion; -use Flarum\Core\Notification\DiscussionRenamedBlueprint; -use Flarum\Core\Notification\NotificationSyncer; +use Flarum\Notification\Blueprint\DiscussionRenamedBlueprint; +use Flarum\Notification\NotificationSyncer; use Flarum\Post\DiscussionRenamedPost; use Flarum\Discussion\Event\Renamed; use Illuminate\Contracts\Events\Dispatcher; 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/Core/Notification/BlueprintInterface.php b/framework/core/src/Notification/Blueprint/BlueprintInterface.php similarity index 96% rename from framework/core/src/Core/Notification/BlueprintInterface.php rename to framework/core/src/Notification/Blueprint/BlueprintInterface.php index 67bcc31ff..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 diff --git a/framework/core/src/Core/Notification/DiscussionRenamedBlueprint.php b/framework/core/src/Notification/Blueprint/DiscussionRenamedBlueprint.php similarity index 96% rename from framework/core/src/Core/Notification/DiscussionRenamedBlueprint.php rename to framework/core/src/Notification/Blueprint/DiscussionRenamedBlueprint.php index b642d82b9..996483c27 100644 --- a/framework/core/src/Core/Notification/DiscussionRenamedBlueprint.php +++ b/framework/core/src/Notification/Blueprint/DiscussionRenamedBlueprint.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Notification; +namespace Flarum\Notification\Blueprint; use Flarum\Post\DiscussionRenamedPost; diff --git a/framework/core/src/Event/NotificationWillBeSent.php b/framework/core/src/Notification/Event/Sending.php similarity index 79% rename from framework/core/src/Event/NotificationWillBeSent.php rename to framework/core/src/Notification/Event/Sending.php index 12a90ea9d..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,7 +30,7 @@ class NotificationWillBeSent public $users; /** - * @param BlueprintInterface $blueprint + * @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 99% rename from framework/core/src/Core/Notification.php rename to framework/core/src/Notification/Notification.php index 4429cc4b3..6a32fdd36 100644 --- a/framework/core/src/Core/Notification.php +++ b/framework/core/src/Notification/Notification.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\Notification; use Flarum\Database\AbstractModel; diff --git a/framework/core/src/Core/Notification/NotificationMailer.php b/framework/core/src/Notification/NotificationMailer.php similarity index 96% rename from framework/core/src/Core/Notification/NotificationMailer.php rename to framework/core/src/Notification/NotificationMailer.php index 327f0252e..2bee77e5a 100644 --- a/framework/core/src/Core/Notification/NotificationMailer.php +++ b/framework/core/src/Notification/NotificationMailer.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Notification; +namespace Flarum\Notification; use Flarum\User\User; use Illuminate\Contracts\Mail\Mailer; diff --git a/framework/core/src/Core/Repository/NotificationRepository.php b/framework/core/src/Notification/NotificationRepository.php similarity index 96% rename from framework/core/src/Core/Repository/NotificationRepository.php rename to framework/core/src/Notification/NotificationRepository.php index 1b9fe63fb..ae70ea600 100644 --- a/framework/core/src/Core/Repository/NotificationRepository.php +++ b/framework/core/src/Notification/NotificationRepository.php @@ -9,9 +9,8 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Repository; +namespace Flarum\Notification; -use Flarum\Core\Notification; 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 88% rename from framework/core/src/Core/Notification/NotificationServiceProvider.php rename to framework/core/src/Notification/NotificationServiceProvider.php index d8cf09474..811f3b61e 100644 --- a/framework/core/src/Core/Notification/NotificationServiceProvider.php +++ b/framework/core/src/Notification/NotificationServiceProvider.php @@ -9,9 +9,8 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Notification; +namespace Flarum\Notification; -use Flarum\Core\Notification; use Flarum\Event\ConfigureNotificationTypes; use Flarum\Foundation\AbstractServiceProvider; use Flarum\User\User; @@ -33,7 +32,7 @@ class NotificationServiceProvider extends AbstractServiceProvider public function registerNotificationTypes() { $blueprints = [ - 'Flarum\Core\Notification\DiscussionRenamedBlueprint' => ['alert'] + 'Flarum\Notification\Notification\DiscussionRenamedBlueprint' => ['alert'] ]; $this->app->make('events')->fire( @@ -52,7 +51,7 @@ class NotificationServiceProvider extends AbstractServiceProvider in_array('alert', $enabled) ); - if ((new ReflectionClass($blueprint))->implementsInterface('Flarum\Core\Notification\MailableInterface')) { + if ((new ReflectionClass($blueprint))->implementsInterface('Flarum\Notification\Notification\MailableInterface')) { 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 89% rename from framework/core/src/Core/Notification/NotificationSyncer.php rename to framework/core/src/Notification/NotificationSyncer.php index aab276b5b..5abef59e2 100644 --- a/framework/core/src/Core/Notification/NotificationSyncer.php +++ b/framework/core/src/Notification/NotificationSyncer.php @@ -9,12 +9,11 @@ * 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\Event\NotificationWillBeSent; +use Flarum\Notification\Event\Sending; +use Flarum\Notification\Blueprint\BlueprintInterface; use Flarum\User\User; /** @@ -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); @@ -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/User/User.php b/framework/core/src/User/User.php index 70396e6ff..ea222484f 100755 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -13,7 +13,7 @@ namespace Flarum\User; use DomainException; use Flarum\Group\Group; -use Flarum\Core\Notification; +use Flarum\Notification\Notification; use Flarum\Group\Permission; use Flarum\Foundation\EventGeneratorTrait; use Flarum\Database\ScopeVisibilityTrait; @@ -632,7 +632,7 @@ class User extends AbstractModel */ public function notifications() { - return $this->hasMany('Flarum\Core\Notification'); + return $this->hasMany('Flarum\Notification\Notification'); } /** From d6954a997a7206eae48e104f55cb74682a9d4182 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 14:24:42 +0200 Subject: [PATCH 028/172] Move UserState class to Flarum\Discussion namespace --- .../core/src/Core/Command/ReadDiscussionHandler.php | 2 +- framework/core/src/Discussion/Discussion.php | 10 +++++----- framework/core/src/Discussion/Event/UserDataSaving.php | 8 ++++---- framework/core/src/Discussion/Event/UserRead.php | 8 ++++---- .../DiscussionState.php => Discussion/UserState.php} | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) rename framework/core/src/{Core/DiscussionState.php => Discussion/UserState.php} (97%) diff --git a/framework/core/src/Core/Command/ReadDiscussionHandler.php b/framework/core/src/Core/Command/ReadDiscussionHandler.php index 9be64074b..dea81e8b6 100644 --- a/framework/core/src/Core/Command/ReadDiscussionHandler.php +++ b/framework/core/src/Core/Command/ReadDiscussionHandler.php @@ -39,7 +39,7 @@ class ReadDiscussionHandler /** * @param ReadDiscussion $command - * @return \Flarum\Core\DiscussionState + * @return \Flarum\Discussion\UserState * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(ReadDiscussion $command) diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index 0b06f632f..2c73a5aea 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -11,7 +11,7 @@ namespace Flarum\Discussion; -use Flarum\Core\DiscussionState; +use Flarum\Discussion\UserState; use Flarum\Post\MergeableInterface; use Flarum\Foundation\EventGeneratorTrait; use Flarum\Database\ScopeVisibilityTrait; @@ -44,7 +44,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 @@ -416,7 +416,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); } /** @@ -424,14 +424,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/Discussion/Event/UserDataSaving.php b/framework/core/src/Discussion/Event/UserDataSaving.php index 1574b44b6..52a85fe6b 100644 --- a/framework/core/src/Discussion/Event/UserDataSaving.php +++ b/framework/core/src/Discussion/Event/UserDataSaving.php @@ -11,19 +11,19 @@ namespace Flarum\Discussion\Event; -use Flarum\Core\DiscussionState; +use Flarum\Discussion\UserState; 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/Discussion/Event/UserRead.php b/framework/core/src/Discussion/Event/UserRead.php index 8baf3fc31..972a20129 100644 --- a/framework/core/src/Discussion/Event/UserRead.php +++ b/framework/core/src/Discussion/Event/UserRead.php @@ -11,19 +11,19 @@ namespace Flarum\Discussion\Event; -use Flarum\Core\DiscussionState; +use Flarum\Discussion\UserState; 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/DiscussionState.php b/framework/core/src/Discussion/UserState.php similarity index 97% rename from framework/core/src/Core/DiscussionState.php rename to framework/core/src/Discussion/UserState.php index be5e246fc..68a9ad714 100644 --- a/framework/core/src/Core/DiscussionState.php +++ b/framework/core/src/Discussion/UserState.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\Discussion; use Flarum\Discussion\Discussion; use Flarum\Foundation\EventGeneratorTrait; @@ -31,7 +31,7 @@ use Illuminate\Database\Eloquent\Builder; * @property Discussion $discussion * @property \Flarum\User\User $user */ -class DiscussionState extends AbstractModel +class UserState extends AbstractModel { use EventGeneratorTrait; From e1ca9964b22629dbc430cbf728aefa4747853d29 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 14:27:54 +0200 Subject: [PATCH 029/172] Move ExtensionValidator class to Flarum\Extension namespace --- framework/core/src/Core/CoreServiceProvider.php | 2 +- .../DefaultLanguagePackGuard.php} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename framework/core/src/{Core/Listener/ExtensionValidator.php => Extension/DefaultLanguagePackGuard.php} (95%) diff --git a/framework/core/src/Core/CoreServiceProvider.php b/framework/core/src/Core/CoreServiceProvider.php index dda6e1a28..f5b364f28 100644 --- a/framework/core/src/Core/CoreServiceProvider.php +++ b/framework/core/src/Core/CoreServiceProvider.php @@ -109,7 +109,7 @@ class CoreServiceProvider extends AbstractServiceProvider $events->subscribe('Flarum\Core\Listener\SelfDemotionGuard'); $events->subscribe('Flarum\Discussion\DiscussionMetadataUpdater'); $events->subscribe('Flarum\User\UserMetadataUpdater'); - $events->subscribe('Flarum\Core\Listener\ExtensionValidator'); + $events->subscribe('Flarum\Extension\DefaultLanguagePackGuard'); $events->subscribe('Flarum\User\EmailConfirmationMailer'); $events->subscribe('Flarum\Discussion\DiscussionRenamedNotifier'); diff --git a/framework/core/src/Core/Listener/ExtensionValidator.php b/framework/core/src/Extension/DefaultLanguagePackGuard.php similarity index 95% rename from framework/core/src/Core/Listener/ExtensionValidator.php rename to framework/core/src/Extension/DefaultLanguagePackGuard.php index b7e3634d6..68afffd91 100644 --- a/framework/core/src/Core/Listener/ExtensionValidator.php +++ b/framework/core/src/Extension/DefaultLanguagePackGuard.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Listener; +namespace Flarum\Extension; use Flarum\Event\ExtensionWillBeDisabled; use Flarum\Http\Exception\ForbiddenException; use Illuminate\Contracts\Events\Dispatcher; -class ExtensionValidator +class DefaultLanguagePackGuard { /** * @param Dispatcher $events From ede7e96282ff63938dcfd0df2c4fc900f3ac501c Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 14:37:13 +0200 Subject: [PATCH 030/172] Fix class names in strings --- .../core/src/Notification/NotificationServiceProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Notification/NotificationServiceProvider.php b/framework/core/src/Notification/NotificationServiceProvider.php index 811f3b61e..3edbffcaa 100644 --- a/framework/core/src/Notification/NotificationServiceProvider.php +++ b/framework/core/src/Notification/NotificationServiceProvider.php @@ -32,7 +32,7 @@ class NotificationServiceProvider extends AbstractServiceProvider public function registerNotificationTypes() { $blueprints = [ - 'Flarum\Notification\Notification\DiscussionRenamedBlueprint' => ['alert'] + 'Flarum\Notification\Blueprint\DiscussionRenamedBlueprint' => ['alert'] ]; $this->app->make('events')->fire( @@ -51,7 +51,7 @@ class NotificationServiceProvider extends AbstractServiceProvider in_array('alert', $enabled) ); - if ((new ReflectionClass($blueprint))->implementsInterface('Flarum\Notification\Notification\MailableInterface')) { + if ((new ReflectionClass($blueprint))->implementsInterface('Flarum\Notification\MailableInterface')) { User::addPreference( User::getNotificationPreferenceKey($type, 'email'), 'boolval', From 6e8b8ac357a6ad39eaa6c091e22ddf2bb1c0607a Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 14:51:42 +0200 Subject: [PATCH 031/172] Split up old CoreServiceProvider --- framework/core/src/BusServiceProvider.php | 30 ++++++++++++ .../Discussion/DiscussionServiceProvider.php | 29 +++++++++++ .../Extension/ExtensionServiceProvider.php | 10 ++++ .../core/src/Foundation/AbstractServer.php | 11 ++++- .../src/Frontend/FrontendServiceProvider.php | 25 ++++++++++ .../core/src/Group/GroupServiceProvider.php | 26 ++++++++++ .../src/Install/Console/InstallCommand.php | 8 ++- .../core/src/Post/PostServiceProvider.php | 47 ++++++++++++++++++ .../UserServiceProvider.php} | 49 ++----------------- 9 files changed, 187 insertions(+), 48 deletions(-) create mode 100644 framework/core/src/BusServiceProvider.php create mode 100644 framework/core/src/Discussion/DiscussionServiceProvider.php create mode 100644 framework/core/src/Frontend/FrontendServiceProvider.php create mode 100644 framework/core/src/Group/GroupServiceProvider.php create mode 100644 framework/core/src/Post/PostServiceProvider.php rename framework/core/src/{Core/CoreServiceProvider.php => User/UserServiceProvider.php} (68%) diff --git a/framework/core/src/BusServiceProvider.php b/framework/core/src/BusServiceProvider.php new file mode 100644 index 000000000..4406460f6 --- /dev/null +++ b/framework/core/src/BusServiceProvider.php @@ -0,0 +1,30 @@ +<?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; + +use Flarum\Foundation\AbstractServiceProvider; + +/** + * @deprecated + */ +class BusServiceProvider extends AbstractServiceProvider +{ + /** + * {@inheritdoc} + */ + public function boot() + { + $this->app->make('Illuminate\Contracts\Bus\Dispatcher')->mapUsing(function ($command) { + return get_class($command).'Handler@handle'; + }); + } +} diff --git a/framework/core/src/Discussion/DiscussionServiceProvider.php b/framework/core/src/Discussion/DiscussionServiceProvider.php new file mode 100644 index 000000000..89b9ce30d --- /dev/null +++ b/framework/core/src/Discussion/DiscussionServiceProvider.php @@ -0,0 +1,29 @@ +<?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\Discussion; + +use Flarum\Foundation\AbstractServiceProvider; + +class DiscussionServiceProvider extends AbstractServiceProvider +{ + /** + * {@inheritdoc} + */ + public function boot() + { + $events = $this->app->make('events'); + + $events->subscribe('Flarum\Discussion\DiscussionMetadataUpdater'); + $events->subscribe('Flarum\Discussion\DiscussionPolicy'); + $events->subscribe('Flarum\Discussion\DiscussionRenamedNotifier'); + } +} diff --git a/framework/core/src/Extension/ExtensionServiceProvider.php b/framework/core/src/Extension/ExtensionServiceProvider.php index 522f9d9e5..a421b1865 100644 --- a/framework/core/src/Extension/ExtensionServiceProvider.php +++ b/framework/core/src/Extension/ExtensionServiceProvider.php @@ -30,4 +30,14 @@ class ExtensionServiceProvider extends AbstractServiceProvider $this->app->call($bootstrapper); } } + + /** + * {@inheritdoc} + */ + public function boot() + { + $events = $this->app->make('events'); + + $events->subscribe('Flarum\Extension\DefaultLanguagePackGuard'); + } } diff --git a/framework/core/src/Foundation/AbstractServer.php b/framework/core/src/Foundation/AbstractServer.php index 34ef520d2..bcc7c534b 100644 --- a/framework/core/src/Foundation/AbstractServer.php +++ b/framework/core/src/Foundation/AbstractServer.php @@ -190,7 +190,16 @@ 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\BusServiceProvider'); + + $app->register('Flarum\Discussion\DiscussionServiceProvider'); + $app->register('Flarum\Formatter\FormatterServiceProvider'); + $app->register('Flarum\Group\GroupServiceProvider'); + $app->register('Flarum\Notification\NotificationServiceProvider'); + $app->register('Flarum\Post\PostServiceProvider'); + $app->register('Flarum\Search\SearchServiceProvider'); + $app->register('Flarum\User\UserServiceProvider'); + $app->register('Flarum\Api\ApiServiceProvider'); $app->register('Flarum\Forum\ForumServiceProvider'); $app->register('Flarum\Admin\AdminServiceProvider'); diff --git a/framework/core/src/Frontend/FrontendServiceProvider.php b/framework/core/src/Frontend/FrontendServiceProvider.php new file mode 100644 index 000000000..aa4ba6064 --- /dev/null +++ b/framework/core/src/Frontend/FrontendServiceProvider.php @@ -0,0 +1,25 @@ +<?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\Frontend; + +use Flarum\Foundation\AbstractServiceProvider; + +class FrontendServiceProvider extends AbstractServiceProvider +{ + /** + * {@inheritdoc} + */ + public function boot() + { + $this->loadViewsFrom(__DIR__.'/../../views', 'flarum'); + } +} diff --git a/framework/core/src/Group/GroupServiceProvider.php b/framework/core/src/Group/GroupServiceProvider.php new file mode 100644 index 000000000..bdf1ceb15 --- /dev/null +++ b/framework/core/src/Group/GroupServiceProvider.php @@ -0,0 +1,26 @@ +<?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\Group; + +use Flarum\Foundation\AbstractServiceProvider; + +class GroupServiceProvider extends AbstractServiceProvider +{ + /** + * {@inheritdoc} + */ + public function boot() + { + $events = $this->app->make('events'); + $events->subscribe('Flarum\Group\GroupPolicy'); + } +} diff --git a/framework/core/src/Install/Console/InstallCommand.php b/framework/core/src/Install/Console/InstallCommand.php index ace02e89b..c75928601 100644 --- a/framework/core/src/Install/Console/InstallCommand.php +++ b/framework/core/src/Install/Console/InstallCommand.php @@ -171,7 +171,13 @@ class InstallCommand extends AbstractCommand $this->writeSettings(); - $this->application->register('Flarum\Core\CoreServiceProvider'); + $this->application->register('Flarum\Formatter\FormatterServiceProvider'); + $this->application->register('Flarum\Discussion\DiscussionServiceProvider'); + $this->application->register('Flarum\Group\GroupServiceProvider'); + $this->application->register('Flarum\Notification\NotificationServiceProvider'); + $this->application->register('Flarum\Search\SearchServiceProvider'); + $this->application->register('Flarum\Post\PostServiceProvider'); + $this->application->register('Flarum\User\UserServiceProvider'); $this->seedGroups(); $this->seedPermissions(); 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/CoreServiceProvider.php b/framework/core/src/User/UserServiceProvider.php similarity index 68% rename from framework/core/src/Core/CoreServiceProvider.php rename to framework/core/src/User/UserServiceProvider.php index f5b364f28..45a7e8a24 100644 --- a/framework/core/src/Core/CoreServiceProvider.php +++ b/framework/core/src/User/UserServiceProvider.php @@ -9,20 +9,14 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\User; -use Flarum\Post\CommentPost; -use Flarum\Event\ConfigurePostTypes; use Flarum\Event\ConfigureUserPreferences; use Flarum\Event\GetPermission; use Flarum\Foundation\AbstractServiceProvider; -use Flarum\Post\Post; -use Flarum\User\Gate; -use Flarum\User\User; use Illuminate\Contracts\Container\Container; -use RuntimeException; -class CoreServiceProvider extends AbstractServiceProvider +class UserServiceProvider extends AbstractServiceProvider { /** * {@inheritdoc} @@ -39,10 +33,6 @@ class CoreServiceProvider extends AbstractServiceProvider $this->app->alias('flarum.gate', 'Flarum\User\Gate'); $this->registerAvatarsFilesystem(); - - $this->app->register('Flarum\Notification\Notification\NotificationServiceProvider'); - $this->app->register('Flarum\Search\SearchServiceProvider'); - $this->app->register('Flarum\Formatter\FormatterServiceProvider'); } protected function registerAvatarsFilesystem() @@ -69,12 +59,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 @@ -97,46 +81,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\Discussion\DiscussionMetadataUpdater'); - $events->subscribe('Flarum\User\UserMetadataUpdater'); - $events->subscribe('Flarum\Extension\DefaultLanguagePackGuard'); $events->subscribe('Flarum\User\EmailConfirmationMailer'); - $events->subscribe('Flarum\Discussion\DiscussionRenamedNotifier'); - - $events->subscribe('Flarum\Discussion\DiscussionPolicy'); - $events->subscribe('Flarum\Group\GroupPolicy'); - $events->subscribe('Flarum\Post\PostPolicy'); + $events->subscribe('Flarum\User\UserMetadataUpdater'); $events->subscribe('Flarum\User\UserPolicy'); $events->listen(ConfigureUserPreferences::class, [$this, 'configureUserPreferences']); } - 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); - } - } - /** * @param ConfigureUserPreferences $event */ From f725d897e8a8aaa7727ae19a1040fff9ef52b2c2 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 14:55:47 +0200 Subject: [PATCH 032/172] Rename listener class to DiscussionRenamedLogger --- ...iscussionRenamedNotifier.php => DiscussionRenamedLogger.php} | 2 +- framework/core/src/Discussion/DiscussionServiceProvider.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename framework/core/src/Discussion/{DiscussionRenamedNotifier.php => DiscussionRenamedLogger.php} (98%) diff --git a/framework/core/src/Discussion/DiscussionRenamedNotifier.php b/framework/core/src/Discussion/DiscussionRenamedLogger.php similarity index 98% rename from framework/core/src/Discussion/DiscussionRenamedNotifier.php rename to framework/core/src/Discussion/DiscussionRenamedLogger.php index d4cc7c5e4..8ccf74ff9 100755 --- a/framework/core/src/Discussion/DiscussionRenamedNotifier.php +++ b/framework/core/src/Discussion/DiscussionRenamedLogger.php @@ -17,7 +17,7 @@ use Flarum\Post\DiscussionRenamedPost; use Flarum\Discussion\Event\Renamed; use Illuminate\Contracts\Events\Dispatcher; -class DiscussionRenamedNotifier +class DiscussionRenamedLogger { /** * @var NotificationSyncer diff --git a/framework/core/src/Discussion/DiscussionServiceProvider.php b/framework/core/src/Discussion/DiscussionServiceProvider.php index 89b9ce30d..5f8ca4216 100644 --- a/framework/core/src/Discussion/DiscussionServiceProvider.php +++ b/framework/core/src/Discussion/DiscussionServiceProvider.php @@ -24,6 +24,6 @@ class DiscussionServiceProvider extends AbstractServiceProvider $events->subscribe('Flarum\Discussion\DiscussionMetadataUpdater'); $events->subscribe('Flarum\Discussion\DiscussionPolicy'); - $events->subscribe('Flarum\Discussion\DiscussionRenamedNotifier'); + $events->subscribe('Flarum\Discussion\DiscussionRenamedLogger'); } } From 4562da2cc2aedd16a91a565a61bd2cb80a18fe62 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 15:04:46 +0200 Subject: [PATCH 033/172] Fix namespaces --- .../src/Api/Controller/ListUsersController.php | 2 +- framework/core/src/Event/ConfigureUserSearch.php | 4 ++-- framework/core/src/Post/Post.php | 2 +- .../core/src/Search/SearchServiceProvider.php | 8 ++++---- framework/core/src/User/EmailToken.php | 2 +- framework/core/src/User/PasswordToken.php | 2 +- .../core/src/User/Search/Gambit/EmailGambit.php | 6 +++--- .../src/User/Search/Gambit/FulltextGambit.php | 4 ++-- .../core/src/User/Search/Gambit/GroupGambit.php | 4 ++-- framework/core/src/User/Search/UserSearch.php | 2 +- framework/core/src/User/Search/UserSearcher.php | 15 +++++++-------- 11 files changed, 25 insertions(+), 26 deletions(-) diff --git a/framework/core/src/Api/Controller/ListUsersController.php b/framework/core/src/Api/Controller/ListUsersController.php index 1dadbb103..f953e33b4 100644 --- a/framework/core/src/Api/Controller/ListUsersController.php +++ b/framework/core/src/Api/Controller/ListUsersController.php @@ -14,7 +14,7 @@ namespace Flarum\Api\Controller; use Flarum\Api\UrlGenerator; use Flarum\User\Exception\PermissionDeniedException; use Flarum\Search\SearchCriteria; -use Flarum\Core\User\Search\UserSearcher; +use Flarum\User\Search\UserSearcher; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; diff --git a/framework/core/src/Event/ConfigureUserSearch.php b/framework/core/src/Event/ConfigureUserSearch.php index 309f60c10..1b9a235e4 100644 --- a/framework/core/src/Event/ConfigureUserSearch.php +++ b/framework/core/src/Event/ConfigureUserSearch.php @@ -12,12 +12,12 @@ namespace Flarum\Event; use Flarum\Search\SearchCriteria; -use Flarum\Core\User\Search\UserSearch; +use Flarum\User\Search\UserSearch; class ConfigureUserSearch { /** - * @var \Flarum\Core\User\Search\UserSearch + * @var \Flarum\User\Search\UserSearch */ public $search; diff --git a/framework/core/src/Post/Post.php b/framework/core/src/Post/Post.php index 468a708fb..c85538582 100755 --- a/framework/core/src/Post/Post.php +++ b/framework/core/src/Post/Post.php @@ -11,11 +11,11 @@ namespace Flarum\Post; -use Flarum\Core\User; use Flarum\Foundation\EventGeneratorTrait; use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; use Flarum\Post\Event\Deleted; +use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; /** diff --git a/framework/core/src/Search/SearchServiceProvider.php b/framework/core/src/Search/SearchServiceProvider.php index 9b2ded54b..71d316d54 100644 --- a/framework/core/src/Search/SearchServiceProvider.php +++ b/framework/core/src/Search/SearchServiceProvider.php @@ -37,14 +37,14 @@ class SearchServiceProvider extends AbstractServiceProvider public function registerUserGambits() { - $this->app->when('Flarum\Core\User\Search\UserSearcher') + $this->app->when('Flarum\User\Search\UserSearcher') ->needs('Flarum\Search\GambitManager') ->give(function (Container $app) { $gambits = new GambitManager($app); - $gambits->setFulltextGambit('Flarum\Core\User\Search\Gambit\FulltextGambit'); - $gambits->add('Flarum\Core\User\Search\Gambit\EmailGambit'); - $gambits->add('Flarum\Core\User\Search\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) diff --git a/framework/core/src/User/EmailToken.php b/framework/core/src/User/EmailToken.php index e0383f2ff..f60d35c89 100644 --- a/framework/core/src/User/EmailToken.php +++ b/framework/core/src/User/EmailToken.php @@ -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/User/PasswordToken.php b/framework/core/src/User/PasswordToken.php index 190d1d27a..53b955eda 100644 --- a/framework/core/src/User/PasswordToken.php +++ b/framework/core/src/User/PasswordToken.php @@ -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/User/Search/Gambit/EmailGambit.php b/framework/core/src/User/Search/Gambit/EmailGambit.php index 3d12c02ed..c44ebc1ba 100644 --- a/framework/core/src/User/Search/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\User\Search\Gambit; +namespace Flarum\User\Search\Gambit; -use Flarum\User\UserRepository; use Flarum\Search\AbstractRegexGambit; use Flarum\Search\AbstractSearch; -use Flarum\Core\User\Search\UserSearch; +use Flarum\User\Search\UserSearch; +use Flarum\User\UserRepository; use LogicException; class EmailGambit extends AbstractRegexGambit diff --git a/framework/core/src/User/Search/Gambit/FulltextGambit.php b/framework/core/src/User/Search/Gambit/FulltextGambit.php index 0d2c02baa..a41821693 100644 --- a/framework/core/src/User/Search/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\User\Search\Gambit; +namespace Flarum\User\Search\Gambit; -use Flarum\User\UserRepository; use Flarum\Search\AbstractSearch; use Flarum\Search\GambitInterface; +use Flarum\User\UserRepository; class FulltextGambit implements GambitInterface { diff --git a/framework/core/src/User/Search/Gambit/GroupGambit.php b/framework/core/src/User/Search/Gambit/GroupGambit.php index 317ea8232..e690d93e5 100644 --- a/framework/core/src/User/Search/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\User\Search\Gambit; +namespace Flarum\User\Search\Gambit; use Flarum\Group\GroupRepository; use Flarum\Search\AbstractRegexGambit; use Flarum\Search\AbstractSearch; -use Flarum\Core\User\Search\UserSearch; +use Flarum\User\Search\UserSearch; use LogicException; class GroupGambit extends AbstractRegexGambit diff --git a/framework/core/src/User/Search/UserSearch.php b/framework/core/src/User/Search/UserSearch.php index d26620f5e..d3a7ba28b 100644 --- a/framework/core/src/User/Search/UserSearch.php +++ b/framework/core/src/User/Search/UserSearch.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\User\Search; +namespace Flarum\User\Search; use Flarum\Search\AbstractSearch; diff --git a/framework/core/src/User/Search/UserSearcher.php b/framework/core/src/User/Search/UserSearcher.php index 13b0838aa..2cb5cab2b 100644 --- a/framework/core/src/User/Search/UserSearcher.php +++ b/framework/core/src/User/Search/UserSearcher.php @@ -9,9 +9,8 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\User\Search; +namespace Flarum\User\Search; -use Flarum\Core\User\Search\UserSearch; use Flarum\User\UserRepository; use Flarum\Search\ApplySearchParametersTrait; use Flarum\Search\GambitManager; @@ -28,7 +27,7 @@ class UserSearcher use ApplySearchParametersTrait; /** - * @var \Flarum\Search\GambitManager + * @var GambitManager */ protected $gambits; @@ -38,10 +37,10 @@ class UserSearcher protected $users; /** - * @param \Flarum\Search\GambitManager $gambits + * @param GambitManager $gambits * @param \Flarum\User\UserRepository $users */ - public function __construct(\Flarum\Search\GambitManager $gambits, UserRepository $users) + public function __construct(GambitManager $gambits, UserRepository $users) { $this->gambits = $gambits; $this->users = $users; @@ -52,9 +51,9 @@ class UserSearcher * @param int|null $limit * @param int $offset * @param array $load An array of relationships to load on the results. - * @return \Flarum\Search\SearchResults + * @return SearchResults */ - public function search(\Flarum\Search\SearchCriteria $criteria, $limit = null, $offset = 0, array $load = []) + public function search(SearchCriteria $criteria, $limit = null, $offset = 0, array $load = []) { $actor = $criteria->actor; @@ -83,6 +82,6 @@ class UserSearcher $users->load($load); - return new \Flarum\Search\SearchResults($users, $areMoreResults); + return new SearchResults($users, $areMoreResults); } } From 2e87441f0e91d48d6694998742828483addc8bf7 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 15:21:07 +0200 Subject: [PATCH 034/172] Move command classes to domain namespaces They will probably be refactored away at a later stage (when we get rid of the command bus). Until then, this lets us remove the Flarum\Core namespace and actually feels quite clean. --- .../src/Api/Controller/CreateDiscussionController.php | 4 ++-- .../core/src/Api/Controller/CreateGroupController.php | 2 +- .../core/src/Api/Controller/CreatePostController.php | 4 ++-- .../core/src/Api/Controller/CreateUserController.php | 2 +- .../core/src/Api/Controller/DeleteAvatarController.php | 2 +- .../src/Api/Controller/DeleteDiscussionController.php | 2 +- .../core/src/Api/Controller/DeleteGroupController.php | 2 +- .../core/src/Api/Controller/DeletePostController.php | 2 +- .../core/src/Api/Controller/DeleteUserController.php | 2 +- .../src/Api/Controller/ForgotPasswordController.php | 2 +- .../Api/Controller/ReadAllNotificationsController.php | 2 +- .../src/Api/Controller/UpdateDiscussionController.php | 4 ++-- .../core/src/Api/Controller/UpdateGroupController.php | 2 +- .../Api/Controller/UpdateNotificationController.php | 2 +- .../core/src/Api/Controller/UpdatePostController.php | 2 +- .../core/src/Api/Controller/UpdateUserController.php | 2 +- .../core/src/Api/Controller/UploadAvatarController.php | 2 +- .../{Core => Discussion}/Command/DeleteDiscussion.php | 2 +- .../Command/DeleteDiscussionHandler.php | 8 ++++---- .../{Core => Discussion}/Command/EditDiscussion.php | 2 +- .../Command/EditDiscussionHandler.php | 7 +++---- .../{Core => Discussion}/Command/ReadDiscussion.php | 2 +- .../Command/ReadDiscussionHandler.php | 6 +++--- .../{Core => Discussion}/Command/StartDiscussion.php | 2 +- .../Command/StartDiscussionHandler.php | 6 +++--- .../src/Forum/Controller/ConfirmEmailController.php | 4 ++-- .../core/src/{Core => Group}/Command/CreateGroup.php | 2 +- .../src/{Core => Group}/Command/CreateGroupHandler.php | 8 ++++---- .../core/src/{Core => Group}/Command/DeleteGroup.php | 2 +- .../src/{Core => Group}/Command/DeleteGroupHandler.php | 8 ++++---- .../core/src/{Core => Group}/Command/EditGroup.php | 2 +- .../src/{Core => Group}/Command/EditGroupHandler.php | 10 +++++----- .../Command/ReadAllNotifications.php | 2 +- .../Command/ReadAllNotificationsHandler.php | 4 ++-- .../Command/ReadNotification.php | 2 +- .../Command/ReadNotificationHandler.php | 4 ++-- .../core/src/{Core => Post}/Command/DeletePost.php | 2 +- .../src/{Core => Post}/Command/DeletePostHandler.php | 7 +++---- framework/core/src/{Core => Post}/Command/EditPost.php | 2 +- .../src/{Core => Post}/Command/EditPostHandler.php | 10 +++++----- .../core/src/{Core => Post}/Command/PostReply.php | 2 +- .../src/{Core => Post}/Command/PostReplyHandler.php | 10 +++++----- .../core/src/{Core => User}/Command/ConfirmEmail.php | 2 +- .../src/{Core => User}/Command/ConfirmEmailHandler.php | 6 +++--- .../core/src/{Core => User}/Command/DeleteAvatar.php | 2 +- .../src/{Core => User}/Command/DeleteAvatarHandler.php | 9 ++++----- .../core/src/{Core => User}/Command/DeleteUser.php | 2 +- .../src/{Core => User}/Command/DeleteUserHandler.php | 6 +++--- framework/core/src/{Core => User}/Command/EditUser.php | 2 +- .../src/{Core => User}/Command/EditUserHandler.php | 10 +++++----- .../core/src/{Core => User}/Command/RegisterUser.php | 2 +- .../src/{Core => User}/Command/RegisterUserHandler.php | 10 +++++----- .../{Core => User}/Command/RequestPasswordReset.php | 2 +- .../Command/RequestPasswordResetHandler.php | 7 +++---- .../core/src/{Core => User}/Command/UploadAvatar.php | 2 +- .../src/{Core => User}/Command/UploadAvatarHandler.php | 10 +++++----- framework/core/src/User/UserServiceProvider.php | 6 +++--- 57 files changed, 115 insertions(+), 119 deletions(-) rename framework/core/src/{Core => Discussion}/Command/DeleteDiscussion.php (96%) rename framework/core/src/{Core => Discussion}/Command/DeleteDiscussionHandler.php (97%) rename framework/core/src/{Core => Discussion}/Command/EditDiscussion.php (96%) rename framework/core/src/{Core => Discussion}/Command/EditDiscussionHandler.php (96%) rename framework/core/src/{Core => Discussion}/Command/ReadDiscussion.php (96%) rename framework/core/src/{Core => Discussion}/Command/ReadDiscussionHandler.php (97%) rename framework/core/src/{Core => Discussion}/Command/StartDiscussion.php (95%) rename framework/core/src/{Core => Discussion}/Command/StartDiscussionHandler.php (98%) rename framework/core/src/{Core => Group}/Command/CreateGroup.php (95%) rename framework/core/src/{Core => Group}/Command/CreateGroupHandler.php (98%) rename framework/core/src/{Core => Group}/Command/DeleteGroup.php (97%) rename framework/core/src/{Core => Group}/Command/DeleteGroupHandler.php (97%) rename framework/core/src/{Core => Group}/Command/EditGroup.php (96%) rename framework/core/src/{Core => Group}/Command/EditGroupHandler.php (98%) rename framework/core/src/{Core => Notification}/Command/ReadAllNotifications.php (93%) rename framework/core/src/{Core => Notification}/Command/ReadAllNotificationsHandler.php (96%) rename framework/core/src/{Core => Notification}/Command/ReadNotification.php (95%) rename framework/core/src/{Core => Notification}/Command/ReadNotificationHandler.php (96%) rename framework/core/src/{Core => Post}/Command/DeletePost.php (97%) rename framework/core/src/{Core => Post}/Command/DeletePostHandler.php (94%) rename framework/core/src/{Core => Post}/Command/EditPost.php (96%) rename framework/core/src/{Core => Post}/Command/EditPostHandler.php (98%) rename framework/core/src/{Core => Post}/Command/PostReply.php (97%) rename framework/core/src/{Core => Post}/Command/PostReplyHandler.php (99%) rename framework/core/src/{Core => User}/Command/ConfirmEmail.php (94%) rename framework/core/src/{Core => User}/Command/ConfirmEmailHandler.php (93%) rename framework/core/src/{Core => User}/Command/DeleteAvatar.php (96%) rename framework/core/src/{Core => User}/Command/DeleteAvatarHandler.php (95%) rename framework/core/src/{Core => User}/Command/DeleteUser.php (97%) rename framework/core/src/{Core => User}/Command/DeleteUserHandler.php (97%) rename framework/core/src/{Core => User}/Command/EditUser.php (96%) rename framework/core/src/{Core => User}/Command/EditUserHandler.php (99%) rename framework/core/src/{Core => User}/Command/RegisterUser.php (95%) rename framework/core/src/{Core => User}/Command/RegisterUserHandler.php (99%) rename framework/core/src/{Core => User}/Command/RequestPasswordReset.php (94%) rename framework/core/src/{Core => User}/Command/RequestPasswordResetHandler.php (98%) rename framework/core/src/{Core => User}/Command/UploadAvatar.php (97%) rename framework/core/src/{Core => User}/Command/UploadAvatarHandler.php (99%) diff --git a/framework/core/src/Api/Controller/CreateDiscussionController.php b/framework/core/src/Api/Controller/CreateDiscussionController.php index ab6eb9cde..69f2afc15 100644 --- a/framework/core/src/Api/Controller/CreateDiscussionController.php +++ b/framework/core/src/Api/Controller/CreateDiscussionController.php @@ -11,8 +11,8 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\ReadDiscussion; -use Flarum\Core\Command\StartDiscussion; +use Flarum\Discussion\Command\ReadDiscussion; +use Flarum\Discussion\Command\StartDiscussion; use Flarum\Post\Floodgate; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; 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 a268b7d21..fc7432530 100644 --- a/framework/core/src/Api/Controller/CreatePostController.php +++ b/framework/core/src/Api/Controller/CreatePostController.php @@ -11,8 +11,8 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\PostReply; -use Flarum\Core\Command\ReadDiscussion; +use Flarum\Discussion\Command\ReadDiscussion; +use Flarum\Post\Command\PostReply; use Flarum\Post\Floodgate; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; 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 73cbe9dd1..61ab87109 100644 --- a/framework/core/src/Api/Controller/DeleteAvatarController.php +++ b/framework/core/src/Api/Controller/DeleteAvatarController.php @@ -11,7 +11,7 @@ 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; 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/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/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 5516c6d47..56e638878 100644 --- a/framework/core/src/Api/Controller/ForgotPasswordController.php +++ b/framework/core/src/Api/Controller/ForgotPasswordController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\RequestPasswordReset; +use Flarum\User\Command\RequestPasswordReset; use Flarum\User\UserRepository; use Flarum\Http\Controller\ControllerInterface; use Illuminate\Contracts\Bus\Dispatcher; 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/UpdateDiscussionController.php b/framework/core/src/Api/Controller/UpdateDiscussionController.php index 09ba078c5..4cdd3a0a1 100644 --- a/framework/core/src/Api/Controller/UpdateDiscussionController.php +++ b/framework/core/src/Api/Controller/UpdateDiscussionController.php @@ -11,8 +11,8 @@ 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; diff --git a/framework/core/src/Api/Controller/UpdateGroupController.php b/framework/core/src/Api/Controller/UpdateGroupController.php index ccb6a8b6e..c4bd8f5dd 100644 --- a/framework/core/src/Api/Controller/UpdateGroupController.php +++ b/framework/core/src/Api/Controller/UpdateGroupController.php @@ -11,7 +11,7 @@ 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; diff --git a/framework/core/src/Api/Controller/UpdateNotificationController.php b/framework/core/src/Api/Controller/UpdateNotificationController.php index 01e305bc7..f459e0338 100644 --- a/framework/core/src/Api/Controller/UpdateNotificationController.php +++ b/framework/core/src/Api/Controller/UpdateNotificationController.php @@ -11,7 +11,7 @@ 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; diff --git a/framework/core/src/Api/Controller/UpdatePostController.php b/framework/core/src/Api/Controller/UpdatePostController.php index bb5a5f08a..6f13e3371 100644 --- a/framework/core/src/Api/Controller/UpdatePostController.php +++ b/framework/core/src/Api/Controller/UpdatePostController.php @@ -11,7 +11,7 @@ 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; diff --git a/framework/core/src/Api/Controller/UpdateUserController.php b/framework/core/src/Api/Controller/UpdateUserController.php index 818e4d941..42a57754a 100644 --- a/framework/core/src/Api/Controller/UpdateUserController.php +++ b/framework/core/src/Api/Controller/UpdateUserController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Core\Command\EditUser; +use Flarum\User\Command\EditUser; use Flarum\User\Exception\PermissionDeniedException; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; diff --git a/framework/core/src/Api/Controller/UploadAvatarController.php b/framework/core/src/Api/Controller/UploadAvatarController.php index ac3619d24..b2e23e33b 100644 --- a/framework/core/src/Api/Controller/UploadAvatarController.php +++ b/framework/core/src/Api/Controller/UploadAvatarController.php @@ -11,7 +11,7 @@ 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; diff --git a/framework/core/src/Core/Command/DeleteDiscussion.php b/framework/core/src/Discussion/Command/DeleteDiscussion.php similarity index 96% rename from framework/core/src/Core/Command/DeleteDiscussion.php rename to framework/core/src/Discussion/Command/DeleteDiscussion.php index 3c4d1219b..f79525fb6 100644 --- a/framework/core/src/Core/Command/DeleteDiscussion.php +++ b/framework/core/src/Discussion/Command/DeleteDiscussion.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Discussion\Command; use Flarum\User\User; diff --git a/framework/core/src/Core/Command/DeleteDiscussionHandler.php b/framework/core/src/Discussion/Command/DeleteDiscussionHandler.php similarity index 97% rename from framework/core/src/Core/Command/DeleteDiscussionHandler.php rename to framework/core/src/Discussion/Command/DeleteDiscussionHandler.php index 9643b5e96..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\Discussion\DiscussionRepository; +use Flarum\Discussion\Event\Deleting; +use Flarum\Foundation\DispatchEventsTrait; use Flarum\User\AssertPermissionTrait; use Flarum\User\Exception\PermissionDeniedException; -use Flarum\Discussion\DiscussionRepository; -use Flarum\Foundation\DispatchEventsTrait; -use Flarum\Discussion\Event\Deleting; use Illuminate\Contracts\Events\Dispatcher; class DeleteDiscussionHandler diff --git a/framework/core/src/Core/Command/EditDiscussion.php b/framework/core/src/Discussion/Command/EditDiscussion.php similarity index 96% rename from framework/core/src/Core/Command/EditDiscussion.php rename to framework/core/src/Discussion/Command/EditDiscussion.php index 4ae77a276..660ed8b0d 100644 --- a/framework/core/src/Core/Command/EditDiscussion.php +++ b/framework/core/src/Discussion/Command/EditDiscussion.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Discussion\Command; use Flarum\User\User; diff --git a/framework/core/src/Core/Command/EditDiscussionHandler.php b/framework/core/src/Discussion/Command/EditDiscussionHandler.php similarity index 96% rename from framework/core/src/Core/Command/EditDiscussionHandler.php rename to framework/core/src/Discussion/Command/EditDiscussionHandler.php index 038777d3e..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\User\AssertPermissionTrait; -use Flarum\User\Exception\PermissionDeniedException; use Flarum\Discussion\DiscussionRepository; -use Flarum\Foundation\DispatchEventsTrait; use Flarum\Discussion\DiscussionValidator; use Flarum\Discussion\Event\Saving; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\User\AssertPermissionTrait; use Illuminate\Contracts\Events\Dispatcher; class EditDiscussionHandler diff --git a/framework/core/src/Core/Command/ReadDiscussion.php b/framework/core/src/Discussion/Command/ReadDiscussion.php similarity index 96% rename from framework/core/src/Core/Command/ReadDiscussion.php rename to framework/core/src/Discussion/Command/ReadDiscussion.php index 4a0c8ebd4..c6a8826e3 100644 --- a/framework/core/src/Core/Command/ReadDiscussion.php +++ b/framework/core/src/Discussion/Command/ReadDiscussion.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Discussion\Command; use Flarum\User\User; diff --git a/framework/core/src/Core/Command/ReadDiscussionHandler.php b/framework/core/src/Discussion/Command/ReadDiscussionHandler.php similarity index 97% rename from framework/core/src/Core/Command/ReadDiscussionHandler.php rename to framework/core/src/Discussion/Command/ReadDiscussionHandler.php index dea81e8b6..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\User\AssertPermissionTrait; use Flarum\Discussion\DiscussionRepository; -use Flarum\Foundation\DispatchEventsTrait; use Flarum\Discussion\Event\UserDataSaving; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\User\AssertPermissionTrait; use Illuminate\Contracts\Events\Dispatcher; class ReadDiscussionHandler diff --git a/framework/core/src/Core/Command/StartDiscussion.php b/framework/core/src/Discussion/Command/StartDiscussion.php similarity index 95% rename from framework/core/src/Core/Command/StartDiscussion.php rename to framework/core/src/Discussion/Command/StartDiscussion.php index 9bc0cab10..3b564c0f1 100644 --- a/framework/core/src/Core/Command/StartDiscussion.php +++ b/framework/core/src/Discussion/Command/StartDiscussion.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Discussion\Command; use Flarum\User\User; diff --git a/framework/core/src/Core/Command/StartDiscussionHandler.php b/framework/core/src/Discussion/Command/StartDiscussionHandler.php similarity index 98% rename from framework/core/src/Core/Command/StartDiscussionHandler.php rename to framework/core/src/Discussion/Command/StartDiscussionHandler.php index 7f8586031..01f99b832 100644 --- a/framework/core/src/Core/Command/StartDiscussionHandler.php +++ b/framework/core/src/Discussion/Command/StartDiscussionHandler.php @@ -9,14 +9,14 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Discussion\Command; use Exception; -use Flarum\User\AssertPermissionTrait; use Flarum\Discussion\Discussion; -use Flarum\Foundation\DispatchEventsTrait; use Flarum\Discussion\DiscussionValidator; use Flarum\Discussion\Event\Saving; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\User\AssertPermissionTrait; use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher; use Illuminate\Contracts\Events\Dispatcher as EventDispatcher; diff --git a/framework/core/src/Forum/Controller/ConfirmEmailController.php b/framework/core/src/Forum/Controller/ConfirmEmailController.php index 0284674ed..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\User\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/Core/Command/CreateGroup.php b/framework/core/src/Group/Command/CreateGroup.php similarity index 95% rename from framework/core/src/Core/Command/CreateGroup.php rename to framework/core/src/Group/Command/CreateGroup.php index e67eefea6..e20fb6154 100644 --- a/framework/core/src/Core/Command/CreateGroup.php +++ b/framework/core/src/Group/Command/CreateGroup.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Group\Command; use Flarum\User\User; diff --git a/framework/core/src/Core/Command/CreateGroupHandler.php b/framework/core/src/Group/Command/CreateGroupHandler.php similarity index 98% rename from framework/core/src/Core/Command/CreateGroupHandler.php rename to framework/core/src/Group/Command/CreateGroupHandler.php index ee152d1ec..e18ac566b 100644 --- a/framework/core/src/Core/Command/CreateGroupHandler.php +++ b/framework/core/src/Group/Command/CreateGroupHandler.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Group\Command; -use Flarum\User\AssertPermissionTrait; -use Flarum\Group\Group; use Flarum\Foundation\DispatchEventsTrait; -use Flarum\Group\GroupValidator; use Flarum\Group\Event\Saving; +use Flarum\Group\Group; +use Flarum\Group\GroupValidator; +use Flarum\User\AssertPermissionTrait; use Illuminate\Contracts\Events\Dispatcher; class CreateGroupHandler diff --git a/framework/core/src/Core/Command/DeleteGroup.php b/framework/core/src/Group/Command/DeleteGroup.php similarity index 97% rename from framework/core/src/Core/Command/DeleteGroup.php rename to framework/core/src/Group/Command/DeleteGroup.php index b57bc7c33..b2bb6873e 100644 --- a/framework/core/src/Core/Command/DeleteGroup.php +++ b/framework/core/src/Group/Command/DeleteGroup.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Group\Command; use Flarum\User\User; diff --git a/framework/core/src/Core/Command/DeleteGroupHandler.php b/framework/core/src/Group/Command/DeleteGroupHandler.php similarity index 97% rename from framework/core/src/Core/Command/DeleteGroupHandler.php rename to framework/core/src/Group/Command/DeleteGroupHandler.php index 119758d1f..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\User\AssertPermissionTrait; -use Flarum\User\Exception\PermissionDeniedException; -use Flarum\Group\GroupRepository; 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 diff --git a/framework/core/src/Core/Command/EditGroup.php b/framework/core/src/Group/Command/EditGroup.php similarity index 96% rename from framework/core/src/Core/Command/EditGroup.php rename to framework/core/src/Group/Command/EditGroup.php index f05dc26cd..e64cb9913 100644 --- a/framework/core/src/Core/Command/EditGroup.php +++ b/framework/core/src/Group/Command/EditGroup.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Group\Command; use Flarum\User\User; diff --git a/framework/core/src/Core/Command/EditGroupHandler.php b/framework/core/src/Group/Command/EditGroupHandler.php similarity index 98% rename from framework/core/src/Core/Command/EditGroupHandler.php rename to framework/core/src/Group/Command/EditGroupHandler.php index c3fee99f4..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\User\AssertPermissionTrait; -use Flarum\User\Exception\PermissionDeniedException; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\Group\Event\Saving; use Flarum\Group\Group; use Flarum\Group\GroupRepository; -use Flarum\Foundation\DispatchEventsTrait; use Flarum\Group\GroupValidator; -use Flarum\Group\Event\Saving; +use Flarum\User\AssertPermissionTrait; +use Flarum\User\Exception\PermissionDeniedException; use Illuminate\Contracts\Events\Dispatcher; class EditGroupHandler diff --git a/framework/core/src/Core/Command/ReadAllNotifications.php b/framework/core/src/Notification/Command/ReadAllNotifications.php similarity index 93% rename from framework/core/src/Core/Command/ReadAllNotifications.php rename to framework/core/src/Notification/Command/ReadAllNotifications.php index d231153ce..d0ee62429 100644 --- a/framework/core/src/Core/Command/ReadAllNotifications.php +++ b/framework/core/src/Notification/Command/ReadAllNotifications.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Notification\Command; use Flarum\User\User; diff --git a/framework/core/src/Core/Command/ReadAllNotificationsHandler.php b/framework/core/src/Notification/Command/ReadAllNotificationsHandler.php similarity index 96% rename from framework/core/src/Core/Command/ReadAllNotificationsHandler.php rename to framework/core/src/Notification/Command/ReadAllNotificationsHandler.php index 7e2255fd5..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\User\AssertPermissionTrait; use Flarum\Notification\NotificationRepository; +use Flarum\User\AssertPermissionTrait; class ReadAllNotificationsHandler { diff --git a/framework/core/src/Core/Command/ReadNotification.php b/framework/core/src/Notification/Command/ReadNotification.php similarity index 95% rename from framework/core/src/Core/Command/ReadNotification.php rename to framework/core/src/Notification/Command/ReadNotification.php index f525299b7..93a139ea8 100644 --- a/framework/core/src/Core/Command/ReadNotification.php +++ b/framework/core/src/Notification/Command/ReadNotification.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Notification\Command; use Flarum\User\User; diff --git a/framework/core/src/Core/Command/ReadNotificationHandler.php b/framework/core/src/Notification/Command/ReadNotificationHandler.php similarity index 96% rename from framework/core/src/Core/Command/ReadNotificationHandler.php rename to framework/core/src/Notification/Command/ReadNotificationHandler.php index d8ed0a8fa..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\User\AssertPermissionTrait; use Flarum\Notification\Notification; +use Flarum\User\AssertPermissionTrait; class ReadNotificationHandler { diff --git a/framework/core/src/Core/Command/DeletePost.php b/framework/core/src/Post/Command/DeletePost.php similarity index 97% rename from framework/core/src/Core/Command/DeletePost.php rename to framework/core/src/Post/Command/DeletePost.php index e2c2e897b..27d79dc09 100644 --- a/framework/core/src/Core/Command/DeletePost.php +++ b/framework/core/src/Post/Command/DeletePost.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Post\Command; use Flarum\User\User; diff --git a/framework/core/src/Core/Command/DeletePostHandler.php b/framework/core/src/Post/Command/DeletePostHandler.php similarity index 94% rename from framework/core/src/Core/Command/DeletePostHandler.php rename to framework/core/src/Post/Command/DeletePostHandler.php index 1e5301f2e..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\User\AssertPermissionTrait; -use Flarum\User\Exception\PermissionDeniedException; -use Flarum\Post\PostRepository; use Flarum\Foundation\DispatchEventsTrait; use Flarum\Post\Event\Deleting; +use Flarum\Post\PostRepository; +use Flarum\User\AssertPermissionTrait; use Illuminate\Contracts\Events\Dispatcher; class DeletePostHandler diff --git a/framework/core/src/Core/Command/EditPost.php b/framework/core/src/Post/Command/EditPost.php similarity index 96% rename from framework/core/src/Core/Command/EditPost.php rename to framework/core/src/Post/Command/EditPost.php index 25390c890..270756d30 100644 --- a/framework/core/src/Core/Command/EditPost.php +++ b/framework/core/src/Post/Command/EditPost.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Post\Command; use Flarum\User\User; diff --git a/framework/core/src/Core/Command/EditPostHandler.php b/framework/core/src/Post/Command/EditPostHandler.php similarity index 98% rename from framework/core/src/Core/Command/EditPostHandler.php rename to framework/core/src/Post/Command/EditPostHandler.php index e2b093f9a..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\User\AssertPermissionTrait; -use Flarum\Post\CommentPost; -use Flarum\Post\PostRepository; use Flarum\Foundation\DispatchEventsTrait; -use Flarum\Post\PostValidator; +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 diff --git a/framework/core/src/Core/Command/PostReply.php b/framework/core/src/Post/Command/PostReply.php similarity index 97% rename from framework/core/src/Core/Command/PostReply.php rename to framework/core/src/Post/Command/PostReply.php index 4877b3045..cc7575707 100644 --- a/framework/core/src/Core/Command/PostReply.php +++ b/framework/core/src/Post/Command/PostReply.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\Post\Command; use Flarum\User\User; diff --git a/framework/core/src/Core/Command/PostReplyHandler.php b/framework/core/src/Post/Command/PostReplyHandler.php similarity index 99% rename from framework/core/src/Core/Command/PostReplyHandler.php rename to framework/core/src/Post/Command/PostReplyHandler.php index 2a8314a8e..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\User\AssertPermissionTrait; -use Flarum\Notification\NotificationSyncer; -use Flarum\Post\CommentPost; use Flarum\Discussion\DiscussionRepository; use Flarum\Foundation\DispatchEventsTrait; -use Flarum\Post\PostValidator; +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 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 93% rename from framework/core/src/Core/Command/ConfirmEmailHandler.php rename to framework/core/src/User/Command/ConfirmEmailHandler.php index b657f1972..cef9f70b8 100644 --- a/framework/core/src/Core/Command/ConfirmEmailHandler.php +++ b/framework/core/src/User/Command/ConfirmEmailHandler.php @@ -9,16 +9,16 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; +use Flarum\Foundation\DispatchEventsTrait; use Flarum\User\EmailToken; use Flarum\User\UserRepository; -use Flarum\Foundation\DispatchEventsTrait; use Illuminate\Contracts\Events\Dispatcher; class ConfirmEmailHandler { - use Flarum\Foundation\DispatchEventsTrait; + use DispatchEventsTrait; /** * @var \Flarum\User\UserRepository diff --git a/framework/core/src/Core/Command/DeleteAvatar.php b/framework/core/src/User/Command/DeleteAvatar.php similarity index 96% rename from framework/core/src/Core/Command/DeleteAvatar.php rename to framework/core/src/User/Command/DeleteAvatar.php index a8f757c14..23593c245 100644 --- a/framework/core/src/Core/Command/DeleteAvatar.php +++ b/framework/core/src/User/Command/DeleteAvatar.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; use Flarum\User\User; diff --git a/framework/core/src/Core/Command/DeleteAvatarHandler.php b/framework/core/src/User/Command/DeleteAvatarHandler.php similarity index 95% rename from framework/core/src/Core/Command/DeleteAvatarHandler.php rename to framework/core/src/User/Command/DeleteAvatarHandler.php index 2dfe68efd..f75bea567 100644 --- a/framework/core/src/Core/Command/DeleteAvatarHandler.php +++ b/framework/core/src/User/Command/DeleteAvatarHandler.php @@ -9,13 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; -use Flarum\User\AssertPermissionTrait; -use Flarum\User\Exception\PermissionDeniedException; -use Flarum\User\UserRepository; -use Flarum\Foundation\DispatchEventsTrait; use Flarum\Event\AvatarWillBeDeleted; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\User\AssertPermissionTrait; +use Flarum\User\UserRepository; use Illuminate\Contracts\Events\Dispatcher; use League\Flysystem\FilesystemInterface; diff --git a/framework/core/src/Core/Command/DeleteUser.php b/framework/core/src/User/Command/DeleteUser.php similarity index 97% rename from framework/core/src/Core/Command/DeleteUser.php rename to framework/core/src/User/Command/DeleteUser.php index 2aa0f3edb..43bfd555c 100644 --- a/framework/core/src/Core/Command/DeleteUser.php +++ b/framework/core/src/User/Command/DeleteUser.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; use Flarum\User\User; diff --git a/framework/core/src/Core/Command/DeleteUserHandler.php b/framework/core/src/User/Command/DeleteUserHandler.php similarity index 97% rename from framework/core/src/Core/Command/DeleteUserHandler.php rename to framework/core/src/User/Command/DeleteUserHandler.php index e2f64e482..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\Foundation\DispatchEventsTrait; use Flarum\User\AssertPermissionTrait; +use Flarum\User\Event\Deleting; use Flarum\User\Exception\PermissionDeniedException; use Flarum\User\UserRepository; -use Flarum\Foundation\DispatchEventsTrait; -use Flarum\User\Event\Deleting; use Illuminate\Contracts\Events\Dispatcher; class DeleteUserHandler diff --git a/framework/core/src/Core/Command/EditUser.php b/framework/core/src/User/Command/EditUser.php similarity index 96% rename from framework/core/src/Core/Command/EditUser.php rename to framework/core/src/User/Command/EditUser.php index fa758483f..9ac9382de 100644 --- a/framework/core/src/Core/Command/EditUser.php +++ b/framework/core/src/User/Command/EditUser.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; use Flarum\User\User; diff --git a/framework/core/src/Core/Command/EditUserHandler.php b/framework/core/src/User/Command/EditUserHandler.php similarity index 99% rename from framework/core/src/Core/Command/EditUserHandler.php rename to framework/core/src/User/Command/EditUserHandler.php index cb2b2b725..a9df676c0 100644 --- a/framework/core/src/Core/Command/EditUserHandler.php +++ b/framework/core/src/User/Command/EditUserHandler.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; -use Flarum\User\AssertPermissionTrait; -use Flarum\User\UserRepository; use Flarum\Foundation\DispatchEventsTrait; -use Flarum\User\User; -use Flarum\User\UserValidator; +use Flarum\User\AssertPermissionTrait; 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; class EditUserHandler diff --git a/framework/core/src/Core/Command/RegisterUser.php b/framework/core/src/User/Command/RegisterUser.php similarity index 95% rename from framework/core/src/Core/Command/RegisterUser.php rename to framework/core/src/User/Command/RegisterUser.php index 1d9a32b70..47494cf25 100644 --- a/framework/core/src/Core/Command/RegisterUser.php +++ b/framework/core/src/User/Command/RegisterUser.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; use Flarum\User\User; diff --git a/framework/core/src/Core/Command/RegisterUserHandler.php b/framework/core/src/User/Command/RegisterUserHandler.php similarity index 99% rename from framework/core/src/Core/Command/RegisterUserHandler.php rename to framework/core/src/User/Command/RegisterUserHandler.php index edbf35d65..cab155c22 100644 --- a/framework/core/src/Core/Command/RegisterUserHandler.php +++ b/framework/core/src/User/Command/RegisterUserHandler.php @@ -9,18 +9,18 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; use Exception; +use Flarum\Foundation\Application; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\Settings\SettingsRepositoryInterface; use Flarum\User\AssertPermissionTrait; use Flarum\User\AuthToken; +use Flarum\User\Event\Saving; use Flarum\User\Exception\PermissionDeniedException; -use Flarum\Foundation\DispatchEventsTrait; use Flarum\User\User; use Flarum\User\UserValidator; -use Flarum\User\Event\Saving; -use Flarum\Foundation\Application; -use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Validation\Factory; use Illuminate\Contracts\Validation\ValidationException; 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 98% rename from framework/core/src/Core/Command/RequestPasswordResetHandler.php rename to framework/core/src/User/Command/RequestPasswordResetHandler.php index 4647bc004..ba464a698 100644 --- a/framework/core/src/Core/Command/RequestPasswordResetHandler.php +++ b/framework/core/src/User/Command/RequestPasswordResetHandler.php @@ -9,13 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; -use Flarum\Core; -use Flarum\User\PasswordToken; -use Flarum\User\UserRepository; use Flarum\Forum\UrlGenerator; use Flarum\Settings\SettingsRepositoryInterface; +use Flarum\User\PasswordToken; +use Flarum\User\UserRepository; use Illuminate\Contracts\Mail\Mailer; use Illuminate\Contracts\Validation\Factory; use Illuminate\Contracts\Validation\ValidationException; diff --git a/framework/core/src/Core/Command/UploadAvatar.php b/framework/core/src/User/Command/UploadAvatar.php similarity index 97% rename from framework/core/src/Core/Command/UploadAvatar.php rename to framework/core/src/User/Command/UploadAvatar.php index ac34220e5..6a06cf852 100644 --- a/framework/core/src/Core/Command/UploadAvatar.php +++ b/framework/core/src/User/Command/UploadAvatar.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Command; +namespace Flarum\User\Command; use Flarum\User\User; use Psr\Http\Message\UploadedFileInterface; diff --git a/framework/core/src/Core/Command/UploadAvatarHandler.php b/framework/core/src/User/Command/UploadAvatarHandler.php similarity index 99% rename from framework/core/src/Core/Command/UploadAvatarHandler.php rename to framework/core/src/User/Command/UploadAvatarHandler.php index adcf76ee3..454373099 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 Exception; -use Flarum\User\AssertPermissionTrait; -use Flarum\User\UserRepository; -use Flarum\Foundation\DispatchEventsTrait; -use Flarum\User\AvatarValidator; use Flarum\Event\AvatarWillBeSaved; use Flarum\Foundation\Application; +use Flarum\Foundation\DispatchEventsTrait; +use Flarum\User\AssertPermissionTrait; +use Flarum\User\UserRepository; +use Flarum\User\AvatarValidator; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Support\Str; use Intervention\Image\ImageManager; diff --git a/framework/core/src/User/UserServiceProvider.php b/framework/core/src/User/UserServiceProvider.php index 45a7e8a24..7c17943c6 100644 --- a/framework/core/src/User/UserServiceProvider.php +++ b/framework/core/src/User/UserServiceProvider.php @@ -41,15 +41,15 @@ class UserServiceProvider extends AbstractServiceProvider return $app->make('Illuminate\Contracts\Filesystem\Factory')->disk('flarum-avatars')->getDriver(); }; - $this->app->when('Flarum\Core\Command\UploadAvatarHandler') + $this->app->when('Flarum\User\Command\UploadAvatarHandler') ->needs('League\Flysystem\FilesystemInterface') ->give($avatarsFilesystem); - $this->app->when('Flarum\Core\Command\DeleteAvatarHandler') + $this->app->when('Flarum\User\Command\DeleteAvatarHandler') ->needs('League\Flysystem\FilesystemInterface') ->give($avatarsFilesystem); - $this->app->when('Flarum\Core\Command\RegisterUserHandler') + $this->app->when('Flarum\User\Command\RegisterUserHandler') ->needs('League\Flysystem\FilesystemInterface') ->give($avatarsFilesystem); } From f33de845404b76f47789ee2f2e5fcb70e8648b42 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sat, 24 Jun 2017 15:48:20 +0200 Subject: [PATCH 035/172] Fix namespace orderings (Thanks, StyleCI!) --- .../core/src/Admin/AdminServiceProvider.php | 4 ++-- .../Admin/Controller/FrontendController.php | 4 ++-- framework/core/src/Admin/routes.php | 2 +- framework/core/src/Api/ApiServiceProvider.php | 2 +- .../Controller/DeleteFaviconController.php | 2 +- .../Api/Controller/DeleteLogoController.php | 2 +- .../Controller/ForgotPasswordController.php | 2 +- .../ListNotificationsController.php | 2 +- .../Api/Controller/ListPostsController.php | 2 +- .../Api/Controller/ListUsersController.php | 2 +- .../SendConfirmationEmailController.php | 6 ++--- .../Controller/SetPermissionController.php | 2 +- .../Api/Controller/SetSettingsController.php | 6 ++--- .../src/Api/Controller/TokenController.php | 4 ++-- .../UninstallExtensionController.php | 2 +- .../Controller/UpdateExtensionController.php | 2 +- .../Controller/UploadFaviconController.php | 2 +- .../Api/Controller/UploadLogoController.php | 2 +- .../Api/Serializer/BasicPostSerializer.php | 2 +- .../Api/Serializer/DiscussionSerializer.php | 2 +- .../src/Api/Serializer/PostSerializer.php | 2 +- framework/core/src/Api/routes.php | 2 +- framework/core/src/Console/Server.php | 4 ++-- .../src/Database/ScopeVisibilityTrait.php | 2 +- framework/core/src/Discussion/Discussion.php | 9 ++++---- .../Discussion/DiscussionMetadataUpdater.php | 2 +- .../core/src/Discussion/DiscussionPolicy.php | 1 - .../Discussion/DiscussionRenamedLogger.php | 2 +- .../Discussion/Search/DiscussionSearcher.php | 5 +---- .../Discussion/Search/Gambit/AuthorGambit.php | 4 ++-- .../Search/Gambit/CreatedGambit.php | 2 +- .../Search/Gambit/FulltextGambit.php | 2 +- .../Discussion/Search/Gambit/HiddenGambit.php | 2 +- .../Discussion/Search/Gambit/UnreadGambit.php | 2 +- framework/core/src/Discussion/UserState.php | 3 +-- .../src/Event/AbstractConfigureRoutes.php | 2 +- .../core/src/Extension/ExtensionManager.php | 4 ++-- .../Forum/Controller/DiscussionController.php | 2 +- .../src/Forum/Controller/IndexController.php | 2 +- .../src/Forum/Controller/LogInController.php | 4 ++-- .../src/Forum/Controller/LogOutController.php | 4 ++-- .../Controller/ResetPasswordController.php | 2 +- .../Controller/SavePasswordController.php | 4 ++-- .../core/src/Forum/ForumServiceProvider.php | 4 ++-- framework/core/src/Forum/routes.php | 2 +- .../core/src/Frontend/FrontendAssets.php | 2 +- framework/core/src/Frontend/FrontendView.php | 2 +- framework/core/src/Group/Group.php | 4 ++-- framework/core/src/Http/AbstractServer.php | 4 ++-- .../Middleware/AuthenticateWithHeader.php | 2 +- .../src/Install/Console/InstallCommand.php | 2 +- .../src/Install/InstallServiceProvider.php | 2 +- .../src/Notification/NotificationSyncer.php | 2 +- framework/core/src/Post/CommentPost.php | 2 +- framework/core/src/Post/Post.php | 4 ++-- .../Update/Controller/UpdateController.php | 2 +- .../core/src/Update/UpdateServiceProvider.php | 2 +- framework/core/src/User/AuthToken.php | 2 +- .../src/User/Command/UploadAvatarHandler.php | 2 +- .../core/src/User/EmailConfirmationMailer.php | 4 ++-- framework/core/src/User/EmailToken.php | 2 +- framework/core/src/User/Event/LoggedIn.php | 2 +- .../core/src/User/Search/UserSearcher.php | 4 ++-- framework/core/src/User/User.php | 22 +++++++++---------- framework/core/src/User/UserPolicy.php | 1 - 65 files changed, 95 insertions(+), 102 deletions(-) diff --git a/framework/core/src/Admin/AdminServiceProvider.php b/framework/core/src/Admin/AdminServiceProvider.php index f394637e2..1166ee120 100644 --- a/framework/core/src/Admin/AdminServiceProvider.php +++ b/framework/core/src/Admin/AdminServiceProvider.php @@ -13,10 +13,10 @@ namespace Flarum\Admin; use Flarum\Extension\Event\Disabled; use Flarum\Extension\Event\Enabled; -use Flarum\Settings\Event\Saved; use Flarum\Foundation\AbstractServiceProvider; -use Flarum\Http\RouteHandlerFactory; use Flarum\Http\RouteCollection; +use Flarum\Http\RouteHandlerFactory; +use Flarum\Settings\Event\Saved; class AdminServiceProvider extends AbstractServiceProvider { diff --git a/framework/core/src/Admin/Controller/FrontendController.php b/framework/core/src/Admin/Controller/FrontendController.php index 14258eb05..a274a3d61 100644 --- a/framework/core/src/Admin/Controller/FrontendController.php +++ b/framework/core/src/Admin/Controller/FrontendController.php @@ -12,10 +12,10 @@ namespace Flarum\Admin\Controller; use Flarum\Admin\Frontend; -use Flarum\Group\Permission; -use Flarum\Settings\Event\Deserializing; use Flarum\Extension\ExtensionManager; use Flarum\Frontend\AbstractFrontendController; +use Flarum\Group\Permission; +use Flarum\Settings\Event\Deserializing; use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Events\Dispatcher; use Psr\Http\Message\ServerRequestInterface; diff --git a/framework/core/src/Admin/routes.php b/framework/core/src/Admin/routes.php index f2a04f74b..eac48ca4e 100644 --- a/framework/core/src/Admin/routes.php +++ b/framework/core/src/Admin/routes.php @@ -10,8 +10,8 @@ */ use Flarum\Admin\Controller; -use Flarum\Http\RouteHandlerFactory; use Flarum\Http\RouteCollection; +use Flarum\Http\RouteHandlerFactory; return function (RouteCollection $map, RouteHandlerFactory $route) { $map->get( diff --git a/framework/core/src/Api/ApiServiceProvider.php b/framework/core/src/Api/ApiServiceProvider.php index 8e524324f..c886b25ec 100644 --- a/framework/core/src/Api/ApiServiceProvider.php +++ b/framework/core/src/Api/ApiServiceProvider.php @@ -17,8 +17,8 @@ use Flarum\Api\Serializer\NotificationSerializer; use Flarum\Event\ConfigureApiRoutes; use Flarum\Event\ConfigureNotificationTypes; use Flarum\Foundation\AbstractServiceProvider; -use Flarum\Http\RouteHandlerFactory; use Flarum\Http\RouteCollection; +use Flarum\Http\RouteHandlerFactory; use Tobscure\JsonApi\ErrorHandler; use Tobscure\JsonApi\Exception\Handler\FallbackExceptionHandler; use Tobscure\JsonApi\Exception\Handler\InvalidParameterExceptionHandler; diff --git a/framework/core/src/Api/Controller/DeleteFaviconController.php b/framework/core/src/Api/Controller/DeleteFaviconController.php index 4c2807abc..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\User\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/DeleteLogoController.php b/framework/core/src/Api/Controller/DeleteLogoController.php index 532674577..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\User\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/ForgotPasswordController.php b/framework/core/src/Api/Controller/ForgotPasswordController.php index 56e638878..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\Http\Controller\ControllerInterface; use Flarum\User\Command\RequestPasswordReset; use Flarum\User\UserRepository; -use Flarum\Http\Controller\ControllerInterface; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; use Zend\Diactoros\Response\EmptyResponse; diff --git a/framework/core/src/Api/Controller/ListNotificationsController.php b/framework/core/src/Api/Controller/ListNotificationsController.php index aeca867a8..d86922b42 100644 --- a/framework/core/src/Api/Controller/ListNotificationsController.php +++ b/framework/core/src/Api/Controller/ListNotificationsController.php @@ -12,8 +12,8 @@ namespace Flarum\Api\Controller; use Flarum\Discussion\Discussion; -use Flarum\User\Exception\PermissionDeniedException; use Flarum\Notification\NotificationRepository; +use Flarum\User\Exception\PermissionDeniedException; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; diff --git a/framework/core/src/Api/Controller/ListPostsController.php b/framework/core/src/Api/Controller/ListPostsController.php index 071dbc41d..b506f814a 100644 --- a/framework/core/src/Api/Controller/ListPostsController.php +++ b/framework/core/src/Api/Controller/ListPostsController.php @@ -11,8 +11,8 @@ namespace Flarum\Api\Controller; -use Flarum\Post\PostRepository; use Flarum\Event\ConfigurePostsQuery; +use Flarum\Post\PostRepository; use Illuminate\Database\Eloquent\Builder; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; diff --git a/framework/core/src/Api/Controller/ListUsersController.php b/framework/core/src/Api/Controller/ListUsersController.php index f953e33b4..d27369655 100644 --- a/framework/core/src/Api/Controller/ListUsersController.php +++ b/framework/core/src/Api/Controller/ListUsersController.php @@ -12,8 +12,8 @@ namespace Flarum\Api\Controller; use Flarum\Api\UrlGenerator; -use Flarum\User\Exception\PermissionDeniedException; use Flarum\Search\SearchCriteria; +use Flarum\User\Exception\PermissionDeniedException; use Flarum\User\Search\UserSearcher; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; diff --git a/framework/core/src/Api/Controller/SendConfirmationEmailController.php b/framework/core/src/Api/Controller/SendConfirmationEmailController.php index a6314ad97..2718501ea 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\User\AssertPermissionTrait; -use Flarum\User\EmailToken; -use Flarum\User\Exception\PermissionDeniedException; use Flarum\Forum\UrlGenerator; use Flarum\Http\Controller\ControllerInterface; 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; diff --git a/framework/core/src/Api/Controller/SetPermissionController.php b/framework/core/src/Api/Controller/SetPermissionController.php index a11dc056f..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\User\AssertPermissionTrait; 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 b9cb59cdd..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\User\AssertPermissionTrait; -use Flarum\Settings\Event\Serializing; -use Flarum\Settings\Event\Saved; 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; diff --git a/framework/core/src/Api/Controller/TokenController.php b/framework/core/src/Api/Controller/TokenController.php index 376e48747..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\User\Exception\PermissionDeniedException; -use Flarum\User\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; diff --git a/framework/core/src/Api/Controller/UninstallExtensionController.php b/framework/core/src/Api/Controller/UninstallExtensionController.php index 0e2f02a59..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\User\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/UpdateExtensionController.php b/framework/core/src/Api/Controller/UpdateExtensionController.php index c701ae469..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\User\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/UploadFaviconController.php b/framework/core/src/Api/Controller/UploadFaviconController.php index 80b33abee..757d3f679 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\User\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; diff --git a/framework/core/src/Api/Controller/UploadLogoController.php b/framework/core/src/Api/Controller/UploadLogoController.php index ed10a8b67..d6547d555 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\User\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; diff --git a/framework/core/src/Api/Serializer/BasicPostSerializer.php b/framework/core/src/Api/Serializer/BasicPostSerializer.php index b63b6dec6..a2a10feeb 100644 --- a/framework/core/src/Api/Serializer/BasicPostSerializer.php +++ b/framework/core/src/Api/Serializer/BasicPostSerializer.php @@ -11,8 +11,8 @@ namespace Flarum\Api\Serializer; -use Flarum\Post\Post; use Flarum\Post\CommentPost; +use Flarum\Post\Post; use InvalidArgumentException; class BasicPostSerializer extends AbstractSerializer diff --git a/framework/core/src/Api/Serializer/DiscussionSerializer.php b/framework/core/src/Api/Serializer/DiscussionSerializer.php index 17c43e970..e31811127 100644 --- a/framework/core/src/Api/Serializer/DiscussionSerializer.php +++ b/framework/core/src/Api/Serializer/DiscussionSerializer.php @@ -11,8 +11,8 @@ namespace Flarum\Api\Serializer; -use Flarum\User\Gate; use Flarum\Discussion\Discussion; +use Flarum\User\Gate; class DiscussionSerializer extends BasicDiscussionSerializer { diff --git a/framework/core/src/Api/Serializer/PostSerializer.php b/framework/core/src/Api/Serializer/PostSerializer.php index 9f22c5704..613392427 100644 --- a/framework/core/src/Api/Serializer/PostSerializer.php +++ b/framework/core/src/Api/Serializer/PostSerializer.php @@ -11,8 +11,8 @@ namespace Flarum\Api\Serializer; -use Flarum\User\Gate; use Flarum\Post\CommentPost; +use Flarum\User\Gate; class PostSerializer extends BasicPostSerializer { diff --git a/framework/core/src/Api/routes.php b/framework/core/src/Api/routes.php index f394141a7..b83c57ea9 100644 --- a/framework/core/src/Api/routes.php +++ b/framework/core/src/Api/routes.php @@ -10,8 +10,8 @@ */ use Flarum\Api\Controller; -use Flarum\Http\RouteHandlerFactory; use Flarum\Http\RouteCollection; +use Flarum\Http\RouteHandlerFactory; return function (RouteCollection $map, RouteHandlerFactory $route) { // Get forum information diff --git a/framework/core/src/Console/Server.php b/framework/core/src/Console/Server.php index 45366ec83..f7ad12cbb 100644 --- a/framework/core/src/Console/Server.php +++ b/framework/core/src/Console/Server.php @@ -12,11 +12,11 @@ namespace Flarum\Console; use Flarum\Database\Console\GenerateMigrationCommand; +use Flarum\Database\Console\MigrateCommand; +use Flarum\Foundation\AbstractServer; use Flarum\Foundation\Console\CacheClearCommand; use Flarum\Foundation\Console\InfoCommand; -use Flarum\Foundation\AbstractServer; use Flarum\Install\Console\InstallCommand; -use Flarum\Database\Console\MigrateCommand; use Symfony\Component\Console\Application; class Server extends AbstractServer diff --git a/framework/core/src/Database/ScopeVisibilityTrait.php b/framework/core/src/Database/ScopeVisibilityTrait.php index 276f6a39d..03c18e341 100644 --- a/framework/core/src/Database/ScopeVisibilityTrait.php +++ b/framework/core/src/Database/ScopeVisibilityTrait.php @@ -11,8 +11,8 @@ namespace Flarum\Database; -use Flarum\User\User; use Flarum\Event\ScopeModelVisibility; +use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; trait ScopeVisibilityTrait diff --git a/framework/core/src/Discussion/Discussion.php b/framework/core/src/Discussion/Discussion.php index 2c73a5aea..38e7bb048 100644 --- a/framework/core/src/Discussion/Discussion.php +++ b/framework/core/src/Discussion/Discussion.php @@ -11,18 +11,17 @@ namespace Flarum\Discussion; -use Flarum\Discussion\UserState; -use Flarum\Post\MergeableInterface; -use Flarum\Foundation\EventGeneratorTrait; -use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; +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\Post\Event\Deleted as PostDeleted; 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; diff --git a/framework/core/src/Discussion/DiscussionMetadataUpdater.php b/framework/core/src/Discussion/DiscussionMetadataUpdater.php index 123d8d8c0..b1f894f4c 100755 --- a/framework/core/src/Discussion/DiscussionMetadataUpdater.php +++ b/framework/core/src/Discussion/DiscussionMetadataUpdater.php @@ -11,11 +11,11 @@ namespace Flarum\Discussion; -use Flarum\Post\Post; 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 diff --git a/framework/core/src/Discussion/DiscussionPolicy.php b/framework/core/src/Discussion/DiscussionPolicy.php index b43345727..2839f239f 100644 --- a/framework/core/src/Discussion/DiscussionPolicy.php +++ b/framework/core/src/Discussion/DiscussionPolicy.php @@ -12,7 +12,6 @@ namespace Flarum\Discussion; use Carbon\Carbon; -use Flarum\Discussion\Discussion; use Flarum\Event\ScopeHiddenDiscussionVisibility; use Flarum\Event\ScopePrivateDiscussionVisibility; use Flarum\Settings\SettingsRepositoryInterface; diff --git a/framework/core/src/Discussion/DiscussionRenamedLogger.php b/framework/core/src/Discussion/DiscussionRenamedLogger.php index 8ccf74ff9..961bde5fb 100755 --- a/framework/core/src/Discussion/DiscussionRenamedLogger.php +++ b/framework/core/src/Discussion/DiscussionRenamedLogger.php @@ -11,10 +11,10 @@ namespace Flarum\Discussion; +use Flarum\Discussion\Event\Renamed; use Flarum\Notification\Blueprint\DiscussionRenamedBlueprint; use Flarum\Notification\NotificationSyncer; use Flarum\Post\DiscussionRenamedPost; -use Flarum\Discussion\Event\Renamed; use Illuminate\Contracts\Events\Dispatcher; class DiscussionRenamedLogger diff --git a/framework/core/src/Discussion/Search/DiscussionSearcher.php b/framework/core/src/Discussion/Search/DiscussionSearcher.php index 81ac2803a..9a6e215ae 100644 --- a/framework/core/src/Discussion/Search/DiscussionSearcher.php +++ b/framework/core/src/Discussion/Search/DiscussionSearcher.php @@ -13,13 +13,10 @@ namespace Flarum\Discussion\Search; use Flarum\Discussion\Discussion; use Flarum\Discussion\DiscussionRepository; -use Flarum\Discussion\Search\DiscussionSearch; +use Flarum\Event\ConfigureDiscussionSearch; use Flarum\Post\PostRepository; use Flarum\Search\ApplySearchParametersTrait; use Flarum\Search\GambitManager; -use Flarum\Search\SearchCriteria; -use Flarum\Search\SearchResults; -use Flarum\Event\ConfigureDiscussionSearch; use Illuminate\Database\Eloquent\Collection; /** diff --git a/framework/core/src/Discussion/Search/Gambit/AuthorGambit.php b/framework/core/src/Discussion/Search/Gambit/AuthorGambit.php index 15e425512..d3f4544ab 100644 --- a/framework/core/src/Discussion/Search/Gambit/AuthorGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/AuthorGambit.php @@ -11,10 +11,10 @@ namespace Flarum\Discussion\Search\Gambit; -use Flarum\User\UserRepository; +use Flarum\Discussion\Search\DiscussionSearch; use Flarum\Search\AbstractRegexGambit; use Flarum\Search\AbstractSearch; -use Flarum\Discussion\Search\DiscussionSearch; +use Flarum\User\UserRepository; use LogicException; class AuthorGambit extends AbstractRegexGambit diff --git a/framework/core/src/Discussion/Search/Gambit/CreatedGambit.php b/framework/core/src/Discussion/Search/Gambit/CreatedGambit.php index 0b38fec35..6241c0e16 100644 --- a/framework/core/src/Discussion/Search/Gambit/CreatedGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/CreatedGambit.php @@ -11,9 +11,9 @@ namespace Flarum\Discussion\Search\Gambit; +use Flarum\Discussion\Search\DiscussionSearch; use Flarum\Search\AbstractRegexGambit; use Flarum\Search\AbstractSearch; -use Flarum\Discussion\Search\DiscussionSearch; use LogicException; class CreatedGambit extends AbstractRegexGambit diff --git a/framework/core/src/Discussion/Search/Gambit/FulltextGambit.php b/framework/core/src/Discussion/Search/Gambit/FulltextGambit.php index da54f358f..3019f9f0f 100644 --- a/framework/core/src/Discussion/Search/Gambit/FulltextGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/FulltextGambit.php @@ -11,9 +11,9 @@ namespace Flarum\Discussion\Search\Gambit; -use Flarum\Search\AbstractSearch; use Flarum\Discussion\Search\DiscussionSearch; use Flarum\Discussion\Search\Fulltext\DriverInterface; +use Flarum\Search\AbstractSearch; use Flarum\Search\GambitInterface; use LogicException; diff --git a/framework/core/src/Discussion/Search/Gambit/HiddenGambit.php b/framework/core/src/Discussion/Search/Gambit/HiddenGambit.php index 9bd1c7b24..907991546 100644 --- a/framework/core/src/Discussion/Search/Gambit/HiddenGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/HiddenGambit.php @@ -11,9 +11,9 @@ namespace Flarum\Discussion\Search\Gambit; +use Flarum\Discussion\Search\DiscussionSearch; use Flarum\Search\AbstractRegexGambit; use Flarum\Search\AbstractSearch; -use Flarum\Discussion\Search\DiscussionSearch; use LogicException; class HiddenGambit extends AbstractRegexGambit diff --git a/framework/core/src/Discussion/Search/Gambit/UnreadGambit.php b/framework/core/src/Discussion/Search/Gambit/UnreadGambit.php index 87eb7cfe2..bd9a60629 100644 --- a/framework/core/src/Discussion/Search/Gambit/UnreadGambit.php +++ b/framework/core/src/Discussion/Search/Gambit/UnreadGambit.php @@ -12,9 +12,9 @@ namespace Flarum\Discussion\Search\Gambit; use Flarum\Discussion\DiscussionRepository; +use Flarum\Discussion\Search\DiscussionSearch; use Flarum\Search\AbstractRegexGambit; use Flarum\Search\AbstractSearch; -use Flarum\Discussion\Search\DiscussionSearch; use LogicException; class UnreadGambit extends AbstractRegexGambit diff --git a/framework/core/src/Discussion/UserState.php b/framework/core/src/Discussion/UserState.php index 68a9ad714..481893f91 100644 --- a/framework/core/src/Discussion/UserState.php +++ b/framework/core/src/Discussion/UserState.php @@ -11,10 +11,9 @@ namespace Flarum\Discussion; -use Flarum\Discussion\Discussion; -use Flarum\Foundation\EventGeneratorTrait; use Flarum\Database\AbstractModel; use Flarum\Discussion\Event\UserRead; +use Flarum\Foundation\EventGeneratorTrait; use Illuminate\Database\Eloquent\Builder; /** diff --git a/framework/core/src/Event/AbstractConfigureRoutes.php b/framework/core/src/Event/AbstractConfigureRoutes.php index fec628648..c09ab958c 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\RouteHandlerFactory; use Flarum\Http\RouteCollection; +use Flarum\Http\RouteHandlerFactory; abstract class AbstractConfigureRoutes { diff --git a/framework/core/src/Extension/ExtensionManager.php b/framework/core/src/Extension/ExtensionManager.php index 724250aec..404638fd5 100644 --- a/framework/core/src/Extension/ExtensionManager.php +++ b/framework/core/src/Extension/ExtensionManager.php @@ -13,10 +13,10 @@ namespace Flarum\Extension; use Flarum\Database\Migrator; use Flarum\Extension\Event\Disabled; -use Flarum\Extension\Event\Enabled; -use Flarum\Extension\Event\Uninstalled; 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; diff --git a/framework/core/src/Forum/Controller/DiscussionController.php b/framework/core/src/Forum/Controller/DiscussionController.php index 4b60ecc84..f952ba799 100644 --- a/framework/core/src/Forum/Controller/DiscussionController.php +++ b/framework/core/src/Forum/Controller/DiscussionController.php @@ -12,8 +12,8 @@ namespace Flarum\Forum\Controller; use Flarum\Api\Client; -use Flarum\Forum\UrlGenerator; use Flarum\Forum\Frontend; +use Flarum\Forum\UrlGenerator; use Flarum\Http\Exception\RouteNotFoundException; use Flarum\User\User; use Illuminate\Contracts\Events\Dispatcher; diff --git a/framework/core/src/Forum/Controller/IndexController.php b/framework/core/src/Forum/Controller/IndexController.php index 278710aab..2df0c2158 100644 --- a/framework/core/src/Forum/Controller/IndexController.php +++ b/framework/core/src/Forum/Controller/IndexController.php @@ -12,8 +12,8 @@ namespace Flarum\Forum\Controller; use Flarum\Api\Client as ApiClient; -use Flarum\User\User; use Flarum\Forum\Frontend; +use Flarum\User\User; use Illuminate\Contracts\Events\Dispatcher; use Psr\Http\Message\ServerRequestInterface as Request; diff --git a/framework/core/src/Forum/Controller/LogInController.php b/framework/core/src/Forum/Controller/LogInController.php index 5cabd47dd..493f301df 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\User\UserRepository; -use Flarum\User\Event\LoggedIn; 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; diff --git a/framework/core/src/Forum/Controller/LogOutController.php b/framework/core/src/Forum/Controller/LogOutController.php index af220a6b6..d5d191f7e 100644 --- a/framework/core/src/Forum/Controller/LogOutController.php +++ b/framework/core/src/Forum/Controller/LogOutController.php @@ -11,13 +11,13 @@ namespace Flarum\Forum\Controller; -use Flarum\User\AssertPermissionTrait; -use Flarum\User\Event\LoggedOut; use Flarum\Foundation\Application; use Flarum\Http\Controller\ControllerInterface; use Flarum\Http\Exception\TokenMismatchException; use Flarum\Http\Rememberer; use Flarum\Http\SessionAuthenticator; +use Flarum\User\AssertPermissionTrait; +use Flarum\User\Event\LoggedOut; use Illuminate\Contracts\Events\Dispatcher; use Psr\Http\Message\ServerRequestInterface as Request; use Zend\Diactoros\Response\RedirectResponse; diff --git a/framework/core/src/Forum/Controller/ResetPasswordController.php b/framework/core/src/Forum/Controller/ResetPasswordController.php index 36e313a2e..641da9b42 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\Http\Controller\AbstractHtmlController; use Flarum\User\Exception\InvalidConfirmationTokenException; use Flarum\User\PasswordToken; -use Flarum\Http\Controller\AbstractHtmlController; use Illuminate\Contracts\View\Factory; use Psr\Http\Message\ServerRequestInterface as Request; use Symfony\Component\Translation\TranslatorInterface; diff --git a/framework/core/src/Forum/Controller/SavePasswordController.php b/framework/core/src/Forum/Controller/SavePasswordController.php index 20623cf8f..541113ebd 100644 --- a/framework/core/src/Forum/Controller/SavePasswordController.php +++ b/framework/core/src/Forum/Controller/SavePasswordController.php @@ -11,11 +11,11 @@ namespace Flarum\Forum\Controller; -use Flarum\User\PasswordToken; -use Flarum\User\UserValidator; use Flarum\Forum\UrlGenerator; use Flarum\Http\Controller\ControllerInterface; use Flarum\Http\SessionAuthenticator; +use Flarum\User\PasswordToken; +use Flarum\User\UserValidator; use Illuminate\Contracts\Validation\Factory; use Illuminate\Contracts\Validation\ValidationException; use Psr\Http\Message\ServerRequestInterface as Request; diff --git a/framework/core/src/Forum/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index 8b96164a6..7526ad4b7 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -14,10 +14,10 @@ namespace Flarum\Forum; use Flarum\Event\ConfigureForumRoutes; use Flarum\Extension\Event\Disabled; use Flarum\Extension\Event\Enabled; -use Flarum\Settings\Event\Saved; use Flarum\Foundation\AbstractServiceProvider; -use Flarum\Http\RouteHandlerFactory; use Flarum\Http\RouteCollection; +use Flarum\Http\RouteHandlerFactory; +use Flarum\Settings\Event\Saved; class ForumServiceProvider extends AbstractServiceProvider { diff --git a/framework/core/src/Forum/routes.php b/framework/core/src/Forum/routes.php index 028fe37dd..00f7bf303 100644 --- a/framework/core/src/Forum/routes.php +++ b/framework/core/src/Forum/routes.php @@ -10,8 +10,8 @@ */ use Flarum\Forum\Controller; -use Flarum\Http\RouteHandlerFactory; use Flarum\Http\RouteCollection; +use Flarum\Http\RouteHandlerFactory; return function (RouteCollection $map, RouteHandlerFactory $route) { $map->get( diff --git a/framework/core/src/Frontend/FrontendAssets.php b/framework/core/src/Frontend/FrontendAssets.php index e3bce2f16..277b39547 100644 --- a/framework/core/src/Frontend/FrontendAssets.php +++ b/framework/core/src/Frontend/FrontendAssets.php @@ -11,9 +11,9 @@ namespace Flarum\Frontend; +use Flarum\Foundation\Application; use Flarum\Frontend\Asset\JsCompiler; use Flarum\Frontend\Asset\LessCompiler; -use Flarum\Foundation\Application; use Flarum\Frontend\Asset\LocaleJsCompiler as LocaleJsCompiler; use Flarum\Locale\LocaleManager; use Illuminate\Contracts\Cache\Repository; diff --git a/framework/core/src/Frontend/FrontendView.php b/framework/core/src/Frontend/FrontendView.php index 0593e070a..7a40c7169 100644 --- a/framework/core/src/Frontend/FrontendView.php +++ b/framework/core/src/Frontend/FrontendView.php @@ -13,8 +13,8 @@ namespace Flarum\Frontend; use Flarum\Api\Client; use Flarum\Api\Serializer\AbstractSerializer; -use Flarum\Frontend\Asset\CompilerInterface; use Flarum\Foundation\Application; +use Flarum\Frontend\Asset\CompilerInterface; use Flarum\Frontend\Asset\LocaleJsCompiler; use Flarum\Locale\LocaleManager; use Illuminate\View\Factory; diff --git a/framework/core/src/Group/Group.php b/framework/core/src/Group/Group.php index dd30cbb53..4af4a4d61 100755 --- a/framework/core/src/Group/Group.php +++ b/framework/core/src/Group/Group.php @@ -11,9 +11,9 @@ namespace Flarum\Group; -use Flarum\Foundation\EventGeneratorTrait; -use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; +use Flarum\Database\ScopeVisibilityTrait; +use Flarum\Foundation\EventGeneratorTrait; use Flarum\Group\Event\Created; use Flarum\Group\Event\Deleting; use Flarum\Group\Event\Renamed; diff --git a/framework/core/src/Http/AbstractServer.php b/framework/core/src/Http/AbstractServer.php index de6f923c2..0cf7bd39d 100644 --- a/framework/core/src/Http/AbstractServer.php +++ b/framework/core/src/Http/AbstractServer.php @@ -11,11 +11,11 @@ namespace Flarum\Http; +use Flarum\Foundation\AbstractServer as BaseAbstractServer; +use Flarum\Foundation\Application; use Flarum\User\AuthToken; use Flarum\User\EmailToken; use Flarum\User\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; diff --git a/framework/core/src/Http/Middleware/AuthenticateWithHeader.php b/framework/core/src/Http/Middleware/AuthenticateWithHeader.php index c13313754..85ad9bf1f 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\User\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/Install/Console/InstallCommand.php b/framework/core/src/Install/Console/InstallCommand.php index c75928601..f7f9d3a98 100644 --- a/framework/core/src/Install/Console/InstallCommand.php +++ b/framework/core/src/Install/Console/InstallCommand.php @@ -13,10 +13,10 @@ namespace Flarum\Install\Console; use Exception; use Flarum\Console\AbstractCommand; +use Flarum\Database\AbstractModel; use Flarum\Group\Group; use Flarum\Group\Permission; use Flarum\User\User; -use Flarum\Database\AbstractModel; use Illuminate\Contracts\Foundation\Application; use Illuminate\Filesystem\Filesystem; use Illuminate\Validation\Factory; diff --git a/framework/core/src/Install/InstallServiceProvider.php b/framework/core/src/Install/InstallServiceProvider.php index 26c089c06..733a1ce9e 100644 --- a/framework/core/src/Install/InstallServiceProvider.php +++ b/framework/core/src/Install/InstallServiceProvider.php @@ -12,8 +12,8 @@ namespace Flarum\Install; use Flarum\Foundation\AbstractServiceProvider; -use Flarum\Http\RouteHandlerFactory; use Flarum\Http\RouteCollection; +use Flarum\Http\RouteHandlerFactory; use Flarum\Install\Prerequisite\Composite; use Flarum\Install\Prerequisite\PhpExtensions; use Flarum\Install\Prerequisite\PhpVersion; diff --git a/framework/core/src/Notification/NotificationSyncer.php b/framework/core/src/Notification/NotificationSyncer.php index 5abef59e2..7065c461d 100644 --- a/framework/core/src/Notification/NotificationSyncer.php +++ b/framework/core/src/Notification/NotificationSyncer.php @@ -12,8 +12,8 @@ namespace Flarum\Notification; use Carbon\Carbon; -use Flarum\Notification\Event\Sending; use Flarum\Notification\Blueprint\BlueprintInterface; +use Flarum\Notification\Event\Sending; use Flarum\User\User; /** diff --git a/framework/core/src/Post/CommentPost.php b/framework/core/src/Post/CommentPost.php index e42403b7e..f8edc6834 100755 --- a/framework/core/src/Post/CommentPost.php +++ b/framework/core/src/Post/CommentPost.php @@ -11,11 +11,11 @@ namespace Flarum\Post; +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\Formatter\Formatter; use Flarum\User\User; /** diff --git a/framework/core/src/Post/Post.php b/framework/core/src/Post/Post.php index c85538582..d603c0e03 100755 --- a/framework/core/src/Post/Post.php +++ b/framework/core/src/Post/Post.php @@ -11,9 +11,9 @@ namespace Flarum\Post; -use Flarum\Foundation\EventGeneratorTrait; -use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; +use Flarum\Database\ScopeVisibilityTrait; +use Flarum\Foundation\EventGeneratorTrait; use Flarum\Post\Event\Deleted; use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; diff --git a/framework/core/src/Update/Controller/UpdateController.php b/framework/core/src/Update/Controller/UpdateController.php index 2a0335030..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\Database\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 f45364230..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\RouteHandlerFactory; use Flarum\Http\RouteCollection; +use Flarum\Http\RouteHandlerFactory; class UpdateServiceProvider extends AbstractServiceProvider { diff --git a/framework/core/src/User/AuthToken.php b/framework/core/src/User/AuthToken.php index dd785b72a..2458baca5 100644 --- a/framework/core/src/User/AuthToken.php +++ b/framework/core/src/User/AuthToken.php @@ -12,8 +12,8 @@ namespace Flarum\User; use DateTime; -use Flarum\User\Exception\InvalidConfirmationTokenException; use Flarum\Database\AbstractModel; +use Flarum\User\Exception\InvalidConfirmationTokenException; /** * @todo document database columns with @property diff --git a/framework/core/src/User/Command/UploadAvatarHandler.php b/framework/core/src/User/Command/UploadAvatarHandler.php index 454373099..c674d44b8 100644 --- a/framework/core/src/User/Command/UploadAvatarHandler.php +++ b/framework/core/src/User/Command/UploadAvatarHandler.php @@ -16,8 +16,8 @@ use Flarum\Event\AvatarWillBeSaved; use Flarum\Foundation\Application; use Flarum\Foundation\DispatchEventsTrait; use Flarum\User\AssertPermissionTrait; -use Flarum\User\UserRepository; use Flarum\User\AvatarValidator; +use Flarum\User\UserRepository; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Support\Str; use Intervention\Image\ImageManager; diff --git a/framework/core/src/User/EmailConfirmationMailer.php b/framework/core/src/User/EmailConfirmationMailer.php index b02c3f037..9ff225dc9 100755 --- a/framework/core/src/User/EmailConfirmationMailer.php +++ b/framework/core/src/User/EmailConfirmationMailer.php @@ -11,10 +11,10 @@ namespace Flarum\User; -use Flarum\User\Event\EmailChangeRequested; -use Flarum\User\Event\Registered; use Flarum\Forum\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\Mail\Message; diff --git a/framework/core/src/User/EmailToken.php b/framework/core/src/User/EmailToken.php index f60d35c89..ac143ea12 100644 --- a/framework/core/src/User/EmailToken.php +++ b/framework/core/src/User/EmailToken.php @@ -12,8 +12,8 @@ namespace Flarum\User; use DateTime; -use Flarum\User\Exception\InvalidConfirmationTokenException; use Flarum\Database\AbstractModel; +use Flarum\User\Exception\InvalidConfirmationTokenException; /** * @todo document database columns with @property diff --git a/framework/core/src/User/Event/LoggedIn.php b/framework/core/src/User/Event/LoggedIn.php index 32d17b695..3659a0e40 100644 --- a/framework/core/src/User/Event/LoggedIn.php +++ b/framework/core/src/User/Event/LoggedIn.php @@ -11,8 +11,8 @@ namespace Flarum\User\Event; -use Flarum\User\User; use Flarum\Http\AccessToken; +use Flarum\User\User; class LoggedIn { diff --git a/framework/core/src/User/Search/UserSearcher.php b/framework/core/src/User/Search/UserSearcher.php index 2cb5cab2b..518b4c85e 100644 --- a/framework/core/src/User/Search/UserSearcher.php +++ b/framework/core/src/User/Search/UserSearcher.php @@ -11,12 +11,12 @@ namespace Flarum\User\Search; -use Flarum\User\UserRepository; +use Flarum\Event\ConfigureUserSearch; use Flarum\Search\ApplySearchParametersTrait; use Flarum\Search\GambitManager; use Flarum\Search\SearchCriteria; use Flarum\Search\SearchResults; -use Flarum\Event\ConfigureUserSearch; +use Flarum\User\UserRepository; /** * Takes a UserSearchCriteria object, performs a search using gambits, diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index ea222484f..b035a58f4 100755 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -12,26 +12,26 @@ namespace Flarum\User; use DomainException; -use Flarum\Group\Group; -use Flarum\Notification\Notification; -use Flarum\Group\Permission; -use Flarum\Foundation\EventGeneratorTrait; -use Flarum\Database\ScopeVisibilityTrait; use Flarum\Database\AbstractModel; +use Flarum\Database\ScopeVisibilityTrait; use Flarum\Event\CheckUserPassword; use Flarum\Event\ConfigureUserPreferences; -use Flarum\Post\Event\Deleted as PostDeleted; use Flarum\Event\PrepareUserGroups; +use Flarum\Foundation\Application; +use Flarum\Foundation\EventGeneratorTrait; +use Flarum\Group\Group; +use Flarum\Group\Permission; +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\BioChanged; -use Flarum\User\Event\EmailChangeRequested; -use Flarum\User\Event\EmailChanged; -use Flarum\User\Event\PasswordChanged; -use Flarum\User\Event\Activated; 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 Flarum\Foundation\Application; use Illuminate\Contracts\Hashing\Hasher; use Symfony\Component\HttpFoundation\Session\SessionInterface; diff --git a/framework/core/src/User/UserPolicy.php b/framework/core/src/User/UserPolicy.php index 3a52fcaf0..73754f0b8 100644 --- a/framework/core/src/User/UserPolicy.php +++ b/framework/core/src/User/UserPolicy.php @@ -11,7 +11,6 @@ namespace Flarum\User; -use Flarum\User\AbstractPolicy; use Illuminate\Database\Eloquent\Builder; class UserPolicy extends AbstractPolicy From cc118d4c293151780df7ceea5b820b1901b256b9 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sun, 25 Jun 2017 17:04:33 +0200 Subject: [PATCH 036/172] Move more event classes to appropriate namespaces --- .../Event/Searching.php} | 4 ++-- framework/core/src/Discussion/Search/DiscussionSearcher.php | 4 ++-- framework/core/src/User/Command/DeleteAvatarHandler.php | 4 ++-- framework/core/src/User/Command/UploadAvatarHandler.php | 4 ++-- .../AvatarWillBeDeleted.php => User/Event/AvatarDeleting.php} | 4 ++-- .../AvatarWillBeSaved.php => User/Event/AvatarSaving.php} | 4 ++-- .../ConfigureUserSearch.php => User/Event/Searching.php} | 4 ++-- framework/core/src/User/Search/UserSearcher.php | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) rename framework/core/src/{Event/ConfigureDiscussionSearch.php => Discussion/Event/Searching.php} (92%) rename framework/core/src/{Event/AvatarWillBeDeleted.php => User/Event/AvatarDeleting.php} (93%) rename framework/core/src/{Event/AvatarWillBeSaved.php => User/Event/AvatarSaving.php} (95%) rename framework/core/src/{Event/ConfigureUserSearch.php => User/Event/Searching.php} (93%) diff --git a/framework/core/src/Event/ConfigureDiscussionSearch.php b/framework/core/src/Discussion/Event/Searching.php similarity index 92% rename from framework/core/src/Event/ConfigureDiscussionSearch.php rename to framework/core/src/Discussion/Event/Searching.php index 2b126046e..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\Discussion\Search\DiscussionSearch; use Flarum\Search\SearchCriteria; -class ConfigureDiscussionSearch +class Searching { /** * @var DiscussionSearch diff --git a/framework/core/src/Discussion/Search/DiscussionSearcher.php b/framework/core/src/Discussion/Search/DiscussionSearcher.php index 9a6e215ae..5628dcf2f 100644 --- a/framework/core/src/Discussion/Search/DiscussionSearcher.php +++ b/framework/core/src/Discussion/Search/DiscussionSearcher.php @@ -13,7 +13,7 @@ namespace Flarum\Discussion\Search; use Flarum\Discussion\Discussion; use Flarum\Discussion\DiscussionRepository; -use Flarum\Event\ConfigureDiscussionSearch; +use Flarum\Discussion\Event\Searching; use Flarum\Post\PostRepository; use Flarum\Search\ApplySearchParametersTrait; use Flarum\Search\GambitManager; @@ -81,7 +81,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/User/Command/DeleteAvatarHandler.php b/framework/core/src/User/Command/DeleteAvatarHandler.php index f75bea567..e920f7192 100644 --- a/framework/core/src/User/Command/DeleteAvatarHandler.php +++ b/framework/core/src/User/Command/DeleteAvatarHandler.php @@ -11,7 +11,7 @@ namespace Flarum\User\Command; -use Flarum\Event\AvatarWillBeDeleted; +use Flarum\User\Event\AvatarDeleting; use Flarum\Foundation\DispatchEventsTrait; use Flarum\User\AssertPermissionTrait; use Flarum\User\UserRepository; @@ -64,7 +64,7 @@ class DeleteAvatarHandler $user->changeAvatarPath(null); $this->events->fire( - new AvatarWillBeDeleted($user, $actor) + new AvatarDeleting($user, $actor) ); $user->save(); diff --git a/framework/core/src/User/Command/UploadAvatarHandler.php b/framework/core/src/User/Command/UploadAvatarHandler.php index c674d44b8..2aa28044a 100644 --- a/framework/core/src/User/Command/UploadAvatarHandler.php +++ b/framework/core/src/User/Command/UploadAvatarHandler.php @@ -12,7 +12,7 @@ namespace Flarum\User\Command; use Exception; -use Flarum\Event\AvatarWillBeSaved; +use Flarum\User\Event\AvatarSaving; use Flarum\Foundation\Application; use Flarum\Foundation\DispatchEventsTrait; use Flarum\User\AssertPermissionTrait; @@ -110,7 +110,7 @@ class UploadAvatarHandler file_put_contents($tmpFile, $encodedImage); $this->events->fire( - new AvatarWillBeSaved($user, $actor, $tmpFile) + new AvatarSaving($user, $actor, $tmpFile) ); $mount = new MountManager([ diff --git a/framework/core/src/Event/AvatarWillBeDeleted.php b/framework/core/src/User/Event/AvatarDeleting.php similarity index 93% rename from framework/core/src/Event/AvatarWillBeDeleted.php rename to framework/core/src/User/Event/AvatarDeleting.php index df862684a..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\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 95% rename from framework/core/src/Event/AvatarWillBeSaved.php rename to framework/core/src/User/Event/AvatarSaving.php index 3737bb350..d3b82f741 100644 --- a/framework/core/src/Event/AvatarWillBeSaved.php +++ b/framework/core/src/User/Event/AvatarSaving.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\User\Event; use Flarum\User\User; -class AvatarWillBeSaved +class AvatarSaving { /** * The user whose avatar will be saved. diff --git a/framework/core/src/Event/ConfigureUserSearch.php b/framework/core/src/User/Event/Searching.php similarity index 93% rename from framework/core/src/Event/ConfigureUserSearch.php rename to framework/core/src/User/Event/Searching.php index 1b9a235e4..5f6b0695f 100644 --- a/framework/core/src/Event/ConfigureUserSearch.php +++ b/framework/core/src/User/Event/Searching.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\User\Event; use Flarum\Search\SearchCriteria; use Flarum\User\Search\UserSearch; -class ConfigureUserSearch +class Searching { /** * @var \Flarum\User\Search\UserSearch diff --git a/framework/core/src/User/Search/UserSearcher.php b/framework/core/src/User/Search/UserSearcher.php index 518b4c85e..55ce2b5ff 100644 --- a/framework/core/src/User/Search/UserSearcher.php +++ b/framework/core/src/User/Search/UserSearcher.php @@ -11,7 +11,7 @@ namespace Flarum\User\Search; -use Flarum\Event\ConfigureUserSearch; +use Flarum\User\Event\Searching; use Flarum\Search\ApplySearchParametersTrait; use Flarum\Search\GambitManager; use Flarum\Search\SearchCriteria; @@ -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 From dbd034eaf49e81899d211846d4be7508e0620ab9 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sun, 25 Jun 2017 23:33:02 +0200 Subject: [PATCH 037/172] Combine URL generator classes into one --- .../core/src/Admin/AdminServiceProvider.php | 5 +- framework/core/src/Admin/UrlGenerator.php | 22 ------- framework/core/src/Api/ApiServiceProvider.php | 5 +- .../Controller/ListDiscussionsController.php | 4 +- .../Api/Controller/ListUsersController.php | 4 +- .../SendConfirmationEmailController.php | 4 +- .../src/Api/Serializer/ForumSerializer.php | 6 +- framework/core/src/Api/UrlGenerator.php | 22 ------- .../Forum/Controller/DiscussionController.php | 4 +- .../Controller/SavePasswordController.php | 6 +- .../core/src/Forum/ForumServiceProvider.php | 5 +- framework/core/src/Forum/UrlGenerator.php | 18 ------ ...or.php => RouteCollectionUrlGenerator.php} | 31 ++++------ framework/core/src/Http/UrlGenerator.php | 59 +++++++++++++++++++ .../Command/RequestPasswordResetHandler.php | 4 +- .../core/src/User/EmailConfirmationMailer.php | 4 +- framework/core/src/User/User.php | 4 +- framework/core/views/index.blade.php | 6 +- framework/core/views/reset.blade.php | 2 +- 19 files changed, 104 insertions(+), 111 deletions(-) delete mode 100644 framework/core/src/Admin/UrlGenerator.php delete mode 100644 framework/core/src/Api/UrlGenerator.php delete mode 100644 framework/core/src/Forum/UrlGenerator.php rename framework/core/src/Http/{AbstractUrlGenerator.php => RouteCollectionUrlGenerator.php} (64%) create mode 100644 framework/core/src/Http/UrlGenerator.php diff --git a/framework/core/src/Admin/AdminServiceProvider.php b/framework/core/src/Admin/AdminServiceProvider.php index 1166ee120..913c6493a 100644 --- a/framework/core/src/Admin/AdminServiceProvider.php +++ b/framework/core/src/Admin/AdminServiceProvider.php @@ -16,6 +16,7 @@ use Flarum\Extension\Event\Enabled; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Http\RouteCollection; use Flarum\Http\RouteHandlerFactory; +use Flarum\Http\UrlGenerator; use Flarum\Settings\Event\Saved; class AdminServiceProvider extends AbstractServiceProvider @@ -25,8 +26,8 @@ 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 () { diff --git a/framework/core/src/Admin/UrlGenerator.php b/framework/core/src/Admin/UrlGenerator.php deleted file mode 100644 index efa1a8a45..000000000 --- a/framework/core/src/Admin/UrlGenerator.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -/* - * This file is part of Flarum. - * - * (c) Toby Zerner <toby.zerner@gmail.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Flarum\Admin; - -use Flarum\Http\AbstractUrlGenerator; - -class UrlGenerator extends AbstractUrlGenerator -{ - /** - * {@inheritdoc} - */ - protected $path = 'admin'; -} diff --git a/framework/core/src/Api/ApiServiceProvider.php b/framework/core/src/Api/ApiServiceProvider.php index c886b25ec..ed4f916f3 100644 --- a/framework/core/src/Api/ApiServiceProvider.php +++ b/framework/core/src/Api/ApiServiceProvider.php @@ -19,6 +19,7 @@ use Flarum\Event\ConfigureNotificationTypes; use Flarum\Foundation\AbstractServiceProvider; 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; @@ -30,8 +31,8 @@ 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 () { diff --git a/framework/core/src/Api/Controller/ListDiscussionsController.php b/framework/core/src/Api/Controller/ListDiscussionsController.php index d69e07de6..ee75abc60 100644 --- a/framework/core/src/Api/Controller/ListDiscussionsController.php +++ b/framework/core/src/Api/Controller/ListDiscussionsController.php @@ -11,8 +11,8 @@ namespace Flarum\Api\Controller; -use Flarum\Api\UrlGenerator; use Flarum\Discussion\Search\DiscussionSearcher; +use Flarum\Http\UrlGenerator; use Flarum\Search\SearchCriteria; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; @@ -86,7 +86,7 @@ class ListDiscussionsController extends AbstractListController $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/ListUsersController.php b/framework/core/src/Api/Controller/ListUsersController.php index d27369655..679230a98 100644 --- a/framework/core/src/Api/Controller/ListUsersController.php +++ b/framework/core/src/Api/Controller/ListUsersController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Api\UrlGenerator; +use Flarum\Http\UrlGenerator; use Flarum\Search\SearchCriteria; use Flarum\User\Exception\PermissionDeniedException; use Flarum\User\Search\UserSearcher; @@ -84,7 +84,7 @@ class ListUsersController extends AbstractListController $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/SendConfirmationEmailController.php b/framework/core/src/Api/Controller/SendConfirmationEmailController.php index 2718501ea..2935f0067 100644 --- a/framework/core/src/Api/Controller/SendConfirmationEmailController.php +++ b/framework/core/src/Api/Controller/SendConfirmationEmailController.php @@ -11,8 +11,8 @@ namespace Flarum\Api\Controller; -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; @@ -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/Serializer/ForumSerializer.php b/framework/core/src/Api/Serializer/ForumSerializer.php index 852ec08a6..399fcfd83 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 @@ -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/UrlGenerator.php b/framework/core/src/Api/UrlGenerator.php deleted file mode 100644 index 71dfbfc40..000000000 --- a/framework/core/src/Api/UrlGenerator.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -/* - * This file is part of Flarum. - * - * (c) Toby Zerner <toby.zerner@gmail.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Flarum\Api; - -use Flarum\Http\AbstractUrlGenerator; - -class UrlGenerator extends AbstractUrlGenerator -{ - /** - * {@inheritdoc} - */ - protected $path = 'api'; -} diff --git a/framework/core/src/Forum/Controller/DiscussionController.php b/framework/core/src/Forum/Controller/DiscussionController.php index f952ba799..216f72961 100644 --- a/framework/core/src/Forum/Controller/DiscussionController.php +++ b/framework/core/src/Forum/Controller/DiscussionController.php @@ -13,8 +13,8 @@ namespace Flarum\Forum\Controller; use Flarum\Api\Client; use Flarum\Forum\Frontend; -use Flarum\Forum\UrlGenerator; 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; @@ -73,7 +73,7 @@ class DiscussionController extends FrontendController $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 : ''); }; diff --git a/framework/core/src/Forum/Controller/SavePasswordController.php b/framework/core/src/Forum/Controller/SavePasswordController.php index 541113ebd..0d1c76fa0 100644 --- a/framework/core/src/Forum/Controller/SavePasswordController.php +++ b/framework/core/src/Forum/Controller/SavePasswordController.php @@ -11,9 +11,9 @@ namespace Flarum\Forum\Controller; -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; @@ -81,7 +81,7 @@ class SavePasswordController implements ControllerInterface } catch (ValidationException $e) { $request->getAttribute('session')->set('error', $e->errors()->first()); - 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); @@ -92,6 +92,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 7526ad4b7..682d8194b 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -17,6 +17,7 @@ use Flarum\Extension\Event\Enabled; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Http\RouteCollection; use Flarum\Http\RouteHandlerFactory; +use Flarum\Http\UrlGenerator; use Flarum\Settings\Event\Saved; class ForumServiceProvider extends AbstractServiceProvider @@ -26,8 +27,8 @@ 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 () { 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 @@ -<?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\Forum; - -use Flarum\Http\AbstractUrlGenerator; - -class UrlGenerator extends AbstractUrlGenerator -{ -} 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/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/User/Command/RequestPasswordResetHandler.php b/framework/core/src/User/Command/RequestPasswordResetHandler.php index ba464a698..c0ac0c7fd 100644 --- a/framework/core/src/User/Command/RequestPasswordResetHandler.php +++ b/framework/core/src/User/Command/RequestPasswordResetHandler.php @@ -11,7 +11,7 @@ namespace Flarum\User\Command; -use Flarum\Forum\UrlGenerator; +use Flarum\Http\UrlGenerator; use Flarum\Settings\SettingsRepositoryInterface; use Flarum\User\PasswordToken; use Flarum\User\UserRepository; @@ -107,7 +107,7 @@ class RequestPasswordResetHandler $data = [ '{username}' => $user->username, - '{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/User/EmailConfirmationMailer.php b/framework/core/src/User/EmailConfirmationMailer.php index 9ff225dc9..3273690b1 100755 --- a/framework/core/src/User/EmailConfirmationMailer.php +++ b/framework/core/src/User/EmailConfirmationMailer.php @@ -11,7 +11,7 @@ namespace Flarum\User; -use Flarum\Forum\UrlGenerator; +use Flarum\Http\UrlGenerator; use Flarum\Settings\SettingsRepositoryInterface; use Flarum\User\Event\EmailChangeRequested; use Flarum\User\Event\Registered; @@ -128,7 +128,7 @@ class EmailConfirmationMailer return [ '{username}' => $user->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/User/User.php b/framework/core/src/User/User.php index b035a58f4..8c9cce87f 100755 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -325,9 +325,9 @@ class User extends AbstractModel */ public function getAvatarUrlAttribute() { - $urlGenerator = app('Flarum\Forum\UrlGenerator'); + $urlGenerator = app('Flarum\Http\UrlGenerator'); - return $this->avatar_path ? $urlGenerator->toPath('assets/avatars/'.$this->avatar_path) : null; + return $this->avatar_path ? $urlGenerator->to('forum')->path('assets/avatars/'.$this->avatar_path) : null; } /** diff --git a/framework/core/views/index.blade.php b/framework/core/views/index.blade.php index cbde0cff7..ce3a54feb 100644 --- a/framework/core/views/index.blade.php +++ b/framework/core/views/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> diff --git a/framework/core/views/reset.blade.php b/framework/core/views/reset.blade.php index 671157b38..fd4a254c9 100644 --- a/framework/core/views/reset.blade.php +++ b/framework/core/views/reset.blade.php @@ -15,7 +15,7 @@ <p style="color:red">{{ $error }}</p> @endif - <form class="form-horizontal" role="form" method="POST" action="{{ app('Flarum\Forum\UrlGenerator')->toRoute('savePassword') }}"> + <form class="form-horizontal" role="form" method="POST" action="{{ app('Flarum\Http\UrlGenerator')->to('forum')->route('savePassword') }}"> <input type="hidden" name="csrfToken" value="{{ $csrfToken }}"> <input type="hidden" name="passwordToken" value="{{ $passwordToken }}"> From 2727b8dd8d084870ec943a9995b71f96b96c12e2 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Mon, 26 Jun 2017 09:06:32 +0200 Subject: [PATCH 038/172] Fix order of namespace imports --- framework/core/src/User/Command/DeleteAvatarHandler.php | 2 +- framework/core/src/User/Command/UploadAvatarHandler.php | 2 +- framework/core/src/User/Search/UserSearcher.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/core/src/User/Command/DeleteAvatarHandler.php b/framework/core/src/User/Command/DeleteAvatarHandler.php index e920f7192..e1f5aeecf 100644 --- a/framework/core/src/User/Command/DeleteAvatarHandler.php +++ b/framework/core/src/User/Command/DeleteAvatarHandler.php @@ -11,9 +11,9 @@ namespace Flarum\User\Command; -use Flarum\User\Event\AvatarDeleting; use Flarum\Foundation\DispatchEventsTrait; use Flarum\User\AssertPermissionTrait; +use Flarum\User\Event\AvatarDeleting; use Flarum\User\UserRepository; use Illuminate\Contracts\Events\Dispatcher; use League\Flysystem\FilesystemInterface; diff --git a/framework/core/src/User/Command/UploadAvatarHandler.php b/framework/core/src/User/Command/UploadAvatarHandler.php index 2aa28044a..6bc1aa181 100644 --- a/framework/core/src/User/Command/UploadAvatarHandler.php +++ b/framework/core/src/User/Command/UploadAvatarHandler.php @@ -12,11 +12,11 @@ namespace Flarum\User\Command; use Exception; -use Flarum\User\Event\AvatarSaving; use Flarum\Foundation\Application; use Flarum\Foundation\DispatchEventsTrait; use Flarum\User\AssertPermissionTrait; use Flarum\User\AvatarValidator; +use Flarum\User\Event\AvatarSaving; use Flarum\User\UserRepository; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Support\Str; diff --git a/framework/core/src/User/Search/UserSearcher.php b/framework/core/src/User/Search/UserSearcher.php index 55ce2b5ff..7bc268c23 100644 --- a/framework/core/src/User/Search/UserSearcher.php +++ b/framework/core/src/User/Search/UserSearcher.php @@ -11,11 +11,11 @@ namespace Flarum\User\Search; -use Flarum\User\Event\Searching; 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; /** From e67da1ec1966bf26638c56664274aecbacd082ea Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Mon, 26 Jun 2017 23:28:41 +0200 Subject: [PATCH 039/172] Move events to Flarum\Api namespace --- .../src/Api/Controller/AbstractSerializeController.php | 8 ++++---- .../Event/Serializing.php} | 6 +++--- .../Event/WillGetData.php} | 4 ++-- .../Event/WillSerializeData.php} | 4 ++-- framework/core/src/Api/Serializer/AbstractSerializer.php | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) rename framework/core/src/{Event/PrepareApiAttributes.php => Api/Event/Serializing.php} (92%) rename framework/core/src/{Event/ConfigureApiController.php => Api/Event/WillGetData.php} (98%) rename framework/core/src/{Event/PrepareApiData.php => Api/Event/WillSerializeData.php} (96%) 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/Event/PrepareApiAttributes.php b/framework/core/src/Api/Event/Serializing.php similarity index 92% rename from framework/core/src/Event/PrepareApiAttributes.php rename to framework/core/src/Api/Event/Serializing.php index c97ad794e..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. 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 96% rename from framework/core/src/Event/PrepareApiData.php rename to framework/core/src/Api/Event/WillSerializeData.php index 6d9b8f547..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 diff --git a/framework/core/src/Api/Serializer/AbstractSerializer.php b/framework/core/src/Api/Serializer/AbstractSerializer.php index a11c9e28a..279c976a5 100644 --- a/framework/core/src/Api/Serializer/AbstractSerializer.php +++ b/framework/core/src/Api/Serializer/AbstractSerializer.php @@ -13,8 +13,8 @@ namespace Flarum\Api\Serializer; use Closure; use DateTime; +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; @@ -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; From 7e04823d8212b3bc47887f9b68d131120341d2d1 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Mon, 26 Jun 2017 23:30:51 +0200 Subject: [PATCH 040/172] Move event to Flarum\User namespace --- .../CheckUserPassword.php => User/Event/CheckingPassword.php} | 4 ++-- framework/core/src/User/User.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename framework/core/src/{Event/CheckUserPassword.php => User/Event/CheckingPassword.php} (91%) diff --git a/framework/core/src/Event/CheckUserPassword.php b/framework/core/src/User/Event/CheckingPassword.php similarity index 91% rename from framework/core/src/Event/CheckUserPassword.php rename to framework/core/src/User/Event/CheckingPassword.php index fa9ef2277..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\User\User; -class CheckUserPassword +class CheckingPassword { /** * @var User diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 8c9cce87f..78858643e 100755 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -14,7 +14,6 @@ namespace Flarum\User; use DomainException; use Flarum\Database\AbstractModel; use Flarum\Database\ScopeVisibilityTrait; -use Flarum\Event\CheckUserPassword; use Flarum\Event\ConfigureUserPreferences; use Flarum\Event\PrepareUserGroups; use Flarum\Foundation\Application; @@ -26,6 +25,7 @@ use Flarum\Post\Event\Deleted as PostDeleted; use Flarum\User\Event\Activated; use Flarum\User\Event\AvatarChanged; use Flarum\User\Event\BioChanged; +use Flarum\User\Event\CheckingPassword; use Flarum\User\Event\Deleted; use Flarum\User\Event\EmailChanged; use Flarum\User\Event\EmailChangeRequested; @@ -350,7 +350,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; From f4bbe2f419d378c0cacd06ad9ce20ae4dc86abc0 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Fri, 30 Jun 2017 12:07:20 +0200 Subject: [PATCH 041/172] Get rid of Server classes for Admin, API and Forum The various middleware can be registered in the service provider, and the rest of the logic can all go through one single front controller (index.php in flarum/flarum, and Flarum\Http\Server in flarum/core). This will also simplify the necessary server setup, as only one rewrite rule remains. --- .../core/src/Admin/AdminServiceProvider.php | 33 ++++ framework/core/src/Admin/Server.php | 58 ------- framework/core/src/Api/ApiServiceProvider.php | 32 ++++ framework/core/src/Api/Server.php | 62 ------- .../core/src/Event/ConfigureMiddleware.php | 27 +-- .../core/src/Forum/ForumServiceProvider.php | 31 ++++ framework/core/src/Forum/Server.php | 61 ------- framework/core/src/Http/AbstractServer.php | 81 --------- framework/core/src/Http/FullStackServer.php | 37 ---- framework/core/src/Http/Server.php | 159 ++++++++++++++++++ 10 files changed, 263 insertions(+), 318 deletions(-) delete mode 100644 framework/core/src/Admin/Server.php delete mode 100644 framework/core/src/Api/Server.php delete mode 100644 framework/core/src/Forum/Server.php delete mode 100644 framework/core/src/Http/AbstractServer.php delete mode 100644 framework/core/src/Http/FullStackServer.php create mode 100644 framework/core/src/Http/Server.php diff --git a/framework/core/src/Admin/AdminServiceProvider.php b/framework/core/src/Admin/AdminServiceProvider.php index 913c6493a..f7da26d04 100644 --- a/framework/core/src/Admin/AdminServiceProvider.php +++ b/framework/core/src/Admin/AdminServiceProvider.php @@ -11,13 +11,23 @@ namespace Flarum\Admin; +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\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 { @@ -33,6 +43,29 @@ class AdminServiceProvider extends AbstractServiceProvider $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(); + $errorDir = __DIR__.'/../../error'; + $pipe->pipe(new HandleErrors($errorDir, $app->make('log'), $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; + }); } /** diff --git a/framework/core/src/Admin/Server.php b/framework/core/src/Admin/Server.php deleted file mode 100644 index 43aa38116..000000000 --- a/framework/core/src/Admin/Server.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php - -/* - * This file is part of Flarum. - * - * (c) Toby Zerner <toby.zerner@gmail.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Flarum\Admin; - -use Flarum\Event\ConfigureMiddleware; -use Flarum\Foundation\Application; -use Flarum\Http\AbstractServer; -use Flarum\Http\Middleware\HandleErrors; -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); - $errorDir = __DIR__.'/../../error'; - - // All requests should first be piped through our global error handler - $debugMode = ! $app->isUpToDate() || $app->inDebugMode(); - $pipe->pipe($path, new HandleErrors($errorDir, $app->make('log'), $debugMode)); - - 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/Api/ApiServiceProvider.php b/framework/core/src/Api/ApiServiceProvider.php index ed4f916f3..7360358a3 100644 --- a/framework/core/src/Api/ApiServiceProvider.php +++ b/framework/core/src/Api/ApiServiceProvider.php @@ -12,17 +12,28 @@ 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\NotificationSerializer; use Flarum\Event\ConfigureApiRoutes; +use Flarum\Event\ConfigureMiddleware; use Flarum\Event\ConfigureNotificationTypes; use Flarum\Foundation\AbstractServiceProvider; +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 { @@ -39,6 +50,27 @@ class ApiServiceProvider extends AbstractServiceProvider 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; 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 @@ -<?php - -/* - * This file is part of Flarum. - * - * (c) Toby Zerner <toby.zerner@gmail.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Flarum\Api; - -use Flarum\Event\ConfigureMiddleware; -use Flarum\Foundation\Application; -use Flarum\Http\AbstractServer; -use Tobscure\JsonApi\Document; -use Zend\Stratigility\MiddlewarePipe; - -class Server extends AbstractServer -{ - /** - * {@inheritdoc} - */ - protected function getMiddleware(Application $app) - { - $pipe = new MiddlewarePipe; - $pipe->raiseThrowables(); - - $path = parse_url($app->url('api'), PHP_URL_PATH); - - if ($app->isInstalled() && $app->isUpToDate()) { - $pipe->pipe($path, $app->make('Flarum\Api\Middleware\HandleErrors')); - - $pipe->pipe($path, $app->make('Flarum\Http\Middleware\ParseJsonBody')); - $pipe->pipe($path, $app->make('Flarum\Api\Middleware\FakeHttpMethods')); - $pipe->pipe($path, $app->make('Flarum\Http\Middleware\StartSession')); - $pipe->pipe($path, $app->make('Flarum\Http\Middleware\RememberFromCookie')); - $pipe->pipe($path, $app->make('Flarum\Http\Middleware\AuthenticateWithSession')); - $pipe->pipe($path, $app->make('Flarum\Http\Middleware\AuthenticateWithHeader')); - $pipe->pipe($path, $app->make('Flarum\Http\Middleware\SetLocale')); - - event(new ConfigureMiddleware($pipe, $path, $this)); - - $pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.api.routes')])); - } else { - $pipe->pipe($path, function () { - $document = new Document; - $document->setErrors([ - [ - 'code' => 503, - 'title' => 'Service Unavailable' - ] - ]); - - return new JsonApiResponse($document, 503); - }); - } - - return $pipe; - } -} 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/Forum/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index 682d8194b..1e2e058b4 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -12,13 +12,22 @@ namespace Flarum\Forum; use Flarum\Event\ConfigureForumRoutes; +use Flarum\Event\ConfigureMiddleware; use Flarum\Extension\Event\Disabled; use Flarum\Extension\Event\Enabled; use Flarum\Foundation\AbstractServiceProvider; +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 ForumServiceProvider extends AbstractServiceProvider { @@ -34,6 +43,28 @@ class ForumServiceProvider extends AbstractServiceProvider $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(); + $errorDir = __DIR__.'/../../error'; + $pipe->pipe(new HandleErrors($errorDir, $app->make('log'), $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)); + + event(new ConfigureMiddleware($pipe, 'forum')); + + $pipe->pipe($app->make(DispatchRoute::class, ['routes' => $app->make('flarum.forum.routes')])); + + return $pipe; + }); } /** diff --git a/framework/core/src/Forum/Server.php b/framework/core/src/Forum/Server.php deleted file mode 100644 index 893ddc52c..000000000 --- a/framework/core/src/Forum/Server.php +++ /dev/null @@ -1,61 +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\Forum; - -use Flarum\Event\ConfigureMiddleware; -use Flarum\Foundation\Application; -use Flarum\Http\AbstractServer; -use Flarum\Http\Middleware\HandleErrors; -use Zend\Diactoros\Response\HtmlResponse; -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); - $errorDir = __DIR__.'/../../error'; - - if (! $app->isInstalled()) { - $app->register('Flarum\Install\InstallServiceProvider'); - - $pipe->pipe($path, new HandleErrors($errorDir, $app->make('log'), true)); - - $pipe->pipe($path, $app->make('Flarum\Http\Middleware\StartSession')); - $pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.install.routes')])); - } elseif ($app->isUpToDate() && ! $app->isDownForMaintenance()) { - $pipe->pipe($path, new HandleErrors($errorDir, $app->make('log'), $app->inDebugMode())); - - $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')); - - 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 () use ($errorDir) { - return new HtmlResponse(file_get_contents($errorDir.'/503.html', 503)); - }); - } - - return $pipe; - } -} diff --git a/framework/core/src/Http/AbstractServer.php b/framework/core/src/Http/AbstractServer.php deleted file mode 100644 index 0cf7bd39d..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\Foundation\AbstractServer as BaseAbstractServer; -use Flarum\Foundation\Application; -use Flarum\User\AuthToken; -use Flarum\User\EmailToken; -use Flarum\User\PasswordToken; -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/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/Server.php b/framework/core/src/Http/Server.php new file mode 100644 index 000000000..832b58dce --- /dev/null +++ b/framework/core/src/Http/Server.php @@ -0,0 +1,159 @@ +<?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\AbstractServer; +use Flarum\Foundation\Application; +use Flarum\Http\Middleware\DispatchRoute; +use Flarum\Http\Middleware\HandleErrors; +use Flarum\Http\Middleware\StartSession; +use Flarum\Install\InstallServiceProvider; +use Flarum\Update\UpdateServiceProvider; +use Flarum\User\AuthToken; +use Flarum\User\EmailToken; +use Flarum\User\PasswordToken; +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 extends AbstractServer +{ + 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) + { + $app = $this->getApp(); + + $this->collectGarbage($app); + + $middleware = $this->getMiddleware($app, $request->getUri()->getPath()); + + return $middleware($request, $response, $out); + } + + /** + * @param Application $app + * @param string $requestPath + * @return MiddlewareInterface + */ + protected function getMiddleware(Application $app, $requestPath) + { + $pipe = new MiddlewarePipe; + $pipe->raiseThrowables(); + + if (! $app->isInstalled()) { + return $this->getInstallerMiddleware($pipe, $app); + } else if ($app->isDownForMaintenance()) { + return $this->getMaintenanceMiddleware($pipe); + } else if (! $app->isUpToDate()) { + return $this->getUpdaterMiddleware($pipe, $app); + } + + $forum = parse_url($app->url(''), PHP_URL_PATH) ?: '/'; + $admin = parse_url($app->url('admin'), PHP_URL_PATH); + $api = parse_url($app->url('api'), PHP_URL_PATH); + + if ($this->pathStartsWith($requestPath, $api)) { + $pipe->pipe($api, $app->make('flarum.api.middleware')); + } else if ($this->pathStartsWith($requestPath, $admin)) { + $pipe->pipe($admin, $app->make('flarum.admin.middleware')); + } else { + $pipe->pipe($forum, $app->make('flarum.forum.middleware')); + } + + return $pipe; + } + + private function pathStartsWith($path, $prefix) + { + return $path === $prefix || starts_with($path, "$prefix/"); + } + + protected function getInstallerMiddleware(MiddlewarePipe $pipe, Application $app) + { + $app->register(InstallServiceProvider::class); + + $pipe->pipe(new HandleErrors($this->getErrorDir(), $app->make('log'), true)); + + $pipe->pipe($app->make(StartSession::class)); + $pipe->pipe($app->make(DispatchRoute::class, ['routes' => $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, Application $app) + { + $app->register(UpdateServiceProvider::class); + + $pipe->pipe($app->make(DispatchRoute::class, ['routes' => $app->make('flarum.update.routes')])); + + // TODO: FOR API render JSON-API error document for HTTP 503 + + return $pipe; + } + + 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 getErrorDir() + { + return __DIR__.'/../../error'; + } + + private function hitsLottery() + { + return mt_rand(1, 100) <= 2; + } +} From 9686256f38526b36634f492cc806abbd461d44b8 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Fri, 30 Jun 2017 12:37:33 +0200 Subject: [PATCH 042/172] Fix code style --- framework/core/src/Http/Server.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/core/src/Http/Server.php b/framework/core/src/Http/Server.php index 832b58dce..86ce0af6a 100644 --- a/framework/core/src/Http/Server.php +++ b/framework/core/src/Http/Server.php @@ -74,9 +74,9 @@ class Server extends AbstractServer if (! $app->isInstalled()) { return $this->getInstallerMiddleware($pipe, $app); - } else if ($app->isDownForMaintenance()) { + } elseif ($app->isDownForMaintenance()) { return $this->getMaintenanceMiddleware($pipe); - } else if (! $app->isUpToDate()) { + } elseif (! $app->isUpToDate()) { return $this->getUpdaterMiddleware($pipe, $app); } @@ -86,7 +86,7 @@ class Server extends AbstractServer if ($this->pathStartsWith($requestPath, $api)) { $pipe->pipe($api, $app->make('flarum.api.middleware')); - } else if ($this->pathStartsWith($requestPath, $admin)) { + } elseif ($this->pathStartsWith($requestPath, $admin)) { $pipe->pipe($admin, $app->make('flarum.admin.middleware')); } else { $pipe->pipe($forum, $app->make('flarum.forum.middleware')); From 686797cdf38c8ed50e550db657423e5b92a5882f Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sun, 2 Jul 2017 13:30:02 +0200 Subject: [PATCH 043/172] Extract Flarum\Foundation\Site class This class holds all information relevant to a local Flarum site, such as paths and local configuration. From this information, it is able to instantiate a Flarum\Foundation\Application instance, which represents a Flarum installation's runtime. This will also be useful for setting up e.g. multi-tenant environments. --- framework/core/src/Console/Server.php | 35 +++-- framework/core/src/Foundation/Application.php | 3 +- .../{AbstractServer.php => Site.php} | 147 ++++++++---------- framework/core/src/Http/Server.php | 81 ++++++---- 4 files changed, 143 insertions(+), 123 deletions(-) rename framework/core/src/Foundation/{AbstractServer.php => Site.php} (61%) diff --git a/framework/core/src/Console/Server.php b/framework/core/src/Console/Server.php index f7ad12cbb..36cdea59d 100644 --- a/framework/core/src/Console/Server.php +++ b/framework/core/src/Console/Server.php @@ -13,14 +13,30 @@ namespace Flarum\Console; use Flarum\Database\Console\GenerateMigrationCommand; use Flarum\Database\Console\MigrateCommand; -use Flarum\Foundation\AbstractServer; +use Flarum\Foundation\Application; use Flarum\Foundation\Console\CacheClearCommand; use Flarum\Foundation\Console\InfoCommand; +use Flarum\Foundation\Site; use Flarum\Install\Console\InstallCommand; -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/Foundation/Application.php b/framework/core/src/Foundation/Application.php index a432bdbb8..85533ffd9 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'); diff --git a/framework/core/src/Foundation/AbstractServer.php b/framework/core/src/Foundation/Site.php similarity index 61% rename from framework/core/src/Foundation/AbstractServer.php rename to framework/core/src/Foundation/Site.php index bcc7c534b..d59b6f056 100644 --- a/framework/core/src/Foundation/AbstractServer.php +++ b/framework/core/src/Foundation/Site.php @@ -11,12 +11,35 @@ namespace Flarum\Foundation; +use Flarum\Admin\AdminServiceProvider; +use Flarum\Api\ApiServiceProvider; +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,27 +66,12 @@ 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; + $this->basePath = getcwd(); + $this->publicPath = $this->basePath; if (file_exists($file = $this->basePath.'/config.php')) { $this->config = include $file; @@ -71,81 +79,61 @@ abstract class AbstractServer } /** - * @return string + * @return Application */ - public function getBasePath() + public function boot() { - return $this->basePath; - } - - /** - * @return string - */ - public function getPublicPath() - { - return $this->publicPath; - } - - /** - * @return string - */ - public function getStoragePath() - { - return $this->storagePath; + 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 array - */ - public function getConfig() - { - return $this->config; + return $this; } /** * @param array $config + * @return static */ public function setConfig(array $config) { $this->config = $config; - } - /** - * @param callable $callback - */ - public function extend(callable $callback) - { - $this->extendCallbacks[] = $callback; + return $this; } /** * @return Application */ - public function getApp() + protected function getApp() { if ($this->app !== null) { return $this->app; @@ -167,19 +155,19 @@ abstract class AbstractServer $this->registerCache($app); - $app->register('Flarum\Database\DatabaseServiceProvider'); - $app->register('Flarum\Database\MigrationServiceProvider'); - $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); 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')); @@ -190,25 +178,26 @@ abstract class AbstractServer $config->set('mail.username', $settings->get('mail_username')); $config->set('mail.password', $settings->get('mail_password')); - $app->register('Flarum\BusServiceProvider'); + $app->register(\Flarum\BusServiceProvider::class); - $app->register('Flarum\Discussion\DiscussionServiceProvider'); - $app->register('Flarum\Formatter\FormatterServiceProvider'); - $app->register('Flarum\Group\GroupServiceProvider'); - $app->register('Flarum\Notification\NotificationServiceProvider'); - $app->register('Flarum\Post\PostServiceProvider'); - $app->register('Flarum\Search\SearchServiceProvider'); - $app->register('Flarum\User\UserServiceProvider'); + $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); - $app->register('Flarum\Api\ApiServiceProvider'); - $app->register('Flarum\Forum\ForumServiceProvider'); - $app->register('Flarum\Admin\AdminServiceProvider'); + $app->register(ApiServiceProvider::class); + $app->register(ForumServiceProvider::class); + $app->register(AdminServiceProvider::class); - foreach ($this->extendCallbacks as $callback) { - $app->call($callback); + 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/Http/Server.php b/framework/core/src/Http/Server.php index 86ce0af6a..590a73a24 100644 --- a/framework/core/src/Http/Server.php +++ b/framework/core/src/Http/Server.php @@ -11,8 +11,8 @@ namespace Flarum\Http; -use Flarum\Foundation\AbstractServer; use Flarum\Foundation\Application; +use Flarum\Foundation\Site; use Flarum\Http\Middleware\DispatchRoute; use Flarum\Http\Middleware\HandleErrors; use Flarum\Http\Middleware\StartSession; @@ -29,8 +29,22 @@ use Zend\Stratigility\MiddlewareInterface; use Zend\Stratigility\MiddlewarePipe; use Zend\Stratigility\NoopFinalHandler; -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() { DiactorosServer::createServer( @@ -53,43 +67,44 @@ class Server extends AbstractServer */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out) { - $app = $this->getApp(); + $this->collectGarbage(); - $this->collectGarbage($app); - - $middleware = $this->getMiddleware($app, $request->getUri()->getPath()); + $middleware = $this->getMiddleware($request->getUri()->getPath()); return $middleware($request, $response, $out); } /** - * @param Application $app * @param string $requestPath * @return MiddlewareInterface */ - protected function getMiddleware(Application $app, $requestPath) + protected function getMiddleware($requestPath) { $pipe = new MiddlewarePipe; $pipe->raiseThrowables(); - if (! $app->isInstalled()) { - return $this->getInstallerMiddleware($pipe, $app); - } elseif ($app->isDownForMaintenance()) { - return $this->getMaintenanceMiddleware($pipe); - } elseif (! $app->isUpToDate()) { - return $this->getUpdaterMiddleware($pipe, $app); + if (! $this->app->isInstalled()) { + return $this->getInstallerMiddleware($pipe); } - $forum = parse_url($app->url(''), PHP_URL_PATH) ?: '/'; - $admin = parse_url($app->url('admin'), PHP_URL_PATH); - $api = parse_url($app->url('api'), PHP_URL_PATH); + 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, $app->make('flarum.api.middleware')); + $pipe->pipe($api, $this->app->make('flarum.api.middleware')); } elseif ($this->pathStartsWith($requestPath, $admin)) { - $pipe->pipe($admin, $app->make('flarum.admin.middleware')); + $pipe->pipe($admin, $this->app->make('flarum.admin.middleware')); } else { - $pipe->pipe($forum, $app->make('flarum.forum.middleware')); + $pipe->pipe($forum, $this->app->make('flarum.forum.middleware')); } return $pipe; @@ -100,14 +115,14 @@ class Server extends AbstractServer return $path === $prefix || starts_with($path, "$prefix/"); } - protected function getInstallerMiddleware(MiddlewarePipe $pipe, Application $app) + protected function getInstallerMiddleware(MiddlewarePipe $pipe) { - $app->register(InstallServiceProvider::class); + $this->app->register(InstallServiceProvider::class); - $pipe->pipe(new HandleErrors($this->getErrorDir(), $app->make('log'), true)); + $pipe->pipe(new HandleErrors($this->getErrorDir(), $this->app->make('log'), true)); - $pipe->pipe($app->make(StartSession::class)); - $pipe->pipe($app->make(DispatchRoute::class, ['routes' => $app->make('flarum.install.routes')])); + $pipe->pipe($this->app->make(StartSession::class)); + $pipe->pipe($this->app->make(DispatchRoute::class, ['routes' => $this->app->make('flarum.install.routes')])); return $pipe; } @@ -123,11 +138,11 @@ class Server extends AbstractServer return $pipe; } - protected function getUpdaterMiddleware(MiddlewarePipe $pipe, Application $app) + protected function getUpdaterMiddleware(MiddlewarePipe $pipe) { - $app->register(UpdateServiceProvider::class); + $this->app->register(UpdateServiceProvider::class); - $pipe->pipe($app->make(DispatchRoute::class, ['routes' => $app->make('flarum.update.routes')])); + $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 @@ -147,13 +162,13 @@ class Server extends AbstractServer } } - private function getErrorDir() - { - return __DIR__.'/../../error'; - } - private function hitsLottery() { return mt_rand(1, 100) <= 2; } + + private function getErrorDir() + { + return __DIR__.'/../../error'; + } } From cafb38aa642296592cfc5cf88661e446713ebbbd Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Sun, 2 Jul 2017 13:29:30 +0200 Subject: [PATCH 044/172] Cleanup code, typehints and class references --- framework/core/src/Api/ApiKey.php | 8 ++-- framework/core/src/Database/Migrator.php | 2 +- .../Command/StartDiscussionHandler.php | 1 + .../Discussion/DiscussionServiceProvider.php | 6 +-- .../Discussion/Search/DiscussionSearcher.php | 10 +++-- framework/core/src/Discussion/UserState.php | 5 ++- .../src/Event/AbstractConfigureRoutes.php | 11 +---- .../core/src/Event/ConfigureForumRoutes.php | 4 +- .../Extension/DefaultLanguagePackGuard.php | 8 ++-- .../Formatter/FormatterServiceProvider.php | 2 +- .../Forum/Controller/DiscussionController.php | 2 +- .../Forum/Controller/RegisterController.php | 3 +- .../core/src/Frontend/Event/Rendering.php | 8 ++-- framework/core/src/Group/Group.php | 9 ++-- .../core/src/Group/GroupServiceProvider.php | 2 +- framework/core/src/Group/Permission.php | 2 +- .../src/Install/Console/InstallCommand.php | 45 ++++++++++++------- .../Install/Controller/IndexController.php | 2 +- .../src/Install/InstallServiceProvider.php | 3 +- .../core/src/Locale/LocaleServiceProvider.php | 10 +++-- .../Blueprint/DiscussionRenamedBlueprint.php | 3 +- .../core/src/Notification/Notification.php | 5 ++- .../NotificationServiceProvider.php | 5 ++- 23 files changed, 87 insertions(+), 69 deletions(-) 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/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/Discussion/Command/StartDiscussionHandler.php b/framework/core/src/Discussion/Command/StartDiscussionHandler.php index 01f99b832..c7399210a 100644 --- a/framework/core/src/Discussion/Command/StartDiscussionHandler.php +++ b/framework/core/src/Discussion/Command/StartDiscussionHandler.php @@ -16,6 +16,7 @@ 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; diff --git a/framework/core/src/Discussion/DiscussionServiceProvider.php b/framework/core/src/Discussion/DiscussionServiceProvider.php index 5f8ca4216..e1c0c466a 100644 --- a/framework/core/src/Discussion/DiscussionServiceProvider.php +++ b/framework/core/src/Discussion/DiscussionServiceProvider.php @@ -22,8 +22,8 @@ class DiscussionServiceProvider extends AbstractServiceProvider { $events = $this->app->make('events'); - $events->subscribe('Flarum\Discussion\DiscussionMetadataUpdater'); - $events->subscribe('Flarum\Discussion\DiscussionPolicy'); - $events->subscribe('Flarum\Discussion\DiscussionRenamedLogger'); + $events->subscribe(DiscussionMetadataUpdater::class); + $events->subscribe(DiscussionPolicy::class); + $events->subscribe(DiscussionRenamedLogger::class); } } diff --git a/framework/core/src/Discussion/Search/DiscussionSearcher.php b/framework/core/src/Discussion/Search/DiscussionSearcher.php index 5628dcf2f..c3b5fdb59 100644 --- a/framework/core/src/Discussion/Search/DiscussionSearcher.php +++ b/framework/core/src/Discussion/Search/DiscussionSearcher.php @@ -17,6 +17,8 @@ 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; /** @@ -58,13 +60,13 @@ class DiscussionSearcher } /** - * @param \Flarum\Search\SearchCriteria $criteria + * @param SearchCriteria $criteria * @param int|null $limit * @param int $offset * @param array $load An array of relationships to load on the results. - * @return \Flarum\Search\SearchResults + * @return SearchResults */ - public function search(\Flarum\Search\SearchCriteria $criteria, $limit = null, $offset = 0, array $load = []) + public function search(SearchCriteria $criteria, $limit = null, $offset = 0, array $load = []) { $actor = $criteria->actor; @@ -107,7 +109,7 @@ class DiscussionSearcher Discussion::setStateUser($actor); $discussions->load($load); - return new \Flarum\Search\SearchResults($discussions, $areMoreResults); + return new SearchResults($discussions, $areMoreResults); } /** diff --git a/framework/core/src/Discussion/UserState.php b/framework/core/src/Discussion/UserState.php index 481893f91..a8df0651c 100644 --- a/framework/core/src/Discussion/UserState.php +++ b/framework/core/src/Discussion/UserState.php @@ -14,6 +14,7 @@ namespace Flarum\Discussion; use Flarum\Database\AbstractModel; use Flarum\Discussion\Event\UserRead; use Flarum\Foundation\EventGeneratorTrait; +use Flarum\User\User; use Illuminate\Database\Eloquent\Builder; /** @@ -70,7 +71,7 @@ class UserState extends AbstractModel */ public function discussion() { - return $this->belongsTo('Flarum\Discussion\Discussion', 'discussion_id'); + return $this->belongsTo(Discussion::class, 'discussion_id'); } /** @@ -80,7 +81,7 @@ class UserState extends AbstractModel */ public function user() { - return $this->belongsTo('Flarum\User\User', 'user_id'); + return $this->belongsTo(User::class, 'user_id'); } /** diff --git a/framework/core/src/Event/AbstractConfigureRoutes.php b/framework/core/src/Event/AbstractConfigureRoutes.php index c09ab958c..3ce06cf61 100644 --- a/framework/core/src/Event/AbstractConfigureRoutes.php +++ b/framework/core/src/Event/AbstractConfigureRoutes.php @@ -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/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/Extension/DefaultLanguagePackGuard.php b/framework/core/src/Extension/DefaultLanguagePackGuard.php index 68afffd91..3ec124edc 100644 --- a/framework/core/src/Extension/DefaultLanguagePackGuard.php +++ b/framework/core/src/Extension/DefaultLanguagePackGuard.php @@ -11,7 +11,7 @@ namespace Flarum\Extension; -use Flarum\Event\ExtensionWillBeDisabled; +use Flarum\Extension\Event\Disabling; use Flarum\Http\Exception\ForbiddenException; use Illuminate\Contracts\Events\Dispatcher; @@ -22,14 +22,14 @@ class DefaultLanguagePackGuard */ 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'); diff --git a/framework/core/src/Formatter/FormatterServiceProvider.php b/framework/core/src/Formatter/FormatterServiceProvider.php index de07468dd..25de9fe55 100644 --- a/framework/core/src/Formatter/FormatterServiceProvider.php +++ b/framework/core/src/Formatter/FormatterServiceProvider.php @@ -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/Controller/DiscussionController.php b/framework/core/src/Forum/Controller/DiscussionController.php index 216f72961..a71fc436c 100644 --- a/framework/core/src/Forum/Controller/DiscussionController.php +++ b/framework/core/src/Forum/Controller/DiscussionController.php @@ -22,7 +22,7 @@ use Psr\Http\Message\ServerRequestInterface as Request; class DiscussionController extends FrontendController { /** - * @var ApiClient + * @var Client */ protected $api; 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/Frontend/Event/Rendering.php b/framework/core/src/Frontend/Event/Rendering.php index 6219c557f..a5d81c949 100644 --- a/framework/core/src/Frontend/Event/Rendering.php +++ b/framework/core/src/Frontend/Event/Rendering.php @@ -11,8 +11,8 @@ namespace Flarum\Frontend\Event; -use Flarum\Admin\Controller\FrontendController as AdminWebAppController; -use Flarum\Forum\Controller\FrontendController as ForumWebAppController; +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; @@ -48,12 +48,12 @@ class Rendering 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/Group/Group.php b/framework/core/src/Group/Group.php index 4af4a4d61..14daf1b69 100755 --- a/framework/core/src/Group/Group.php +++ b/framework/core/src/Group/Group.php @@ -15,8 +15,9 @@ use Flarum\Database\AbstractModel; use Flarum\Database\ScopeVisibilityTrait; use Flarum\Foundation\EventGeneratorTrait; use Flarum\Group\Event\Created; -use Flarum\Group\Event\Deleting; +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 Deleting($group)); + $group->raise(new Deleted($group)); $group->permissions()->delete(); }); @@ -120,7 +121,7 @@ class Group extends AbstractModel */ public function users() { - return $this->belongsToMany('Flarum\User\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\Group\Permission'); + return $this->hasMany(Permission::class); } } diff --git a/framework/core/src/Group/GroupServiceProvider.php b/framework/core/src/Group/GroupServiceProvider.php index bdf1ceb15..ad923df9f 100644 --- a/framework/core/src/Group/GroupServiceProvider.php +++ b/framework/core/src/Group/GroupServiceProvider.php @@ -21,6 +21,6 @@ class GroupServiceProvider extends AbstractServiceProvider public function boot() { $events = $this->app->make('events'); - $events->subscribe('Flarum\Group\GroupPolicy'); + $events->subscribe(GroupPolicy::class); } } diff --git a/framework/core/src/Group/Permission.php b/framework/core/src/Group/Permission.php index 0ed470e3b..110c365b0 100755 --- a/framework/core/src/Group/Permission.php +++ b/framework/core/src/Group/Permission.php @@ -31,7 +31,7 @@ class Permission extends AbstractModel */ public function group() { - return $this->belongsTo('Flarum\Group\Group', 'group_id'); + return $this->belongsTo(Group::class, 'group_id'); } /** diff --git a/framework/core/src/Install/Console/InstallCommand.php b/framework/core/src/Install/Console/InstallCommand.php index f7f9d3a98..1255e6216 100644 --- a/framework/core/src/Install/Console/InstallCommand.php +++ b/framework/core/src/Install/Console/InstallCommand.php @@ -14,14 +14,29 @@ namespace Flarum\Install\Console; use Exception; 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\Database\ConnectionInterface; +use Illuminate\Database\ConnectionResolverInterface; +use Illuminate\Database\Schema\Builder; use Illuminate\Filesystem\Filesystem; use Illuminate\Validation\Factory; use PDO; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Translation\TranslatorInterface; class InstallCommand extends AbstractCommand { @@ -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,13 +186,13 @@ class InstallCommand extends AbstractCommand $this->writeSettings(); - $this->application->register('Flarum\Formatter\FormatterServiceProvider'); - $this->application->register('Flarum\Discussion\DiscussionServiceProvider'); - $this->application->register('Flarum\Group\GroupServiceProvider'); - $this->application->register('Flarum\Notification\NotificationServiceProvider'); - $this->application->register('Flarum\Search\SearchServiceProvider'); - $this->application->register('Flarum\Post\PostServiceProvider'); - $this->application->register('Flarum\User\UserServiceProvider'); + $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->application->register(UserServiceProvider::class); $this->seedGroups(); $this->seedPermissions(); @@ -240,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'); @@ -256,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'); @@ -341,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(); @@ -386,7 +401,7 @@ class InstallCommand extends AbstractCommand */ protected function getPrerequisites() { - return $this->application->make('Flarum\Install\Prerequisite\PrerequisiteInterface'); + return $this->application->make(PrerequisiteInterface::class); } /** @@ -394,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(TranslatorInterface::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 733a1ce9e..e57f47ab1 100644 --- a/framework/core/src/Install/InstallServiceProvider.php +++ b/framework/core/src/Install/InstallServiceProvider.php @@ -17,6 +17,7 @@ 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/LocaleServiceProvider.php b/framework/core/src/Locale/LocaleServiceProvider.php index 034e21a1c..4ddcc46f5 100644 --- a/framework/core/src/Locale/LocaleServiceProvider.php +++ b/framework/core/src/Locale/LocaleServiceProvider.php @@ -15,6 +15,8 @@ use Flarum\Event\ConfigureLocales; use Flarum\Foundation\AbstractServiceProvider; use Illuminate\Contracts\Events\Dispatcher; use Symfony\Component\Translation\MessageSelector; +use Symfony\Component\Translation\Translator; +use Symfony\Component\Translation\TranslatorInterface; class LocaleServiceProvider extends AbstractServiceProvider { @@ -35,8 +37,8 @@ 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(); @@ -47,8 +49,8 @@ class LocaleServiceProvider extends AbstractServiceProvider 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', TranslatorInterface::class); } private function getDefaultLocale() diff --git a/framework/core/src/Notification/Blueprint/DiscussionRenamedBlueprint.php b/framework/core/src/Notification/Blueprint/DiscussionRenamedBlueprint.php index 996483c27..50d2e6146 100644 --- a/framework/core/src/Notification/Blueprint/DiscussionRenamedBlueprint.php +++ b/framework/core/src/Notification/Blueprint/DiscussionRenamedBlueprint.php @@ -11,6 +11,7 @@ namespace Flarum\Notification\Blueprint; +use Flarum\Discussion\Discussion; use Flarum\Post\DiscussionRenamedPost; class DiscussionRenamedBlueprint implements BlueprintInterface @@ -65,6 +66,6 @@ class DiscussionRenamedBlueprint implements BlueprintInterface */ public static function getSubjectModel() { - return 'Flarum\Discussion\Discussion'; + return Discussion::class; } } diff --git a/framework/core/src/Notification/Notification.php b/framework/core/src/Notification/Notification.php index 6a32fdd36..ad289ca08 100644 --- a/framework/core/src/Notification/Notification.php +++ b/framework/core/src/Notification/Notification.php @@ -12,6 +12,7 @@ namespace Flarum\Notification; use Flarum\Database\AbstractModel; +use Flarum\User\User; /** * Models a notification record in the database. @@ -113,7 +114,7 @@ class Notification extends AbstractModel */ public function user() { - return $this->belongsTo('Flarum\User\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\User\User', 'sender_id'); + return $this->belongsTo(User::class, 'sender_id'); } /** diff --git a/framework/core/src/Notification/NotificationServiceProvider.php b/framework/core/src/Notification/NotificationServiceProvider.php index 3edbffcaa..8771198a0 100644 --- a/framework/core/src/Notification/NotificationServiceProvider.php +++ b/framework/core/src/Notification/NotificationServiceProvider.php @@ -13,6 +13,7 @@ namespace Flarum\Notification; use Flarum\Event\ConfigureNotificationTypes; use Flarum\Foundation\AbstractServiceProvider; +use Flarum\Notification\Blueprint\DiscussionRenamedBlueprint; use Flarum\User\User; use ReflectionClass; @@ -32,7 +33,7 @@ class NotificationServiceProvider extends AbstractServiceProvider public function registerNotificationTypes() { $blueprints = [ - 'Flarum\Notification\Blueprint\DiscussionRenamedBlueprint' => ['alert'] + DiscussionRenamedBlueprint::class => ['alert'] ]; $this->app->make('events')->fire( @@ -51,7 +52,7 @@ class NotificationServiceProvider extends AbstractServiceProvider in_array('alert', $enabled) ); - if ((new ReflectionClass($blueprint))->implementsInterface('Flarum\Notification\MailableInterface')) { + if ((new ReflectionClass($blueprint))->implementsInterface(MailableInterface::class)) { User::addPreference( User::getNotificationPreferenceKey($type, 'email'), 'boolval', From d995cfe6e01905159cfe0eb7a56be04c93cee049 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Mon, 3 Jul 2017 10:10:03 +0200 Subject: [PATCH 045/172] Use ::class constant instead of hardcoded strings --- framework/core/src/Extension/ExtensionServiceProvider.php | 4 ++-- framework/core/src/Settings/SettingsServiceProvider.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/core/src/Extension/ExtensionServiceProvider.php b/framework/core/src/Extension/ExtensionServiceProvider.php index a421b1865..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(); @@ -38,6 +38,6 @@ class ExtensionServiceProvider extends AbstractServiceProvider { $events = $this->app->make('events'); - $events->subscribe('Flarum\Extension\DefaultLanguagePackGuard'); + $events->subscribe(DefaultLanguagePackGuard::class); } } 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'); } } From 45bb311ca7c4124ac118716fd312b52ce9953b86 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Mon, 3 Jul 2017 10:15:09 +0200 Subject: [PATCH 046/172] Inject settings repository in event listener `$this->app` was not defined here anyway. Refs #1032. --- .../src/Extension/DefaultLanguagePackGuard.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Extension/DefaultLanguagePackGuard.php b/framework/core/src/Extension/DefaultLanguagePackGuard.php index 3ec124edc..d8fd3dc8a 100644 --- a/framework/core/src/Extension/DefaultLanguagePackGuard.php +++ b/framework/core/src/Extension/DefaultLanguagePackGuard.php @@ -13,10 +13,21 @@ namespace Flarum\Extension; use Flarum\Extension\Event\Disabling; use Flarum\Http\Exception\ForbiddenException; +use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Events\Dispatcher; class DefaultLanguagePackGuard { + /** + * @var SettingsRepositoryInterface + */ + protected $settings; + + public function __construct(SettingsRepositoryInterface $settings) + { + $this->settings = $settings; + } + /** * @param Dispatcher $events */ @@ -32,9 +43,9 @@ class DefaultLanguagePackGuard 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!'); } } From 399ff616ff0aee11714400064f1338d68bad985c Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Tue, 3 Oct 2017 16:53:18 +0200 Subject: [PATCH 047/172] Change order of service provider registration Here, the order is relevant, because at this point, the application has already been booted. Hence, all boot() methods are called immediately, which might depend on other service providers' register() methods having run. In this case, the DiscussionServiceProvider depends on the Gate class being registered in the container by the UserServiceProvider. --- framework/core/src/Install/Console/InstallCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Install/Console/InstallCommand.php b/framework/core/src/Install/Console/InstallCommand.php index 1255e6216..6c628fcbd 100644 --- a/framework/core/src/Install/Console/InstallCommand.php +++ b/framework/core/src/Install/Console/InstallCommand.php @@ -186,13 +186,13 @@ class InstallCommand extends AbstractCommand $this->writeSettings(); + $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->application->register(UserServiceProvider::class); $this->seedGroups(); $this->seedPermissions(); From 5b6ee0181a81f5cfa4095799e5e195037b785201 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers <daniel@productip.com> Date: Thu, 5 Oct 2017 13:39:41 +0200 Subject: [PATCH 048/172] lists > pluck --- framework/core/composer.json | 38 +++++++++---------- .../Api/Controller/CreatePostController.php | 2 +- .../Api/Controller/ListPostsController.php | 2 +- .../Controller/ShowDiscussionController.php | 2 +- .../Controller/UpdateDiscussionController.php | 2 +- .../Database/DatabaseMigrationRepository.php | 2 +- .../src/Discussion/DiscussionRepository.php | 2 +- .../Search/Fulltext/MySqlFulltextDriver.php | 2 +- .../src/Notification/NotificationSyncer.php | 2 +- framework/core/src/Post/PostRepository.php | 4 +- .../Settings/DatabaseSettingsRepository.php | 2 +- framework/core/src/User/User.php | 4 +- framework/core/src/User/UserRepository.php | 2 +- 13 files changed, 33 insertions(+), 33 deletions(-) diff --git a/framework/core/composer.json b/framework/core/composer.json index efdb49182..ffe0a7205 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,10 +46,10 @@ "nikic/fast-route": "^0.6", "oyejorge/less.php": "~1.5", "psr/http-message": "^1.0", - "symfony/console": "^2.7", - "symfony/http-foundation": "^2.7", - "symfony/translation": "^2.7", - "symfony/yaml": "^2.7", + "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.1", @@ -57,7 +57,7 @@ }, "require-dev": { "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^4.8" + "phpunit/phpunit": "^6.0" }, "autoload": { "psr-4": { diff --git a/framework/core/src/Api/Controller/CreatePostController.php b/framework/core/src/Api/Controller/CreatePostController.php index fc7432530..1d7e9f5c2 100644 --- a/framework/core/src/Api/Controller/CreatePostController.php +++ b/framework/core/src/Api/Controller/CreatePostController.php @@ -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/ListPostsController.php b/framework/core/src/Api/Controller/ListPostsController.php index b506f814a..5c732bc6f 100644 --- a/framework/core/src/Api/Controller/ListPostsController.php +++ b/framework/core/src/Api/Controller/ListPostsController.php @@ -122,7 +122,7 @@ class ListPostsController extends AbstractListController $query->orderBy($field, $order); } - return $query->lists('id')->all(); + return $query->pluck('id')->all(); } /** diff --git a/framework/core/src/Api/Controller/ShowDiscussionController.php b/framework/core/src/Api/Controller/ShowDiscussionController.php index 4ee73d225..8cd8a2a06 100644 --- a/framework/core/src/Api/Controller/ShowDiscussionController.php +++ b/framework/core/src/Api/Controller/ShowDiscussionController.php @@ -117,7 +117,7 @@ class ShowDiscussionController extends AbstractShowController */ 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/UpdateDiscussionController.php b/framework/core/src/Api/Controller/UpdateDiscussionController.php index 4cdd3a0a1..3fa1900f3 100644 --- a/framework/core/src/Api/Controller/UpdateDiscussionController.php +++ b/framework/core/src/Api/Controller/UpdateDiscussionController.php @@ -63,7 +63,7 @@ class UpdateDiscussionController extends AbstractShowController 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/Database/DatabaseMigrationRepository.php b/framework/core/src/Database/DatabaseMigrationRepository.php index 49a1978e4..fdce0f00e 100755 --- a/framework/core/src/Database/DatabaseMigrationRepository.php +++ b/framework/core/src/Database/DatabaseMigrationRepository.php @@ -58,7 +58,7 @@ class DatabaseMigrationRepository implements MigrationRepositoryInterface return $this->table() ->where('extension', $extension) ->orderBy('migration', 'asc') - ->lists('migration'); + ->pluck('migration'); } /** diff --git a/framework/core/src/Discussion/DiscussionRepository.php b/framework/core/src/Discussion/DiscussionRepository.php index 11c64664a..b5dbcfcb4 100644 --- a/framework/core/src/Discussion/DiscussionRepository.php +++ b/framework/core/src/Discussion/DiscussionRepository.php @@ -53,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/Search/Fulltext/MySqlFulltextDriver.php b/framework/core/src/Discussion/Search/Fulltext/MySqlFulltextDriver.php index 0c1136297..f3e1a0be2 100644 --- a/framework/core/src/Discussion/Search/Fulltext/MySqlFulltextDriver.php +++ b/framework/core/src/Discussion/Search/Fulltext/MySqlFulltextDriver.php @@ -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/Notification/NotificationSyncer.php b/framework/core/src/Notification/NotificationSyncer.php index 7065c461d..5dc3a1843 100644 --- a/framework/core/src/Notification/NotificationSyncer.php +++ b/framework/core/src/Notification/NotificationSyncer.php @@ -106,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)) { diff --git a/framework/core/src/Post/PostRepository.php b/framework/core/src/Post/PostRepository.php index e6a38af03..06ba1db71 100644 --- a/framework/core/src/Post/PostRepository.php +++ b/framework/core/src/Post/PostRepository.php @@ -70,7 +70,7 @@ class PostRepository $query->orderBy($field, $order); } - $ids = $query->lists('id')->all(); + $ids = $query->pluck('id')->all(); return $this->findByIds($ids, $actor); } @@ -111,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(); } /** diff --git a/framework/core/src/Settings/DatabaseSettingsRepository.php b/framework/core/src/Settings/DatabaseSettingsRepository.php index 3179d23b9..943342d6b 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'); } public function get($key, $default = null) diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 78858643e..e33c58493 100755 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -650,7 +650,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)); @@ -665,7 +665,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/User/UserRepository.php b/framework/core/src/User/UserRepository.php index bea76c55d..8619446b9 100644 --- a/framework/core/src/User/UserRepository.php +++ b/framework/core/src/User/UserRepository.php @@ -94,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(); } /** From 79da73f645968535d06bdf1fab64f53d28a87131 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers <daniel@productip.com> Date: Thu, 5 Oct 2017 13:57:31 +0200 Subject: [PATCH 049/172] fixed those exception handling tests --- framework/core/.travis.yml | 5 ++++- .../IlluminateValidationExceptionHandler.php | 5 +++-- .../Handler/IlluminateValidationExceptionHandlerTest.php | 8 +++++--- framework/core/tests/Test/TestCase.php | 4 ++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/framework/core/.travis.yml b/framework/core/.travis.yml index 2226ea1a2..4a684b9be 100644 --- a/framework/core/.travis.yml +++ b/framework/core/.travis.yml @@ -1,11 +1,14 @@ language: php php: - - 5.6 - 7.0 - 7.1 + - 7.2 - hhvm +services: + - mysql + matrix: allow_failures: - php: hhvm diff --git a/framework/core/src/Api/ExceptionHandler/IlluminateValidationExceptionHandler.php b/framework/core/src/Api/ExceptionHandler/IlluminateValidationExceptionHandler.php index ab5bfadcf..31bf030ca 100644 --- a/framework/core/src/Api/ExceptionHandler/IlluminateValidationExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/IlluminateValidationExceptionHandler.php @@ -12,7 +12,7 @@ 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/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php index 4960aba36..298cee7b2 100644 --- a/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php @@ -13,9 +13,11 @@ namespace Tests\Flarum\Api\Handler; use Exception; use Flarum\Api\ExceptionHandler\IlluminateValidationExceptionHandler; -use Illuminate\Contracts\Validation\ValidationException; +use Illuminate\Translation\{ + Translator, ArrayLoader +}; +use Illuminate\Validation\ValidationException; use Illuminate\Validation\Factory; -use Symfony\Component\Translation\Translator; use Tests\Test\TestCase; class IlluminateValidationExceptionHandlerTest extends TestCase @@ -54,7 +56,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/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() { From c7bd017bf3b5c002675faf79b1982f62f97ad6e8 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers <daniel@productip.com> Date: Thu, 5 Oct 2017 14:02:54 +0200 Subject: [PATCH 050/172] satisfying styleci, undo mysql in travis --- framework/core/.travis.yml | 3 --- .../IlluminateValidationExceptionHandler.php | 2 +- .../Api/Handler/IlluminateValidationExceptionHandlerTest.php | 5 ++--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/framework/core/.travis.yml b/framework/core/.travis.yml index 4a684b9be..b217e0233 100644 --- a/framework/core/.travis.yml +++ b/framework/core/.travis.yml @@ -6,9 +6,6 @@ php: - 7.2 - hhvm -services: - - mysql - matrix: allow_failures: - php: hhvm diff --git a/framework/core/src/Api/ExceptionHandler/IlluminateValidationExceptionHandler.php b/framework/core/src/Api/ExceptionHandler/IlluminateValidationExceptionHandler.php index 31bf030ca..afc496c1d 100644 --- a/framework/core/src/Api/ExceptionHandler/IlluminateValidationExceptionHandler.php +++ b/framework/core/src/Api/ExceptionHandler/IlluminateValidationExceptionHandler.php @@ -32,7 +32,7 @@ class IlluminateValidationExceptionHandler implements ExceptionHandlerInterface public function handle(Exception $e) { $status = 422; - + $errors = $this->formatErrors($e->errors()); return new ResponseBag($status, $errors); diff --git a/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php index 298cee7b2..fb2262624 100644 --- a/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php @@ -13,9 +13,8 @@ namespace Tests\Flarum\Api\Handler; use Exception; use Flarum\Api\ExceptionHandler\IlluminateValidationExceptionHandler; -use Illuminate\Translation\{ - Translator, ArrayLoader -}; +use Illuminate\Translation\ArrayLoader; +use Illuminate\Translation\Translator; use Illuminate\Validation\ValidationException; use Illuminate\Validation\Factory; use Tests\Test\TestCase; From 5a99f13f3fa64e3c464ba77d7a4ee11bb2acb754 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers <daniel@productip.com> Date: Thu, 5 Oct 2017 16:25:01 +0200 Subject: [PATCH 051/172] added new methods etc --- framework/core/src/BusServiceProvider.php | 30 ------------ .../src/Database/DatabaseServiceProvider.php | 1 - framework/core/src/Foundation/Application.php | 18 +++++++ framework/core/src/Foundation/Site.php | 2 - framework/core/src/User/Gate.php | 47 +++++++++++++++++++ 5 files changed, 65 insertions(+), 33 deletions(-) delete mode 100644 framework/core/src/BusServiceProvider.php diff --git a/framework/core/src/BusServiceProvider.php b/framework/core/src/BusServiceProvider.php deleted file mode 100644 index 4406460f6..000000000 --- a/framework/core/src/BusServiceProvider.php +++ /dev/null @@ -1,30 +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; - -use Flarum\Foundation\AbstractServiceProvider; - -/** - * @deprecated - */ -class BusServiceProvider extends AbstractServiceProvider -{ - /** - * {@inheritdoc} - */ - public function boot() - { - $this->app->make('Illuminate\Contracts\Bus\Dispatcher')->mapUsing(function ($command) { - return get_class($command).'Handler@handle'; - }); - } -} diff --git a/framework/core/src/Database/DatabaseServiceProvider.php b/framework/core/src/Database/DatabaseServiceProvider.php index c4b349074..e54fb3e8e 100644 --- a/framework/core/src/Database/DatabaseServiceProvider.php +++ b/framework/core/src/Database/DatabaseServiceProvider.php @@ -28,7 +28,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; }); diff --git a/framework/core/src/Foundation/Application.php b/framework/core/src/Foundation/Application.php index 85533ffd9..3e9a5c7df 100644 --- a/framework/core/src/Foundation/Application.php +++ b/framework/core/src/Foundation/Application.php @@ -737,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/Foundation/Site.php b/framework/core/src/Foundation/Site.php index d59b6f056..cd1484dab 100644 --- a/framework/core/src/Foundation/Site.php +++ b/framework/core/src/Foundation/Site.php @@ -178,8 +178,6 @@ class Site $config->set('mail.username', $settings->get('mail_username')); $config->set('mail.password', $settings->get('mail_password')); - $app->register(\Flarum\BusServiceProvider::class); - $app->register(DiscussionServiceProvider::class); $app->register(FormatterServiceProvider::class); $app->register(GroupServiceProvider::class); diff --git a/framework/core/src/User/Gate.php b/framework/core/src/User/Gate.php index 9a9e91a27..7d9ac895c 100644 --- a/framework/core/src/User/Gate.php +++ b/framework/core/src/User/Gate.php @@ -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. + } } From b7800d2272e1889315650fa7c83f9bb98390a774 Mon Sep 17 00:00:00 2001 From: Joseph <josephle@me.com> Date: Sun, 22 Oct 2017 13:37:08 -0700 Subject: [PATCH 052/172] Add drag and drop avatar uploading --- .../js/forum/src/components/AvatarEditor.js | 100 ++++++++++++++---- framework/core/less/forum/AvatarEditor.less | 5 +- 2 files changed, 83 insertions(+), 22 deletions(-) diff --git a/framework/core/js/forum/src/components/AvatarEditor.js b/framework/core/js/forum/src/components/AvatarEditor.js index 8d7f6c525..869904b33 100644 --- a/framework/core/js/forum/src/components/AvatarEditor.js +++ b/framework/core/js/forum/src/components/AvatarEditor.js @@ -23,6 +23,13 @@ export default class AvatarEditor extends Component { * @type {Boolean} */ this.loading = false; + + /** + * Whether or not an image has been dragged over the dropzone. + * + * @type {Boolean} + */ + this.isDraggedOver = false; } static initProps(props) { @@ -35,12 +42,17 @@ export default class AvatarEditor extends Component { const user = this.props.user; return ( - <div className={'AvatarEditor Dropdown ' + this.props.className + (this.loading ? ' loading' : '')}> + <div className={'AvatarEditor Dropdown ' + this.props.className + (this.loading ? ' loading' : '') + (this.isDraggedOver ? ' dragover' : '')}> {avatar(user)} <a className={ user.avatarUrl() ? "Dropdown-toggle" : "Dropdown-toggle AvatarEditor--noAvatar" } title={app.translator.trans('core.forum.user.avatar_upload_tooltip')} data-toggle="dropdown" - onclick={this.quickUpload.bind(this)}> + onclick={this.quickUpload.bind(this)} + ondragover={this.enableDragover.bind(this)} + ondragenter={this.enableDragover.bind(this)} + ondragleave={this.disableDragover.bind(this)} + ondragend={this.disableDragover.bind(this)} + ondrop={this.dropUpload.bind(this)}> {this.loading ? LoadingIndicator.component() : (user.avatarUrl() ? icon('pencil') : icon('plus-circle'))} </a> <ul className="Dropdown-menu Menu"> @@ -62,7 +74,7 @@ export default class AvatarEditor extends Component { Button.component({ icon: 'upload', children: app.translator.trans('core.forum.user.avatar_upload_button'), - onclick: this.upload.bind(this) + onclick: this.openPicker.bind(this) }) ); @@ -77,6 +89,40 @@ export default class AvatarEditor extends Component { return items; } + /** + * Enable dragover style + * + * @param {Event} e + */ + enableDragover(e) { + e.preventDefault(); + e.stopPropagation(); + this.isDraggedOver = true; + } + + /** + * Disable dragover style + * + * @param {Event} e + */ + disableDragover(e) { + e.preventDefault(); + e.stopPropagation(); + this.isDraggedOver = false; + } + + /** + * Upload avatar when file is dropped into dropzone. + * + * @param {Event} e + */ + dropUpload(e) { + e.preventDefault(); + e.stopPropagation(); + this.isDraggedOver = false; + this.upload(e.dataTransfer.files[0]); + } + /** * If the user doesn't have an avatar, there's no point in showing the * controls dropdown, because only one option would be viable: uploading. @@ -89,14 +135,14 @@ export default class AvatarEditor extends Component { if (!this.props.user.avatarUrl()) { e.preventDefault(); e.stopPropagation(); - this.upload(); + this.openPicker(); } } /** - * Prompt the user to upload a new avatar. + * Upload avatar using file picker */ - upload() { + openPicker() { if (this.loading) return; // Create a hidden HTML input element and click on it so the user can select @@ -105,24 +151,36 @@ export default class AvatarEditor extends Component { const $input = $('<input type="file">'); $input.appendTo('body').hide().click().on('change', e => { - const data = new FormData(); - data.append('avatar', $(e.target)[0].files[0]); - - this.loading = true; - m.redraw(); - - app.request({ - method: 'POST', - url: app.forum.attribute('apiUrl') + '/users/' + user.id() + '/avatar', - serialize: raw => raw, - data - }).then( - this.success.bind(this), - this.failure.bind(this) - ); + this.upload($(e.target)[0].files[0]); }); } + /** + * Upload avatar + * + * @param {File} file + */ + upload(file) { + if (this.loading) return; + + const user = this.props.user; + const data = new FormData(); + data.append('avatar', file); + + this.loading = true; + m.redraw(); + + app.request({ + method: 'POST', + url: app.forum.attribute('apiUrl') + '/users/' + user.id() + '/avatar', + serialize: raw => raw, + data + }).then( + this.success.bind(this), + this.failure.bind(this) + ); + } + /** * Remove the user's avatar. */ diff --git a/framework/core/less/forum/AvatarEditor.less b/framework/core/less/forum/AvatarEditor.less index 72fc55eda..7f6dc7a9b 100644 --- a/framework/core/less/forum/AvatarEditor.less +++ b/framework/core/less/forum/AvatarEditor.less @@ -17,7 +17,10 @@ .AvatarEditor--noAvatar { opacity: 0.7; } - &:hover .Dropdown-toggle, &.open .Dropdown-toggle, &.loading .Dropdown-toggle { + &:hover .Dropdown-toggle, + &.open .Dropdown-toggle, + &.loading .Dropdown-toggle, + &.dragover .Dropdown-toggle { opacity: 1; } .LoadingIndicator { From 244280ae057425b7a4db713c47fab4bdeb0001b7 Mon Sep 17 00:00:00 2001 From: Mark <markvapps@gmail.com> Date: Mon, 30 Oct 2017 02:54:02 +1030 Subject: [PATCH 053/172] Fix blurry chrome image rendering for Avatar / Logo - closes #1259 (#1276) * Fix blurry chrome image rendering for Avatar / Logo - closes #1259 * Add comments for Chrome css fix --- framework/core/less/lib/App.less | 2 ++ framework/core/less/lib/Avatar.less | 2 ++ 2 files changed, 4 insertions(+) diff --git a/framework/core/less/lib/App.less b/framework/core/less/lib/App.less index c8af74833..0ee490ba5 100755 --- a/framework/core/less/lib/App.less +++ b/framework/core/less/lib/App.less @@ -171,6 +171,8 @@ .Header-logo { max-height: 30px; vertical-align: middle; + // Prevent blurriness in Chrome + image-rendering: -webkit-optimize-contrast; } // On phones, the header is displayed inside of the drawer. We lay its diff --git a/framework/core/less/lib/Avatar.less b/framework/core/less/lib/Avatar.less index 5fe5054c8..b65e014c8 100755 --- a/framework/core/less/lib/Avatar.less +++ b/framework/core/less/lib/Avatar.less @@ -14,6 +14,8 @@ height: 100%; border-radius: 100%; vertical-align: top; + // Prevent blurriness in Chrome + image-rendering: -webkit-optimize-contrast; } } From 1cc6deabec4362c048cca0373e7312bed9c0a13a Mon Sep 17 00:00:00 2001 From: Daniel Klabbers <daniel@productip.com> Date: Wed, 1 Nov 2017 13:22:16 +0100 Subject: [PATCH 054/172] using blade @json directive to parse raw json into frontend` --- framework/core/views/app.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/views/app.blade.php b/framework/core/views/app.blade.php index 2f98cb715..89e94ad36 100644 --- a/framework/core/views/app.blade.php +++ b/framework/core/views/app.blade.php @@ -49,7 +49,7 @@ if (module.default) module.default(app); } - app.boot({!! json_encode($payload) !!}); + app.boot(@json($payload)); @if (! $debug) } catch (e) { window.location += (window.location.search ? '&' : '?') + 'nojs=1'; From ab42c3bc8bf2ec570eec797068f195d675544852 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers <daniel@productip.com> Date: Wed, 1 Nov 2017 17:01:50 +0100 Subject: [PATCH 055/172] fixed an issue where the mail provider would not be able to instantiate --- framework/core/src/Settings/DatabaseSettingsRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Settings/DatabaseSettingsRepository.php b/framework/core/src/Settings/DatabaseSettingsRepository.php index 943342d6b..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')->pluck('value', 'key'); + return $this->database->table('settings')->pluck('value', 'key')->all(); } public function get($key, $default = null) From 949244ae56878b0ace75c6789973c514b3ba78fd Mon Sep 17 00:00:00 2001 From: Daniel Klabbers <daniel@productip.com> Date: Wed, 1 Nov 2017 17:07:22 +0100 Subject: [PATCH 056/172] fixed symfony translator now using catalogues --- framework/core/src/Frontend/AbstractFrontend.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Frontend/AbstractFrontend.php b/framework/core/src/Frontend/AbstractFrontend.php index af4fc954e..8b112a0e7 100644 --- a/framework/core/src/Frontend/AbstractFrontend.php +++ b/framework/core/src/Frontend/AbstractFrontend.php @@ -158,7 +158,7 @@ abstract class AbstractFrontend */ 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); From 59dc82eb70017a22e9b061807d15581a6b1dc944 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers <daniel@productip.com> Date: Wed, 1 Nov 2017 17:20:12 +0100 Subject: [PATCH 057/172] array_build => array_map --- framework/core/src/User/User.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index e33c58493..cde9e256f 100755 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -484,9 +484,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)); From 0bd569aa7591c73e1d2d4d651c6fdc0d01580a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= <daniel@klabbers.email> Date: Wed, 1 Nov 2017 22:12:56 +0100 Subject: [PATCH 058/172] fixed renamed interface for Scope --- framework/core/src/Post/RegisteredTypesScope.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Post/RegisteredTypesScope.php b/framework/core/src/Post/RegisteredTypesScope.php index e18945259..51c04018a 100644 --- a/framework/core/src/Post/RegisteredTypesScope.php +++ b/framework/core/src/Post/RegisteredTypesScope.php @@ -13,9 +13,9 @@ namespace Flarum\Post; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\ScopeInterface; +use Illuminate\Database\Eloquent\Scope; -class RegisteredTypesScope implements ScopeInterface +class RegisteredTypesScope implements Scope { /** * The index at which we added a where clause. From a18088f38522138e635dd40f645ad2c58d60bf56 Mon Sep 17 00:00:00 2001 From: Lukas <LukBukkit@users.noreply.github.com> Date: Thu, 2 Nov 2017 00:51:31 +0100 Subject: [PATCH 059/172] The CookieFactory now also works if no configuration exists (#1258) * Returning the $default value if there's no config This is especially important for the CookieFactory which accesses the configuration before the application is installed * Injecting the configuration values into the CookieFactory --- framework/core/src/Foundation/Application.php | 2 +- framework/core/src/Http/CookieFactory.php | 52 ++++++++++++++----- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/framework/core/src/Foundation/Application.php b/framework/core/src/Foundation/Application.php index a432bdbb8..b3edee9fe 100644 --- a/framework/core/src/Foundation/Application.php +++ b/framework/core/src/Foundation/Application.php @@ -143,7 +143,7 @@ class Application extends Container implements ApplicationContract */ public function config($key, $default = null) { - return array_get($this->make('flarum.config'), $key, $default); + return $this->isInstalled() ? array_get($this->make('flarum.config'), $key, $default) : $default; } /** diff --git a/framework/core/src/Http/CookieFactory.php b/framework/core/src/Http/CookieFactory.php index aacaff7f5..0ddb3de4c 100644 --- a/framework/core/src/Http/CookieFactory.php +++ b/framework/core/src/Http/CookieFactory.php @@ -17,16 +17,46 @@ use Flarum\Foundation\Application; class CookieFactory { /** - * @var Application + * The prefix for the cookie names. + * + * @var string */ - protected $app; + protected $prefix; + + /** + * A path scope for the cookies. + * + * @var string + */ + protected $path; + + /** + * A domain scope for the cookies. + * + * @var string + */ + protected $domain; + + /** + * Whether the cookie(s) can be requested only over HTTPS. + * + * @var bool + */ + protected $secure; /** * @param Application $app */ public function __construct(Application $app) { - $this->app = $app; + // Parse the forum's base URL so that we can determine the optimal cookie settings + $url = parse_url(rtrim($app->url(), '/')); + + // Get the cookie settings from the config or use the default values + $this->prefix = $app->config('cookie.name', 'flarum'); + $this->path = $app->config('cookie.path', array_get($url, 'path') ?: '/'); + $this->domain = $app->config('cookie.domain'); + $this->secure = $app->config('cookie.secure', array_get($url, 'scheme') === 'https'); } /** @@ -42,9 +72,6 @@ class CookieFactory */ public function make($name, $value = null, $maxAge = null) { - // Parse the forum's base URL so that we can determine the optimal cookie settings - $url = parse_url(rtrim($this->app->url(), '/')); - $cookie = SetCookie::create($this->getName($name), $value); // Make sure we send both the MaxAge and Expires parameters (the former @@ -55,16 +82,13 @@ class CookieFactory ->withExpires(time() + $maxAge); } - if ($domain = $this->app->config('cookie.domain')) { - $cookie = $cookie->withDomain($domain); + if ($this->domain != null) { + $cookie = $cookie->withDomain($this->domain); } - $path = $this->app->config('cookie.path', array_get($url, 'path') ?: '/'); - $secure = $this->app->config('cookie.secure', array_get($url, 'scheme') === 'https'); - return $cookie - ->withPath($path) - ->withSecure($secure) + ->withPath($this->path) + ->withSecure($this->secure) ->withHttpOnly(true); } @@ -87,6 +111,6 @@ class CookieFactory */ public function getName($name) { - return $this->app->config('cookie.name', 'flarum').'_'.$name; + return $this->prefix.'_'.$name; } } From 6614fddbcd93f68bd668f7a5d8d356a775dd4ac3 Mon Sep 17 00:00:00 2001 From: Franz Liedke <franz@develophp.org> Date: Thu, 2 Nov 2017 01:12:49 +0100 Subject: [PATCH 060/172] Remove user bio feature (#1214) The feature is very limited in scope, and we hope for community extensions to take over this feature and make it much better. --- framework/core/js/admin/dist/app.js | 4 - framework/core/js/forum/dist/app.js | 148 +----------------- .../core/js/forum/src/components/UserBio.js | 104 ------------ .../core/js/forum/src/components/UserCard.js | 8 - framework/core/js/lib/models/User.js | 2 - framework/core/less/forum/UserCard.less | 31 ---- .../src/Api/Serializer/UserSerializer.php | 1 - .../core/src/Core/Command/EditUserHandler.php | 8 - framework/core/src/Core/User.php | 17 -- .../core/src/Event/UserBioWasChanged.php | 37 ----- 10 files changed, 2 insertions(+), 358 deletions(-) delete mode 100644 framework/core/js/forum/src/components/UserBio.js delete mode 100644 framework/core/src/Event/UserBioWasChanged.php diff --git a/framework/core/js/admin/dist/app.js b/framework/core/js/admin/dist/app.js index b8f9c3745..4a38b31f5 100644 --- a/framework/core/js/admin/dist/app.js +++ b/framework/core/js/admin/dist/app.js @@ -22451,10 +22451,6 @@ System.register('flarum/models/User', ['flarum/Model', 'flarum/utils/stringToCol password: Model.attribute('password'), avatarUrl: Model.attribute('avatarUrl'), - bio: Model.attribute('bio'), - bioHtml: computed('bio', function (bio) { - return bio ? '<p>' + $('<div/>').text(bio).html().replace(/\n/g, '<br>').autoLink({ rel: 'nofollow' }) + '</p>' : ''; - }), preferences: Model.attribute('preferences'), groups: Model.hasMany('groups'), diff --git a/framework/core/js/forum/dist/app.js b/framework/core/js/forum/dist/app.js index 8a51d8577..efc6992d7 100644 --- a/framework/core/js/forum/dist/app.js +++ b/framework/core/js/forum/dist/app.js @@ -28478,143 +28478,10 @@ System.register('flarum/components/TextEditor', ['flarum/Component', 'flarum/uti });; 'use strict'; -System.register('flarum/components/UserBio', ['flarum/Component', 'flarum/components/LoadingIndicator', 'flarum/utils/classList', 'flarum/utils/extractText'], function (_export, _context) { +System.register('flarum/components/UserCard', ['flarum/Component', 'flarum/utils/humanTime', 'flarum/utils/ItemList', 'flarum/utils/UserControls', 'flarum/helpers/avatar', 'flarum/helpers/username', 'flarum/helpers/icon', 'flarum/components/Dropdown', 'flarum/components/AvatarEditor', 'flarum/helpers/listItems'], function (_export, _context) { "use strict"; - var Component, LoadingIndicator, classList, extractText, UserBio; - return { - setters: [function (_flarumComponent) { - Component = _flarumComponent.default; - }, function (_flarumComponentsLoadingIndicator) { - LoadingIndicator = _flarumComponentsLoadingIndicator.default; - }, function (_flarumUtilsClassList) { - classList = _flarumUtilsClassList.default; - }, function (_flarumUtilsExtractText) { - extractText = _flarumUtilsExtractText.default; - }], - execute: function () { - UserBio = function (_Component) { - babelHelpers.inherits(UserBio, _Component); - - function UserBio() { - babelHelpers.classCallCheck(this, UserBio); - return babelHelpers.possibleConstructorReturn(this, (UserBio.__proto__ || Object.getPrototypeOf(UserBio)).apply(this, arguments)); - } - - babelHelpers.createClass(UserBio, [{ - key: 'init', - value: function init() { - /** - * Whether or not the bio is currently being edited. - * - * @type {Boolean} - */ - this.editing = false; - - /** - * Whether or not the bio is currently being saved. - * - * @type {Boolean} - */ - this.loading = false; - } - }, { - key: 'view', - value: function view() { - var user = this.props.user; - var content = void 0; - - if (this.editing) { - content = m('textarea', { className: 'FormControl', placeholder: extractText(app.translator.trans('core.forum.user.bio_placeholder')), rows: '3', value: user.bio() }); - } else { - var subContent = void 0; - - if (this.loading) { - subContent = m( - 'p', - { className: 'UserBio-placeholder' }, - LoadingIndicator.component({ size: 'tiny' }) - ); - } else { - var bioHtml = user.bioHtml(); - - if (bioHtml) { - subContent = m.trust(bioHtml); - } else if (this.props.editable) { - subContent = m( - 'p', - { className: 'UserBio-placeholder' }, - app.translator.trans('core.forum.user.bio_placeholder') - ); - } - } - - content = m( - 'div', - { className: 'UserBio-content', onclick: this.edit.bind(this) }, - subContent - ); - } - - return m( - 'div', - { className: 'UserBio ' + classList({ - editable: this.props.editable, - editing: this.editing - }) }, - content - ); - } - }, { - key: 'edit', - value: function edit() { - if (!this.props.editable) return; - - this.editing = true; - m.redraw(); - - var bio = this; - var save = function save(e) { - if (e.shiftKey) return; - e.preventDefault(); - bio.save($(this).val()); - }; - - this.$('textarea').focus().bind('blur', save).bind('keydown', 'return', save); - } - }, { - key: 'save', - value: function save(value) { - var _this2 = this; - - var user = this.props.user; - - if (user.bio() !== value) { - this.loading = true; - - user.save({ bio: value }).catch(function () {}).then(function () { - _this2.loading = false; - m.redraw(); - }); - } - - this.editing = false; - m.redraw(); - } - }]); - return UserBio; - }(Component); - - _export('default', UserBio); - } - }; -});; -'use strict'; - -System.register('flarum/components/UserCard', ['flarum/Component', 'flarum/utils/humanTime', 'flarum/utils/ItemList', 'flarum/utils/UserControls', 'flarum/helpers/avatar', 'flarum/helpers/username', 'flarum/helpers/icon', 'flarum/components/Dropdown', 'flarum/components/UserBio', 'flarum/components/AvatarEditor', 'flarum/helpers/listItems'], function (_export, _context) { - "use strict"; - - var Component, humanTime, ItemList, UserControls, avatar, username, icon, Dropdown, UserBio, AvatarEditor, listItems, UserCard; + var Component, humanTime, ItemList, UserControls, avatar, username, icon, Dropdown, AvatarEditor, listItems, UserCard; return { setters: [function (_flarumComponent) { Component = _flarumComponent.default; @@ -28632,8 +28499,6 @@ System.register('flarum/components/UserCard', ['flarum/Component', 'flarum/utils icon = _flarumHelpersIcon.default; }, function (_flarumComponentsDropdown) { Dropdown = _flarumComponentsDropdown.default; - }, function (_flarumComponentsUserBio) { - UserBio = _flarumComponentsUserBio.default; }, function (_flarumComponentsAvatarEditor) { AvatarEditor = _flarumComponentsAvatarEditor.default; }, function (_flarumHelpersListItems) { @@ -28713,11 +28578,6 @@ System.register('flarum/components/UserCard', ['flarum/Component', 'flarum/utils var user = this.props.user; var lastSeenTime = user.lastSeenTime(); - items.add('bio', UserBio.component({ - user: user, - editable: this.props.editable - })); - if (lastSeenTime) { var online = user.isOnline(); @@ -30541,10 +30401,6 @@ System.register('flarum/models/User', ['flarum/Model', 'flarum/utils/stringToCol password: Model.attribute('password'), avatarUrl: Model.attribute('avatarUrl'), - bio: Model.attribute('bio'), - bioHtml: computed('bio', function (bio) { - return bio ? '<p>' + $('<div/>').text(bio).html().replace(/\n/g, '<br>').autoLink({ rel: 'nofollow' }) + '</p>' : ''; - }), preferences: Model.attribute('preferences'), groups: Model.hasMany('groups'), diff --git a/framework/core/js/forum/src/components/UserBio.js b/framework/core/js/forum/src/components/UserBio.js deleted file mode 100644 index 41795a05f..000000000 --- a/framework/core/js/forum/src/components/UserBio.js +++ /dev/null @@ -1,104 +0,0 @@ -import Component from 'flarum/Component'; -import LoadingIndicator from 'flarum/components/LoadingIndicator'; -import classList from 'flarum/utils/classList'; -import extractText from 'flarum/utils/extractText'; - -/** - * The `UserBio` component displays a user's bio, optionally letting the user - * edit it. - */ -export default class UserBio extends Component { - init() { - /** - * Whether or not the bio is currently being edited. - * - * @type {Boolean} - */ - this.editing = false; - - /** - * Whether or not the bio is currently being saved. - * - * @type {Boolean} - */ - this.loading = false; - } - - view() { - const user = this.props.user; - let content; - - if (this.editing) { - content = <textarea className="FormControl" placeholder={extractText(app.translator.trans('core.forum.user.bio_placeholder'))} rows="3" value={user.bio()}/>; - } else { - let subContent; - - if (this.loading) { - subContent = <p className="UserBio-placeholder">{LoadingIndicator.component({size: 'tiny'})}</p>; - } else { - const bioHtml = user.bioHtml(); - - if (bioHtml) { - subContent = m.trust(bioHtml); - } else if (this.props.editable) { - subContent = <p className="UserBio-placeholder">{app.translator.trans('core.forum.user.bio_placeholder')}</p>; - } - } - - content = <div className="UserBio-content" onclick={this.edit.bind(this)}>{subContent}</div>; - } - - return ( - <div className={'UserBio ' + classList({ - editable: this.props.editable, - editing: this.editing - })}> - {content} - </div> - ); - } - - /** - * Edit the bio. - */ - edit() { - if (!this.props.editable) return; - - this.editing = true; - m.redraw(); - - const bio = this; - const save = function(e) { - if (e.shiftKey) return; - e.preventDefault(); - bio.save($(this).val()); - }; - - this.$('textarea').focus() - .bind('blur', save) - .bind('keydown', 'return', save); - } - - /** - * Save the bio. - * - * @param {String} value - */ - save(value) { - const user = this.props.user; - - if (user.bio() !== value) { - this.loading = true; - - user.save({bio: value}) - .catch(() => {}) - .then(() => { - this.loading = false; - m.redraw(); - }); - } - - this.editing = false; - m.redraw(); - } -} diff --git a/framework/core/js/forum/src/components/UserCard.js b/framework/core/js/forum/src/components/UserCard.js index 6b9fec29c..94c116a44 100644 --- a/framework/core/js/forum/src/components/UserCard.js +++ b/framework/core/js/forum/src/components/UserCard.js @@ -6,7 +6,6 @@ import avatar from 'flarum/helpers/avatar'; import username from 'flarum/helpers/username'; import icon from 'flarum/helpers/icon'; import Dropdown from 'flarum/components/Dropdown'; -import UserBio from 'flarum/components/UserBio'; import AvatarEditor from 'flarum/components/AvatarEditor'; import listItems from 'flarum/helpers/listItems'; @@ -82,13 +81,6 @@ export default class UserCard extends Component { const user = this.props.user; const lastSeenTime = user.lastSeenTime(); - items.add('bio', - UserBio.component({ - user, - editable: this.props.editable - }) - ); - if (lastSeenTime) { const online = user.isOnline(); diff --git a/framework/core/js/lib/models/User.js b/framework/core/js/lib/models/User.js index 07d5aaf1b..e81e1ebcb 100644 --- a/framework/core/js/lib/models/User.js +++ b/framework/core/js/lib/models/User.js @@ -16,8 +16,6 @@ Object.assign(User.prototype, { password: Model.attribute('password'), avatarUrl: Model.attribute('avatarUrl'), - bio: Model.attribute('bio'), - bioHtml: computed('bio', bio => bio ? '<p>' + $('<div/>').text(bio).html().replace(/\n/g, '<br>').autoLink({rel: 'nofollow'}) + '</p>' : ''), preferences: Model.attribute('preferences'), groups: Model.hasMany('groups'), diff --git a/framework/core/less/forum/UserCard.less b/framework/core/less/forum/UserCard.less index 731ea28c2..8c9caa50b 100644 --- a/framework/core/less/forum/UserCard.less +++ b/framework/core/less/forum/UserCard.less @@ -90,37 +90,6 @@ display: inline-block; margin-right: 15px; } - .item-bio { - display: block; - margin: 0; - } -} -.UserBio { - margin: -10px -10px 10px; - border: 1px dashed transparent; - border-radius: @border-radius; - - &.editable:not(.editing) { - cursor: text; - - &:hover { - border-color: rgba(255, 255, 255, 0.2); - } - } - &, textarea { - font-size: 14px; - } - textarea { - padding: 10px; - font-size: 14px; - resize: none; - } -} -.UserBio-content { - padding: 10px 10px 1px; -} -.UserBio-placeholder { - opacity: 0.3; } .UserCard-lastSeen { & .icon { diff --git a/framework/core/src/Api/Serializer/UserSerializer.php b/framework/core/src/Api/Serializer/UserSerializer.php index 5db640678..0a289284c 100644 --- a/framework/core/src/Api/Serializer/UserSerializer.php +++ b/framework/core/src/Api/Serializer/UserSerializer.php @@ -40,7 +40,6 @@ class UserSerializer extends UserBasicSerializer $canEdit = $gate->allows('edit', $user); $attributes += [ - 'bio' => $user->bio, 'joinTime' => $this->formatDate($user->join_time), 'discussionsCount' => (int) $user->discussions_count, 'commentsCount' => (int) $user->comments_count, diff --git a/framework/core/src/Core/Command/EditUserHandler.php b/framework/core/src/Core/Command/EditUserHandler.php index 0b366dcec..7b336ae93 100644 --- a/framework/core/src/Core/Command/EditUserHandler.php +++ b/framework/core/src/Core/Command/EditUserHandler.php @@ -114,14 +114,6 @@ class EditUserHandler $validate['password'] = $attributes['password']; } - if (isset($attributes['bio'])) { - if (! $isSelf) { - $this->assertPermission($canEdit); - } - - $user->changeBio($attributes['bio']); - } - if (! empty($attributes['readTime'])) { $this->assertPermission($isSelf); $user->markAllAsRead(); diff --git a/framework/core/src/Core/User.php b/framework/core/src/Core/User.php index e8325b0e5..13f57e728 100755 --- a/framework/core/src/Core/User.php +++ b/framework/core/src/Core/User.php @@ -22,7 +22,6 @@ use Flarum\Event\GetDisplayName; use Flarum\Event\PostWasDeleted; use Flarum\Event\PrepareUserGroups; use Flarum\Event\UserAvatarWasChanged; -use Flarum\Event\UserBioWasChanged; use Flarum\Event\UserEmailChangeWasRequested; use Flarum\Event\UserEmailWasChanged; use Flarum\Event\UserPasswordWasChanged; @@ -42,7 +41,6 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface; * @property bool $is_activated * @property string $password * @property string $locale - * @property string $bio * @property string|null $avatar_path * @property string $avatar_url * @property array $preferences @@ -263,21 +261,6 @@ class User extends AbstractModel $this->attributes['password'] = $value ? static::$hasher->make($value) : ''; } - /** - * Change the user's bio. - * - * @param string $bio - * @return $this - */ - public function changeBio($bio) - { - $this->bio = $bio; - - $this->raise(new UserBioWasChanged($this)); - - return $this; - } - /** * Mark all discussions as read. * diff --git a/framework/core/src/Event/UserBioWasChanged.php b/framework/core/src/Event/UserBioWasChanged.php deleted file mode 100644 index dfde182b0..000000000 --- a/framework/core/src/Event/UserBioWasChanged.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\Event; - -use Flarum\Core\User; - -class UserBioWasChanged -{ - /** - * @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; - } -} From ccfa3482f1368795cadf150a03e676c3d8ccaba9 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers <daniel@productip.com> Date: Thu, 2 Nov 2017 10:48:33 +0100 Subject: [PATCH 061/172] fixed the Bus command Handling forwarding the call to a matching Handler class --- framework/core/src/Bus/BusServiceProvider.php | 28 +++++++++++++++++++ framework/core/src/Bus/Dispatcher.php | 19 +++++++++++++ framework/core/src/Foundation/Site.php | 3 ++ .../core/src/Locale/LocaleServiceProvider.php | 8 ++++-- 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 framework/core/src/Bus/BusServiceProvider.php create mode 100644 framework/core/src/Bus/Dispatcher.php diff --git a/framework/core/src/Bus/BusServiceProvider.php b/framework/core/src/Bus/BusServiceProvider.php new file mode 100644 index 000000000..d6d152839 --- /dev/null +++ b/framework/core/src/Bus/BusServiceProvider.php @@ -0,0 +1,28 @@ +<?php + +/* + * This file is part of Flarum. + * + * (c) Toby Zerner <toby.zerner@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Bus; + +use Flarum\Foundation\AbstractServiceProvider; +use Illuminate\Contracts\Bus\Dispatcher as BusContract; +use Illuminate\Contracts\Queue\Factory as QueueFactoryContract; + +class BusServiceProvider extends AbstractServiceProvider +{ + public function boot() + { + $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..13a3839ed --- /dev/null +++ b/framework/core/src/Bus/Dispatcher.php @@ -0,0 +1,19 @@ +<?php + +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/Foundation/Site.php b/framework/core/src/Foundation/Site.php index cd1484dab..904e403de 100644 --- a/framework/core/src/Foundation/Site.php +++ b/framework/core/src/Foundation/Site.php @@ -13,6 +13,7 @@ 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; @@ -166,6 +167,8 @@ class Site $app->register(ViewServiceProvider::class); $app->register(ValidationServiceProvider::class); + $app->register(BusProvider::class); + if ($app->isInstalled() && $app->isUpToDate()) { $settings = $app->make(SettingsRepositoryInterface::class); diff --git a/framework/core/src/Locale/LocaleServiceProvider.php b/framework/core/src/Locale/LocaleServiceProvider.php index 4ddcc46f5..05484575b 100644 --- a/framework/core/src/Locale/LocaleServiceProvider.php +++ b/framework/core/src/Locale/LocaleServiceProvider.php @@ -14,9 +14,11 @@ namespace Flarum\Locale; use Flarum\Event\ConfigureLocales; use Flarum\Foundation\AbstractServiceProvider; use Illuminate\Contracts\Events\Dispatcher; -use Symfony\Component\Translation\MessageSelector; -use Symfony\Component\Translation\Translator; -use Symfony\Component\Translation\TranslatorInterface; +use Illuminate\Translation\Translator; +use Illuminate\Translation\FileLoader; +//use Symfony\Component\Translation\MessageSelector; +//use Symfony\Component\Translation\Translator; +//use Symfony\Component\Translation\TranslatorInterface; class LocaleServiceProvider extends AbstractServiceProvider { From 1d0df71c191f2c6984c25de3e284b4b483255824 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers <daniel@productip.com> Date: Thu, 2 Nov 2017 10:52:52 +0100 Subject: [PATCH 062/172] moved from boot to register --- framework/core/src/Bus/BusServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Bus/BusServiceProvider.php b/framework/core/src/Bus/BusServiceProvider.php index d6d152839..c07b9b812 100644 --- a/framework/core/src/Bus/BusServiceProvider.php +++ b/framework/core/src/Bus/BusServiceProvider.php @@ -17,7 +17,7 @@ use Illuminate\Contracts\Queue\Factory as QueueFactoryContract; class BusServiceProvider extends AbstractServiceProvider { - public function boot() + public function register() { $this->app->bind(BusContract::class, function ($app) { return new Dispatcher($app, function ($connection = null) use ($app) { From 5343d6eff9ab0cd1b8af7e11990f45e124c0698e Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Sun, 5 Nov 2017 16:12:26 +1030 Subject: [PATCH 063/172] Fix admin navigation not rendering Not sure why this started happening now, but the admin navigation dropdown wasn't receiving its children properly. This commit fixes a flaw in our Mithril patch and allows an array of children to be passed in the normal JSX way, rather than as an attribute. --- framework/core/js/admin/src/components/AdminNav.js | 6 +++--- framework/core/js/lib/utils/patchMithril.js | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/framework/core/js/admin/src/components/AdminNav.js b/framework/core/js/admin/src/components/AdminNav.js index 64c6d547c..5384e2bc7 100644 --- a/framework/core/js/admin/src/components/AdminNav.js +++ b/framework/core/js/admin/src/components/AdminNav.js @@ -18,9 +18,9 @@ export default class AdminNav extends Component { return ( <SelectDropdown className="AdminNav App-titleControl" - buttonClassName="Button" - children={this.items().toArray()} - /> + buttonClassName="Button"> + {this.items().toArray()} + </SelectDropdown> ); } diff --git a/framework/core/js/lib/utils/patchMithril.js b/framework/core/js/lib/utils/patchMithril.js index 8935b2e79..3b88e1035 100644 --- a/framework/core/js/lib/utils/patchMithril.js +++ b/framework/core/js/lib/utils/patchMithril.js @@ -5,7 +5,12 @@ export default function patchMithril(global) { const m = function(comp, ...args) { if (comp.prototype && comp.prototype instanceof Component) { - return comp.component(args[0], args.slice(1)); + let children = args.slice(1); + if (children.length === 1 && Array.isArray(children[0])) { + children = children[0] + } + + return comp.component(args[0], children); } const node = mo.apply(this, arguments); From a6553954e2e55ff378ff3610d6dac5c03e927a81 Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Sun, 5 Nov 2017 16:17:15 +1030 Subject: [PATCH 064/172] Revert color to text input type #1074 changed the input type for these fields to "color", but it turns out the browser support for this input type sucks (they give you a very limited color picker, and make it hard to input hex codes). --- framework/core/js/admin/dist/app.js | 29 +++++++++++++------ .../js/admin/src/components/AppearancePage.js | 4 +-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/framework/core/js/admin/dist/app.js b/framework/core/js/admin/dist/app.js index 4a38b31f5..bacc3fc03 100644 --- a/framework/core/js/admin/dist/app.js +++ b/framework/core/js/admin/dist/app.js @@ -17536,11 +17536,13 @@ System.register('flarum/components/AdminNav', ['flarum/Component', 'flarum/compo babelHelpers.createClass(AdminNav, [{ key: 'view', value: function view() { - return m(SelectDropdown, { - className: 'AdminNav App-titleControl', - buttonClassName: 'Button', - children: this.items().toArray() - }); + return m( + SelectDropdown, + { + className: 'AdminNav App-titleControl', + buttonClassName: 'Button' }, + this.items().toArray() + ); } }, { key: 'items', @@ -17832,8 +17834,8 @@ System.register('flarum/components/AppearancePage', ['flarum/components/Page', ' m( 'div', { className: 'AppearancePage-colors-input' }, - m('input', { className: 'FormControl', type: 'color', placeholder: '#aaaaaa', value: this.primaryColor(), onchange: m.withAttr('value', this.primaryColor) }), - m('input', { className: 'FormControl', type: 'color', placeholder: '#aaaaaa', value: this.secondaryColor(), onchange: m.withAttr('value', this.secondaryColor) }) + m('input', { className: 'FormControl', type: 'text', placeholder: '#aaaaaa', value: this.primaryColor(), onchange: m.withAttr('value', this.primaryColor) }), + m('input', { className: 'FormControl', type: 'text', placeholder: '#aaaaaa', value: this.secondaryColor(), onchange: m.withAttr('value', this.secondaryColor) }) ), Switch.component({ state: this.darkMode(), @@ -18509,6 +18511,10 @@ System.register('flarum/components/Dropdown', ['flarum/Component', 'flarum/helpe $menu.toggleClass('Dropdown-menu--top', $menu.offset().top + $menu.height() > $(window).scrollTop() + $(window).height()); + if ($menu.offset().top < 0) { + $menu.removeClass('Dropdown-menu--top'); + } + $menu.toggleClass('Dropdown-menu--right', isRight || $menu.offset().left + $menu.width() > $(window).scrollLeft() + $(window).width()); }); @@ -23313,7 +23319,7 @@ System.register('flarum/utils/extractText', [], function (_export, _context) { return vdom.map(function (element) { return extractText(element); }).join(''); - } else if ((typeof vdom === 'undefined' ? 'undefined' : babelHelpers.typeof(vdom)) === 'object') { + } else if ((typeof vdom === 'undefined' ? 'undefined' : babelHelpers.typeof(vdom)) === 'object' && vdom !== null) { return extractText(vdom.children); } else { return vdom; @@ -23599,7 +23605,12 @@ System.register('flarum/utils/patchMithril', ['../Component'], function (_export } if (comp.prototype && comp.prototype instanceof Component) { - return comp.component.apply(comp, args); + var children = args.slice(1); + if (children.length === 1 && Array.isArray(children[0])) { + children = children[0]; + } + + return comp.component(args[0], children); } var node = mo.apply(this, arguments); diff --git a/framework/core/js/admin/src/components/AppearancePage.js b/framework/core/js/admin/src/components/AppearancePage.js index 8e35a958a..c59a039af 100644 --- a/framework/core/js/admin/src/components/AppearancePage.js +++ b/framework/core/js/admin/src/components/AppearancePage.js @@ -28,8 +28,8 @@ export default class AppearancePage extends Page { </div> <div className="AppearancePage-colors-input"> - <input className="FormControl" type="color" placeholder="#aaaaaa" value={this.primaryColor()} onchange={m.withAttr('value', this.primaryColor)}/> - <input className="FormControl" type="color" placeholder="#aaaaaa" value={this.secondaryColor()} onchange={m.withAttr('value', this.secondaryColor)}/> + <input className="FormControl" type="text" placeholder="#aaaaaa" value={this.primaryColor()} onchange={m.withAttr('value', this.primaryColor)}/> + <input className="FormControl" type="text" placeholder="#aaaaaa" value={this.secondaryColor()} onchange={m.withAttr('value', this.secondaryColor)}/> </div> {Switch.component({ From 9682cd5f2620da0c3e475a58482407e28bd1302c Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Sun, 5 Nov 2017 16:17:50 +1030 Subject: [PATCH 065/172] Make sure dropdowns don't go above the edge of the screen --- framework/core/js/lib/components/Dropdown.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/framework/core/js/lib/components/Dropdown.js b/framework/core/js/lib/components/Dropdown.js index 8093ba506..d3fa8ae3f 100644 --- a/framework/core/js/lib/components/Dropdown.js +++ b/framework/core/js/lib/components/Dropdown.js @@ -69,6 +69,10 @@ export default class Dropdown extends Component { $menu.offset().top + $menu.height() > $(window).scrollTop() + $(window).height() ); + if ($menu.offset().top < 0) { + $menu.removeClass('Dropdown-menu--top'); + } + $menu.toggleClass( 'Dropdown-menu--right', isRight || $menu.offset().left + $menu.width() > $(window).scrollLeft() + $(window).width() From 16e55f724dd2c13342e0903689e8db300ea4fc59 Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Sun, 5 Nov 2017 16:21:18 +1030 Subject: [PATCH 066/172] Attempt fix for #1268 I believe the constant overlay of a loading div may be what's causing the iOS cursor issues. This commit removes the fade animation so that we can simply set display to none, which will hopefully fix the issue. --- framework/core/less/forum/Composer.less | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/framework/core/less/forum/Composer.less b/framework/core/less/forum/Composer.less index 4bb7668ce..9707b9327 100644 --- a/framework/core/less/forum/Composer.less +++ b/framework/core/less/forum/Composer.less @@ -88,14 +88,11 @@ right: 0; bottom: 0; background: fade(@body-bg, 90%); - opacity: 0; - pointer-events: none; + display: none; border-radius: @border-radius @border-radius 0 0; - .transition(opacity 0.2s); &.active { - opacity: 1; - pointer-events: auto; + display: block; } } .ComposerBody-editor { From 141d6dfbbc72b470680c069e0e3af7eba2a9e536 Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Sun, 5 Nov 2017 16:25:21 +1030 Subject: [PATCH 067/172] Improve mobile composer behaviour - Don't scroll to the bottom of the discussion when selecting "Reply" from the menu if the composer is in full screen mode (ie. on mobile). ref #1271 - After posting a reply, scroll to the end of the discussion - Reduce the textarea height - previously it was 100vh, but this doesn't account for the height of the iOS keyboard, so I've just arbitrarily chosen 300px instead. There may be a better solution for this. ref #1269 --- framework/core/js/forum/dist/app.js | 26 ++++++++++++++----- .../js/forum/src/components/PostStream.js | 2 +- .../js/forum/src/components/ReplyComposer.js | 5 ++-- .../js/forum/src/utils/DiscussionControls.js | 2 +- framework/core/less/forum/Composer.less | 2 +- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/framework/core/js/forum/dist/app.js b/framework/core/js/forum/dist/app.js index efc6992d7..dfc862936 100644 --- a/framework/core/js/forum/dist/app.js +++ b/framework/core/js/forum/dist/app.js @@ -22359,6 +22359,10 @@ System.register('flarum/components/Dropdown', ['flarum/Component', 'flarum/helpe $menu.toggleClass('Dropdown-menu--top', $menu.offset().top + $menu.height() > $(window).scrollTop() + $(window).height()); + if ($menu.offset().top < 0) { + $menu.removeClass('Dropdown-menu--top'); + } + $menu.toggleClass('Dropdown-menu--right', isRight || $menu.offset().left + $menu.width() > $(window).scrollLeft() + $(window).width()); }); @@ -25654,7 +25658,7 @@ System.register('flarum/components/PostStream', ['flarum/Component', 'flarum/uti this.visibleEnd = this.count(); - this.loadRange(this.visibleStart, this.visibleEnd).then(function () { + return this.loadRange(this.visibleStart, this.visibleEnd).then(function () { return m.redraw(); }); } @@ -27033,9 +27037,11 @@ System.register('flarum/components/ReplyComposer', ['flarum/components/ComposerB app.store.createRecord('posts').save(data).then(function (post) { // If we're currently viewing the discussion which this reply was made - // in, then we can update the post stream. + // in, then we can update the post stream and scroll to the post. if (app.viewingDiscussion(discussion)) { - app.current.stream.update(); + app.current.stream.update().then(function () { + return app.current.stream.goToNumber(post.number()); + }); } else { // Otherwise, we'll create an alert message to inform the user that // their reply has been posted, containing a button which will @@ -28413,7 +28419,8 @@ System.register('flarum/components/TextEditor', ['flarum/Component', 'flarum/uti items.add('preview', Button.component({ icon: 'eye', className: 'Button Button--icon', - onclick: this.props.preview + onclick: this.props.preview, + title: app.translator.trans('core.forum.composer.preview_tooltip') })); } @@ -31279,7 +31286,7 @@ System.register('flarum/utils/DiscussionControls', ['flarum/components/Discussio } app.composer.show(); - if (goToLast && app.viewingDiscussion(this)) { + if (goToLast && app.viewingDiscussion(this) && !app.composer.isFullScreen()) { app.current.stream.goToNumber('reply'); } @@ -31489,7 +31496,7 @@ System.register('flarum/utils/extractText', [], function (_export, _context) { return vdom.map(function (element) { return extractText(element); }).join(''); - } else if ((typeof vdom === 'undefined' ? 'undefined' : babelHelpers.typeof(vdom)) === 'object') { + } else if ((typeof vdom === 'undefined' ? 'undefined' : babelHelpers.typeof(vdom)) === 'object' && vdom !== null) { return extractText(vdom.children); } else { return vdom; @@ -32107,7 +32114,12 @@ System.register('flarum/utils/patchMithril', ['../Component'], function (_export } if (comp.prototype && comp.prototype instanceof Component) { - return comp.component.apply(comp, args); + var children = args.slice(1); + if (children.length === 1 && Array.isArray(children[0])) { + children = children[0]; + } + + return comp.component(args[0], children); } var node = mo.apply(this, arguments); diff --git a/framework/core/js/forum/src/components/PostStream.js b/framework/core/js/forum/src/components/PostStream.js index 5fc1cff41..3b27884c4 100644 --- a/framework/core/js/forum/src/components/PostStream.js +++ b/framework/core/js/forum/src/components/PostStream.js @@ -126,7 +126,7 @@ class PostStream extends Component { this.visibleEnd = this.count(); - this.loadRange(this.visibleStart, this.visibleEnd).then(() => m.redraw()); + return this.loadRange(this.visibleStart, this.visibleEnd).then(() => m.redraw()); } /** diff --git a/framework/core/js/forum/src/components/ReplyComposer.js b/framework/core/js/forum/src/components/ReplyComposer.js index 7048ae7ba..e1601315b 100644 --- a/framework/core/js/forum/src/components/ReplyComposer.js +++ b/framework/core/js/forum/src/components/ReplyComposer.js @@ -82,9 +82,10 @@ export default class ReplyComposer extends ComposerBody { app.store.createRecord('posts').save(data).then( post => { // If we're currently viewing the discussion which this reply was made - // in, then we can update the post stream. + // in, then we can update the post stream and scroll to the post. if (app.viewingDiscussion(discussion)) { - app.current.stream.update(); + app.current.stream.update().then(() => app.current.stream.goToNumber(post.number())); + } else { // Otherwise, we'll create an alert message to inform the user that // their reply has been posted, containing a button which will diff --git a/framework/core/js/forum/src/utils/DiscussionControls.js b/framework/core/js/forum/src/utils/DiscussionControls.js index 02355d43f..8d897eee6 100644 --- a/framework/core/js/forum/src/utils/DiscussionControls.js +++ b/framework/core/js/forum/src/utils/DiscussionControls.js @@ -162,7 +162,7 @@ export default { } app.composer.show(); - if (goToLast && app.viewingDiscussion(this)) { + if (goToLast && app.viewingDiscussion(this) && ! app.composer.isFullScreen()) { app.current.stream.goToNumber('reply'); } diff --git a/framework/core/less/forum/Composer.less b/framework/core/less/forum/Composer.less index 9707b9327..da922dd33 100644 --- a/framework/core/less/forum/Composer.less +++ b/framework/core/less/forum/Composer.less @@ -116,7 +116,7 @@ &:not(.minimized) { position: absolute; top: 0; - height: 100vh !important; + height: 300px !important; padding-top: @header-height-phone; &:before { From 1cc6c06946eca4f7051114b8d23340e553594afd Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Sun, 5 Nov 2017 16:25:34 +1030 Subject: [PATCH 068/172] Add a tooltip to the Preview button --- framework/core/js/forum/src/components/TextEditor.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/framework/core/js/forum/src/components/TextEditor.js b/framework/core/js/forum/src/components/TextEditor.js index 3bc299c2d..1b8d2cd4d 100644 --- a/framework/core/js/forum/src/components/TextEditor.js +++ b/framework/core/js/forum/src/components/TextEditor.js @@ -82,7 +82,8 @@ export default class TextEditor extends Component { Button.component({ icon: 'eye', className: 'Button Button--icon', - onclick: this.props.preview + onclick: this.props.preview, + title: app.translator.trans('core.forum.composer.preview_tooltip') }) ); } From a8cce49b853c16b0e6fef717d880d092a6875f5c Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Sun, 5 Nov 2017 16:27:28 +1030 Subject: [PATCH 069/172] Update asset revision whenever custom LESS is changed This should remove the need for a hard browser refresh whenever you update the custom LESS. --- framework/core/src/Asset/RevisionCompiler.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/framework/core/src/Asset/RevisionCompiler.php b/framework/core/src/Asset/RevisionCompiler.php index 3993b90a7..9911c5b11 100644 --- a/framework/core/src/Asset/RevisionCompiler.php +++ b/framework/core/src/Asset/RevisionCompiler.php @@ -81,6 +81,10 @@ class RevisionCompiler implements CompilerInterface $cacheDifferentiator[] = [$source, filemtime($source)]; } + foreach ($this->strings as $callback) { + $cacheDifferentiator[] = $callback(); + } + $current = hash('crc32b', serialize($cacheDifferentiator)); } From f638fb9300fea84e5c542b28713cf6d84eaaef42 Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Sun, 5 Nov 2017 17:32:43 +1030 Subject: [PATCH 070/172] Remove FastClick. Fixes #1268 Turns out FastClick was causing textareas to be buggy on iOS Safari, and it wasn't really doing any good. --- framework/core/js/bower.json | 1 - framework/core/js/forum/Gulpfile.js | 1 - framework/core/js/forum/src/initializers/boot.js | 4 ---- 3 files changed, 6 deletions(-) diff --git a/framework/core/js/bower.json b/framework/core/js/bower.json index d6532da73..d4d647f54 100644 --- a/framework/core/js/bower.json +++ b/framework/core/js/bower.json @@ -9,7 +9,6 @@ "color-thief": "v2.0", "mithril": "lhorie/mithril.js#v0.2.5", "es6-micro-loader": "caridy/es6-micro-loader#v0.2.1", - "fastclick": "~1.0.6", "autolink": "~1.0.0", "m.attrs.bidi": "tobscure/m.attrs.bidi", "punycode": "http://cdnjs.cloudflare.com/ajax/libs/punycode/1.4.1/punycode.js" diff --git a/framework/core/js/forum/Gulpfile.js b/framework/core/js/forum/Gulpfile.js index 338eabc31..491fcde63 100644 --- a/framework/core/js/forum/Gulpfile.js +++ b/framework/core/js/forum/Gulpfile.js @@ -23,7 +23,6 @@ gulp({ bowerDir + '/spin.js/spin.js', bowerDir + '/spin.js/jquery.spin.js', - bowerDir + '/fastclick/lib/fastclick.js', bowerDir + '/punycode/index.js' ], modules: { diff --git a/framework/core/js/forum/src/initializers/boot.js b/framework/core/js/forum/src/initializers/boot.js index f2b919024..1cf42350d 100644 --- a/framework/core/js/forum/src/initializers/boot.js +++ b/framework/core/js/forum/src/initializers/boot.js @@ -78,11 +78,7 @@ export default function boot(app) { .toggleClass('scrolled', top > offset); }).start(); - // Initialize FastClick, which makes links and buttons much more responsive on - // touch devices. $(() => { - FastClick.attach(document.body); - $('body').addClass('ontouchstart' in window ? 'touch' : 'no-touch'); }); From 659be3811da1115bc559f3504086c3f0e87e51d7 Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Sun, 5 Nov 2017 17:35:13 +1030 Subject: [PATCH 071/172] Give the mobile composer a bit more height --- framework/core/less/forum/Composer.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/less/forum/Composer.less b/framework/core/less/forum/Composer.less index da922dd33..ebddc5538 100644 --- a/framework/core/less/forum/Composer.less +++ b/framework/core/less/forum/Composer.less @@ -116,7 +116,7 @@ &:not(.minimized) { position: absolute; top: 0; - height: 300px !important; + height: 350px !important; padding-top: @header-height-phone; &:before { From e0079f2e604a806a874f338a29cb7a00a6743a4c Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Sun, 5 Nov 2017 17:38:30 +1030 Subject: [PATCH 072/172] Recompile JS --- framework/core/js/forum/dist/app.js | 899 +--------------------------- 1 file changed, 26 insertions(+), 873 deletions(-) diff --git a/framework/core/js/forum/dist/app.js b/framework/core/js/forum/dist/app.js index dfc862936..c0f196994 100644 --- a/framework/core/js/forum/dist/app.js +++ b/framework/core/js/forum/dist/app.js @@ -17672,848 +17672,6 @@ $('#el').spin('flower', 'red'); })); ; -;(function () { - 'use strict'; - - /** - * @preserve FastClick: polyfill to remove click delays on browsers with touch UIs. - * - * @codingstandard ftlabs-jsv2 - * @copyright The Financial Times Limited [All Rights Reserved] - * @license MIT License (see LICENSE.txt) - */ - - /*jslint browser:true, node:true*/ - /*global define, Event, Node*/ - - - /** - * Instantiate fast-clicking listeners on the specified layer. - * - * @constructor - * @param {Element} layer The layer to listen on - * @param {Object} [options={}] The options to override the defaults - */ - function FastClick(layer, options) { - var oldOnClick; - - options = options || {}; - - /** - * Whether a click is currently being tracked. - * - * @type boolean - */ - this.trackingClick = false; - - - /** - * Timestamp for when click tracking started. - * - * @type number - */ - this.trackingClickStart = 0; - - - /** - * The element being tracked for a click. - * - * @type EventTarget - */ - this.targetElement = null; - - - /** - * X-coordinate of touch start event. - * - * @type number - */ - this.touchStartX = 0; - - - /** - * Y-coordinate of touch start event. - * - * @type number - */ - this.touchStartY = 0; - - - /** - * ID of the last touch, retrieved from Touch.identifier. - * - * @type number - */ - this.lastTouchIdentifier = 0; - - - /** - * Touchmove boundary, beyond which a click will be cancelled. - * - * @type number - */ - this.touchBoundary = options.touchBoundary || 10; - - - /** - * The FastClick layer. - * - * @type Element - */ - this.layer = layer; - - /** - * The minimum time between tap(touchstart and touchend) events - * - * @type number - */ - this.tapDelay = options.tapDelay || 200; - - /** - * The maximum time for a tap - * - * @type number - */ - this.tapTimeout = options.tapTimeout || 700; - - if (FastClick.notNeeded(layer)) { - return; - } - - // Some old versions of Android don't have Function.prototype.bind - function bind(method, context) { - return function() { return method.apply(context, arguments); }; - } - - - var methods = ['onMouse', 'onClick', 'onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel']; - var context = this; - for (var i = 0, l = methods.length; i < l; i++) { - context[methods[i]] = bind(context[methods[i]], context); - } - - // Set up event handlers as required - if (deviceIsAndroid) { - layer.addEventListener('mouseover', this.onMouse, true); - layer.addEventListener('mousedown', this.onMouse, true); - layer.addEventListener('mouseup', this.onMouse, true); - } - - layer.addEventListener('click', this.onClick, true); - layer.addEventListener('touchstart', this.onTouchStart, false); - layer.addEventListener('touchmove', this.onTouchMove, false); - layer.addEventListener('touchend', this.onTouchEnd, false); - layer.addEventListener('touchcancel', this.onTouchCancel, false); - - // Hack is required for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2) - // which is how FastClick normally stops click events bubbling to callbacks registered on the FastClick - // layer when they are cancelled. - if (!Event.prototype.stopImmediatePropagation) { - layer.removeEventListener = function(type, callback, capture) { - var rmv = Node.prototype.removeEventListener; - if (type === 'click') { - rmv.call(layer, type, callback.hijacked || callback, capture); - } else { - rmv.call(layer, type, callback, capture); - } - }; - - layer.addEventListener = function(type, callback, capture) { - var adv = Node.prototype.addEventListener; - if (type === 'click') { - adv.call(layer, type, callback.hijacked || (callback.hijacked = function(event) { - if (!event.propagationStopped) { - callback(event); - } - }), capture); - } else { - adv.call(layer, type, callback, capture); - } - }; - } - - // If a handler is already declared in the element's onclick attribute, it will be fired before - // FastClick's onClick handler. Fix this by pulling out the user-defined handler function and - // adding it as listener. - if (typeof layer.onclick === 'function') { - - // Android browser on at least 3.2 requires a new reference to the function in layer.onclick - // - the old one won't work if passed to addEventListener directly. - oldOnClick = layer.onclick; - layer.addEventListener('click', function(event) { - oldOnClick(event); - }, false); - layer.onclick = null; - } - } - - /** - * Windows Phone 8.1 fakes user agent string to look like Android and iPhone. - * - * @type boolean - */ - var deviceIsWindowsPhone = navigator.userAgent.indexOf("Windows Phone") >= 0; - - /** - * Android requires exceptions. - * - * @type boolean - */ - var deviceIsAndroid = navigator.userAgent.indexOf('Android') > 0 && !deviceIsWindowsPhone; - - - /** - * iOS requires exceptions. - * - * @type boolean - */ - var deviceIsIOS = /iP(ad|hone|od)/.test(navigator.userAgent) && !deviceIsWindowsPhone; - - - /** - * iOS 4 requires an exception for select elements. - * - * @type boolean - */ - var deviceIsIOS4 = deviceIsIOS && (/OS 4_\d(_\d)?/).test(navigator.userAgent); - - - /** - * iOS 6.0-7.* requires the target element to be manually derived - * - * @type boolean - */ - var deviceIsIOSWithBadTarget = deviceIsIOS && (/OS [6-7]_\d/).test(navigator.userAgent); - - /** - * BlackBerry requires exceptions. - * - * @type boolean - */ - var deviceIsBlackBerry10 = navigator.userAgent.indexOf('BB10') > 0; - - /** - * Determine whether a given element requires a native click. - * - * @param {EventTarget|Element} target Target DOM element - * @returns {boolean} Returns true if the element needs a native click - */ - FastClick.prototype.needsClick = function(target) { - switch (target.nodeName.toLowerCase()) { - - // Don't send a synthetic click to disabled inputs (issue #62) - case 'button': - case 'select': - case 'textarea': - if (target.disabled) { - return true; - } - - break; - case 'input': - - // File inputs need real clicks on iOS 6 due to a browser bug (issue #68) - if ((deviceIsIOS && target.type === 'file') || target.disabled) { - return true; - } - - break; - case 'label': - case 'iframe': // iOS8 homescreen apps can prevent events bubbling into frames - case 'video': - return true; - } - - return (/\bneedsclick\b/).test(target.className); - }; - - - /** - * Determine whether a given element requires a call to focus to simulate click into element. - * - * @param {EventTarget|Element} target Target DOM element - * @returns {boolean} Returns true if the element requires a call to focus to simulate native click. - */ - FastClick.prototype.needsFocus = function(target) { - switch (target.nodeName.toLowerCase()) { - case 'textarea': - return true; - case 'select': - return !deviceIsAndroid; - case 'input': - switch (target.type) { - case 'button': - case 'checkbox': - case 'file': - case 'image': - case 'radio': - case 'submit': - return false; - } - - // No point in attempting to focus disabled inputs - return !target.disabled && !target.readOnly; - default: - return (/\bneedsfocus\b/).test(target.className); - } - }; - - - /** - * Send a click event to the specified element. - * - * @param {EventTarget|Element} targetElement - * @param {Event} event - */ - FastClick.prototype.sendClick = function(targetElement, event) { - var clickEvent, touch; - - // On some Android devices activeElement needs to be blurred otherwise the synthetic click will have no effect (#24) - if (document.activeElement && document.activeElement !== targetElement) { - document.activeElement.blur(); - } - - touch = event.changedTouches[0]; - - // Synthesise a click event, with an extra attribute so it can be tracked - clickEvent = document.createEvent('MouseEvents'); - clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null); - clickEvent.forwardedTouchEvent = true; - targetElement.dispatchEvent(clickEvent); - }; - - FastClick.prototype.determineEventType = function(targetElement) { - - //Issue #159: Android Chrome Select Box does not open with a synthetic click event - if (deviceIsAndroid && targetElement.tagName.toLowerCase() === 'select') { - return 'mousedown'; - } - - return 'click'; - }; - - - /** - * @param {EventTarget|Element} targetElement - */ - FastClick.prototype.focus = function(targetElement) { - var length; - - // Issue #160: on iOS 7, some input elements (e.g. date datetime month) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724. - if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month') { - length = targetElement.value.length; - targetElement.setSelectionRange(length, length); - } else { - targetElement.focus(); - } - }; - - - /** - * Check whether the given target element is a child of a scrollable layer and if so, set a flag on it. - * - * @param {EventTarget|Element} targetElement - */ - FastClick.prototype.updateScrollParent = function(targetElement) { - var scrollParent, parentElement; - - scrollParent = targetElement.fastClickScrollParent; - - // Attempt to discover whether the target element is contained within a scrollable layer. Re-check if the - // target element was moved to another parent. - if (!scrollParent || !scrollParent.contains(targetElement)) { - parentElement = targetElement; - do { - if (parentElement.scrollHeight > parentElement.offsetHeight) { - scrollParent = parentElement; - targetElement.fastClickScrollParent = parentElement; - break; - } - - parentElement = parentElement.parentElement; - } while (parentElement); - } - - // Always update the scroll top tracker if possible. - if (scrollParent) { - scrollParent.fastClickLastScrollTop = scrollParent.scrollTop; - } - }; - - - /** - * @param {EventTarget} targetElement - * @returns {Element|EventTarget} - */ - FastClick.prototype.getTargetElementFromEventTarget = function(eventTarget) { - - // On some older browsers (notably Safari on iOS 4.1 - see issue #56) the event target may be a text node. - if (eventTarget.nodeType === Node.TEXT_NODE) { - return eventTarget.parentNode; - } - - return eventTarget; - }; - - - /** - * On touch start, record the position and scroll offset. - * - * @param {Event} event - * @returns {boolean} - */ - FastClick.prototype.onTouchStart = function(event) { - var targetElement, touch, selection; - - // Ignore multiple touches, otherwise pinch-to-zoom is prevented if both fingers are on the FastClick element (issue #111). - if (event.targetTouches.length > 1) { - return true; - } - - targetElement = this.getTargetElementFromEventTarget(event.target); - touch = event.targetTouches[0]; - - if (deviceIsIOS) { - - // Only trusted events will deselect text on iOS (issue #49) - selection = window.getSelection(); - if (selection.rangeCount && !selection.isCollapsed) { - return true; - } - - if (!deviceIsIOS4) { - - // Weird things happen on iOS when an alert or confirm dialog is opened from a click event callback (issue #23): - // when the user next taps anywhere else on the page, new touchstart and touchend events are dispatched - // with the same identifier as the touch event that previously triggered the click that triggered the alert. - // Sadly, there is an issue on iOS 4 that causes some normal touch events to have the same identifier as an - // immediately preceeding touch event (issue #52), so this fix is unavailable on that platform. - // Issue 120: touch.identifier is 0 when Chrome dev tools 'Emulate touch events' is set with an iOS device UA string, - // which causes all touch events to be ignored. As this block only applies to iOS, and iOS identifiers are always long, - // random integers, it's safe to to continue if the identifier is 0 here. - if (touch.identifier && touch.identifier === this.lastTouchIdentifier) { - event.preventDefault(); - return false; - } - - this.lastTouchIdentifier = touch.identifier; - - // If the target element is a child of a scrollable layer (using -webkit-overflow-scrolling: touch) and: - // 1) the user does a fling scroll on the scrollable layer - // 2) the user stops the fling scroll with another tap - // then the event.target of the last 'touchend' event will be the element that was under the user's finger - // when the fling scroll was started, causing FastClick to send a click event to that layer - unless a check - // is made to ensure that a parent layer was not scrolled before sending a synthetic click (issue #42). - this.updateScrollParent(targetElement); - } - } - - this.trackingClick = true; - this.trackingClickStart = event.timeStamp; - this.targetElement = targetElement; - - this.touchStartX = touch.pageX; - this.touchStartY = touch.pageY; - - // Prevent phantom clicks on fast double-tap (issue #36) - if ((event.timeStamp - this.lastClickTime) < this.tapDelay) { - event.preventDefault(); - } - - return true; - }; - - - /** - * Based on a touchmove event object, check whether the touch has moved past a boundary since it started. - * - * @param {Event} event - * @returns {boolean} - */ - FastClick.prototype.touchHasMoved = function(event) { - var touch = event.changedTouches[0], boundary = this.touchBoundary; - - if (Math.abs(touch.pageX - this.touchStartX) > boundary || Math.abs(touch.pageY - this.touchStartY) > boundary) { - return true; - } - - return false; - }; - - - /** - * Update the last position. - * - * @param {Event} event - * @returns {boolean} - */ - FastClick.prototype.onTouchMove = function(event) { - if (!this.trackingClick) { - return true; - } - - // If the touch has moved, cancel the click tracking - if (this.targetElement !== this.getTargetElementFromEventTarget(event.target) || this.touchHasMoved(event)) { - this.trackingClick = false; - this.targetElement = null; - } - - return true; - }; - - - /** - * Attempt to find the labelled control for the given label element. - * - * @param {EventTarget|HTMLLabelElement} labelElement - * @returns {Element|null} - */ - FastClick.prototype.findControl = function(labelElement) { - - // Fast path for newer browsers supporting the HTML5 control attribute - if (labelElement.control !== undefined) { - return labelElement.control; - } - - // All browsers under test that support touch events also support the HTML5 htmlFor attribute - if (labelElement.htmlFor) { - return document.getElementById(labelElement.htmlFor); - } - - // If no for attribute exists, attempt to retrieve the first labellable descendant element - // the list of which is defined here: http://www.w3.org/TR/html5/forms.html#category-label - return labelElement.querySelector('button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea'); - }; - - - /** - * On touch end, determine whether to send a click event at once. - * - * @param {Event} event - * @returns {boolean} - */ - FastClick.prototype.onTouchEnd = function(event) { - var forElement, trackingClickStart, targetTagName, scrollParent, touch, targetElement = this.targetElement; - - if (!this.trackingClick) { - return true; - } - - // Prevent phantom clicks on fast double-tap (issue #36) - if ((event.timeStamp - this.lastClickTime) < this.tapDelay) { - this.cancelNextClick = true; - return true; - } - - if ((event.timeStamp - this.trackingClickStart) > this.tapTimeout) { - return true; - } - - // Reset to prevent wrong click cancel on input (issue #156). - this.cancelNextClick = false; - - this.lastClickTime = event.timeStamp; - - trackingClickStart = this.trackingClickStart; - this.trackingClick = false; - this.trackingClickStart = 0; - - // On some iOS devices, the targetElement supplied with the event is invalid if the layer - // is performing a transition or scroll, and has to be re-detected manually. Note that - // for this to function correctly, it must be called *after* the event target is checked! - // See issue #57; also filed as rdar://13048589 . - if (deviceIsIOSWithBadTarget) { - touch = event.changedTouches[0]; - - // In certain cases arguments of elementFromPoint can be negative, so prevent setting targetElement to null - targetElement = document.elementFromPoint(touch.pageX - window.pageXOffset, touch.pageY - window.pageYOffset) || targetElement; - targetElement.fastClickScrollParent = this.targetElement.fastClickScrollParent; - } - - targetTagName = targetElement.tagName.toLowerCase(); - if (targetTagName === 'label') { - forElement = this.findControl(targetElement); - if (forElement) { - this.focus(targetElement); - if (deviceIsAndroid) { - return false; - } - - targetElement = forElement; - } - } else if (this.needsFocus(targetElement)) { - - // Case 1: If the touch started a while ago (best guess is 100ms based on tests for issue #36) then focus will be triggered anyway. Return early and unset the target element reference so that the subsequent click will be allowed through. - // Case 2: Without this exception for input elements tapped when the document is contained in an iframe, then any inputted text won't be visible even though the value attribute is updated as the user types (issue #37). - if ((event.timeStamp - trackingClickStart) > 100 || (deviceIsIOS && window.top !== window && targetTagName === 'input')) { - this.targetElement = null; - return false; - } - - this.focus(targetElement); - this.sendClick(targetElement, event); - - // Select elements need the event to go through on iOS 4, otherwise the selector menu won't open. - // Also this breaks opening selects when VoiceOver is active on iOS6, iOS7 (and possibly others) - if (!deviceIsIOS || targetTagName !== 'select') { - this.targetElement = null; - event.preventDefault(); - } - - return false; - } - - if (deviceIsIOS && !deviceIsIOS4) { - - // Don't send a synthetic click event if the target element is contained within a parent layer that was scrolled - // and this tap is being used to stop the scrolling (usually initiated by a fling - issue #42). - scrollParent = targetElement.fastClickScrollParent; - if (scrollParent && scrollParent.fastClickLastScrollTop !== scrollParent.scrollTop) { - return true; - } - } - - // Prevent the actual click from going though - unless the target node is marked as requiring - // real clicks or if it is in the whitelist in which case only non-programmatic clicks are permitted. - if (!this.needsClick(targetElement)) { - event.preventDefault(); - this.sendClick(targetElement, event); - } - - return false; - }; - - - /** - * On touch cancel, stop tracking the click. - * - * @returns {void} - */ - FastClick.prototype.onTouchCancel = function() { - this.trackingClick = false; - this.targetElement = null; - }; - - - /** - * Determine mouse events which should be permitted. - * - * @param {Event} event - * @returns {boolean} - */ - FastClick.prototype.onMouse = function(event) { - - // If a target element was never set (because a touch event was never fired) allow the event - if (!this.targetElement) { - return true; - } - - if (event.forwardedTouchEvent) { - return true; - } - - // Programmatically generated events targeting a specific element should be permitted - if (!event.cancelable) { - return true; - } - - // Derive and check the target element to see whether the mouse event needs to be permitted; - // unless explicitly enabled, prevent non-touch click events from triggering actions, - // to prevent ghost/doubleclicks. - if (!this.needsClick(this.targetElement) || this.cancelNextClick) { - - // Prevent any user-added listeners declared on FastClick element from being fired. - if (event.stopImmediatePropagation) { - event.stopImmediatePropagation(); - } else { - - // Part of the hack for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2) - event.propagationStopped = true; - } - - // Cancel the event - event.stopPropagation(); - event.preventDefault(); - - return false; - } - - // If the mouse event is permitted, return true for the action to go through. - return true; - }; - - - /** - * On actual clicks, determine whether this is a touch-generated click, a click action occurring - * naturally after a delay after a touch (which needs to be cancelled to avoid duplication), or - * an actual click which should be permitted. - * - * @param {Event} event - * @returns {boolean} - */ - FastClick.prototype.onClick = function(event) { - var permitted; - - // It's possible for another FastClick-like library delivered with third-party code to fire a click event before FastClick does (issue #44). In that case, set the click-tracking flag back to false and return early. This will cause onTouchEnd to return early. - if (this.trackingClick) { - this.targetElement = null; - this.trackingClick = false; - return true; - } - - // Very odd behaviour on iOS (issue #18): if a submit element is present inside a form and the user hits enter in the iOS simulator or clicks the Go button on the pop-up OS keyboard the a kind of 'fake' click event will be triggered with the submit-type input element as the target. - if (event.target.type === 'submit' && event.detail === 0) { - return true; - } - - permitted = this.onMouse(event); - - // Only unset targetElement if the click is not permitted. This will ensure that the check for !targetElement in onMouse fails and the browser's click doesn't go through. - if (!permitted) { - this.targetElement = null; - } - - // If clicks are permitted, return true for the action to go through. - return permitted; - }; - - - /** - * Remove all FastClick's event listeners. - * - * @returns {void} - */ - FastClick.prototype.destroy = function() { - var layer = this.layer; - - if (deviceIsAndroid) { - layer.removeEventListener('mouseover', this.onMouse, true); - layer.removeEventListener('mousedown', this.onMouse, true); - layer.removeEventListener('mouseup', this.onMouse, true); - } - - layer.removeEventListener('click', this.onClick, true); - layer.removeEventListener('touchstart', this.onTouchStart, false); - layer.removeEventListener('touchmove', this.onTouchMove, false); - layer.removeEventListener('touchend', this.onTouchEnd, false); - layer.removeEventListener('touchcancel', this.onTouchCancel, false); - }; - - - /** - * Check whether FastClick is needed. - * - * @param {Element} layer The layer to listen on - */ - FastClick.notNeeded = function(layer) { - var metaViewport; - var chromeVersion; - var blackberryVersion; - var firefoxVersion; - - // Devices that don't support touch don't need FastClick - if (typeof window.ontouchstart === 'undefined') { - return true; - } - - // Chrome version - zero for other browsers - chromeVersion = +(/Chrome\/([0-9]+)/.exec(navigator.userAgent) || [,0])[1]; - - if (chromeVersion) { - - if (deviceIsAndroid) { - metaViewport = document.querySelector('meta[name=viewport]'); - - if (metaViewport) { - // Chrome on Android with user-scalable="no" doesn't need FastClick (issue #89) - if (metaViewport.content.indexOf('user-scalable=no') !== -1) { - return true; - } - // Chrome 32 and above with width=device-width or less don't need FastClick - if (chromeVersion > 31 && document.documentElement.scrollWidth <= window.outerWidth) { - return true; - } - } - - // Chrome desktop doesn't need FastClick (issue #15) - } else { - return true; - } - } - - if (deviceIsBlackBerry10) { - blackberryVersion = navigator.userAgent.match(/Version\/([0-9]*)\.([0-9]*)/); - - // BlackBerry 10.3+ does not require Fastclick library. - // https://github.com/ftlabs/fastclick/issues/251 - if (blackberryVersion[1] >= 10 && blackberryVersion[2] >= 3) { - metaViewport = document.querySelector('meta[name=viewport]'); - - if (metaViewport) { - // user-scalable=no eliminates click delay. - if (metaViewport.content.indexOf('user-scalable=no') !== -1) { - return true; - } - // width=device-width (or less than device-width) eliminates click delay. - if (document.documentElement.scrollWidth <= window.outerWidth) { - return true; - } - } - } - } - - // IE10 with -ms-touch-action: none or manipulation, which disables double-tap-to-zoom (issue #97) - if (layer.style.msTouchAction === 'none' || layer.style.touchAction === 'manipulation') { - return true; - } - - // Firefox version - zero for other browsers - firefoxVersion = +(/Firefox\/([0-9]+)/.exec(navigator.userAgent) || [,0])[1]; - - if (firefoxVersion >= 27) { - // Firefox 27+ does not have tap delay if the content is not zoomable - https://bugzilla.mozilla.org/show_bug.cgi?id=922896 - - metaViewport = document.querySelector('meta[name=viewport]'); - if (metaViewport && (metaViewport.content.indexOf('user-scalable=no') !== -1 || document.documentElement.scrollWidth <= window.outerWidth)) { - return true; - } - } - - // IE11: prefixed -ms-touch-action is no longer supported and it's recomended to use non-prefixed version - // http://msdn.microsoft.com/en-us/library/windows/apps/Hh767313.aspx - if (layer.style.touchAction === 'none' || layer.style.touchAction === 'manipulation') { - return true; - } - - return false; - }; - - - /** - * Factory method for creating a FastClick object - * - * @param {Element} layer The layer to listen on - * @param {Object} [options={}] The options to override the defaults - */ - FastClick.attach = function(layer, options) { - return new FastClick(layer, options); - }; - - - if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) { - - // AMD. Register as an anonymous module. - define(function() { - return FastClick; - }); - } else if (typeof module !== 'undefined' && module.exports) { - module.exports = FastClick.attach; - module.exports.FastClick = FastClick; - } else { - window.FastClick = FastClick; - } -}()); -; /*! https://mths.be/punycode v1.4.1 by @mathias */ ;(function(root) { @@ -21255,10 +20413,10 @@ System.register('flarum/components/DiscussionComposer', ['flarum/components/Comp });; 'use strict'; -System.register('flarum/components/DiscussionHero', ['flarum/Component', 'flarum/utils/ItemList', 'flarum/helpers/listItems'], function (_export, _context) { +System.register('flarum/components/DiscussionHeader', ['flarum/Component', 'flarum/utils/ItemList', 'flarum/helpers/listItems'], function (_export, _context) { "use strict"; - var Component, ItemList, listItems, DiscussionHero; + var Component, ItemList, listItems, DiscussionHeader; return { setters: [function (_flarumComponent) { Component = _flarumComponent.default; @@ -21268,28 +20426,24 @@ System.register('flarum/components/DiscussionHero', ['flarum/Component', 'flarum listItems = _flarumHelpersListItems.default; }], execute: function () { - DiscussionHero = function (_Component) { - babelHelpers.inherits(DiscussionHero, _Component); + DiscussionHeader = function (_Component) { + babelHelpers.inherits(DiscussionHeader, _Component); - function DiscussionHero() { - babelHelpers.classCallCheck(this, DiscussionHero); - return babelHelpers.possibleConstructorReturn(this, (DiscussionHero.__proto__ || Object.getPrototypeOf(DiscussionHero)).apply(this, arguments)); + function DiscussionHeader() { + babelHelpers.classCallCheck(this, DiscussionHeader); + return babelHelpers.possibleConstructorReturn(this, (DiscussionHeader.__proto__ || Object.getPrototypeOf(DiscussionHeader)).apply(this, arguments)); } - babelHelpers.createClass(DiscussionHero, [{ + babelHelpers.createClass(DiscussionHeader, [{ key: 'view', value: function view() { return m( 'header', - { className: 'Hero DiscussionHero' }, + { className: 'DiscussionHeader' }, m( - 'div', - { className: 'container' }, - m( - 'ul', - { className: 'DiscussionHero-items' }, - listItems(this.items().toArray()) - ) + 'ul', + { className: 'DiscussionHeader-items' }, + listItems(this.items().toArray()) ) ); } @@ -21303,24 +20457,24 @@ System.register('flarum/components/DiscussionHero', ['flarum/Component', 'flarum if (badges.length) { items.add('badges', m( 'ul', - { className: 'DiscussionHero-badges badges' }, + { className: 'DiscussionHeader-badges badges' }, listItems(badges) ), 10); } items.add('title', m( 'h2', - { className: 'DiscussionHero-title' }, + { className: 'DiscussionHeader-title' }, discussion.title() )); return items; } }]); - return DiscussionHero; + return DiscussionHeader; }(Component); - _export('default', DiscussionHero); + _export('default', DiscussionHeader); } }; });; @@ -21756,17 +20910,17 @@ System.register('flarum/components/DiscussionListItem', ['flarum/Component', 'fl });; 'use strict'; -System.register('flarum/components/DiscussionPage', ['flarum/components/Page', 'flarum/utils/ItemList', 'flarum/components/DiscussionHero', 'flarum/components/PostStream', 'flarum/components/PostStreamScrubber', 'flarum/components/LoadingIndicator', 'flarum/components/SplitDropdown', 'flarum/helpers/listItems', 'flarum/utils/DiscussionControls'], function (_export, _context) { +System.register('flarum/components/DiscussionPage', ['flarum/components/Page', 'flarum/utils/ItemList', 'flarum/components/DiscussionHeader', 'flarum/components/PostStream', 'flarum/components/PostStreamScrubber', 'flarum/components/LoadingIndicator', 'flarum/components/SplitDropdown', 'flarum/helpers/listItems', 'flarum/utils/DiscussionControls', 'flarum/utils/affixSidebar'], function (_export, _context) { "use strict"; - var Page, ItemList, DiscussionHero, PostStream, PostStreamScrubber, LoadingIndicator, SplitDropdown, listItems, DiscussionControls, DiscussionPage; + var Page, ItemList, DiscussionHeader, PostStream, PostStreamScrubber, LoadingIndicator, SplitDropdown, listItems, DiscussionControls, affixSidebar, DiscussionPage; return { setters: [function (_flarumComponentsPage) { Page = _flarumComponentsPage.default; }, function (_flarumUtilsItemList) { ItemList = _flarumUtilsItemList.default; - }, function (_flarumComponentsDiscussionHero) { - DiscussionHero = _flarumComponentsDiscussionHero.default; + }, function (_flarumComponentsDiscussionHeader) { + DiscussionHeader = _flarumComponentsDiscussionHeader.default; }, function (_flarumComponentsPostStream) { PostStream = _flarumComponentsPostStream.default; }, function (_flarumComponentsPostStreamScrubber) { @@ -21779,6 +20933,8 @@ System.register('flarum/components/DiscussionPage', ['flarum/components/Page', ' listItems = _flarumHelpersListItems.default; }, function (_flarumUtilsDiscussionControls) { DiscussionControls = _flarumUtilsDiscussionControls.default; + }, function (_flarumUtilsAffixSidebar) { + affixSidebar = _flarumUtilsAffixSidebar.default; }], execute: function () { DiscussionPage = function (_Page) { @@ -21879,12 +21035,12 @@ System.register('flarum/components/DiscussionPage', ['flarum/components/Page', ' m( 'div', { className: 'DiscussionPage-discussion' }, - discussion ? [DiscussionHero.component({ discussion: discussion }), m( + discussion ? m( 'div', { className: 'container' }, m( 'nav', - { className: 'DiscussionPage-nav' }, + { className: 'DiscussionPage-nav', config: affixSidebar }, m( 'ul', null, @@ -21894,9 +21050,10 @@ System.register('flarum/components/DiscussionPage', ['flarum/components/Page', ' m( 'div', { className: 'DiscussionPage-stream' }, + DiscussionHeader.component({ discussion: discussion }), this.stream.render() ) - )] : LoadingIndicator.component({ className: 'LoadingIndicator--block' }) + ) : LoadingIndicator.component({ className: 'LoadingIndicator--block' }) ) ); } @@ -29587,11 +28744,7 @@ System.register('flarum/initializers/boot', ['flarum/utils/ScrollListener', 'fla $app.toggleClass('affix', top >= offset).toggleClass('scrolled', top > offset); }).start(); - // Initialize FastClick, which makes links and buttons much more responsive on - // touch devices. $(function () { - FastClick.attach(document.body); - $('body').addClass('ontouchstart' in window ? 'touch' : 'no-touch'); }); From 091305cce2604ee5e2b1517ccf7ccfa971d1a3f5 Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Sun, 5 Nov 2017 17:57:56 +1030 Subject: [PATCH 073/172] Oops, recompile JS properly --- framework/core/js/forum/dist/app.js | 53 +++++++++++++++-------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/framework/core/js/forum/dist/app.js b/framework/core/js/forum/dist/app.js index c0f196994..60e3bd907 100644 --- a/framework/core/js/forum/dist/app.js +++ b/framework/core/js/forum/dist/app.js @@ -20413,10 +20413,10 @@ System.register('flarum/components/DiscussionComposer', ['flarum/components/Comp });; 'use strict'; -System.register('flarum/components/DiscussionHeader', ['flarum/Component', 'flarum/utils/ItemList', 'flarum/helpers/listItems'], function (_export, _context) { +System.register('flarum/components/DiscussionHero', ['flarum/Component', 'flarum/utils/ItemList', 'flarum/helpers/listItems'], function (_export, _context) { "use strict"; - var Component, ItemList, listItems, DiscussionHeader; + var Component, ItemList, listItems, DiscussionHero; return { setters: [function (_flarumComponent) { Component = _flarumComponent.default; @@ -20426,24 +20426,28 @@ System.register('flarum/components/DiscussionHeader', ['flarum/Component', 'flar listItems = _flarumHelpersListItems.default; }], execute: function () { - DiscussionHeader = function (_Component) { - babelHelpers.inherits(DiscussionHeader, _Component); + DiscussionHero = function (_Component) { + babelHelpers.inherits(DiscussionHero, _Component); - function DiscussionHeader() { - babelHelpers.classCallCheck(this, DiscussionHeader); - return babelHelpers.possibleConstructorReturn(this, (DiscussionHeader.__proto__ || Object.getPrototypeOf(DiscussionHeader)).apply(this, arguments)); + function DiscussionHero() { + babelHelpers.classCallCheck(this, DiscussionHero); + return babelHelpers.possibleConstructorReturn(this, (DiscussionHero.__proto__ || Object.getPrototypeOf(DiscussionHero)).apply(this, arguments)); } - babelHelpers.createClass(DiscussionHeader, [{ + babelHelpers.createClass(DiscussionHero, [{ key: 'view', value: function view() { return m( 'header', - { className: 'DiscussionHeader' }, + { className: 'Hero DiscussionHero' }, m( - 'ul', - { className: 'DiscussionHeader-items' }, - listItems(this.items().toArray()) + 'div', + { className: 'container' }, + m( + 'ul', + { className: 'DiscussionHero-items' }, + listItems(this.items().toArray()) + ) ) ); } @@ -20457,24 +20461,24 @@ System.register('flarum/components/DiscussionHeader', ['flarum/Component', 'flar if (badges.length) { items.add('badges', m( 'ul', - { className: 'DiscussionHeader-badges badges' }, + { className: 'DiscussionHero-badges badges' }, listItems(badges) ), 10); } items.add('title', m( 'h2', - { className: 'DiscussionHeader-title' }, + { className: 'DiscussionHero-title' }, discussion.title() )); return items; } }]); - return DiscussionHeader; + return DiscussionHero; }(Component); - _export('default', DiscussionHeader); + _export('default', DiscussionHero); } }; });; @@ -20910,17 +20914,17 @@ System.register('flarum/components/DiscussionListItem', ['flarum/Component', 'fl });; 'use strict'; -System.register('flarum/components/DiscussionPage', ['flarum/components/Page', 'flarum/utils/ItemList', 'flarum/components/DiscussionHeader', 'flarum/components/PostStream', 'flarum/components/PostStreamScrubber', 'flarum/components/LoadingIndicator', 'flarum/components/SplitDropdown', 'flarum/helpers/listItems', 'flarum/utils/DiscussionControls', 'flarum/utils/affixSidebar'], function (_export, _context) { +System.register('flarum/components/DiscussionPage', ['flarum/components/Page', 'flarum/utils/ItemList', 'flarum/components/DiscussionHero', 'flarum/components/PostStream', 'flarum/components/PostStreamScrubber', 'flarum/components/LoadingIndicator', 'flarum/components/SplitDropdown', 'flarum/helpers/listItems', 'flarum/utils/DiscussionControls'], function (_export, _context) { "use strict"; - var Page, ItemList, DiscussionHeader, PostStream, PostStreamScrubber, LoadingIndicator, SplitDropdown, listItems, DiscussionControls, affixSidebar, DiscussionPage; + var Page, ItemList, DiscussionHero, PostStream, PostStreamScrubber, LoadingIndicator, SplitDropdown, listItems, DiscussionControls, DiscussionPage; return { setters: [function (_flarumComponentsPage) { Page = _flarumComponentsPage.default; }, function (_flarumUtilsItemList) { ItemList = _flarumUtilsItemList.default; - }, function (_flarumComponentsDiscussionHeader) { - DiscussionHeader = _flarumComponentsDiscussionHeader.default; + }, function (_flarumComponentsDiscussionHero) { + DiscussionHero = _flarumComponentsDiscussionHero.default; }, function (_flarumComponentsPostStream) { PostStream = _flarumComponentsPostStream.default; }, function (_flarumComponentsPostStreamScrubber) { @@ -20933,8 +20937,6 @@ System.register('flarum/components/DiscussionPage', ['flarum/components/Page', ' listItems = _flarumHelpersListItems.default; }, function (_flarumUtilsDiscussionControls) { DiscussionControls = _flarumUtilsDiscussionControls.default; - }, function (_flarumUtilsAffixSidebar) { - affixSidebar = _flarumUtilsAffixSidebar.default; }], execute: function () { DiscussionPage = function (_Page) { @@ -21035,12 +21037,12 @@ System.register('flarum/components/DiscussionPage', ['flarum/components/Page', ' m( 'div', { className: 'DiscussionPage-discussion' }, - discussion ? m( + discussion ? [DiscussionHero.component({ discussion: discussion }), m( 'div', { className: 'container' }, m( 'nav', - { className: 'DiscussionPage-nav', config: affixSidebar }, + { className: 'DiscussionPage-nav' }, m( 'ul', null, @@ -21050,10 +21052,9 @@ System.register('flarum/components/DiscussionPage', ['flarum/components/Page', ' m( 'div', { className: 'DiscussionPage-stream' }, - DiscussionHeader.component({ discussion: discussion }), this.stream.render() ) - ) : LoadingIndicator.component({ className: 'LoadingIndicator--block' }) + )] : LoadingIndicator.component({ className: 'LoadingIndicator--block' }) ) ); } From b4375e4f7d42d0264bcfb538fc8ed0526438c674 Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Tue, 7 Nov 2017 21:12:03 +1030 Subject: [PATCH 074/172] Fix Composer textarea losing its height across route changes There is a Mithril bug which causes context.retain to be ineffective for children nodes. https://github.com/MithrilJS/mithril.js/issues/1300 Thus, we have to assume that the children nodes (like the textarea) may be recreated and thus we need to update its height on each redraw. fixes #948 --- framework/core/js/forum/dist/app.js | 4 ++++ framework/core/js/forum/src/components/Composer.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/framework/core/js/forum/dist/app.js b/framework/core/js/forum/dist/app.js index 60e3bd907..21e7cf8ef 100644 --- a/framework/core/js/forum/dist/app.js +++ b/framework/core/js/forum/dist/app.js @@ -19820,6 +19820,10 @@ System.register('flarum/components/Composer', ['flarum/Component', 'flarum/utils defaultHeight = this.$().height(); } + // Set the height of the Composer element and its contents on each redraw, + // so that they do not lose it if their DOM elements are recreated. + this.updateHeight(); + if (isInitialized) return; // Since this component is a part of the global UI that persists between diff --git a/framework/core/js/forum/src/components/Composer.js b/framework/core/js/forum/src/components/Composer.js index f498333e6..93532d700 100644 --- a/framework/core/js/forum/src/components/Composer.js +++ b/framework/core/js/forum/src/components/Composer.js @@ -91,6 +91,10 @@ class Composer extends Component { defaultHeight = this.$().height(); } + // Set the height of the Composer element and its contents on each redraw, + // so that they do not lose it if their DOM elements are recreated. + this.updateHeight(); + if (isInitialized) return; // Since this component is a part of the global UI that persists between From 99686ef8bba4bd230a65027e88360da52bb3cc0b Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Sat, 11 Nov 2017 22:44:45 +1030 Subject: [PATCH 075/172] Performance: Assign parent discussion to posts so it doesn't have to be reloaded --- .../Api/Controller/ListDiscussionsController.php | 14 +++++++++++++- .../Api/Controller/ShowDiscussionController.php | 8 +++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Api/Controller/ListDiscussionsController.php b/framework/core/src/Api/Controller/ListDiscussionsController.php index ab8b21283..04db95c3a 100644 --- a/framework/core/src/Api/Controller/ListDiscussionsController.php +++ b/framework/core/src/Api/Controller/ListDiscussionsController.php @@ -93,6 +93,18 @@ class ListDiscussionsController extends AbstractCollectionController $results->areMoreResults() ? null : 0 ); - return $results->getResults(); + $results = $results->getResults(); + + if ($relations = array_intersect($load, ['startPost', 'lastPost'])) { + foreach ($results as $discussion) { + foreach ($relations as $relation) { + if ($discussion->$relation) { + $discussion->$relation->discussion = $discussion; + } + } + } + } + + return $results; } } diff --git a/framework/core/src/Api/Controller/ShowDiscussionController.php b/framework/core/src/Api/Controller/ShowDiscussionController.php index 7f04ca167..e99ec54b0 100644 --- a/framework/core/src/Api/Controller/ShowDiscussionController.php +++ b/framework/core/src/Api/Controller/ShowDiscussionController.php @@ -173,6 +173,12 @@ class ShowDiscussionController extends AbstractResourceController $query->orderBy('time')->skip($offset)->take($limit)->with($include); - return $query->get()->all(); + $posts = $query->get()->all(); + + foreach ($posts as $post) { + $post->discussion = $discussion; + } + + return $posts; } } From 89a43d1adff1faccdbfbcdbde6772917c97c97e6 Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Sat, 11 Nov 2017 22:45:38 +1030 Subject: [PATCH 076/172] Performance: Cache translation catalogue to avoid reparsing YAML --- framework/core/composer.json | 1 + .../src/Debug/Console/CacheClearCommand.php | 20 +++++++++++++++---- .../core/src/Locale/LocaleServiceProvider.php | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/framework/core/composer.json b/framework/core/composer.json index 1ee4195f0..5bfcb2a57 100644 --- a/framework/core/composer.json +++ b/framework/core/composer.json @@ -46,6 +46,7 @@ "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", diff --git a/framework/core/src/Debug/Console/CacheClearCommand.php b/framework/core/src/Debug/Console/CacheClearCommand.php index cf8e4b466..97142ad6e 100644 --- a/framework/core/src/Debug/Console/CacheClearCommand.php +++ b/framework/core/src/Debug/Console/CacheClearCommand.php @@ -14,35 +14,43 @@ namespace Flarum\Debug\Console; use Flarum\Admin\WebApp as AdminWebApp; use Flarum\Console\Command\AbstractCommand; use Flarum\Forum\WebApp as ForumWebApp; +use Flarum\Foundation\Application; use Illuminate\Contracts\Cache\Store; class CacheClearCommand extends AbstractCommand { /** - * @var \Illuminate\Contracts\Cache\Store + * @var Store */ protected $cache; /** - * @var \Flarum\Forum\WebApp + * @var ForumWebApp */ protected $forum; /** - * @var \Flarum\Admin\WebApp + * @var AdminWebApp */ protected $admin; + /** + * @var Application + */ + protected $app; + /** * @param Store $cache * @param ForumWebApp $forum * @param AdminWebApp $admin + * @param Application $app */ - public function __construct(Store $cache, ForumWebApp $forum, AdminWebApp $admin) + public function __construct(Store $cache, ForumWebApp $forum, AdminWebApp $admin, Application $app) { $this->cache = $cache; $this->forum = $forum; $this->admin = $admin; + $this->app = $app; parent::__construct(); } @@ -68,5 +76,9 @@ class CacheClearCommand extends AbstractCommand $this->admin->getAssets()->flush(); $this->cache->flush(); + + $storagePath = $this->app->storagePath(); + array_map('unlink', glob($storagePath.'/formatter/*')); + array_map('unlink', glob($storagePath.'/locale/*')); } } diff --git a/framework/core/src/Locale/LocaleServiceProvider.php b/framework/core/src/Locale/LocaleServiceProvider.php index 034e21a1c..3e038950b 100644 --- a/framework/core/src/Locale/LocaleServiceProvider.php +++ b/framework/core/src/Locale/LocaleServiceProvider.php @@ -41,7 +41,7 @@ class LocaleServiceProvider extends AbstractServiceProvider $this->app->singleton('translator', function () { $defaultLocale = $this->getDefaultLocale(); - $translator = new Translator($defaultLocale, new MessageSelector()); + $translator = new Translator($defaultLocale, null, $this->app->storagePath().'/locale', $this->app->inDebugMode()); $translator->setFallbackLocales([$defaultLocale, 'en']); $translator->addLoader('prefixed_yaml', new PrefixedYamlFileLoader()); From a4849355aae6834d38601ebf6fbf8ef86f726c88 Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Sat, 11 Nov 2017 22:57:41 +1030 Subject: [PATCH 077/172] Performance: Load only basic information about terminal/relevant posts --- .../Api/Serializer/DiscussionBasicSerializer.php | 14 +++++++++++--- .../src/Api/Serializer/DiscussionSerializer.php | 8 -------- .../src/Api/Serializer/PostBasicSerializer.php | 7 +++++++ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/framework/core/src/Api/Serializer/DiscussionBasicSerializer.php b/framework/core/src/Api/Serializer/DiscussionBasicSerializer.php index 99416b10e..ec5040f9d 100644 --- a/framework/core/src/Api/Serializer/DiscussionBasicSerializer.php +++ b/framework/core/src/Api/Serializer/DiscussionBasicSerializer.php @@ -54,7 +54,7 @@ class DiscussionBasicSerializer extends AbstractSerializer */ protected function startPost($discussion) { - return $this->hasOne($discussion, 'Flarum\Api\Serializer\PostSerializer'); + return $this->hasOne($discussion, 'Flarum\Api\Serializer\PostBasicSerializer'); } /** @@ -70,7 +70,7 @@ class DiscussionBasicSerializer extends AbstractSerializer */ protected function lastPost($discussion) { - return $this->hasOne($discussion, 'Flarum\Api\Serializer\PostSerializer'); + return $this->hasOne($discussion, 'Flarum\Api\Serializer\PostBasicSerializer'); } /** @@ -86,6 +86,14 @@ class DiscussionBasicSerializer extends AbstractSerializer */ protected function relevantPosts($discussion) { - return $this->hasMany($discussion, 'Flarum\Api\Serializer\PostSerializer'); + return $this->hasMany($discussion, 'Flarum\Api\Serializer\PostBasicSerializer'); + } + + /** + * @return \Tobscure\JsonApi\Relationship + */ + protected function hideUser($discussion) + { + return $this->hasOne($discussion, 'Flarum\Api\Serializer\UserBasicSerializer'); } } diff --git a/framework/core/src/Api/Serializer/DiscussionSerializer.php b/framework/core/src/Api/Serializer/DiscussionSerializer.php index 47ef8c0ea..eee9c38a0 100644 --- a/framework/core/src/Api/Serializer/DiscussionSerializer.php +++ b/framework/core/src/Api/Serializer/DiscussionSerializer.php @@ -64,12 +64,4 @@ class DiscussionSerializer extends DiscussionBasicSerializer return $attributes; } - - /** - * @return \Tobscure\JsonApi\Relationship - */ - protected function hideUser($discussion) - { - return $this->hasOne($discussion, 'Flarum\Api\Serializer\UserSerializer'); - } } diff --git a/framework/core/src/Api/Serializer/PostBasicSerializer.php b/framework/core/src/Api/Serializer/PostBasicSerializer.php index 3a79eed84..962a7b28b 100644 --- a/framework/core/src/Api/Serializer/PostBasicSerializer.php +++ b/framework/core/src/Api/Serializer/PostBasicSerializer.php @@ -12,6 +12,7 @@ namespace Flarum\Api\Serializer; use Flarum\Core\Post; +use Flarum\Core\Post\CommentPost; use InvalidArgumentException; class PostBasicSerializer extends AbstractSerializer @@ -42,6 +43,12 @@ class PostBasicSerializer extends AbstractSerializer 'contentType' => $post->type ]; + if ($post instanceof CommentPost) { + $attributes['contentHtml'] = $post->content_html; + } else { + $attributes['content'] = $post->content; + } + return $attributes; } From 5116cf7d75967d9fa58a9a52a2724c2a52cab353 Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Sat, 11 Nov 2017 23:15:36 +1030 Subject: [PATCH 078/172] Performance: Load only basic information about post discussion/users --- framework/core/src/Api/Serializer/PostSerializer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/core/src/Api/Serializer/PostSerializer.php b/framework/core/src/Api/Serializer/PostSerializer.php index cb6a40457..4290c5b03 100644 --- a/framework/core/src/Api/Serializer/PostSerializer.php +++ b/framework/core/src/Api/Serializer/PostSerializer.php @@ -85,7 +85,7 @@ class PostSerializer extends PostBasicSerializer */ protected function discussion($post) { - return $this->hasOne($post, 'Flarum\Api\Serializer\DiscussionSerializer'); + return $this->hasOne($post, 'Flarum\Api\Serializer\DiscussionBasicSerializer'); } /** @@ -93,7 +93,7 @@ class PostSerializer extends PostBasicSerializer */ protected function editUser($post) { - return $this->hasOne($post, 'Flarum\Api\Serializer\UserSerializer'); + return $this->hasOne($post, 'Flarum\Api\Serializer\UserBasicSerializer'); } /** @@ -101,6 +101,6 @@ class PostSerializer extends PostBasicSerializer */ protected function hideUser($post) { - return $this->hasOne($post, 'Flarum\Api\Serializer\UserSerializer'); + return $this->hasOne($post, 'Flarum\Api\Serializer\UserBasicSerializer'); } } From 19794bb19b154aba8fbb11a0e4f52e43f2597d3a Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Sun, 12 Nov 2017 21:14:19 +1030 Subject: [PATCH 079/172] Performance: Assign parent discussions to posts so they don't have to be reloaded --- framework/core/src/Core/Repository/PostRepository.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/framework/core/src/Core/Repository/PostRepository.php b/framework/core/src/Core/Repository/PostRepository.php index 7ce6b0906..93f74a7ce 100644 --- a/framework/core/src/Core/Repository/PostRepository.php +++ b/framework/core/src/Core/Repository/PostRepository.php @@ -153,7 +153,7 @@ class PostRepository { $discussions = $this->getDiscussionsForPosts($ids, $actor); - return Post::whereIn('id', $ids) + $posts = Post::whereIn('id', $ids) ->where(function ($query) use ($discussions, $actor) { foreach ($discussions as $discussion) { $query->orWhere(function ($query) use ($discussion, $actor) { @@ -165,6 +165,12 @@ class PostRepository $query->orWhereRaw('FALSE'); }); + + foreach ($posts as $post) { + $post->discussion = $discussions->find($post->discussion_id); + } + + return $posts; } /** From 78dafa76c5cfe708334949fff8eb1f20d4d6e67c Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Mon, 20 Nov 2017 09:17:44 +1030 Subject: [PATCH 080/172] Fix email gambit --- framework/core/src/Core/Search/User/Gambit/EmailGambit.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/framework/core/src/Core/Search/User/Gambit/EmailGambit.php b/framework/core/src/Core/Search/User/Gambit/EmailGambit.php index 8d14fd921..b175b6193 100644 --- a/framework/core/src/Core/Search/User/Gambit/EmailGambit.php +++ b/framework/core/src/Core/Search/User/Gambit/EmailGambit.php @@ -60,8 +60,6 @@ class EmailGambit extends AbstractRegexGambit $email = trim($matches[1], '"'); - $user = $this->users->findByEmail($email); - - $search->getQuery()->where('id', $negate ? '!=' : '=', $user->id); + $search->getQuery()->where('email', $negate ? '!=' : '=', $email); } } From 95285a9a543d0a8d06887101e7787197cdd30b26 Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Mon, 20 Nov 2017 10:37:21 +1030 Subject: [PATCH 081/172] Actually list users returned from the API when searching --- framework/core/js/forum/dist/app.js | 95 +++++++++++++++---- .../forum/src/components/UsersSearchSource.js | 13 ++- 2 files changed, 85 insertions(+), 23 deletions(-) diff --git a/framework/core/js/forum/dist/app.js b/framework/core/js/forum/dist/app.js index 21e7cf8ef..9ae4848fa 100644 --- a/framework/core/js/forum/dist/app.js +++ b/framework/core/js/forum/dist/app.js @@ -18948,6 +18948,13 @@ System.register('flarum/components/AvatarEditor', ['flarum/Component', 'flarum/h * @type {Boolean} */ this.loading = false; + + /** + * Whether or not an image has been dragged over the dropzone. + * + * @type {Boolean} + */ + this.isDraggedOver = false; } }, { key: 'view', @@ -18956,14 +18963,19 @@ System.register('flarum/components/AvatarEditor', ['flarum/Component', 'flarum/h return m( 'div', - { className: 'AvatarEditor Dropdown ' + this.props.className + (this.loading ? ' loading' : '') }, + { className: 'AvatarEditor Dropdown ' + this.props.className + (this.loading ? ' loading' : '') + (this.isDraggedOver ? ' dragover' : '') }, avatar(user), m( 'a', { className: user.avatarUrl() ? "Dropdown-toggle" : "Dropdown-toggle AvatarEditor--noAvatar", title: app.translator.trans('core.forum.user.avatar_upload_tooltip'), 'data-toggle': 'dropdown', - onclick: this.quickUpload.bind(this) }, + onclick: this.quickUpload.bind(this), + ondragover: this.enableDragover.bind(this), + ondragenter: this.enableDragover.bind(this), + ondragleave: this.disableDragover.bind(this), + ondragend: this.disableDragover.bind(this), + ondrop: this.dropUpload.bind(this) }, this.loading ? LoadingIndicator.component() : user.avatarUrl() ? icon('pencil') : icon('plus-circle') ), m( @@ -18981,7 +18993,7 @@ System.register('flarum/components/AvatarEditor', ['flarum/Component', 'flarum/h items.add('upload', Button.component({ icon: 'upload', children: app.translator.trans('core.forum.user.avatar_upload_button'), - onclick: this.upload.bind(this) + onclick: this.openPicker.bind(this) })); items.add('remove', Button.component({ @@ -18992,18 +19004,40 @@ System.register('flarum/components/AvatarEditor', ['flarum/Component', 'flarum/h return items; } + }, { + key: 'enableDragover', + value: function enableDragover(e) { + e.preventDefault(); + e.stopPropagation(); + this.isDraggedOver = true; + } + }, { + key: 'disableDragover', + value: function disableDragover(e) { + e.preventDefault(); + e.stopPropagation(); + this.isDraggedOver = false; + } + }, { + key: 'dropUpload', + value: function dropUpload(e) { + e.preventDefault(); + e.stopPropagation(); + this.isDraggedOver = false; + this.upload(e.dataTransfer.files[0]); + } }, { key: 'quickUpload', value: function quickUpload(e) { if (!this.props.user.avatarUrl()) { e.preventDefault(); e.stopPropagation(); - this.upload(); + this.openPicker(); } } }, { - key: 'upload', - value: function upload() { + key: 'openPicker', + value: function openPicker() { var _this2 = this; if (this.loading) return; @@ -19014,22 +19048,30 @@ System.register('flarum/components/AvatarEditor', ['flarum/Component', 'flarum/h var $input = $('<input type="file">'); $input.appendTo('body').hide().click().on('change', function (e) { - var data = new FormData(); - data.append('avatar', $(e.target)[0].files[0]); - - _this2.loading = true; - m.redraw(); - - app.request({ - method: 'POST', - url: app.forum.attribute('apiUrl') + '/users/' + user.id() + '/avatar', - serialize: function serialize(raw) { - return raw; - }, - data: data - }).then(_this2.success.bind(_this2), _this2.failure.bind(_this2)); + _this2.upload($(e.target)[0].files[0]); }); } + }, { + key: 'upload', + value: function upload(file) { + if (this.loading) return; + + var user = this.props.user; + var data = new FormData(); + data.append('avatar', file); + + this.loading = true; + m.redraw(); + + app.request({ + method: 'POST', + url: app.forum.attribute('apiUrl') + '/users/' + user.id() + '/avatar', + serialize: function serialize(raw) { + return raw; + }, + data: data + }).then(this.success.bind(this), this.failure.bind(this)); + } }, { key: 'remove', value: function remove() { @@ -27955,14 +27997,21 @@ System.register('flarum/components/UsersSearchSource', ['flarum/helpers/highligh UsersSearchResults = function () { function UsersSearchResults() { babelHelpers.classCallCheck(this, UsersSearchResults); + + this.results = {}; } babelHelpers.createClass(UsersSearchResults, [{ key: 'search', value: function search(query) { + var _this = this; + return app.store.find('users', { filter: { q: query }, page: { limit: 5 } + }).then(function (results) { + _this.results[query] = results; + m.redraw(); }); } }, { @@ -27970,10 +28019,14 @@ System.register('flarum/components/UsersSearchSource', ['flarum/helpers/highligh value: function view(query) { query = query.toLowerCase(); - var results = app.store.all('users').filter(function (user) { + var results = (this.results[query] || []).concat(app.store.all('users').filter(function (user) { return [user.username(), user.displayName()].some(function (value) { return value.toLowerCase().substr(0, query.length) === query; }); + })).filter(function (e, i, arr) { + return arr.lastIndexOf(e) === i; + }).sort(function (a, b) { + return a.displayName().localeCompare(b.displayName()); }); if (!results.length) return ''; diff --git a/framework/core/js/forum/src/components/UsersSearchSource.js b/framework/core/js/forum/src/components/UsersSearchSource.js index 7f687b811..69cc98a6f 100644 --- a/framework/core/js/forum/src/components/UsersSearchSource.js +++ b/framework/core/js/forum/src/components/UsersSearchSource.js @@ -9,18 +9,27 @@ import username from 'flarum/helpers/username'; * @implements SearchSource */ export default class UsersSearchResults { + constructor() { + this.results = {}; + } + search(query) { return app.store.find('users', { filter: {q: query}, page: {limit: 5} + }).then(results => { + this.results[query] = results; + m.redraw(); }); } view(query) { query = query.toLowerCase(); - const results = app.store.all('users') - .filter(user => [user.username(), user.displayName()].some(value => value.toLowerCase().substr(0, query.length) === query)); + const results = (this.results[query] || []) + .concat(app.store.all('users').filter(user => [user.username(), user.displayName()].some(value => value.toLowerCase().substr(0, query.length) === query))) + .filter((e, i, arr) => arr.lastIndexOf(e) === i) + .sort((a, b) => a.displayName().localeCompare(b.displayName())); if (!results.length) return ''; From 4c94ad5df41a2598a60b2b4bcb57b62ff677febd Mon Sep 17 00:00:00 2001 From: Daniel Klabbers <daniel@productip.com> Date: Mon, 27 Nov 2017 09:49:19 +0100 Subject: [PATCH 082/172] applied laravel contract --- framework/core/src/Locale/LocaleServiceProvider.php | 10 +++++----- framework/core/src/Locale/Translator.php | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/framework/core/src/Locale/LocaleServiceProvider.php b/framework/core/src/Locale/LocaleServiceProvider.php index 05484575b..76a7081ab 100644 --- a/framework/core/src/Locale/LocaleServiceProvider.php +++ b/framework/core/src/Locale/LocaleServiceProvider.php @@ -14,11 +14,10 @@ namespace Flarum\Locale; use Flarum\Event\ConfigureLocales; use Flarum\Foundation\AbstractServiceProvider; use Illuminate\Contracts\Events\Dispatcher; -use Illuminate\Translation\Translator; -use Illuminate\Translation\FileLoader; -//use Symfony\Component\Translation\MessageSelector; -//use Symfony\Component\Translation\Translator; -//use Symfony\Component\Translation\TranslatorInterface; +use Illuminate\Contracts\Translation\Translator as TranslatorContract; +use Symfony\Component\Translation\MessageSelector; +use Symfony\Component\Translation\Translator; +use Symfony\Component\Translation\TranslatorInterface; class LocaleServiceProvider extends AbstractServiceProvider { @@ -53,6 +52,7 @@ class LocaleServiceProvider extends AbstractServiceProvider }); $this->app->alias('translator', Translator::class); $this->app->alias('translator', TranslatorInterface::class); + $this->app->alias('translator', TranslatorContract::class); } private function getDefaultLocale() diff --git a/framework/core/src/Locale/Translator.php b/framework/core/src/Locale/Translator.php index 0e68b8280..b80ba7966 100644 --- a/framework/core/src/Locale/Translator.php +++ b/framework/core/src/Locale/Translator.php @@ -13,8 +13,9 @@ namespace Flarum\Locale; use Symfony\Component\Translation\MessageCatalogueInterface; use Symfony\Component\Translation\Translator as BaseTranslator; +use Illuminate\Contracts\Translation\Translator as TranslatorContract; -class Translator extends BaseTranslator +class Translator extends BaseTranslator implements TranslatorContract { const REFERENCE_REGEX = '/^=>\s*([a-z0-9_\-\.]+)$/i'; From 386416c017248ee09df846f57d58b766004342c2 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers <daniel@productip.com> Date: Mon, 27 Nov 2017 10:35:57 +0100 Subject: [PATCH 083/172] fixed alias/reference loading for translation strings --- framework/core/src/Locale/LocaleManager.php | 9 +++++---- framework/core/src/Locale/LocaleServiceProvider.php | 9 +++------ framework/core/src/Locale/Translator.php | 1 - 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/framework/core/src/Locale/LocaleManager.php b/framework/core/src/Locale/LocaleManager.php index 7be082085..837cd80ee 100644 --- a/framework/core/src/Locale/LocaleManager.php +++ b/framework/core/src/Locale/LocaleManager.php @@ -11,12 +11,13 @@ namespace Flarum\Locale; -use Symfony\Component\Translation\Translator as SymfonyTranslator; + +use Illuminate\Contracts\Translation\Translator; class LocaleManager { /** - * @var SymfonyTranslator + * @var Translator */ protected $translator; @@ -27,9 +28,9 @@ class LocaleManager protected $css = []; /** - * @param SymfonyTranslator $translator + * @param Translator $translator */ - public function __construct(SymfonyTranslator $translator) + public function __construct(Translator $translator) { $this->translator = $translator; } diff --git a/framework/core/src/Locale/LocaleServiceProvider.php b/framework/core/src/Locale/LocaleServiceProvider.php index 76a7081ab..ac179c52a 100644 --- a/framework/core/src/Locale/LocaleServiceProvider.php +++ b/framework/core/src/Locale/LocaleServiceProvider.php @@ -16,7 +16,6 @@ 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\Translator; use Symfony\Component\Translation\TranslatorInterface; class LocaleServiceProvider extends AbstractServiceProvider @@ -42,10 +41,8 @@ class LocaleServiceProvider extends AbstractServiceProvider $this->app->alias(LocaleManager::class, 'flarum.localeManager'); $this->app->singleton('translator', function () { - $defaultLocale = $this->getDefaultLocale(); - - $translator = new Translator($defaultLocale, new MessageSelector()); - $translator->setFallbackLocales([$defaultLocale, 'en']); + $translator = new Translator($this->getDefaultLocale(), new MessageSelector()); + $translator->setFallbackLocales(['en']); $translator->addLoader('prefixed_yaml', new PrefixedYamlFileLoader()); return $translator; @@ -55,7 +52,7 @@ class LocaleServiceProvider extends AbstractServiceProvider $this->app->alias('translator', TranslatorContract::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 b80ba7966..4e3668a4b 100644 --- a/framework/core/src/Locale/Translator.php +++ b/framework/core/src/Locale/Translator.php @@ -29,7 +29,6 @@ class Translator extends BaseTranslator implements TranslatorContract } else { $this->assertValidLocale($locale); } - $parse = ! isset($this->catalogues[$locale]); $catalogue = parent::getCatalogue($locale); From c8e1d717029d19769b0d2eed4b687eec06e51d5f Mon Sep 17 00:00:00 2001 From: Daniel Klabbers <daniel@productip.com> Date: Mon, 27 Nov 2017 10:42:16 +0100 Subject: [PATCH 084/172] replaced the Symfony\Component\Translation\TranslationInterface with the Illuminate\Contracts\Translation\Translator, deprecating the Symfony version --- .../Api/Controller/SendConfirmationEmailController.php | 8 ++++---- framework/core/src/Api/Serializer/GroupSerializer.php | 8 ++++---- .../core/src/Forum/Controller/ResetPasswordController.php | 6 +++--- framework/core/src/Foundation/AbstractValidator.php | 8 ++++---- framework/core/src/Install/Console/InstallCommand.php | 4 ++-- framework/core/src/Locale/LocaleServiceProvider.php | 2 -- .../core/src/User/Command/RequestPasswordResetHandler.php | 8 ++++---- framework/core/src/User/EmailConfirmationMailer.php | 8 ++++---- 8 files changed, 25 insertions(+), 27 deletions(-) diff --git a/framework/core/src/Api/Controller/SendConfirmationEmailController.php b/framework/core/src/Api/Controller/SendConfirmationEmailController.php index 2935f0067..8140fa997 100644 --- a/framework/core/src/Api/Controller/SendConfirmationEmailController.php +++ b/framework/core/src/Api/Controller/SendConfirmationEmailController.php @@ -20,7 +20,7 @@ use Flarum\User\Exception\PermissionDeniedException; use Illuminate\Contracts\Mail\Mailer; use Illuminate\Mail\Message; use Psr\Http\Message\ServerRequestInterface; -use Symfony\Component\Translation\TranslatorInterface; +use Illuminate\Contracts\Translation\Translator; use Zend\Diactoros\Response\EmptyResponse; class SendConfirmationEmailController implements ControllerInterface @@ -43,7 +43,7 @@ class SendConfirmationEmailController implements ControllerInterface protected $url; /** - * @var TranslatorInterface + * @var Translator */ protected $translator; @@ -51,9 +51,9 @@ class SendConfirmationEmailController implements ControllerInterface * @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; diff --git a/framework/core/src/Api/Serializer/GroupSerializer.php b/framework/core/src/Api/Serializer/GroupSerializer.php index 7cd1eb989..820803223 100644 --- a/framework/core/src/Api/Serializer/GroupSerializer.php +++ b/framework/core/src/Api/Serializer/GroupSerializer.php @@ -13,7 +13,7 @@ namespace Flarum\Api\Serializer; use Flarum\Group\Group; use InvalidArgumentException; -use Symfony\Component\Translation\TranslatorInterface; +use Illuminate\Contracts\Translation\Translator; class GroupSerializer extends AbstractSerializer { @@ -23,14 +23,14 @@ class GroupSerializer extends AbstractSerializer protected $type = 'groups'; /** - * @var TranslatorInterface + * @var Translator */ private $translator; /** - * @param TranslatorInterface $translator + * @param Translator $translator */ - public function __construct(TranslatorInterface $translator) + public function __construct(Translator $translator) { $this->translator = $translator; } diff --git a/framework/core/src/Forum/Controller/ResetPasswordController.php b/framework/core/src/Forum/Controller/ResetPasswordController.php index 641da9b42..4a737b497 100644 --- a/framework/core/src/Forum/Controller/ResetPasswordController.php +++ b/framework/core/src/Forum/Controller/ResetPasswordController.php @@ -17,7 +17,7 @@ use Flarum\User\Exception\InvalidConfirmationTokenException; use Flarum\User\PasswordToken; use Illuminate\Contracts\View\Factory; use Psr\Http\Message\ServerRequestInterface as Request; -use Symfony\Component\Translation\TranslatorInterface; +use Illuminate\Contracts\Translation\Translator; class ResetPasswordController extends AbstractHtmlController { @@ -27,14 +27,14 @@ class ResetPasswordController extends AbstractHtmlController protected $view; /** - * @var TranslatorInterface + * @var Translator */ protected $translator; /** * @param Factory $view */ - public function __construct(Factory $view, TranslatorInterface $translator) + public function __construct(Factory $view, Translator $translator) { $this->view = $view; $this->translator = $translator; diff --git a/framework/core/src/Foundation/AbstractValidator.php b/framework/core/src/Foundation/AbstractValidator.php index ee1062af5..4d1a1fd4e 100644 --- a/framework/core/src/Foundation/AbstractValidator.php +++ b/framework/core/src/Foundation/AbstractValidator.php @@ -15,7 +15,7 @@ use Flarum\Foundation\Event\Validating; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Validation\ValidationException; use Illuminate\Validation\Factory; -use Symfony\Component\Translation\TranslatorInterface; +use Illuminate\Contracts\Translation\Translator; abstract class AbstractValidator { @@ -35,16 +35,16 @@ abstract class AbstractValidator protected $events; /** - * @var TranslatorInterface + * @var Translator */ protected $translator; /** * @param Factory $validator * @param Dispatcher $events - * @param TranslatorInterface $translator + * @param Translator $translator */ - public function __construct(Factory $validator, Dispatcher $events, TranslatorInterface $translator) + public function __construct(Factory $validator, Dispatcher $events, Translator $translator) { $this->validator = $validator; $this->events = $events; diff --git a/framework/core/src/Install/Console/InstallCommand.php b/framework/core/src/Install/Console/InstallCommand.php index 6c628fcbd..de49c11f6 100644 --- a/framework/core/src/Install/Console/InstallCommand.php +++ b/framework/core/src/Install/Console/InstallCommand.php @@ -36,7 +36,7 @@ use Illuminate\Filesystem\Filesystem; use Illuminate\Validation\Factory; use PDO; use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Translation\TranslatorInterface; +use Illuminate\Contracts\Translation\Translator; class InstallCommand extends AbstractCommand { @@ -409,7 +409,7 @@ class InstallCommand extends AbstractCommand */ protected function getValidator() { - return new Factory($this->application->make(TranslatorInterface::class)); + return new Factory($this->application->make(Translator::class)); } protected function showErrors($errors) diff --git a/framework/core/src/Locale/LocaleServiceProvider.php b/framework/core/src/Locale/LocaleServiceProvider.php index ac179c52a..35b52eef7 100644 --- a/framework/core/src/Locale/LocaleServiceProvider.php +++ b/framework/core/src/Locale/LocaleServiceProvider.php @@ -16,7 +16,6 @@ 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 { @@ -48,7 +47,6 @@ class LocaleServiceProvider extends AbstractServiceProvider return $translator; }); $this->app->alias('translator', Translator::class); - $this->app->alias('translator', TranslatorInterface::class); $this->app->alias('translator', TranslatorContract::class); } diff --git a/framework/core/src/User/Command/RequestPasswordResetHandler.php b/framework/core/src/User/Command/RequestPasswordResetHandler.php index c0ac0c7fd..fc03314d4 100644 --- a/framework/core/src/User/Command/RequestPasswordResetHandler.php +++ b/framework/core/src/User/Command/RequestPasswordResetHandler.php @@ -20,7 +20,7 @@ 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\Contracts\Translation\Translator; class RequestPasswordResetHandler { @@ -45,7 +45,7 @@ class RequestPasswordResetHandler protected $url; /** - * @var TranslatorInterface + * @var Translator */ protected $translator; @@ -59,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( @@ -67,7 +67,7 @@ class RequestPasswordResetHandler SettingsRepositoryInterface $settings, Mailer $mailer, UrlGenerator $url, - TranslatorInterface $translator, + Translator $translator, Factory $validatorFactory ) { $this->users = $users; diff --git a/framework/core/src/User/EmailConfirmationMailer.php b/framework/core/src/User/EmailConfirmationMailer.php index 3273690b1..59b892ad3 100755 --- a/framework/core/src/User/EmailConfirmationMailer.php +++ b/framework/core/src/User/EmailConfirmationMailer.php @@ -18,7 +18,7 @@ use Flarum\User\Event\Registered; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Mail\Mailer; use Illuminate\Mail\Message; -use Symfony\Component\Translation\TranslatorInterface; +use Illuminate\Contracts\Translation\Translator; class EmailConfirmationMailer { @@ -38,7 +38,7 @@ class EmailConfirmationMailer protected $url; /** - * @var TranslatorInterface + * @var Translator */ protected $translator; @@ -46,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; From 2e571c425ad96cce5be077d086028977d37d5d4b Mon Sep 17 00:00:00 2001 From: Daniel Klabbers <daniel@productip.com> Date: Mon, 27 Nov 2017 11:05:15 +0100 Subject: [PATCH 085/172] pleasing the angry god Circle --- .../Controller/SendConfirmationEmailController.php | 2 +- framework/core/src/Api/Serializer/GroupSerializer.php | 2 +- framework/core/src/Bus/Dispatcher.php | 11 ++++++++++- .../core/src/Database/DatabaseServiceProvider.php | 1 - .../src/Forum/Controller/ResetPasswordController.php | 2 +- framework/core/src/Foundation/AbstractValidator.php | 2 +- framework/core/src/Install/Console/InstallCommand.php | 2 +- framework/core/src/Locale/LocaleManager.php | 1 - framework/core/src/Locale/Translator.php | 2 +- .../src/User/Command/RequestPasswordResetHandler.php | 2 +- framework/core/src/User/EmailConfirmationMailer.php | 2 +- .../IlluminateValidationExceptionHandlerTest.php | 2 +- 12 files changed, 19 insertions(+), 12 deletions(-) diff --git a/framework/core/src/Api/Controller/SendConfirmationEmailController.php b/framework/core/src/Api/Controller/SendConfirmationEmailController.php index 8140fa997..dd9e37afa 100644 --- a/framework/core/src/Api/Controller/SendConfirmationEmailController.php +++ b/framework/core/src/Api/Controller/SendConfirmationEmailController.php @@ -18,9 +18,9 @@ use Flarum\User\AssertPermissionTrait; use Flarum\User\EmailToken; use Flarum\User\Exception\PermissionDeniedException; use Illuminate\Contracts\Mail\Mailer; +use Illuminate\Contracts\Translation\Translator; use Illuminate\Mail\Message; use Psr\Http\Message\ServerRequestInterface; -use Illuminate\Contracts\Translation\Translator; use Zend\Diactoros\Response\EmptyResponse; class SendConfirmationEmailController implements ControllerInterface diff --git a/framework/core/src/Api/Serializer/GroupSerializer.php b/framework/core/src/Api/Serializer/GroupSerializer.php index 820803223..94bf6b80f 100644 --- a/framework/core/src/Api/Serializer/GroupSerializer.php +++ b/framework/core/src/Api/Serializer/GroupSerializer.php @@ -12,8 +12,8 @@ namespace Flarum\Api\Serializer; use Flarum\Group\Group; -use InvalidArgumentException; use Illuminate\Contracts\Translation\Translator; +use InvalidArgumentException; class GroupSerializer extends AbstractSerializer { diff --git a/framework/core/src/Bus/Dispatcher.php b/framework/core/src/Bus/Dispatcher.php index 13a3839ed..c0836d129 100644 --- a/framework/core/src/Bus/Dispatcher.php +++ b/framework/core/src/Bus/Dispatcher.php @@ -1,5 +1,14 @@ <?php +/* + * This file is part of Flarum. + * + * (c) Toby Zerner <toby.zerner@gmail.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Flarum\Bus; use Illuminate\Bus\Dispatcher as BaseDispatcher; @@ -8,7 +17,7 @@ class Dispatcher extends BaseDispatcher { public function getCommandHandler($command) { - $handler = get_class($command) . 'Handler'; + $handler = get_class($command).'Handler'; if (class_exists($handler)) { return $this->container->make($handler); diff --git a/framework/core/src/Database/DatabaseServiceProvider.php b/framework/core/src/Database/DatabaseServiceProvider.php index e54fb3e8e..8d3c08262 100644 --- a/framework/core/src/Database/DatabaseServiceProvider.php +++ b/framework/core/src/Database/DatabaseServiceProvider.php @@ -14,7 +14,6 @@ namespace Flarum\Database; use Flarum\Foundation\AbstractServiceProvider; use Illuminate\Database\ConnectionResolver; use Illuminate\Database\Connectors\ConnectionFactory; -use PDO; class DatabaseServiceProvider extends AbstractServiceProvider { diff --git a/framework/core/src/Forum/Controller/ResetPasswordController.php b/framework/core/src/Forum/Controller/ResetPasswordController.php index 4a737b497..0be98834d 100644 --- a/framework/core/src/Forum/Controller/ResetPasswordController.php +++ b/framework/core/src/Forum/Controller/ResetPasswordController.php @@ -15,9 +15,9 @@ use DateTime; use Flarum\Http\Controller\AbstractHtmlController; use Flarum\User\Exception\InvalidConfirmationTokenException; use Flarum\User\PasswordToken; +use Illuminate\Contracts\Translation\Translator; use Illuminate\Contracts\View\Factory; use Psr\Http\Message\ServerRequestInterface as Request; -use Illuminate\Contracts\Translation\Translator; class ResetPasswordController extends AbstractHtmlController { diff --git a/framework/core/src/Foundation/AbstractValidator.php b/framework/core/src/Foundation/AbstractValidator.php index 4d1a1fd4e..90b3af47c 100644 --- a/framework/core/src/Foundation/AbstractValidator.php +++ b/framework/core/src/Foundation/AbstractValidator.php @@ -13,9 +13,9 @@ namespace Flarum\Foundation; use Flarum\Foundation\Event\Validating; use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Contracts\Translation\Translator; use Illuminate\Contracts\Validation\ValidationException; use Illuminate\Validation\Factory; -use Illuminate\Contracts\Translation\Translator; abstract class AbstractValidator { diff --git a/framework/core/src/Install/Console/InstallCommand.php b/framework/core/src/Install/Console/InstallCommand.php index de49c11f6..61c473f72 100644 --- a/framework/core/src/Install/Console/InstallCommand.php +++ b/framework/core/src/Install/Console/InstallCommand.php @@ -29,6 +29,7 @@ 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; @@ -36,7 +37,6 @@ use Illuminate\Filesystem\Filesystem; use Illuminate\Validation\Factory; use PDO; use Symfony\Component\Console\Input\InputOption; -use Illuminate\Contracts\Translation\Translator; class InstallCommand extends AbstractCommand { diff --git a/framework/core/src/Locale/LocaleManager.php b/framework/core/src/Locale/LocaleManager.php index 837cd80ee..7bfa4b1eb 100644 --- a/framework/core/src/Locale/LocaleManager.php +++ b/framework/core/src/Locale/LocaleManager.php @@ -11,7 +11,6 @@ namespace Flarum\Locale; - use Illuminate\Contracts\Translation\Translator; class LocaleManager diff --git a/framework/core/src/Locale/Translator.php b/framework/core/src/Locale/Translator.php index 4e3668a4b..718a59e27 100644 --- a/framework/core/src/Locale/Translator.php +++ b/framework/core/src/Locale/Translator.php @@ -11,9 +11,9 @@ namespace Flarum\Locale; +use Illuminate\Contracts\Translation\Translator as TranslatorContract; use Symfony\Component\Translation\MessageCatalogueInterface; use Symfony\Component\Translation\Translator as BaseTranslator; -use Illuminate\Contracts\Translation\Translator as TranslatorContract; class Translator extends BaseTranslator implements TranslatorContract { diff --git a/framework/core/src/User/Command/RequestPasswordResetHandler.php b/framework/core/src/User/Command/RequestPasswordResetHandler.php index fc03314d4..e1bb365bc 100644 --- a/framework/core/src/User/Command/RequestPasswordResetHandler.php +++ b/framework/core/src/User/Command/RequestPasswordResetHandler.php @@ -16,11 +16,11 @@ 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 Illuminate\Contracts\Translation\Translator; class RequestPasswordResetHandler { diff --git a/framework/core/src/User/EmailConfirmationMailer.php b/framework/core/src/User/EmailConfirmationMailer.php index 59b892ad3..fdafc8718 100755 --- a/framework/core/src/User/EmailConfirmationMailer.php +++ b/framework/core/src/User/EmailConfirmationMailer.php @@ -17,8 +17,8 @@ use Flarum\User\Event\EmailChangeRequested; use Flarum\User\Event\Registered; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Mail\Mailer; -use Illuminate\Mail\Message; use Illuminate\Contracts\Translation\Translator; +use Illuminate\Mail\Message; class EmailConfirmationMailer { diff --git a/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php index fb2262624..fbdf16559 100644 --- a/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php +++ b/framework/core/tests/Flarum/Api/Handler/IlluminateValidationExceptionHandlerTest.php @@ -15,8 +15,8 @@ use Exception; use Flarum\Api\ExceptionHandler\IlluminateValidationExceptionHandler; use Illuminate\Translation\ArrayLoader; use Illuminate\Translation\Translator; -use Illuminate\Validation\ValidationException; use Illuminate\Validation\Factory; +use Illuminate\Validation\ValidationException; use Tests\Test\TestCase; class IlluminateValidationExceptionHandlerTest extends TestCase From 4b7eeb2564c8c5b2f6ce999c7239e43c20da704b Mon Sep 17 00:00:00 2001 From: Daniel Klabbers <daniel@productip.com> Date: Mon, 27 Nov 2017 14:03:45 +0100 Subject: [PATCH 086/172] Using Core Translator in Locale Manager, type hinted its methods and removed unnecessary phpdoc --- framework/core/src/Locale/LocaleManager.php | 35 +++++++-------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/framework/core/src/Locale/LocaleManager.php b/framework/core/src/Locale/LocaleManager.php index 7bfa4b1eb..5fdd4d492 100644 --- a/framework/core/src/Locale/LocaleManager.php +++ b/framework/core/src/Locale/LocaleManager.php @@ -11,8 +11,6 @@ namespace Flarum\Locale; -use Illuminate\Contracts\Translation\Translator; - class LocaleManager { /** @@ -26,52 +24,49 @@ class LocaleManager protected $css = []; - /** - * @param Translator $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; } From a7bcc79085e71e7ddbed7d53018e23b541e7bf93 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers <daniel@productip.com> Date: Mon, 27 Nov 2017 14:17:17 +0100 Subject: [PATCH 087/172] patched up the Scope implementation as requested --- .../core/src/Post/RegisteredTypesScope.php | 46 ------------------- 1 file changed, 46 deletions(-) diff --git a/framework/core/src/Post/RegisteredTypesScope.php b/framework/core/src/Post/RegisteredTypesScope.php index 51c04018a..8d27eb4f1 100644 --- a/framework/core/src/Post/RegisteredTypesScope.php +++ b/framework/core/src/Post/RegisteredTypesScope.php @@ -17,62 +17,16 @@ use Illuminate\Database\Eloquent\Scope; class RegisteredTypesScope implements Scope { - /** - * 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)); - } } From 9e9136d9be80d89c97493e5980b4c19525623dca Mon Sep 17 00:00:00 2001 From: Daniel Klabbers <daniel@productip.com> Date: Mon, 27 Nov 2017 14:18:28 +0100 Subject: [PATCH 088/172] re-added a precious line --- framework/core/src/Locale/Translator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/core/src/Locale/Translator.php b/framework/core/src/Locale/Translator.php index 718a59e27..d37f8c8c3 100644 --- a/framework/core/src/Locale/Translator.php +++ b/framework/core/src/Locale/Translator.php @@ -29,6 +29,7 @@ class Translator extends BaseTranslator implements TranslatorContract } else { $this->assertValidLocale($locale); } + $parse = ! isset($this->catalogues[$locale]); $catalogue = parent::getCatalogue($locale); From 6e8b9f88141b8c2404a46fd1307cd9f363d9166e Mon Sep 17 00:00:00 2001 From: Daniel Klabbers <daniel@productip.com> Date: Mon, 27 Nov 2017 14:19:18 +0100 Subject: [PATCH 089/172] must be an empty line --- framework/core/src/Locale/Translator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Locale/Translator.php b/framework/core/src/Locale/Translator.php index d37f8c8c3..70acf299d 100644 --- a/framework/core/src/Locale/Translator.php +++ b/framework/core/src/Locale/Translator.php @@ -29,7 +29,7 @@ class Translator extends BaseTranslator implements TranslatorContract } else { $this->assertValidLocale($locale); } - + $parse = ! isset($this->catalogues[$locale]); $catalogue = parent::getCatalogue($locale); From 35a8fe97f65177d1c7ad7fcbe7c7b2b6098401ed Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Wed, 29 Nov 2017 12:49:09 +1030 Subject: [PATCH 090/172] Restructure views - Use Laravel's view namespacing rather than the full file path - Organise views into directories --- .../core/src/Forum/Controller/DiscussionController.php | 2 +- framework/core/src/Forum/Controller/IndexController.php | 2 +- framework/core/src/Http/WebApp/AbstractWebApp.php | 2 +- framework/core/src/Http/WebApp/WebAppView.php | 6 +++--- framework/core/views/{ => frontend}/admin.blade.php | 0 framework/core/views/{ => frontend}/app.blade.php | 0 framework/core/views/{ => frontend}/content.blade.php | 0 .../core/views/{ => frontend/content}/discussion.blade.php | 0 framework/core/views/{ => frontend/content}/index.blade.php | 0 framework/core/views/{ => frontend}/forum.blade.php | 0 10 files changed, 6 insertions(+), 6 deletions(-) rename framework/core/views/{ => frontend}/admin.blade.php (100%) rename framework/core/views/{ => frontend}/app.blade.php (100%) rename framework/core/views/{ => frontend}/content.blade.php (100%) rename framework/core/views/{ => frontend/content}/discussion.blade.php (100%) rename framework/core/views/{ => frontend/content}/index.blade.php (100%) rename framework/core/views/{ => frontend}/forum.blade.php (100%) diff --git a/framework/core/src/Forum/Controller/DiscussionController.php b/framework/core/src/Forum/Controller/DiscussionController.php index ebc7ab0de..c7bb5dcd9 100644 --- a/framework/core/src/Forum/Controller/DiscussionController.php +++ b/framework/core/src/Forum/Controller/DiscussionController.php @@ -87,7 +87,7 @@ class DiscussionController extends WebAppController $view->title = $document->data->attributes->title; $view->document = $document; - $view->content = app('view')->make('flarum.forum::discussion', compact('document', 'page', 'getResource', 'posts', 'url')); + $view->content = app('view')->make('flarum::frontend.content.discussion', compact('document', 'page', 'getResource', 'posts', 'url')); return $view; } diff --git a/framework/core/src/Forum/Controller/IndexController.php b/framework/core/src/Forum/Controller/IndexController.php index a4c059f34..0a52ed7cd 100644 --- a/framework/core/src/Forum/Controller/IndexController.php +++ b/framework/core/src/Forum/Controller/IndexController.php @@ -68,7 +68,7 @@ class IndexController extends WebAppController $document = $this->getDocument($request->getAttribute('actor'), $params); $view->document = $document; - $view->content = app('view')->make('flarum.forum::index', compact('document', 'page', 'forum')); + $view->content = app('view')->make('flarum::frontend.content.index', compact('document', 'page', 'forum')); return $view; } diff --git a/framework/core/src/Http/WebApp/AbstractWebApp.php b/framework/core/src/Http/WebApp/AbstractWebApp.php index e20ec3cac..68f9b80f5 100644 --- a/framework/core/src/Http/WebApp/AbstractWebApp.php +++ b/framework/core/src/Http/WebApp/AbstractWebApp.php @@ -86,7 +86,7 @@ abstract class AbstractWebApp */ protected function getLayout() { - return __DIR__.'/../../../views/'.$this->getName().'.blade.php'; + return 'flarum::frontend.'.$this->getName(); } /** diff --git a/framework/core/src/Http/WebApp/WebAppView.php b/framework/core/src/Http/WebApp/WebAppView.php index d38e95839..78af25540 100644 --- a/framework/core/src/Http/WebApp/WebAppView.php +++ b/framework/core/src/Http/WebApp/WebAppView.php @@ -287,7 +287,7 @@ class WebAppView $this->view->share('forum', array_get($forum, 'data')); $this->view->share('debug', $this->app->inDebugMode()); - $view = $this->view->file(__DIR__.'/../../../views/app.blade.php'); + $view = $this->view->make('flarum::frontend.app'); $view->title = $this->buildTitle(array_get($forum, 'data.attributes.title')); $view->description = $this->description ?: array_get($forum, 'data.attributes.description'); @@ -336,7 +336,7 @@ class WebAppView protected function buildLayout() { - $view = $this->view->file($this->layout); + $view = $this->view->make($this->layout); $view->content = $this->buildContent(); @@ -345,7 +345,7 @@ class WebAppView protected function buildContent() { - $view = $this->view->file(__DIR__.'/../../../views/content.blade.php'); + $view = $this->view->make('flarum::frontend.content'); $view->content = $this->content; diff --git a/framework/core/views/admin.blade.php b/framework/core/views/frontend/admin.blade.php similarity index 100% rename from framework/core/views/admin.blade.php rename to framework/core/views/frontend/admin.blade.php diff --git a/framework/core/views/app.blade.php b/framework/core/views/frontend/app.blade.php similarity index 100% rename from framework/core/views/app.blade.php rename to framework/core/views/frontend/app.blade.php diff --git a/framework/core/views/content.blade.php b/framework/core/views/frontend/content.blade.php similarity index 100% rename from framework/core/views/content.blade.php rename to framework/core/views/frontend/content.blade.php diff --git a/framework/core/views/discussion.blade.php b/framework/core/views/frontend/content/discussion.blade.php similarity index 100% rename from framework/core/views/discussion.blade.php rename to framework/core/views/frontend/content/discussion.blade.php diff --git a/framework/core/views/index.blade.php b/framework/core/views/frontend/content/index.blade.php similarity index 100% rename from framework/core/views/index.blade.php rename to framework/core/views/frontend/content/index.blade.php diff --git a/framework/core/views/forum.blade.php b/framework/core/views/frontend/forum.blade.php similarity index 100% rename from framework/core/views/forum.blade.php rename to framework/core/views/frontend/forum.blade.php From b43a60280ac80b537720af0171294b19b0a66e83 Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Wed, 29 Nov 2017 12:52:49 +1030 Subject: [PATCH 091/172] New design for reset password view --- .../Controller/ResetPasswordController.php | 14 +-- .../Controller/SavePasswordController.php | 3 +- .../core/src/Forum/ForumServiceProvider.php | 7 ++ .../Middleware/ShareErrorsFromSession.php | 62 ++++++++++ framework/core/views/layouts/basic.blade.php | 106 ++++++++++++++++++ framework/core/views/reset-password.blade.php | 33 ++++++ framework/core/views/reset.blade.php | 37 ------ 7 files changed, 213 insertions(+), 49 deletions(-) create mode 100644 framework/core/src/Http/Middleware/ShareErrorsFromSession.php create mode 100644 framework/core/views/layouts/basic.blade.php create mode 100644 framework/core/views/reset-password.blade.php delete mode 100644 framework/core/views/reset.blade.php diff --git a/framework/core/src/Forum/Controller/ResetPasswordController.php b/framework/core/src/Forum/Controller/ResetPasswordController.php index 42a47b288..1e87fdf0c 100644 --- a/framework/core/src/Forum/Controller/ResetPasswordController.php +++ b/framework/core/src/Forum/Controller/ResetPasswordController.php @@ -26,18 +26,12 @@ class ResetPasswordController extends AbstractHtmlController */ protected $view; - /** - * @var TranslatorInterface - */ - protected $translator; - /** * @param Factory $view */ - public function __construct(Factory $view, TranslatorInterface $translator) + public function __construct(Factory $view) { $this->view = $view; - $this->translator = $translator; } /** @@ -55,10 +49,8 @@ class ResetPasswordController extends AbstractHtmlController throw new InvalidConfirmationTokenException; } - return $this->view->make('flarum::reset') - ->with('translator', $this->translator) + return $this->view->make('flarum.forum::reset-password') ->with('passwordToken', $token->id) - ->with('csrfToken', $request->getAttribute('session')->get('csrf_token')) - ->with('error', $request->getAttribute('session')->get('error')); + ->with('csrfToken', $request->getAttribute('session')->get('csrf_token')); } } diff --git a/framework/core/src/Forum/Controller/SavePasswordController.php b/framework/core/src/Forum/Controller/SavePasswordController.php index 0b36f9779..3a9fc4605 100644 --- a/framework/core/src/Forum/Controller/SavePasswordController.php +++ b/framework/core/src/Forum/Controller/SavePasswordController.php @@ -75,11 +75,12 @@ class SavePasswordController implements ControllerInterface $this->validator->assertValid(compact('password')); $validator = $this->validatorFactory->make($input, ['password' => 'required|confirmed']); + if ($validator->fails()) { throw new ValidationException($validator); } } catch (ValidationException $e) { - $request->getAttribute('session')->set('error', $e->errors()->first()); + $request->getAttribute('session')->set('errors', $e->errors()); return new RedirectResponse($this->url->toRoute('resetPassword', ['token' => $token->id])); } diff --git a/framework/core/src/Forum/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index 43f4c2bed..766cdc618 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -18,6 +18,8 @@ use Flarum\Event\SettingWasSet; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Http\Handler\RouteHandlerFactory; use Flarum\Http\RouteCollection; +use Flarum\Settings\SettingsRepositoryInterface; +use Symfony\Component\Translation\TranslatorInterface; class ForumServiceProvider extends AbstractServiceProvider { @@ -44,6 +46,11 @@ class ForumServiceProvider extends AbstractServiceProvider $this->loadViewsFrom(__DIR__.'/../../views', 'flarum.forum'); + $this->app->make('view')->share([ + 'translator' => $this->app->make(TranslatorInterface::class), + 'settings' => $this->app->make(SettingsRepositoryInterface::class) + ]); + $this->flushWebAppAssetsWhenThemeChanged(); $this->flushWebAppAssetsWhenExtensionsChanged(); diff --git a/framework/core/src/Http/Middleware/ShareErrorsFromSession.php b/framework/core/src/Http/Middleware/ShareErrorsFromSession.php new file mode 100644 index 000000000..4ab83d2f8 --- /dev/null +++ b/framework/core/src/Http/Middleware/ShareErrorsFromSession.php @@ -0,0 +1,62 @@ +<?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 Illuminate\Support\ViewErrorBag; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Psr\Http\Message\ResponseInterface as Response; +use Psr\Http\Message\ServerRequestInterface as Request; +use Zend\Stratigility\MiddlewareInterface; + +/** + * Inspired by Illuminate\View\Middleware\ShareErrorsFromSession + * + * @author Taylor Otwell + */ +class ShareErrorsFromSession implements MiddlewareInterface +{ + /** + * @var ViewFactory + */ + protected $view; + + /** + * @param ViewFactory $view + */ + public function __construct(ViewFactory $view) + { + $this->view = $view; + } + + /** + * {@inheritdoc} + */ + public function __invoke(Request $request, Response $response, callable $out = null) + { + $session = $request->getAttribute('session'); + + // If the current session has an "errors" variable bound to it, we will share + // its value with all view instances so the views can easily access errors + // without having to bind. An empty bag is set when there aren't errors. + $this->view->share( + 'errors', $session->get('errors', new ViewErrorBag) + ); + + // Putting the errors in the view for every view allows the developer to just + // assume that some errors are always available, which is convenient since + // they don't have to continually run checks for the presence of errors. + + $session->remove('errors'); + + return $out ? $out($request, $response) : $response; + } +} + diff --git a/framework/core/views/layouts/basic.blade.php b/framework/core/views/layouts/basic.blade.php new file mode 100644 index 000000000..7143e24c9 --- /dev/null +++ b/framework/core/views/layouts/basic.blade.php @@ -0,0 +1,106 @@ +{{-- TODO: Change below to @php when Laravel is upgraded --}} +<?php + $primaryColor = $settings->get('theme_primary_color', '#000'); +?> + +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + {{-- TODO: Change below to @hasSection when Laravel is upgraded --}} + <title>@if ($__env->hasSection('title')) @yield('title') - @endif{{ $settings->get('forum_title') }} + + + + + + +
+ @yield('content') +
+ + diff --git a/framework/core/views/reset-password.blade.php b/framework/core/views/reset-password.blade.php new file mode 100644 index 000000000..11ac7020e --- /dev/null +++ b/framework/core/views/reset-password.blade.php @@ -0,0 +1,33 @@ +@extends('flarum.forum::layouts.basic') +@inject('url', 'Flarum\Forum\UrlGenerator') + +@section('title', $translator->trans('core.views.reset_password.title')) + +@section('content') + @if ($errors->any()) +
+
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+ @endif + +
+ + + +

+ +

+ +

+ +

+ +

+ +

+
+@endsection diff --git a/framework/core/views/reset.blade.php b/framework/core/views/reset.blade.php deleted file mode 100644 index 671157b38..000000000 --- a/framework/core/views/reset.blade.php +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - Reset Your Password - - - - - -

{{ $translator->trans('core.views.reset.title') }}

- - @if (! empty($error)) -

{{ $error }}

- @endif - -
- - - -

-
- -

- -

-
- -

- -

- -

-
- - From 41a4551d94d6726cace1391de594644adab623b7 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 29 Nov 2017 12:53:39 +1030 Subject: [PATCH 092/172] Make URLs more verbose --- framework/core/src/Forum/ForumServiceProvider.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/core/src/Forum/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index 766cdc618..30741572d 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -114,19 +114,19 @@ class ForumServiceProvider extends AbstractServiceProvider ); $routes->get( - '/confirm/{token}', + '/confirm-email/{token}', 'confirmEmail', $route->toController(Controller\ConfirmEmailController::class) ); $routes->get( - '/reset/{token}', + '/reset-password/{token}', 'resetPassword', $route->toController(Controller\ResetPasswordController::class) ); $routes->post( - '/reset', + '/reset-password', 'savePassword', $route->toController(Controller\SavePasswordController::class) ); From 243275de89d7d8d93ee68024aa1be43c1ff3f253 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 29 Nov 2017 12:54:11 +1030 Subject: [PATCH 093/172] Use HtmlResponse in AbstractHtmlController --- .../src/Http/Controller/AbstractHtmlController.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/framework/core/src/Http/Controller/AbstractHtmlController.php b/framework/core/src/Http/Controller/AbstractHtmlController.php index 1bbb7463d..2f56ed7ef 100644 --- a/framework/core/src/Http/Controller/AbstractHtmlController.php +++ b/framework/core/src/Http/Controller/AbstractHtmlController.php @@ -11,28 +11,30 @@ namespace Flarum\Http\Controller; +use Illuminate\Contracts\Support\Renderable; use Psr\Http\Message\ServerRequestInterface as Request; -use Zend\Diactoros\Response; +use Zend\Diactoros\Response\HtmlResponse; abstract class AbstractHtmlController implements ControllerInterface { /** * @param Request $request - * @return \Zend\Diactoros\Response + * @return HtmlResponse */ public function handle(Request $request) { $view = $this->render($request); - $response = new Response; - $response->getBody()->write($view); + if ($view instanceof Renderable) { + $view = $view->render(); + } - return $response; + return new HtmlResponse($view); } /** * @param Request $request - * @return \Illuminate\Contracts\Support\Renderable + * @return string|Renderable */ abstract protected function render(Request $request); } From 68ca96cb7be702c16deeb761fc37edb5a8868fd7 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 29 Nov 2017 13:03:16 +1030 Subject: [PATCH 094/172] Add log out confirmation if CSRF token is invalid. fixes #1282 --- .../src/Forum/Controller/LogOutController.php | 51 +++++++++++++++---- framework/core/views/log-out.blade.php | 14 +++++ 2 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 framework/core/views/log-out.blade.php diff --git a/framework/core/src/Forum/Controller/LogOutController.php b/framework/core/src/Forum/Controller/LogOutController.php index 1aef40efb..4dbb891cf 100644 --- a/framework/core/src/Forum/Controller/LogOutController.php +++ b/framework/core/src/Forum/Controller/LogOutController.php @@ -18,8 +18,11 @@ use Flarum\Http\Controller\ControllerInterface; use Flarum\Http\Exception\TokenMismatchException; use Flarum\Http\Rememberer; use Flarum\Http\SessionAuthenticator; +use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Contracts\View\Factory; use Psr\Http\Message\ServerRequestInterface as Request; +use Zend\Diactoros\Response\HtmlResponse; use Zend\Diactoros\Response\RedirectResponse; class LogOutController implements ControllerInterface @@ -46,18 +49,38 @@ class LogOutController implements ControllerInterface */ protected $rememberer; + /** + * @var Factory + */ + protected $view; + + /** + * @var SettingsRepositoryInterface + */ + protected $settings; + /** * @param Application $app * @param Dispatcher $events * @param SessionAuthenticator $authenticator * @param Rememberer $rememberer + * @param Factory $view + * @param SettingsRepositoryInterface $settings */ - public function __construct(Application $app, Dispatcher $events, SessionAuthenticator $authenticator, Rememberer $rememberer) - { + public function __construct( + Application $app, + Dispatcher $events, + SessionAuthenticator $authenticator, + Rememberer $rememberer, + Factory $view, + SettingsRepositoryInterface $settings + ) { $this->app = $app; $this->events = $events; $this->authenticator = $authenticator; $this->rememberer = $rememberer; + $this->view = $view; + $this->settings = $settings; } /** @@ -68,17 +91,27 @@ class LogOutController implements ControllerInterface public function handle(Request $request) { $session = $request->getAttribute('session'); - - if (array_get($request->getQueryParams(), 'token') !== $session->get('csrf_token')) { - throw new TokenMismatchException; - } - $actor = $request->getAttribute('actor'); - $this->assertRegistered($actor); - $url = array_get($request->getQueryParams(), 'return', $this->app->url()); + // If there is no user logged in, return to the index. + if ($actor->isGuest()) { + return new RedirectResponse($url); + } + + // If a valid CSRF token hasn't been provided, show a view which will + // allow the user to press a button to complete the log out process. + $csrfToken = $session->get('csrf_token'); + + if (array_get($request->getQueryParams(), 'token') !== $csrfToken) { + $view = $this->view->make('flarum.forum::log-out') + ->with('csrfToken', $csrfToken) + ->with('forumTitle', $this->settings->get('forum_title')); + + return new HtmlResponse($view->render()); + } + $response = new RedirectResponse($url); $this->authenticator->logOut($session); diff --git a/framework/core/views/log-out.blade.php b/framework/core/views/log-out.blade.php new file mode 100644 index 000000000..5f777dda3 --- /dev/null +++ b/framework/core/views/log-out.blade.php @@ -0,0 +1,14 @@ +@extends('flarum.forum::layouts.basic') +@inject('url', 'Flarum\Forum\UrlGenerator') + +@section('title', $translator->trans('core.views.log_out.title')) + +@section('content') +

{{ $translator->trans('core.views.log_out.log_out_confirmation', ['{forum}' => $forumTitle]) }}

+ +

+ + {{ $translator->trans('core.views.log_out.log_out_button') }} + +

+@endsection From ca1f2d8a803adb8ab34fd113cdf348a936ffa12f Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 29 Nov 2017 13:03:55 +1030 Subject: [PATCH 095/172] New design for error pages. closes #252 --- framework/core/error/403.html | 13 -------- framework/core/error/404.html | 13 -------- framework/core/error/500.html | 13 -------- framework/core/error/503.html | 13 -------- framework/core/src/Forum/Server.php | 18 +++++------ .../core/src/Http/Middleware/HandleErrors.php | 30 ++++++------------- framework/core/views/error.blade.php | 22 ++++++++++++++ 7 files changed, 38 insertions(+), 84 deletions(-) delete mode 100644 framework/core/error/403.html delete mode 100644 framework/core/error/404.html delete mode 100644 framework/core/error/500.html delete mode 100644 framework/core/error/503.html create mode 100644 framework/core/views/error.blade.php diff --git a/framework/core/error/403.html b/framework/core/error/403.html deleted file mode 100644 index 1ed30a168..000000000 --- a/framework/core/error/403.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - -

403 Forbidden

-

You do not have permissions to access this page.

- - - \ No newline at end of file diff --git a/framework/core/error/404.html b/framework/core/error/404.html deleted file mode 100644 index 262b80985..000000000 --- a/framework/core/error/404.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - -

404 Not Found

-

Looks like this page could not be found.

- - - \ No newline at end of file diff --git a/framework/core/error/500.html b/framework/core/error/500.html deleted file mode 100644 index f9af9e116..000000000 --- a/framework/core/error/500.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - -

500 Internal Server Error

-

Something went wrong on our server.

- - - diff --git a/framework/core/error/503.html b/framework/core/error/503.html deleted file mode 100644 index 46243a1c5..000000000 --- a/framework/core/error/503.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - -

503 Service Unavailable

-

This forum is down for maintenance.

- - - diff --git a/framework/core/src/Forum/Server.php b/framework/core/src/Forum/Server.php index 893ddc52c..81072e964 100644 --- a/framework/core/src/Forum/Server.php +++ b/framework/core/src/Forum/Server.php @@ -11,11 +11,10 @@ namespace Flarum\Forum; +use Exception; use Flarum\Event\ConfigureMiddleware; use Flarum\Foundation\Application; use Flarum\Http\AbstractServer; -use Flarum\Http\Middleware\HandleErrors; -use Zend\Diactoros\Response\HtmlResponse; use Zend\Stratigility\MiddlewarePipe; class Server extends AbstractServer @@ -29,30 +28,27 @@ class Server extends AbstractServer $pipe->raiseThrowables(); $path = parse_url($app->url(), PHP_URL_PATH); - $errorDir = __DIR__.'/../../error'; + + $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, new HandleErrors($errorDir, $app->make('log'), true)); - - $pipe->pipe($path, $app->make('Flarum\Http\Middleware\StartSession')); $pipe->pipe($path, $app->make('Flarum\Http\Middleware\DispatchRoute', ['routes' => $app->make('flarum.install.routes')])); } elseif ($app->isUpToDate() && ! $app->isDownForMaintenance()) { - $pipe->pipe($path, new HandleErrors($errorDir, $app->make('log'), $app->inDebugMode())); - $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\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 () use ($errorDir) { - return new HtmlResponse(file_get_contents($errorDir.'/503.html', 503)); + $pipe->pipe($path, function () { + throw new Exception('', 503); }); } diff --git a/framework/core/src/Http/Middleware/HandleErrors.php b/framework/core/src/Http/Middleware/HandleErrors.php index 2790584a8..d7302332c 100644 --- a/framework/core/src/Http/Middleware/HandleErrors.php +++ b/framework/core/src/Http/Middleware/HandleErrors.php @@ -13,6 +13,7 @@ namespace Flarum\Http\Middleware; use Exception; use Franzl\Middleware\Whoops\ErrorMiddleware as WhoopsMiddleware; +use Illuminate\Contracts\View\Factory as ViewFactory; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Log\LoggerInterface; @@ -21,9 +22,9 @@ use Zend\Diactoros\Response\HtmlResponse; class HandleErrors { /** - * @var string + * @var ViewFactory */ - protected $templateDir; + protected $view; /** * @var LoggerInterface @@ -36,13 +37,13 @@ class HandleErrors protected $debug; /** - * @param string $templateDir + * @param ViewFactory $view * @param LoggerInterface $logger * @param bool $debug */ - public function __construct($templateDir, LoggerInterface $logger, $debug = false) + public function __construct(ViewFactory $view, LoggerInterface $logger, $debug = false) { - $this->templateDir = $templateDir; + $this->view = $view; $this->logger = $logger; $this->debug = $debug; } @@ -75,7 +76,7 @@ class HandleErrors $status = $errorCode; } - if ($this->debug && ! in_array($errorCode, [403, 404])) { + if ($this->debug) { $whoops = new WhoopsMiddleware; return $whoops($error, $request, $response, $out); @@ -84,21 +85,8 @@ class HandleErrors // Log the exception (with trace) $this->logger->debug($error); - $errorPage = $this->getErrorPage($status); + $view = $this->view->make('flarum::error')->with('error', $error); - return new HtmlResponse($errorPage, $status); - } - - /** - * @param string $status - * @return string - */ - protected function getErrorPage($status) - { - if (! file_exists($errorPage = $this->templateDir."/$status.html")) { - $errorPage = $this->templateDir.'/500.html'; - } - - return file_get_contents($errorPage); + return new HtmlResponse($view->render(), $status); } } diff --git a/framework/core/views/error.blade.php b/framework/core/views/error.blade.php new file mode 100644 index 000000000..c7fca235c --- /dev/null +++ b/framework/core/views/error.blade.php @@ -0,0 +1,22 @@ +@extends('flarum.forum::layouts.basic') + +@section('content') +

+ {{-- TODO: Change below to @php when Laravel is upgraded --}} + trans($key, ['{forum}' => $settings->get('forum_title')]); + + return $translation === $key ? false : $translation; + }; + + if (! $translation = $getTranslationIfExists($error->getCode())) { + if (! $translation = $getTranslationIfExists(500)) { + $translation = 'An error occurred while trying to load this page.'; + } + } + ?> + {{ $translation }} +

+@endsection From 21c9eae502d4015d30d83dab581e57460f8e9c4a Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 29 Nov 2017 13:23:25 +1030 Subject: [PATCH 096/172] Add a "return home" link to 404 errors --- framework/core/src/Http/Middleware/HandleErrors.php | 6 +++++- framework/core/views/error/404.blade.php | 12 ++++++++++++ .../{error.blade.php => error/default.blade.php} | 0 framework/core/views/layouts/basic.blade.php | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 framework/core/views/error/404.blade.php rename framework/core/views/{error.blade.php => error/default.blade.php} (100%) diff --git a/framework/core/src/Http/Middleware/HandleErrors.php b/framework/core/src/Http/Middleware/HandleErrors.php index d7302332c..45b087b03 100644 --- a/framework/core/src/Http/Middleware/HandleErrors.php +++ b/framework/core/src/Http/Middleware/HandleErrors.php @@ -85,7 +85,11 @@ class HandleErrors // Log the exception (with trace) $this->logger->debug($error); - $view = $this->view->make('flarum::error')->with('error', $error); + if (! $this->view->exists($name = 'flarum::error.'.$status)) { + $name = 'flarum::error.default'; + } + + $view = $this->view->make($name)->with('error', $error); return new HtmlResponse($view->render(), $status); } diff --git a/framework/core/views/error/404.blade.php b/framework/core/views/error/404.blade.php new file mode 100644 index 000000000..e54955574 --- /dev/null +++ b/framework/core/views/error/404.blade.php @@ -0,0 +1,12 @@ +@extends('flarum.forum::layouts.basic') + +@section('content') +

+ {{ $translator->trans('core.views.error.404_message') }} +

+

+ + {{ $translator->trans('core.views.error.404_return_link', ['{forum}' => $settings->get('forum_title')]) }} + +

+@endsection diff --git a/framework/core/views/error.blade.php b/framework/core/views/error/default.blade.php similarity index 100% rename from framework/core/views/error.blade.php rename to framework/core/views/error/default.blade.php diff --git a/framework/core/views/layouts/basic.blade.php b/framework/core/views/layouts/basic.blade.php index 7143e24c9..dcaa72d16 100644 --- a/framework/core/views/layouts/basic.blade.php +++ b/framework/core/views/layouts/basic.blade.php @@ -34,6 +34,7 @@ cursor: pointer; color: {{ $primaryColor }}; text-decoration: none; + font-weight: bold; } a:hover { text-decoration: underline; From 034ee27522075ad55db3215576fd06d1e1623c79 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 29 Nov 2017 13:47:00 +1030 Subject: [PATCH 097/172] Preserve return URL when confirming logout --- framework/core/src/Forum/Controller/LogOutController.php | 3 ++- framework/core/views/log-out.blade.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Forum/Controller/LogOutController.php b/framework/core/src/Forum/Controller/LogOutController.php index 4dbb891cf..35bd09af3 100644 --- a/framework/core/src/Forum/Controller/LogOutController.php +++ b/framework/core/src/Forum/Controller/LogOutController.php @@ -107,7 +107,8 @@ class LogOutController implements ControllerInterface if (array_get($request->getQueryParams(), 'token') !== $csrfToken) { $view = $this->view->make('flarum.forum::log-out') ->with('csrfToken', $csrfToken) - ->with('forumTitle', $this->settings->get('forum_title')); + ->with('forumTitle', $this->settings->get('forum_title')) + ->with('return', array_get($request->getQueryParams(), 'return')); return new HtmlResponse($view->render()); } diff --git a/framework/core/views/log-out.blade.php b/framework/core/views/log-out.blade.php index 5f777dda3..988beeeef 100644 --- a/framework/core/views/log-out.blade.php +++ b/framework/core/views/log-out.blade.php @@ -7,7 +7,7 @@

{{ $translator->trans('core.views.log_out.log_out_confirmation', ['{forum}' => $forumTitle]) }}

- + {{ $translator->trans('core.views.log_out.log_out_button') }}

From 93355a3ceba92b1e9accaf3e896fbc7c16dd6c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Wed, 29 Nov 2017 06:26:48 +0100 Subject: [PATCH 098/172] reverting translator contract --- .../Api/Controller/SendConfirmationEmailController.php | 8 ++++---- framework/core/src/Api/Serializer/GroupSerializer.php | 8 ++++---- .../core/src/Forum/Controller/ResetPasswordController.php | 7 ++++--- framework/core/src/Foundation/AbstractValidator.php | 8 ++++---- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/framework/core/src/Api/Controller/SendConfirmationEmailController.php b/framework/core/src/Api/Controller/SendConfirmationEmailController.php index dd9e37afa..2935f0067 100644 --- a/framework/core/src/Api/Controller/SendConfirmationEmailController.php +++ b/framework/core/src/Api/Controller/SendConfirmationEmailController.php @@ -18,9 +18,9 @@ use Flarum\User\AssertPermissionTrait; use Flarum\User\EmailToken; use Flarum\User\Exception\PermissionDeniedException; use Illuminate\Contracts\Mail\Mailer; -use Illuminate\Contracts\Translation\Translator; use Illuminate\Mail\Message; use Psr\Http\Message\ServerRequestInterface; +use Symfony\Component\Translation\TranslatorInterface; use Zend\Diactoros\Response\EmptyResponse; class SendConfirmationEmailController implements ControllerInterface @@ -43,7 +43,7 @@ class SendConfirmationEmailController implements ControllerInterface protected $url; /** - * @var Translator + * @var TranslatorInterface */ protected $translator; @@ -51,9 +51,9 @@ class SendConfirmationEmailController implements ControllerInterface * @param \Flarum\Settings\SettingsRepositoryInterface $settings * @param Mailer $mailer * @param UrlGenerator $url - * @param Translator $translator + * @param TranslatorInterface $translator */ - public function __construct(SettingsRepositoryInterface $settings, Mailer $mailer, UrlGenerator $url, Translator $translator) + public function __construct(SettingsRepositoryInterface $settings, Mailer $mailer, UrlGenerator $url, TranslatorInterface $translator) { $this->settings = $settings; $this->mailer = $mailer; diff --git a/framework/core/src/Api/Serializer/GroupSerializer.php b/framework/core/src/Api/Serializer/GroupSerializer.php index 94bf6b80f..7cd1eb989 100644 --- a/framework/core/src/Api/Serializer/GroupSerializer.php +++ b/framework/core/src/Api/Serializer/GroupSerializer.php @@ -12,8 +12,8 @@ namespace Flarum\Api\Serializer; use Flarum\Group\Group; -use Illuminate\Contracts\Translation\Translator; use InvalidArgumentException; +use Symfony\Component\Translation\TranslatorInterface; class GroupSerializer extends AbstractSerializer { @@ -23,14 +23,14 @@ class GroupSerializer extends AbstractSerializer protected $type = 'groups'; /** - * @var Translator + * @var TranslatorInterface */ private $translator; /** - * @param Translator $translator + * @param TranslatorInterface $translator */ - public function __construct(Translator $translator) + public function __construct(TranslatorInterface $translator) { $this->translator = $translator; } diff --git a/framework/core/src/Forum/Controller/ResetPasswordController.php b/framework/core/src/Forum/Controller/ResetPasswordController.php index 0be98834d..f5f7e9300 100644 --- a/framework/core/src/Forum/Controller/ResetPasswordController.php +++ b/framework/core/src/Forum/Controller/ResetPasswordController.php @@ -15,9 +15,9 @@ use DateTime; use Flarum\Http\Controller\AbstractHtmlController; use Flarum\User\Exception\InvalidConfirmationTokenException; use Flarum\User\PasswordToken; -use Illuminate\Contracts\Translation\Translator; use Illuminate\Contracts\View\Factory; use Psr\Http\Message\ServerRequestInterface as Request; +use Symfony\Component\Translation\TranslatorInterface; class ResetPasswordController extends AbstractHtmlController { @@ -27,14 +27,15 @@ class ResetPasswordController extends AbstractHtmlController protected $view; /** - * @var Translator + * @var TranslatorInterface */ protected $translator; /** * @param Factory $view + * @param TranslatorInterface $translator */ - public function __construct(Factory $view, Translator $translator) + public function __construct(Factory $view, TranslatorInterface $translator) { $this->view = $view; $this->translator = $translator; diff --git a/framework/core/src/Foundation/AbstractValidator.php b/framework/core/src/Foundation/AbstractValidator.php index 90b3af47c..ee1062af5 100644 --- a/framework/core/src/Foundation/AbstractValidator.php +++ b/framework/core/src/Foundation/AbstractValidator.php @@ -13,9 +13,9 @@ namespace Flarum\Foundation; use Flarum\Foundation\Event\Validating; use Illuminate\Contracts\Events\Dispatcher; -use Illuminate\Contracts\Translation\Translator; use Illuminate\Contracts\Validation\ValidationException; use Illuminate\Validation\Factory; +use Symfony\Component\Translation\TranslatorInterface; abstract class AbstractValidator { @@ -35,16 +35,16 @@ abstract class AbstractValidator protected $events; /** - * @var Translator + * @var TranslatorInterface */ protected $translator; /** * @param Factory $validator * @param Dispatcher $events - * @param Translator $translator + * @param TranslatorInterface $translator */ - public function __construct(Factory $validator, Dispatcher $events, Translator $translator) + public function __construct(Factory $validator, Dispatcher $events, TranslatorInterface $translator) { $this->validator = $validator; $this->events = $events; From cb8c6d71bcace83711f1f17e093f2679c3a040ce Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 29 Nov 2017 16:10:22 +1030 Subject: [PATCH 099/172] Fix admin error handling --- framework/core/src/Admin/Server.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/framework/core/src/Admin/Server.php b/framework/core/src/Admin/Server.php index 43aa38116..00b3e686e 100644 --- a/framework/core/src/Admin/Server.php +++ b/framework/core/src/Admin/Server.php @@ -29,11 +29,8 @@ class Server extends AbstractServer if ($app->isInstalled()) { $path = parse_url($app->url('admin'), PHP_URL_PATH); - $errorDir = __DIR__.'/../../error'; - // All requests should first be piped through our global error handler - $debugMode = ! $app->isUpToDate() || $app->inDebugMode(); - $pipe->pipe($path, new HandleErrors($errorDir, $app->make('log'), $debugMode)); + $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')); From 50047851d171bd456740bc2e646dee1fb09351e2 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 29 Nov 2017 17:02:49 +1030 Subject: [PATCH 100/172] More precise permission check for email gambit --- framework/core/src/Core/Search/User/Gambit/EmailGambit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Core/Search/User/Gambit/EmailGambit.php b/framework/core/src/Core/Search/User/Gambit/EmailGambit.php index b175b6193..4f8d1254d 100644 --- a/framework/core/src/Core/Search/User/Gambit/EmailGambit.php +++ b/framework/core/src/Core/Search/User/Gambit/EmailGambit.php @@ -42,7 +42,7 @@ class EmailGambit extends AbstractRegexGambit */ public function apply(AbstractSearch $search, $bit) { - if (! $search->getActor()->isAdmin()) { + if (! $search->getActor()->hasPermission('user.edit')) { return false; } From d592322a61fce840074ceafca77c96818a695e88 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 29 Nov 2017 17:19:20 +1030 Subject: [PATCH 101/172] Basic implementation of dashboard widgets, statistics Currently not user-customizable. Just needed to display statistics for a client, so figured I'd make a start at this. Nothing too fancy for now, but I'm sure some people will be happy to have this information at their fingertips. --- framework/core/js/admin/dist/app.js | 412 +++++++++++++++--- .../js/admin/src/components/DashboardPage.js | 14 +- .../admin/src/components/DashboardWidget.js | 38 ++ .../admin/src/components/StatisticsWidget.js | 60 +++ .../js/admin/src/components/StatusWidget.js | 41 ++ .../core/js/admin/src/components/Widget.js | 38 ++ framework/core/less/admin/DashboardPage.less | 75 +++- .../src/Admin/Controller/WebAppController.php | 43 +- 8 files changed, 646 insertions(+), 75 deletions(-) create mode 100644 framework/core/js/admin/src/components/DashboardWidget.js create mode 100644 framework/core/js/admin/src/components/StatisticsWidget.js create mode 100644 framework/core/js/admin/src/components/StatusWidget.js create mode 100644 framework/core/js/admin/src/components/Widget.js diff --git a/framework/core/js/admin/dist/app.js b/framework/core/js/admin/dist/app.js index bacc3fc03..7d1a68eb7 100644 --- a/framework/core/js/admin/dist/app.js +++ b/framework/core/js/admin/dist/app.js @@ -18358,15 +18358,19 @@ System.register('flarum/components/Checkbox', ['flarum/Component', 'flarum/compo } }; });; -"use strict"; +'use strict'; -System.register("flarum/components/DashboardPage", ["flarum/components/Page"], function (_export, _context) { +System.register('flarum/components/DashboardPage', ['flarum/components/Page', 'flarum/components/StatusWidget', 'flarum/components/StatisticsWidget'], function (_export, _context) { "use strict"; - var Page, DashboardPage; + var Page, StatusWidget, StatisticsWidget, DashboardPage; return { setters: [function (_flarumComponentsPage) { Page = _flarumComponentsPage.default; + }, function (_flarumComponentsStatusWidget) { + StatusWidget = _flarumComponentsStatusWidget.default; + }, function (_flarumComponentsStatisticsWidget) { + StatisticsWidget = _flarumComponentsStatisticsWidget.default; }], execute: function () { DashboardPage = function (_Page) { @@ -18378,62 +18382,16 @@ System.register("flarum/components/DashboardPage", ["flarum/components/Page"], f } babelHelpers.createClass(DashboardPage, [{ - key: "view", + key: 'view', value: function view() { return m( - "div", - { className: "DashboardPage" }, + 'div', + { className: 'DashboardPage' }, m( - "div", - { className: "container" }, - m( - "h2", - null, - app.translator.trans('core.admin.dashboard.welcome_text') - ), - m( - "p", - null, - app.translator.trans('core.admin.dashboard.version_text', { version: m( - "strong", - null, - app.forum.attribute('version') - ) }) - ), - m( - "p", - null, - app.translator.trans('core.admin.dashboard.beta_warning_text', { strong: m("strong", null) }) - ), - m( - "ul", - null, - m( - "li", - null, - app.translator.trans('core.admin.dashboard.contributing_text', { a: m("a", { href: "http://flarum.org/docs/contributing", target: "_blank" }) }) - ), - m( - "li", - null, - app.translator.trans('core.admin.dashboard.troubleshooting_text', { a: m("a", { href: "http://flarum.org/docs/troubleshooting", target: "_blank" }) }) - ), - m( - "li", - null, - app.translator.trans('core.admin.dashboard.support_text', { a: m("a", { href: "http://discuss.flarum.org/t/support", target: "_blank" }) }) - ), - m( - "li", - null, - app.translator.trans('core.admin.dashboard.features_text', { a: m("a", { href: "http://discuss.flarum.org/t/features", target: "_blank" }) }) - ), - m( - "li", - null, - app.translator.trans('core.admin.dashboard.extension_text', { a: m("a", { href: "http://flarum.org/docs/extend", target: "_blank" }) }) - ) - ) + 'div', + { className: 'container' }, + m(StatusWidget, null), + m(StatisticsWidget, null) ) ); } @@ -18441,7 +18399,53 @@ System.register("flarum/components/DashboardPage", ["flarum/components/Page"], f return DashboardPage; }(Page); - _export("default", DashboardPage); + _export('default', DashboardPage); + } + }; +});; +'use strict'; + +System.register('flarum/components/DashboardWidget', ['flarum/Component'], function (_export, _context) { + "use strict"; + + var Component, Widget; + return { + setters: [function (_flarumComponent) { + Component = _flarumComponent.default; + }], + execute: function () { + Widget = function (_Component) { + babelHelpers.inherits(Widget, _Component); + + function Widget() { + babelHelpers.classCallCheck(this, Widget); + return babelHelpers.possibleConstructorReturn(this, (Widget.__proto__ || Object.getPrototypeOf(Widget)).apply(this, arguments)); + } + + babelHelpers.createClass(Widget, [{ + key: 'view', + value: function view() { + return m( + 'div', + { className: "Widget " + this.className() }, + this.content() + ); + } + }, { + key: 'className', + value: function className() { + return ''; + } + }, { + key: 'content', + value: function content() { + return []; + } + }]); + return Widget; + }(Component); + + _export('default', Widget); } }; });; @@ -21108,6 +21112,254 @@ System.register('flarum/components/SplitDropdown', ['flarum/components/Dropdown' });; 'use strict'; +System.register('flarum/components/StatisticsWidget', ['flarum/components/DashboardWidget', 'flarum/helpers/icon', 'flarum/helpers/listItems', 'flarum/utils/ItemList'], function (_export, _context) { + "use strict"; + + var DashboardWidget, icon, listItems, ItemList, StatisticsWidget; + return { + setters: [function (_flarumComponentsDashboardWidget) { + DashboardWidget = _flarumComponentsDashboardWidget.default; + }, function (_flarumHelpersIcon) { + icon = _flarumHelpersIcon.default; + }, function (_flarumHelpersListItems) { + listItems = _flarumHelpersListItems.default; + }, function (_flarumUtilsItemList) { + ItemList = _flarumUtilsItemList.default; + }], + execute: function () { + StatisticsWidget = function (_DashboardWidget) { + babelHelpers.inherits(StatisticsWidget, _DashboardWidget); + + function StatisticsWidget() { + babelHelpers.classCallCheck(this, StatisticsWidget); + return babelHelpers.possibleConstructorReturn(this, (StatisticsWidget.__proto__ || Object.getPrototypeOf(StatisticsWidget)).apply(this, arguments)); + } + + babelHelpers.createClass(StatisticsWidget, [{ + key: 'className', + value: function className() { + return 'StatisticsWidget'; + } + }, { + key: 'content', + value: function content() { + return m( + 'table', + null, + m( + 'thead', + null, + m( + 'tr', + null, + m('th', null), + m( + 'th', + null, + app.translator.trans('core.admin.statistics.users_heading') + ), + m( + 'th', + null, + app.translator.trans('core.admin.statistics.discussions_heading') + ), + m( + 'th', + null, + app.translator.trans('core.admin.statistics.posts_heading') + ) + ) + ), + m( + 'tbody', + null, + m( + 'tr', + { className: 'StatisticsWidget-total' }, + m( + 'th', + null, + app.translator.trans('core.admin.statistics.total_label') + ), + m( + 'td', + null, + app.data.statistics.total.users + ), + m( + 'td', + null, + app.data.statistics.total.discussions + ), + m( + 'td', + null, + app.data.statistics.total.posts + ) + ), + m( + 'tr', + null, + m( + 'th', + null, + app.translator.trans('core.admin.statistics.last_28_days_label') + ), + m( + 'td', + null, + app.data.statistics.month.users + ), + m( + 'td', + null, + app.data.statistics.month.discussions + ), + m( + 'td', + null, + app.data.statistics.month.posts + ) + ), + m( + 'tr', + null, + m( + 'th', + null, + app.translator.trans('core.admin.statistics.last_7_days_label') + ), + m( + 'td', + null, + app.data.statistics.week.users + ), + m( + 'td', + null, + app.data.statistics.week.discussions + ), + m( + 'td', + null, + app.data.statistics.week.posts + ) + ), + m( + 'tr', + null, + m( + 'th', + null, + app.translator.trans('core.admin.statistics.today_label') + ), + m( + 'td', + null, + app.data.statistics.today.users + ), + m( + 'td', + null, + app.data.statistics.today.discussions + ), + m( + 'td', + null, + app.data.statistics.today.posts + ) + ) + ) + ); + } + }]); + return StatisticsWidget; + }(DashboardWidget); + + _export('default', StatisticsWidget); + } + }; +});; +'use strict'; + +System.register('flarum/components/StatusWidget', ['flarum/components/DashboardWidget', 'flarum/helpers/icon', 'flarum/helpers/listItems', 'flarum/utils/ItemList'], function (_export, _context) { + "use strict"; + + var DashboardWidget, icon, listItems, ItemList, StatusWidget; + return { + setters: [function (_flarumComponentsDashboardWidget) { + DashboardWidget = _flarumComponentsDashboardWidget.default; + }, function (_flarumHelpersIcon) { + icon = _flarumHelpersIcon.default; + }, function (_flarumHelpersListItems) { + listItems = _flarumHelpersListItems.default; + }, function (_flarumUtilsItemList) { + ItemList = _flarumUtilsItemList.default; + }], + execute: function () { + StatusWidget = function (_DashboardWidget) { + babelHelpers.inherits(StatusWidget, _DashboardWidget); + + function StatusWidget() { + babelHelpers.classCallCheck(this, StatusWidget); + return babelHelpers.possibleConstructorReturn(this, (StatusWidget.__proto__ || Object.getPrototypeOf(StatusWidget)).apply(this, arguments)); + } + + babelHelpers.createClass(StatusWidget, [{ + key: 'className', + value: function className() { + return 'StatusWidget'; + } + }, { + key: 'content', + value: function content() { + return m( + 'ul', + null, + listItems(this.items().toArray()) + ); + } + }, { + key: 'items', + value: function items() { + var items = new ItemList(); + + items.add('help', m( + 'a', + { href: 'http://flarum.org/docs/troubleshooting', target: '_blank' }, + icon('question-circle'), + ' ', + app.translator.trans('core.admin.dashboard.help_link') + )); + + items.add('version-flarum', [m( + 'strong', + null, + 'Flarum' + ), m('br', null), app.forum.attribute('version')]); + items.add('version-php', [m( + 'strong', + null, + 'PHP' + ), m('br', null), app.data.phpVersion]); + items.add('version-mysql', [m( + 'strong', + null, + 'MySQL' + ), m('br', null), app.data.mysqlVersion]); + + return items; + } + }]); + return StatusWidget; + }(DashboardWidget); + + _export('default', StatusWidget); + } + }; +});; +'use strict'; + System.register('flarum/components/Switch', ['flarum/components/Checkbox'], function (_export, _context) { "use strict"; @@ -21261,6 +21513,52 @@ System.register('flarum/components/UploadImageButton', ['flarum/components/Butto } }; });; +'use strict'; + +System.register('flarum/components/Widget', ['flarum/Component'], function (_export, _context) { + "use strict"; + + var Component, DashboardWidget; + return { + setters: [function (_flarumComponent) { + Component = _flarumComponent.default; + }], + execute: function () { + DashboardWidget = function (_Component) { + babelHelpers.inherits(DashboardWidget, _Component); + + function DashboardWidget() { + babelHelpers.classCallCheck(this, DashboardWidget); + return babelHelpers.possibleConstructorReturn(this, (DashboardWidget.__proto__ || Object.getPrototypeOf(DashboardWidget)).apply(this, arguments)); + } + + babelHelpers.createClass(DashboardWidget, [{ + key: 'view', + value: function view() { + return m( + 'div', + { className: "DashboardWidget " + this.className() }, + this.content() + ); + } + }, { + key: 'className', + value: function className() { + return ''; + } + }, { + key: 'content', + value: function content() { + return []; + } + }]); + return DashboardWidget; + }(Component); + + _export('default', DashboardWidget); + } + }; +});; "use strict"; System.register("flarum/extend", [], function (_export, _context) { diff --git a/framework/core/js/admin/src/components/DashboardPage.js b/framework/core/js/admin/src/components/DashboardPage.js index 0c7207d26..c1a7bd888 100644 --- a/framework/core/js/admin/src/components/DashboardPage.js +++ b/framework/core/js/admin/src/components/DashboardPage.js @@ -1,20 +1,14 @@ import Page from 'flarum/components/Page'; +import StatusWidget from 'flarum/components/StatusWidget'; +import StatisticsWidget from 'flarum/components/StatisticsWidget'; export default class DashboardPage extends Page { view() { return (
-

{app.translator.trans('core.admin.dashboard.welcome_text')}

-

{app.translator.trans('core.admin.dashboard.version_text', {version: {app.forum.attribute('version')}})}

-

{app.translator.trans('core.admin.dashboard.beta_warning_text', {strong: })}

- + +
); diff --git a/framework/core/js/admin/src/components/DashboardWidget.js b/framework/core/js/admin/src/components/DashboardWidget.js new file mode 100644 index 000000000..4e0b0ea96 --- /dev/null +++ b/framework/core/js/admin/src/components/DashboardWidget.js @@ -0,0 +1,38 @@ +/* + * This file is part of Flarum. + * + * (c) Toby Zerner + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +import Component from 'flarum/Component'; + +export default class Widget extends Component { + view() { + return ( +
+ {this.content()} +
+ ); + } + + /** + * Get the class name to apply to the widget. + * + * @return {String} + */ + className() { + return ''; + } + + /** + * Get the content of the widget. + * + * @return {VirtualElement} + */ + content() { + return []; + } +} diff --git a/framework/core/js/admin/src/components/StatisticsWidget.js b/framework/core/js/admin/src/components/StatisticsWidget.js new file mode 100644 index 000000000..a653a3c0c --- /dev/null +++ b/framework/core/js/admin/src/components/StatisticsWidget.js @@ -0,0 +1,60 @@ +/* + * This file is part of Flarum. + * + * (c) Toby Zerner + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +import DashboardWidget from 'flarum/components/DashboardWidget'; +import icon from 'flarum/helpers/icon'; +import listItems from 'flarum/helpers/listItems'; +import ItemList from 'flarum/utils/ItemList'; + +export default class StatisticsWidget extends DashboardWidget { + className() { + return 'StatisticsWidget'; + } + + content() { + return ( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{app.translator.trans('core.admin.statistics.users_heading')}{app.translator.trans('core.admin.statistics.discussions_heading')}{app.translator.trans('core.admin.statistics.posts_heading')}
{app.translator.trans('core.admin.statistics.total_label')}{app.data.statistics.total.users}{app.data.statistics.total.discussions}{app.data.statistics.total.posts}
{app.translator.trans('core.admin.statistics.last_28_days_label')}{app.data.statistics.month.users}{app.data.statistics.month.discussions}{app.data.statistics.month.posts}
{app.translator.trans('core.admin.statistics.last_7_days_label')}{app.data.statistics.week.users}{app.data.statistics.week.discussions}{app.data.statistics.week.posts}
{app.translator.trans('core.admin.statistics.today_label')}{app.data.statistics.today.users}{app.data.statistics.today.discussions}{app.data.statistics.today.posts}
+ ); + } +} diff --git a/framework/core/js/admin/src/components/StatusWidget.js b/framework/core/js/admin/src/components/StatusWidget.js new file mode 100644 index 000000000..429b7a504 --- /dev/null +++ b/framework/core/js/admin/src/components/StatusWidget.js @@ -0,0 +1,41 @@ +/* + * This file is part of Flarum. + * + * (c) Toby Zerner + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +import DashboardWidget from 'flarum/components/DashboardWidget'; +import icon from 'flarum/helpers/icon'; +import listItems from 'flarum/helpers/listItems'; +import ItemList from 'flarum/utils/ItemList'; + +export default class StatusWidget extends DashboardWidget { + className() { + return 'StatusWidget'; + } + + content() { + return ( +
    {listItems(this.items().toArray())}
+ ); + } + + items() { + const items = new ItemList(); + + items.add('help', ( +
+ {icon('question-circle')} {app.translator.trans('core.admin.dashboard.help_link')} + + )); + + items.add('version-flarum', [Flarum,
, app.forum.attribute('version')]); + items.add('version-php', [PHP,
, app.data.phpVersion]); + items.add('version-mysql', [MySQL,
, app.data.mysqlVersion]); + + return items; + } +} diff --git a/framework/core/js/admin/src/components/Widget.js b/framework/core/js/admin/src/components/Widget.js new file mode 100644 index 000000000..df0b2f999 --- /dev/null +++ b/framework/core/js/admin/src/components/Widget.js @@ -0,0 +1,38 @@ +/* + * This file is part of Flarum. + * + * (c) Toby Zerner + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +import Component from 'flarum/Component'; + +export default class DashboardWidget extends Component { + view() { + return ( +
+ {this.content()} +
+ ); + } + + /** + * Get the class name to apply to the widget. + * + * @return {String} + */ + className() { + return ''; + } + + /** + * Get the content of the widget. + * + * @return {VirtualElement} + */ + content() { + return []; + } +} diff --git a/framework/core/less/admin/DashboardPage.less b/framework/core/less/admin/DashboardPage.less index fceee2a30..3c97eedc3 100644 --- a/framework/core/less/admin/DashboardPage.less +++ b/framework/core/less/admin/DashboardPage.less @@ -2,20 +2,81 @@ background: @control-bg; color: @control-color; min-height: 100vh; - font-size: 14px; - line-height: 1.7; @media @desktop-up { .container { - max-width: 600px; padding: 30px; margin: 0; } } +} - h2 { - font-size: 26px; - font-weight: 300; - margin-top: 0; +.Widget { + background: @body-bg; + color: @text-color; + border-radius: @border-radius; + padding: 20px; + margin-bottom: 20px; +} + +.StatusWidget { + color: @muted-color; + + > ul { + margin: 0; + padding: 0; + list-style-type: none; + + > li { + display: inline-block; + margin-right: 30px; + vertical-align: middle; + + &[class^="item-version-"] { + max-width: 100px; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + &.item-help { + float: right; + margin-right: 0; + } + } + } +} + +.StatisticsWidget { + td { + font-size: 14px; + } + td, th { + padding: 5px 20px 5px 0; + text-align: left; + font-weight: normal; + border-bottom: 1px solid @control-bg; + } + tbody tr:last-child { + td, th { + border-bottom: 0; + } + } + th { + color: @muted-color; + } + thead th { + font-weight: bold; + } +} +.StatisticsWidget-total { + td, th { + font-weight: bold; + } +} +@media @tablet-up { + .StatisticsWidget { + td, th { + min-width: 120px; + } } } diff --git a/framework/core/src/Admin/Controller/WebAppController.php b/framework/core/src/Admin/Controller/WebAppController.php index d0870900a..30c660ff3 100644 --- a/framework/core/src/Admin/Controller/WebAppController.php +++ b/framework/core/src/Admin/Controller/WebAppController.php @@ -11,13 +11,18 @@ namespace Flarum\Admin\Controller; +use DateTime; use Flarum\Admin\WebApp; +use Flarum\Core\Discussion; use Flarum\Core\Permission; +use Flarum\Core\Post; +use Flarum\Core\User; use Flarum\Event\PrepareUnserializedSettings; use Flarum\Extension\ExtensionManager; use Flarum\Http\Controller\AbstractWebAppController; use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Database\ConnectionInterface; use Psr\Http\Message\ServerRequestInterface; class WebAppController extends AbstractWebAppController @@ -37,13 +42,15 @@ class WebAppController extends AbstractWebAppController * @param Dispatcher $events * @param SettingsRepositoryInterface $settings * @param ExtensionManager $extensions + * @param ConnectionInterface $db */ - public function __construct(WebApp $webApp, Dispatcher $events, SettingsRepositoryInterface $settings, ExtensionManager $extensions) + public function __construct(WebApp $webApp, Dispatcher $events, SettingsRepositoryInterface $settings, ExtensionManager $extensions, ConnectionInterface $db) { $this->webApp = $webApp; $this->events = $events; $this->settings = $settings; $this->extensions = $extensions; + $this->db = $db; } /** @@ -63,6 +70,40 @@ class WebAppController extends AbstractWebAppController $view->setVariable('permissions', Permission::map()); $view->setVariable('extensions', $this->extensions->getExtensions()->toArray()); + $view->setVariable('phpVersion', PHP_VERSION); + $view->setVariable('mysqlVersion', $this->db->selectOne('select version() as version')->version); + + $view->setVariable('statistics', $this->getStatistics()); + return $view; } + + private function getStatistics() + { + return [ + 'total' => $this->getEntityCounts(), + 'month' => $this->getEntityCounts(new DateTime('-28 days')), + 'week' => $this->getEntityCounts(new DateTime('-7 days')), + 'today' => $this->getEntityCounts(new DateTime('-1 day')) + ]; + } + + private function getEntityCounts($since = null) + { + $queries = [ + 'users' => User::query(), + 'discussions' => Discussion::query(), + 'posts' => Post::where('type', 'comment') + ]; + + if ($since) { + $queries['users']->where('join_time', '>', $since); + $queries['discussions']->where('start_time', '>', $since); + $queries['posts']->where('time', '>', $since); + } + + return array_map(function ($query) { + return $query->count(); + }, $queries); + } } From 1584261541d7a2454d1c1ff05c486e4de03d5566 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 29 Nov 2017 22:20:06 +1030 Subject: [PATCH 102/172] Generate URL in the controller instead of the view --- .../core/src/Forum/Controller/LogOutController.php | 14 ++++++-------- framework/core/views/log-out.blade.php | 5 ++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/framework/core/src/Forum/Controller/LogOutController.php b/framework/core/src/Forum/Controller/LogOutController.php index 35bd09af3..ce5517469 100644 --- a/framework/core/src/Forum/Controller/LogOutController.php +++ b/framework/core/src/Forum/Controller/LogOutController.php @@ -13,6 +13,7 @@ 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; @@ -55,9 +56,9 @@ class LogOutController implements ControllerInterface protected $view; /** - * @var SettingsRepositoryInterface + * @var UrlGenerator */ - protected $settings; + protected $url; /** * @param Application $app @@ -65,7 +66,6 @@ class LogOutController implements ControllerInterface * @param SessionAuthenticator $authenticator * @param Rememberer $rememberer * @param Factory $view - * @param SettingsRepositoryInterface $settings */ public function __construct( Application $app, @@ -73,14 +73,14 @@ class LogOutController implements ControllerInterface SessionAuthenticator $authenticator, Rememberer $rememberer, Factory $view, - SettingsRepositoryInterface $settings + UrlGenerator $url ) { $this->app = $app; $this->events = $events; $this->authenticator = $authenticator; $this->rememberer = $rememberer; $this->view = $view; - $this->settings = $settings; + $this->url = $url; } /** @@ -106,9 +106,7 @@ class LogOutController implements ControllerInterface if (array_get($request->getQueryParams(), 'token') !== $csrfToken) { $view = $this->view->make('flarum.forum::log-out') - ->with('csrfToken', $csrfToken) - ->with('forumTitle', $this->settings->get('forum_title')) - ->with('return', array_get($request->getQueryParams(), 'return')); + ->with('url', $this->url->toRoute('logout').'?token='.$csrfToken.($return ? '&return='.urlencode($return) : '')); return new HtmlResponse($view->render()); } diff --git a/framework/core/views/log-out.blade.php b/framework/core/views/log-out.blade.php index 988beeeef..e8eb7fea7 100644 --- a/framework/core/views/log-out.blade.php +++ b/framework/core/views/log-out.blade.php @@ -1,13 +1,12 @@ @extends('flarum.forum::layouts.basic') -@inject('url', 'Flarum\Forum\UrlGenerator') @section('title', $translator->trans('core.views.log_out.title')) @section('content') -

{{ $translator->trans('core.views.log_out.log_out_confirmation', ['{forum}' => $forumTitle]) }}

+

{{ $translator->trans('core.views.log_out.log_out_confirmation', ['{forum}' => $settings->get('forum_title')]) }}

- + {{ $translator->trans('core.views.log_out.log_out_button') }}

From e10baaaf62cc5bdddc20af8804a0dd7dfb6a6156 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 29 Nov 2017 22:22:14 +1030 Subject: [PATCH 103/172] Fix last commit --- framework/core/src/Forum/Controller/LogOutController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/framework/core/src/Forum/Controller/LogOutController.php b/framework/core/src/Forum/Controller/LogOutController.php index ce5517469..0d15c3340 100644 --- a/framework/core/src/Forum/Controller/LogOutController.php +++ b/framework/core/src/Forum/Controller/LogOutController.php @@ -105,6 +105,8 @@ class LogOutController implements ControllerInterface $csrfToken = $session->get('csrf_token'); if (array_get($request->getQueryParams(), 'token') !== $csrfToken) { + $return = array_get($request->getQueryParams(), 'return'); + $view = $this->view->make('flarum.forum::log-out') ->with('url', $this->url->toRoute('logout').'?token='.$csrfToken.($return ? '&return='.urlencode($return) : '')); From 603561566005358d9d70cd1e5089ff27e6b7c258 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 29 Nov 2017 22:25:57 +1030 Subject: [PATCH 104/172] Move view logic into middleware --- .../core/src/Http/Middleware/HandleErrors.php | 39 ++++++++++++++++++- framework/core/views/error/404.blade.php | 2 +- framework/core/views/error/default.blade.php | 17 +------- 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/framework/core/src/Http/Middleware/HandleErrors.php b/framework/core/src/Http/Middleware/HandleErrors.php index 45b087b03..d72b6ed81 100644 --- a/framework/core/src/Http/Middleware/HandleErrors.php +++ b/framework/core/src/Http/Middleware/HandleErrors.php @@ -12,11 +12,13 @@ namespace Flarum\Http\Middleware; use Exception; +use Flarum\Settings\SettingsRepositoryInterface; use Franzl\Middleware\Whoops\ErrorMiddleware as WhoopsMiddleware; use Illuminate\Contracts\View\Factory as ViewFactory; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Log\LoggerInterface; +use Symfony\Component\Translation\TranslatorInterface; use Zend\Diactoros\Response\HtmlResponse; class HandleErrors @@ -31,6 +33,16 @@ class HandleErrors */ protected $logger; + /** + * @var TranslatorInterface + */ + protected $translator; + + /** + * @var SettingsRepositoryInterface + */ + protected $settings; + /** * @var bool */ @@ -41,10 +53,12 @@ class HandleErrors * @param LoggerInterface $logger * @param bool $debug */ - public function __construct(ViewFactory $view, LoggerInterface $logger, $debug = false) + public function __construct(ViewFactory $view, LoggerInterface $logger, TranslatorInterface $translator, SettingsRepositoryInterface $settings, $debug = false) { $this->view = $view; $this->logger = $logger; + $this->translator = $translator; + $this->settings = $settings; $this->debug = $debug; } @@ -89,8 +103,29 @@ class HandleErrors $name = 'flarum::error.default'; } - $view = $this->view->make($name)->with('error', $error); + $view = $this->view->make($name) + ->with('error', $error) + ->with('message', $this->getMessage($status)); return new HtmlResponse($view->render(), $status); } + + private function getMessage($status) + { + if (! $translation = $this->getTranslationIfExists($status)) { + if (! $translation = $this->getTranslationIfExists(500)) { + $translation = 'An error occurred while trying to load this page.'; + } + } + + return $translation; + } + + private function getTranslationIfExists($status) + { + $key = 'core.views.error.'.$status.'_message'; + $translation = $this->translator->trans($key, ['{forum}' => $this->settings->get('forum_title')]); + + return $translation === $key ? false : $translation; + } } diff --git a/framework/core/views/error/404.blade.php b/framework/core/views/error/404.blade.php index e54955574..928b4a8a3 100644 --- a/framework/core/views/error/404.blade.php +++ b/framework/core/views/error/404.blade.php @@ -2,7 +2,7 @@ @section('content')

- {{ $translator->trans('core.views.error.404_message') }} + {{ $message }}

diff --git a/framework/core/views/error/default.blade.php b/framework/core/views/error/default.blade.php index c7fca235c..a5fbc351e 100644 --- a/framework/core/views/error/default.blade.php +++ b/framework/core/views/error/default.blade.php @@ -2,21 +2,6 @@ @section('content')

- {{-- TODO: Change below to @php when Laravel is upgraded --}} - trans($key, ['{forum}' => $settings->get('forum_title')]); - - return $translation === $key ? false : $translation; - }; - - if (! $translation = $getTranslationIfExists($error->getCode())) { - if (! $translation = $getTranslationIfExists(500)) { - $translation = 'An error occurred while trying to load this page.'; - } - } - ?> - {{ $translation }} + {{ $message }}

@endsection From 85a13c123595cb159ccf6b2060687a35e2261cec Mon Sep 17 00:00:00 2001 From: Sajjad Hashemian Date: Thu, 30 Nov 2017 13:38:12 +0330 Subject: [PATCH 105/172] remove autolink #1214 --- framework/core/js/bower.json | 1 - framework/core/js/forum/Gulpfile.js | 1 - framework/core/js/forum/dist/app.js | 3 --- 3 files changed, 5 deletions(-) diff --git a/framework/core/js/bower.json b/framework/core/js/bower.json index d4d647f54..a72c86f2a 100644 --- a/framework/core/js/bower.json +++ b/framework/core/js/bower.json @@ -9,7 +9,6 @@ "color-thief": "v2.0", "mithril": "lhorie/mithril.js#v0.2.5", "es6-micro-loader": "caridy/es6-micro-loader#v0.2.1", - "autolink": "~1.0.0", "m.attrs.bidi": "tobscure/m.attrs.bidi", "punycode": "http://cdnjs.cloudflare.com/ajax/libs/punycode/1.4.1/punycode.js" } diff --git a/framework/core/js/forum/Gulpfile.js b/framework/core/js/forum/Gulpfile.js index 491fcde63..4899090d3 100644 --- a/framework/core/js/forum/Gulpfile.js +++ b/framework/core/js/forum/Gulpfile.js @@ -13,7 +13,6 @@ gulp({ bowerDir + '/jquery.hotkeys/jquery.hotkeys.js', bowerDir + '/color-thief/src/color-thief.js', bowerDir + '/moment/moment.js', - bowerDir + '/autolink/autolink-min.js', bowerDir + '/bootstrap/js/affix.js', bowerDir + '/bootstrap/js/dropdown.js', diff --git a/framework/core/js/forum/dist/app.js b/framework/core/js/forum/dist/app.js index 9ae4848fa..c19f8ae36 100644 --- a/framework/core/js/forum/dist/app.js +++ b/framework/core/js/forum/dist/app.js @@ -16000,9 +16000,6 @@ var MMCQ = (function() { } }).call(this); ; -(function(){var h=[].slice;String.prototype.autoLink=function(){var b,f,d,a,e,g;a=1<=arguments.length?h.call(arguments,0):[];e=/(^|[\s\n]|<[A-Za-z]*\/?>)((?:https?|ftp):\/\/[\-A-Z0-9+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/gi;if(!(0$2");d=a[0];f=function(){var c;c=[];for(b in d)g=d[b],"callback"!==b&&c.push(" "+b+"='"+g+"'");return c}().join("");return this.replace(e,function(c,b,a){c=("function"===typeof d.callback?d.callback(a): -void 0)||""+a+"";return""+b+c})}}).call(this); -; /* ======================================================================== * Bootstrap: affix.js v3.3.7 * http://getbootstrap.com/javascript/#affix From 54a5ee8edc24c3730036f1eeb67c28a4f5f885e7 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sun, 10 Dec 2017 21:02:35 +1030 Subject: [PATCH 106/172] Fix crash when post's user has been deleted --- framework/core/views/frontend/content/discussion.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/views/frontend/content/discussion.blade.php b/framework/core/views/frontend/content/discussion.blade.php index d66aae568..3a0aaa2e3 100644 --- a/framework/core/views/frontend/content/discussion.blade.php +++ b/framework/core/views/frontend/content/discussion.blade.php @@ -8,7 +8,7 @@ $postsCount = count($discussion->relationships->posts->data);
@foreach ($posts as $post)
- relationships->user->data); ?> + relationships->user->data) ? $getResource($post->relationships->user->data) : null; ?>

{{ $user ? $user->attributes->username : $translator->trans('core.lib.username.deleted_text') }}

{!! $post->attributes->contentHtml !!} From 113ed7cbf841def3504e6aff95de994016c87d98 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sun, 10 Dec 2017 21:02:47 +1030 Subject: [PATCH 107/172] Fix PHP 7.2 warning --- framework/core/src/Core/Post/RegisteredTypesScope.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Core/Post/RegisteredTypesScope.php b/framework/core/src/Core/Post/RegisteredTypesScope.php index 35dd977e8..e0cf51707 100644 --- a/framework/core/src/Core/Post/RegisteredTypesScope.php +++ b/framework/core/src/Core/Post/RegisteredTypesScope.php @@ -49,7 +49,7 @@ class RegisteredTypesScope implements ScopeInterface { $query = $builder->getQuery(); - $this->whereIndex = count($query->wheres); + $this->whereIndex = count($query->wheres ?: []); $this->bindingIndex = count($query->getRawBindings()['where']); $types = array_keys($post::getModels()); From 0c1e90719cbfe3aef36c5ff47fe66594edf088b6 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sun, 10 Dec 2017 21:03:48 +1030 Subject: [PATCH 108/172] Extract admin dashboard statistics from core into an extension --- framework/core/js/admin/dist/app.js | 184 +----------------- .../js/admin/src/components/DashboardPage.js | 8 +- .../admin/src/components/StatisticsWidget.js | 60 ------ framework/core/less/admin/DashboardPage.less | 35 ---- .../src/Admin/Controller/WebAppController.php | 35 ---- 5 files changed, 13 insertions(+), 309 deletions(-) delete mode 100644 framework/core/js/admin/src/components/StatisticsWidget.js diff --git a/framework/core/js/admin/dist/app.js b/framework/core/js/admin/dist/app.js index 7d1a68eb7..64c0aa374 100644 --- a/framework/core/js/admin/dist/app.js +++ b/framework/core/js/admin/dist/app.js @@ -18360,17 +18360,15 @@ System.register('flarum/components/Checkbox', ['flarum/Component', 'flarum/compo });; 'use strict'; -System.register('flarum/components/DashboardPage', ['flarum/components/Page', 'flarum/components/StatusWidget', 'flarum/components/StatisticsWidget'], function (_export, _context) { +System.register('flarum/components/DashboardPage', ['flarum/components/Page', 'flarum/components/StatusWidget'], function (_export, _context) { "use strict"; - var Page, StatusWidget, StatisticsWidget, DashboardPage; + var Page, StatusWidget, DashboardPage; return { setters: [function (_flarumComponentsPage) { Page = _flarumComponentsPage.default; }, function (_flarumComponentsStatusWidget) { StatusWidget = _flarumComponentsStatusWidget.default; - }, function (_flarumComponentsStatisticsWidget) { - StatisticsWidget = _flarumComponentsStatisticsWidget.default; }], execute: function () { DashboardPage = function (_Page) { @@ -18390,11 +18388,15 @@ System.register('flarum/components/DashboardPage', ['flarum/components/Page', 'f m( 'div', { className: 'container' }, - m(StatusWidget, null), - m(StatisticsWidget, null) + this.availableWidgets() ) ); } + }, { + key: 'availableWidgets', + value: function availableWidgets() { + return [m(StatusWidget, null)]; + } }]); return DashboardPage; }(Page); @@ -21112,176 +21114,6 @@ System.register('flarum/components/SplitDropdown', ['flarum/components/Dropdown' });; 'use strict'; -System.register('flarum/components/StatisticsWidget', ['flarum/components/DashboardWidget', 'flarum/helpers/icon', 'flarum/helpers/listItems', 'flarum/utils/ItemList'], function (_export, _context) { - "use strict"; - - var DashboardWidget, icon, listItems, ItemList, StatisticsWidget; - return { - setters: [function (_flarumComponentsDashboardWidget) { - DashboardWidget = _flarumComponentsDashboardWidget.default; - }, function (_flarumHelpersIcon) { - icon = _flarumHelpersIcon.default; - }, function (_flarumHelpersListItems) { - listItems = _flarumHelpersListItems.default; - }, function (_flarumUtilsItemList) { - ItemList = _flarumUtilsItemList.default; - }], - execute: function () { - StatisticsWidget = function (_DashboardWidget) { - babelHelpers.inherits(StatisticsWidget, _DashboardWidget); - - function StatisticsWidget() { - babelHelpers.classCallCheck(this, StatisticsWidget); - return babelHelpers.possibleConstructorReturn(this, (StatisticsWidget.__proto__ || Object.getPrototypeOf(StatisticsWidget)).apply(this, arguments)); - } - - babelHelpers.createClass(StatisticsWidget, [{ - key: 'className', - value: function className() { - return 'StatisticsWidget'; - } - }, { - key: 'content', - value: function content() { - return m( - 'table', - null, - m( - 'thead', - null, - m( - 'tr', - null, - m('th', null), - m( - 'th', - null, - app.translator.trans('core.admin.statistics.users_heading') - ), - m( - 'th', - null, - app.translator.trans('core.admin.statistics.discussions_heading') - ), - m( - 'th', - null, - app.translator.trans('core.admin.statistics.posts_heading') - ) - ) - ), - m( - 'tbody', - null, - m( - 'tr', - { className: 'StatisticsWidget-total' }, - m( - 'th', - null, - app.translator.trans('core.admin.statistics.total_label') - ), - m( - 'td', - null, - app.data.statistics.total.users - ), - m( - 'td', - null, - app.data.statistics.total.discussions - ), - m( - 'td', - null, - app.data.statistics.total.posts - ) - ), - m( - 'tr', - null, - m( - 'th', - null, - app.translator.trans('core.admin.statistics.last_28_days_label') - ), - m( - 'td', - null, - app.data.statistics.month.users - ), - m( - 'td', - null, - app.data.statistics.month.discussions - ), - m( - 'td', - null, - app.data.statistics.month.posts - ) - ), - m( - 'tr', - null, - m( - 'th', - null, - app.translator.trans('core.admin.statistics.last_7_days_label') - ), - m( - 'td', - null, - app.data.statistics.week.users - ), - m( - 'td', - null, - app.data.statistics.week.discussions - ), - m( - 'td', - null, - app.data.statistics.week.posts - ) - ), - m( - 'tr', - null, - m( - 'th', - null, - app.translator.trans('core.admin.statistics.today_label') - ), - m( - 'td', - null, - app.data.statistics.today.users - ), - m( - 'td', - null, - app.data.statistics.today.discussions - ), - m( - 'td', - null, - app.data.statistics.today.posts - ) - ) - ) - ); - } - }]); - return StatisticsWidget; - }(DashboardWidget); - - _export('default', StatisticsWidget); - } - }; -});; -'use strict'; - System.register('flarum/components/StatusWidget', ['flarum/components/DashboardWidget', 'flarum/helpers/icon', 'flarum/helpers/listItems', 'flarum/utils/ItemList'], function (_export, _context) { "use strict"; diff --git a/framework/core/js/admin/src/components/DashboardPage.js b/framework/core/js/admin/src/components/DashboardPage.js index c1a7bd888..30e0fb589 100644 --- a/framework/core/js/admin/src/components/DashboardPage.js +++ b/framework/core/js/admin/src/components/DashboardPage.js @@ -1,16 +1,18 @@ import Page from 'flarum/components/Page'; import StatusWidget from 'flarum/components/StatusWidget'; -import StatisticsWidget from 'flarum/components/StatisticsWidget'; export default class DashboardPage extends Page { view() { return (
- - + {this.availableWidgets()}
); } + + availableWidgets() { + return []; + } } diff --git a/framework/core/js/admin/src/components/StatisticsWidget.js b/framework/core/js/admin/src/components/StatisticsWidget.js deleted file mode 100644 index a653a3c0c..000000000 --- a/framework/core/js/admin/src/components/StatisticsWidget.js +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is part of Flarum. - * - * (c) Toby Zerner - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -import DashboardWidget from 'flarum/components/DashboardWidget'; -import icon from 'flarum/helpers/icon'; -import listItems from 'flarum/helpers/listItems'; -import ItemList from 'flarum/utils/ItemList'; - -export default class StatisticsWidget extends DashboardWidget { - className() { - return 'StatisticsWidget'; - } - - content() { - return ( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{app.translator.trans('core.admin.statistics.users_heading')}{app.translator.trans('core.admin.statistics.discussions_heading')}{app.translator.trans('core.admin.statistics.posts_heading')}
{app.translator.trans('core.admin.statistics.total_label')}{app.data.statistics.total.users}{app.data.statistics.total.discussions}{app.data.statistics.total.posts}
{app.translator.trans('core.admin.statistics.last_28_days_label')}{app.data.statistics.month.users}{app.data.statistics.month.discussions}{app.data.statistics.month.posts}
{app.translator.trans('core.admin.statistics.last_7_days_label')}{app.data.statistics.week.users}{app.data.statistics.week.discussions}{app.data.statistics.week.posts}
{app.translator.trans('core.admin.statistics.today_label')}{app.data.statistics.today.users}{app.data.statistics.today.discussions}{app.data.statistics.today.posts}
- ); - } -} diff --git a/framework/core/less/admin/DashboardPage.less b/framework/core/less/admin/DashboardPage.less index 3c97eedc3..0ec7f6534 100644 --- a/framework/core/less/admin/DashboardPage.less +++ b/framework/core/less/admin/DashboardPage.less @@ -45,38 +45,3 @@ } } } - -.StatisticsWidget { - td { - font-size: 14px; - } - td, th { - padding: 5px 20px 5px 0; - text-align: left; - font-weight: normal; - border-bottom: 1px solid @control-bg; - } - tbody tr:last-child { - td, th { - border-bottom: 0; - } - } - th { - color: @muted-color; - } - thead th { - font-weight: bold; - } -} -.StatisticsWidget-total { - td, th { - font-weight: bold; - } -} -@media @tablet-up { - .StatisticsWidget { - td, th { - min-width: 120px; - } - } -} diff --git a/framework/core/src/Admin/Controller/WebAppController.php b/framework/core/src/Admin/Controller/WebAppController.php index 30c660ff3..a3d5a8100 100644 --- a/framework/core/src/Admin/Controller/WebAppController.php +++ b/framework/core/src/Admin/Controller/WebAppController.php @@ -11,12 +11,8 @@ namespace Flarum\Admin\Controller; -use DateTime; use Flarum\Admin\WebApp; -use Flarum\Core\Discussion; use Flarum\Core\Permission; -use Flarum\Core\Post; -use Flarum\Core\User; use Flarum\Event\PrepareUnserializedSettings; use Flarum\Extension\ExtensionManager; use Flarum\Http\Controller\AbstractWebAppController; @@ -73,37 +69,6 @@ class WebAppController extends AbstractWebAppController $view->setVariable('phpVersion', PHP_VERSION); $view->setVariable('mysqlVersion', $this->db->selectOne('select version() as version')->version); - $view->setVariable('statistics', $this->getStatistics()); - return $view; } - - private function getStatistics() - { - return [ - 'total' => $this->getEntityCounts(), - 'month' => $this->getEntityCounts(new DateTime('-28 days')), - 'week' => $this->getEntityCounts(new DateTime('-7 days')), - 'today' => $this->getEntityCounts(new DateTime('-1 day')) - ]; - } - - private function getEntityCounts($since = null) - { - $queries = [ - 'users' => User::query(), - 'discussions' => Discussion::query(), - 'posts' => Post::where('type', 'comment') - ]; - - if ($since) { - $queries['users']->where('join_time', '>', $since); - $queries['discussions']->where('start_time', '>', $since); - $queries['posts']->where('time', '>', $since); - } - - return array_map(function ($query) { - return $query->count(); - }, $queries); - } } From 3e29761d124c69391a1871bcf3f199b9b48aef19 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 13 Dec 2017 15:28:54 +1030 Subject: [PATCH 109/172] Add infinite scrolling in the notifications list --- framework/core/js/forum/dist/app.js | 206 +++++++++++------- .../forum/src/components/NotificationList.js | 146 +++++++++---- .../less/forum/NotificationsDropdown.less | 1 - .../ListNotificationsController.php | 31 ++- 4 files changed, 260 insertions(+), 124 deletions(-) diff --git a/framework/core/js/forum/dist/app.js b/framework/core/js/forum/dist/app.js index c19f8ae36..f3bccdee2 100644 --- a/framework/core/js/forum/dist/app.js +++ b/framework/core/js/forum/dist/app.js @@ -23964,39 +23964,18 @@ System.register('flarum/components/NotificationList', ['flarum/Component', 'flar * @type {Boolean} */ this.loading = false; + + /** + * Whether or not there are more results that can be loaded. + * + * @type {Boolean} + */ + this.moreResults = false; } }, { key: 'view', value: function view() { - var groups = []; - - if (app.cache.notifications) { - var discussions = {}; - - // Build an array of discussions which the notifications are related to, - // and add the notifications as children. - app.cache.notifications.forEach(function (notification) { - var subject = notification.subject(); - - if (typeof subject === 'undefined') return; - - // Get the discussion that this notification is related to. If it's not - // directly related to a discussion, it may be related to a post or - // other entity which is related to a discussion. - var discussion = false; - if (subject instanceof Discussion) discussion = subject;else if (subject && subject.discussion) discussion = subject.discussion(); - - // If the notification is not related to a discussion directly or - // indirectly, then we will assign it to a neutral group. - var key = discussion ? discussion.id() : 0; - discussions[key] = discussions[key] || { discussion: discussion, notifications: [] }; - discussions[key].notifications.push(notification); - - if (groups.indexOf(discussions[key]) === -1) { - groups.push(discussions[key]); - } - }); - } + var pages = app.cache.notifications || []; return m( 'div', @@ -24023,71 +24002,144 @@ System.register('flarum/components/NotificationList', ['flarum/Component', 'flar m( 'div', { className: 'NotificationList-content' }, - groups.length ? groups.map(function (group) { - var badges = group.discussion && group.discussion.badges().toArray(); + pages.length ? pages.map(function (notifications) { + var groups = []; + var discussions = {}; - return m( - 'div', - { className: 'NotificationGroup' }, - group.discussion ? m( - 'a', - { className: 'NotificationGroup-header', - href: app.route.discussion(group.discussion), - config: m.route }, - badges && badges.length ? m( - 'ul', - { className: 'NotificationGroup-badges badges' }, - listItems(badges) - ) : '', - group.discussion.title() - ) : m( + notifications.forEach(function (notification) { + var subject = notification.subject(); + + if (typeof subject === 'undefined') return; + + // Get the discussion that this notification is related to. If it's not + // directly related to a discussion, it may be related to a post or + // other entity which is related to a discussion. + var discussion = false; + if (subject instanceof Discussion) discussion = subject;else if (subject && subject.discussion) discussion = subject.discussion(); + + // If the notification is not related to a discussion directly or + // indirectly, then we will assign it to a neutral group. + var key = discussion ? discussion.id() : 0; + discussions[key] = discussions[key] || { discussion: discussion, notifications: [] }; + discussions[key].notifications.push(notification); + + if (groups.indexOf(discussions[key]) === -1) { + groups.push(discussions[key]); + } + }); + + return groups.map(function (group) { + var badges = group.discussion && group.discussion.badges().toArray(); + + return m( 'div', - { className: 'NotificationGroup-header' }, - app.forum.attribute('title') - ), - m( - 'ul', - { className: 'NotificationGroup-content' }, - group.notifications.map(function (notification) { - var NotificationComponent = app.notificationComponents[notification.contentType()]; - return NotificationComponent ? m( - 'li', - null, - NotificationComponent.component({ notification: notification }) - ) : ''; - }) - ) - ); - }) : !this.loading ? m( + { className: 'NotificationGroup' }, + group.discussion ? m( + 'a', + { className: 'NotificationGroup-header', + href: app.route.discussion(group.discussion), + config: m.route }, + badges && badges.length ? m( + 'ul', + { className: 'NotificationGroup-badges badges' }, + listItems(badges) + ) : '', + group.discussion.title() + ) : m( + 'div', + { className: 'NotificationGroup-header' }, + app.forum.attribute('title') + ), + m( + 'ul', + { className: 'NotificationGroup-content' }, + group.notifications.map(function (notification) { + var NotificationComponent = app.notificationComponents[notification.contentType()]; + return NotificationComponent ? m( + 'li', + null, + NotificationComponent.component({ notification: notification }) + ) : ''; + }) + ) + ); + }); + }) : '', + this.loading ? m(LoadingIndicator, { className: 'LoadingIndicator--block' }) : pages.length ? '' : m( 'div', { className: 'NotificationList-empty' }, app.translator.trans('core.forum.notifications.empty_text') - ) : LoadingIndicator.component({ className: 'LoadingIndicator--block' }) + ) ) ); } }, { - key: 'load', - value: function load() { + key: 'config', + value: function config(isInitialized, context) { var _this2 = this; - if (app.cache.notifications && !app.session.user.newNotificationsCount()) { + if (isInitialized) return; + + var $notifications = this.$('.NotificationList-content'); + var $scrollParent = $notifications.css('overflow') === 'auto' ? $notifications : $(window); + + var scrollHandler = function scrollHandler() { + var scrollTop = $scrollParent.scrollTop(); + var viewportHeight = $scrollParent.height(); + var contentTop = $scrollParent === $notifications ? 0 : $notifications.offset().top; + var contentHeight = $notifications[0].scrollHeight; + + if (_this2.moreResults && !_this2.loading && scrollTop + viewportHeight >= contentTop + contentHeight) { + _this2.loadMore(); + } + }; + + $scrollParent.on('scroll', scrollHandler); + + context.onunload = function () { + $scrollParent.off('scroll', scrollHandler); + }; + } + }, { + key: 'load', + value: function load() { + if (app.session.user.newNotificationsCount()) { + delete app.cache.notifications; + } + + if (app.cache.notifications) { return; } + app.session.user.pushAttributes({ newNotificationsCount: 0 }); + + this.loadMore(); + } + }, { + key: 'loadMore', + value: function loadMore() { + var _this3 = this; + this.loading = true; m.redraw(); - app.store.find('notifications').then(function (notifications) { - app.session.user.pushAttributes({ newNotificationsCount: 0 }); - app.cache.notifications = notifications.sort(function (a, b) { - return b.time() - a.time(); - }); - }).catch(function () {}).then(function () { - _this2.loading = false; + var params = app.cache.notifications ? { page: { offset: app.cache.notifications.length * 10 } } : null; + + return app.store.find('notifications', params).then(this.parseResults.bind(this)).catch(function () {}).then(function () { + _this3.loading = false; m.redraw(); }); } + }, { + key: 'parseResults', + value: function parseResults(results) { + app.cache.notifications = app.cache.notifications || []; + app.cache.notifications.push(results); + + this.moreResults = !!results.payload.links.next; + + return results; + } }, { key: 'markAllAsRead', value: function markAllAsRead() { @@ -24095,8 +24147,10 @@ System.register('flarum/components/NotificationList', ['flarum/Component', 'flar app.session.user.pushAttributes({ unreadNotificationsCount: 0 }); - app.cache.notifications.forEach(function (notification) { - return notification.pushAttributes({ isRead: true }); + app.cache.notifications.forEach(function (notifications) { + notifications.forEach(function (notification) { + return notification.pushAttributes({ isRead: true }); + }); }); app.request({ diff --git a/framework/core/js/forum/src/components/NotificationList.js b/framework/core/js/forum/src/components/NotificationList.js index 23b644344..7032b339b 100644 --- a/framework/core/js/forum/src/components/NotificationList.js +++ b/framework/core/js/forum/src/components/NotificationList.js @@ -16,39 +16,17 @@ export default class NotificationList extends Component { * @type {Boolean} */ this.loading = false; + + /** + * Whether or not there are more results that can be loaded. + * + * @type {Boolean} + */ + this.moreResults = false; } view() { - const groups = []; - - if (app.cache.notifications) { - const discussions = {}; - - // Build an array of discussions which the notifications are related to, - // and add the notifications as children. - app.cache.notifications.forEach(notification => { - const subject = notification.subject(); - - if (typeof subject === 'undefined') return; - - // Get the discussion that this notification is related to. If it's not - // directly related to a discussion, it may be related to a post or - // other entity which is related to a discussion. - let discussion = false; - if (subject instanceof Discussion) discussion = subject; - else if (subject && subject.discussion) discussion = subject.discussion(); - - // If the notification is not related to a discussion directly or - // indirectly, then we will assign it to a neutral group. - const key = discussion ? discussion.id() : 0; - discussions[key] = discussions[key] || {discussion: discussion, notifications: []}; - discussions[key].notifications.push(notification); - - if (groups.indexOf(discussions[key]) === -1) { - groups.push(discussions[key]); - } - }); - } + const pages = app.cache.notifications || []; return (
@@ -66,8 +44,34 @@ export default class NotificationList extends Component {
- {groups.length - ? groups.map(group => { + {pages.length ? pages.map(notifications => { + const groups = []; + const discussions = {}; + + notifications.forEach(notification => { + const subject = notification.subject(); + + if (typeof subject === 'undefined') return; + + // Get the discussion that this notification is related to. If it's not + // directly related to a discussion, it may be related to a post or + // other entity which is related to a discussion. + let discussion = false; + if (subject instanceof Discussion) discussion = subject; + else if (subject && subject.discussion) discussion = subject.discussion(); + + // If the notification is not related to a discussion directly or + // indirectly, then we will assign it to a neutral group. + const key = discussion ? discussion.id() : 0; + discussions[key] = discussions[key] || {discussion: discussion, notifications: []}; + discussions[key].notifications.push(notification); + + if (groups.indexOf(discussions[key]) === -1) { + groups.push(discussions[key]); + } + }); + + return groups.map(group => { const badges = group.discussion && group.discussion.badges().toArray(); return ( @@ -94,32 +98,71 @@ export default class NotificationList extends Component {
); - }) - : !this.loading - ?
{app.translator.trans('core.forum.notifications.empty_text')}
- : LoadingIndicator.component({className: 'LoadingIndicator--block'})} + }); + }) : ''} + {this.loading + ? + : (pages.length ? '' :
{app.translator.trans('core.forum.notifications.empty_text')}
)}
); } + config(isInitialized, context) { + if (isInitialized) return; + + const $notifications = this.$('.NotificationList-content'); + const $scrollParent = $notifications.css('overflow') === 'auto' ? $notifications : $(window); + + const scrollHandler = () => { + const scrollTop = $scrollParent.scrollTop(); + const viewportHeight = $scrollParent.height(); + const contentTop = $scrollParent === $notifications ? 0 : $notifications.offset().top; + const contentHeight = $notifications[0].scrollHeight; + + if (this.moreResults && !this.loading && scrollTop + viewportHeight >= contentTop + contentHeight) { + this.loadMore(); + } + }; + + $scrollParent.on('scroll', scrollHandler); + + context.onunload = () => { + $scrollParent.off('scroll', scrollHandler); + }; + } + /** * Load notifications into the application's cache if they haven't already * been loaded. */ load() { - if (app.cache.notifications && !app.session.user.newNotificationsCount()) { + if (app.session.user.newNotificationsCount()) { + delete app.cache.notifications; + } + + if (app.cache.notifications) { return; } + app.session.user.pushAttributes({newNotificationsCount: 0}); + + this.loadMore(); + } + + /** + * Load the next page of notification results. + * + * @public + */ + loadMore() { this.loading = true; m.redraw(); - app.store.find('notifications') - .then(notifications => { - app.session.user.pushAttributes({newNotificationsCount: 0}); - app.cache.notifications = notifications.sort((a, b) => b.time() - a.time()); - }) + const params = app.cache.notifications ? {page: {offset: app.cache.notifications.length * 10}} : null; + + return app.store.find('notifications', params) + .then(this.parseResults.bind(this)) .catch(() => {}) .then(() => { this.loading = false; @@ -127,6 +170,21 @@ export default class NotificationList extends Component { }); } + /** + * Parse results and append them to the notification list. + * + * @param {Notification[]} results + * @return {Notification[]} + */ + parseResults(results) { + app.cache.notifications = app.cache.notifications || []; + app.cache.notifications.push(results); + + this.moreResults = !!results.payload.links.next; + + return results; + } + /** * Mark all of the notifications as read. */ @@ -135,7 +193,9 @@ export default class NotificationList extends Component { app.session.user.pushAttributes({unreadNotificationsCount: 0}); - app.cache.notifications.forEach(notification => notification.pushAttributes({isRead: true})); + app.cache.notifications.forEach(notifications => { + notifications.forEach(notification => notification.pushAttributes({isRead: true})) + }); app.request({ url: app.forum.attribute('apiUrl') + '/notifications/read', diff --git a/framework/core/less/forum/NotificationsDropdown.less b/framework/core/less/forum/NotificationsDropdown.less index 7ce7bfb1d..a36c635ee 100644 --- a/framework/core/less/forum/NotificationsDropdown.less +++ b/framework/core/less/forum/NotificationsDropdown.less @@ -6,7 +6,6 @@ .NotificationList-content { max-height: 70vh; overflow: auto; - padding-bottom: 10px; } } & .Dropdown-toggle .Button-label { diff --git a/framework/core/src/Api/Controller/ListNotificationsController.php b/framework/core/src/Api/Controller/ListNotificationsController.php index 7af1cd561..284f103b3 100644 --- a/framework/core/src/Api/Controller/ListNotificationsController.php +++ b/framework/core/src/Api/Controller/ListNotificationsController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\UrlGenerator; use Flarum\Core\Discussion; use Flarum\Core\Exception\PermissionDeniedException; use Flarum\Core\Repository\NotificationRepository; @@ -39,16 +40,23 @@ class ListNotificationsController extends AbstractCollectionController public $limit = 10; /** - * @var \Flarum\Core\Repository\NotificationRepository + * @var NotificationRepository */ protected $notifications; /** - * @param \Flarum\Core\Repository\NotificationRepository $notifications + * @var UrlGenerator */ - public function __construct(NotificationRepository $notifications) + protected $url; + + /** + * @param NotificationRepository $notifications + * @param UrlGenerator $url + */ + public function __construct(NotificationRepository $notifications, UrlGenerator $url) { $this->notifications = $notifications; + $this->url = $url; } /** @@ -68,10 +76,25 @@ class ListNotificationsController extends AbstractCollectionController $offset = $this->extractOffset($request); $include = $this->extractInclude($request); - $notifications = $this->notifications->findByUser($actor, $limit, $offset) + $notifications = $this->notifications->findByUser($actor, $limit + 1, $offset) ->load(array_diff($include, ['subject.discussion'])) ->all(); + $areMoreResults = false; + + if (count($notifications) > $limit) { + array_pop($notifications); + $areMoreResults = true; + } + + $document->addPaginationLinks( + $this->url->toRoute('notifications.index'), + $request->getQueryParams(), + $offset, + $limit, + $areMoreResults ? null : 0 + ); + if (in_array('subject.discussion', $include)) { $this->loadSubjectDiscussions($notifications); } From f4f4ce17b6ae0fc7a6606e5cda5e6009570178af Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 13 Dec 2017 15:54:16 +1030 Subject: [PATCH 110/172] Filter out notifications with non-existent subjects ref #1025 #1238. This should prevent the frontend from crashing when opening the notifications menu, but we still need to make sure notifications are deleted properly when subjects are deleted. --- .../src/Api/Controller/ListNotificationsController.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/framework/core/src/Api/Controller/ListNotificationsController.php b/framework/core/src/Api/Controller/ListNotificationsController.php index 284f103b3..f53f3be60 100644 --- a/framework/core/src/Api/Controller/ListNotificationsController.php +++ b/framework/core/src/Api/Controller/ListNotificationsController.php @@ -76,6 +76,10 @@ class ListNotificationsController extends AbstractCollectionController $offset = $this->extractOffset($request); $include = $this->extractInclude($request); + if (! in_array('subject', $include)) { + $include[] = 'subject'; + } + $notifications = $this->notifications->findByUser($actor, $limit + 1, $offset) ->load(array_diff($include, ['subject.discussion'])) ->all(); @@ -95,6 +99,10 @@ class ListNotificationsController extends AbstractCollectionController $areMoreResults ? null : 0 ); + $notifications = array_filter($notifications, function ($notification) { + return ! $notification->subjectModel || $notification->subject; + }); + if (in_array('subject.discussion', $include)) { $this->loadSubjectDiscussions($notifications); } From 317d8270468dd22696e54f1df2b25b6a8e3c8433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Wed, 13 Dec 2017 21:45:55 +0100 Subject: [PATCH 111/172] re-using symfony translator --- framework/core/src/Locale/LocaleServiceProvider.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/framework/core/src/Locale/LocaleServiceProvider.php b/framework/core/src/Locale/LocaleServiceProvider.php index 35b52eef7..73eb156f5 100644 --- a/framework/core/src/Locale/LocaleServiceProvider.php +++ b/framework/core/src/Locale/LocaleServiceProvider.php @@ -16,6 +16,7 @@ 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 { @@ -48,6 +49,7 @@ class LocaleServiceProvider extends AbstractServiceProvider }); $this->app->alias('translator', Translator::class); $this->app->alias('translator', TranslatorContract::class); + $this->app->alias('translator', TranslatorInterface::class); } private function getDefaultLocale(): string From 29f7863b3a97ab51a5103c416c88ef2a75c7a5a3 Mon Sep 17 00:00:00 2001 From: Clark Winkelmann Date: Wed, 13 Dec 2017 22:39:09 +0100 Subject: [PATCH 112/172] Prevent saving invalid custom less (#1273) * Prevent saving invalid custom less * Fix formatting * Fix formatting again * Move custom less format check to its own listener * Move listener to AdminServiceProvider * Rename listener method --- .../core/src/Admin/AdminServiceProvider.php | 10 +++++ .../Core/Listener/CheckCustomLessFormat.php | 43 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 framework/core/src/Core/Listener/CheckCustomLessFormat.php diff --git a/framework/core/src/Admin/AdminServiceProvider.php b/framework/core/src/Admin/AdminServiceProvider.php index 576f0e7bd..2dfc9f53f 100644 --- a/framework/core/src/Admin/AdminServiceProvider.php +++ b/framework/core/src/Admin/AdminServiceProvider.php @@ -11,6 +11,7 @@ namespace Flarum\Admin; +use Flarum\Core\Listener\CheckCustomLessFormat; use Flarum\Event\ExtensionWasDisabled; use Flarum\Event\ExtensionWasEnabled; use Flarum\Event\SettingWasSet; @@ -46,6 +47,8 @@ class AdminServiceProvider extends AbstractServiceProvider $this->flushWebAppAssetsWhenThemeChanged(); $this->flushWebAppAssetsWhenExtensionsChanged(); + + $this->checkCustomLessFormat(); } /** @@ -93,4 +96,11 @@ class AdminServiceProvider extends AbstractServiceProvider { return $this->app->make(WebApp::class)->getAssets(); } + + protected function checkCustomLessFormat() + { + $events = $this->app->make('events'); + + $events->subscribe(CheckCustomLessFormat::class); + } } diff --git a/framework/core/src/Core/Listener/CheckCustomLessFormat.php b/framework/core/src/Core/Listener/CheckCustomLessFormat.php new file mode 100644 index 000000000..324b62bae --- /dev/null +++ b/framework/core/src/Core/Listener/CheckCustomLessFormat.php @@ -0,0 +1,43 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Core\Listener; + +use Flarum\Core\Exception\ValidationException; +use Flarum\Event\PrepareSerializedSetting; +use Illuminate\Contracts\Events\Dispatcher; +use Less_Exception_Parser; +use Less_Parser; + +class CheckCustomLessFormat +{ + public function subscribe(Dispatcher $events) + { + $events->listen(PrepareSerializedSetting::class, [$this, 'check']); + } + + public function check(PrepareSerializedSetting $event) + { + if ($event->key === 'custom_less') { + $parser = new Less_Parser(); + + try { + // Check the custom less format before saving + // Variables names are not checked, we would have to set them and call getCss() to check them + $parser->parse($event->value); + } catch (Less_Exception_Parser $e) { + throw new ValidationException([ + 'custom_less' => $e->getMessage(), + ]); + } + } + } +} From 4941ad7cf1e6cb5c6c3d00e4c3f2b2ffb08c7d1a Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 13 Dec 2017 23:08:35 +0100 Subject: [PATCH 113/172] Apply suggestions from StyleCI --- framework/core/src/Admin/Server.php | 1 - framework/core/src/Forum/Controller/LogOutController.php | 1 - .../core/src/Forum/Controller/ResetPasswordController.php | 1 - framework/core/src/Http/Middleware/ShareErrorsFromSession.php | 4 ++-- framework/core/src/Locale/LocaleServiceProvider.php | 1 - 5 files changed, 2 insertions(+), 6 deletions(-) diff --git a/framework/core/src/Admin/Server.php b/framework/core/src/Admin/Server.php index 00b3e686e..73002a1bb 100644 --- a/framework/core/src/Admin/Server.php +++ b/framework/core/src/Admin/Server.php @@ -14,7 +14,6 @@ namespace Flarum\Admin; use Flarum\Event\ConfigureMiddleware; use Flarum\Foundation\Application; use Flarum\Http\AbstractServer; -use Flarum\Http\Middleware\HandleErrors; use Zend\Stratigility\MiddlewarePipe; class Server extends AbstractServer diff --git a/framework/core/src/Forum/Controller/LogOutController.php b/framework/core/src/Forum/Controller/LogOutController.php index 0d15c3340..f19b7ea9c 100644 --- a/framework/core/src/Forum/Controller/LogOutController.php +++ b/framework/core/src/Forum/Controller/LogOutController.php @@ -19,7 +19,6 @@ use Flarum\Http\Controller\ControllerInterface; use Flarum\Http\Exception\TokenMismatchException; use Flarum\Http\Rememberer; use Flarum\Http\SessionAuthenticator; -use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\View\Factory; use Psr\Http\Message\ServerRequestInterface as Request; diff --git a/framework/core/src/Forum/Controller/ResetPasswordController.php b/framework/core/src/Forum/Controller/ResetPasswordController.php index 1e87fdf0c..278dc897e 100644 --- a/framework/core/src/Forum/Controller/ResetPasswordController.php +++ b/framework/core/src/Forum/Controller/ResetPasswordController.php @@ -17,7 +17,6 @@ use Flarum\Core\PasswordToken; use Flarum\Http\Controller\AbstractHtmlController; use Illuminate\Contracts\View\Factory; use Psr\Http\Message\ServerRequestInterface as Request; -use Symfony\Component\Translation\TranslatorInterface; class ResetPasswordController extends AbstractHtmlController { diff --git a/framework/core/src/Http/Middleware/ShareErrorsFromSession.php b/framework/core/src/Http/Middleware/ShareErrorsFromSession.php index 4ab83d2f8..5d0a5ed9b 100644 --- a/framework/core/src/Http/Middleware/ShareErrorsFromSession.php +++ b/framework/core/src/Http/Middleware/ShareErrorsFromSession.php @@ -10,14 +10,14 @@ namespace Flarum\Http\Middleware; -use Illuminate\Support\ViewErrorBag; use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Support\ViewErrorBag; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Zend\Stratigility\MiddlewareInterface; /** - * Inspired by Illuminate\View\Middleware\ShareErrorsFromSession + * Inspired by Illuminate\View\Middleware\ShareErrorsFromSession. * * @author Taylor Otwell */ diff --git a/framework/core/src/Locale/LocaleServiceProvider.php b/framework/core/src/Locale/LocaleServiceProvider.php index 3e038950b..d9b75383c 100644 --- a/framework/core/src/Locale/LocaleServiceProvider.php +++ b/framework/core/src/Locale/LocaleServiceProvider.php @@ -14,7 +14,6 @@ namespace Flarum\Locale; use Flarum\Event\ConfigureLocales; use Flarum\Foundation\AbstractServiceProvider; use Illuminate\Contracts\Events\Dispatcher; -use Symfony\Component\Translation\MessageSelector; class LocaleServiceProvider extends AbstractServiceProvider { From 5efe267acb34a6b99eefe289daad50ca8e0beffb Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 14 Dec 2017 22:18:12 +0100 Subject: [PATCH 114/172] Apply suggestions from StyleCI --- framework/core/src/Http/Middleware/ShareErrorsFromSession.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Http/Middleware/ShareErrorsFromSession.php b/framework/core/src/Http/Middleware/ShareErrorsFromSession.php index 5d0a5ed9b..6f03c6215 100644 --- a/framework/core/src/Http/Middleware/ShareErrorsFromSession.php +++ b/framework/core/src/Http/Middleware/ShareErrorsFromSession.php @@ -1,4 +1,5 @@ Date: Fri, 15 Dec 2017 08:10:32 +0100 Subject: [PATCH 115/172] - satisfying styleci - cleared the merge conflict in the phpdoc - changed some string class names to use ::class --- framework/core/src/Admin/AdminServiceProvider.php | 5 +---- .../Listener/CheckCustomLessFormat.php | 10 +++++----- .../Api/Controller/ListNotificationsController.php | 2 +- framework/core/src/Forum/ForumServiceProvider.php | 2 +- .../src/Foundation/Console/CacheClearCommand.php | 8 -------- .../src/Http/Middleware/ShareErrorsFromSession.php | 1 - .../core/src/{Core => User}/AvatarUploader.php | 3 +-- .../core/src/User/Command/DeleteAvatarHandler.php | 2 +- .../core/src/User/Command/EditUserHandler.php | 2 +- .../core/src/User/Command/RegisterUserHandler.php | 2 +- .../core/src/User/Command/UploadAvatarHandler.php | 3 +-- .../{Core => User}/Listener/SelfDemotionGuard.php | 14 +++++++------- framework/core/src/User/User.php | 8 -------- framework/core/src/User/UserServiceProvider.php | 14 +++++++------- 14 files changed, 27 insertions(+), 49 deletions(-) rename framework/core/src/{Core => Admin}/Listener/CheckCustomLessFormat.php (78%) rename framework/core/src/{Core => User}/AvatarUploader.php (96%) rename framework/core/src/{Core => User}/Listener/SelfDemotionGuard.php (82%) diff --git a/framework/core/src/Admin/AdminServiceProvider.php b/framework/core/src/Admin/AdminServiceProvider.php index 9104bef74..d517f1fe6 100644 --- a/framework/core/src/Admin/AdminServiceProvider.php +++ b/framework/core/src/Admin/AdminServiceProvider.php @@ -11,14 +11,11 @@ namespace Flarum\Admin; +use Flarum\Admin\Listener\CheckCustomLessFormat; use Flarum\Admin\Middleware\RequireAdministrateAbility; use Flarum\Event\ConfigureMiddleware; use Flarum\Extension\Event\Disabled; use Flarum\Extension\Event\Enabled; -use Flarum\Core\Listener\CheckCustomLessFormat; -use Flarum\Event\ExtensionWasDisabled; -use Flarum\Event\ExtensionWasEnabled; -use Flarum\Event\SettingWasSet; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Http\Middleware\AuthenticateWithSession; use Flarum\Http\Middleware\DispatchRoute; diff --git a/framework/core/src/Core/Listener/CheckCustomLessFormat.php b/framework/core/src/Admin/Listener/CheckCustomLessFormat.php similarity index 78% rename from framework/core/src/Core/Listener/CheckCustomLessFormat.php rename to framework/core/src/Admin/Listener/CheckCustomLessFormat.php index 324b62bae..c8d80d2b0 100644 --- a/framework/core/src/Core/Listener/CheckCustomLessFormat.php +++ b/framework/core/src/Admin/Listener/CheckCustomLessFormat.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Listener; +namespace Flarum\Admin\Listener; -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/Api/Controller/ListNotificationsController.php b/framework/core/src/Api/Controller/ListNotificationsController.php index 434078944..ceb9a2a6f 100644 --- a/framework/core/src/Api/Controller/ListNotificationsController.php +++ b/framework/core/src/Api/Controller/ListNotificationsController.php @@ -11,10 +11,10 @@ namespace Flarum\Api\Controller; +use Flarum\Api\UrlGenerator; use Flarum\Discussion\Discussion; use Flarum\Notification\NotificationRepository; use Flarum\User\Exception\PermissionDeniedException; -use Flarum\Api\UrlGenerator; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; diff --git a/framework/core/src/Forum/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index 530d0e589..175346ad3 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -26,9 +26,9 @@ use Flarum\Http\Middleware\StartSession; use Flarum\Http\RouteCollection; use Flarum\Http\RouteHandlerFactory; use Flarum\Http\UrlGenerator; -use Zend\Stratigility\MiddlewarePipe; use Flarum\Settings\SettingsRepositoryInterface; use Symfony\Component\Translation\TranslatorInterface; +use Zend\Stratigility\MiddlewarePipe; class ForumServiceProvider extends AbstractServiceProvider { diff --git a/framework/core/src/Foundation/Console/CacheClearCommand.php b/framework/core/src/Foundation/Console/CacheClearCommand.php index 4b2a8ee99..6bd6650da 100644 --- a/framework/core/src/Foundation/Console/CacheClearCommand.php +++ b/framework/core/src/Foundation/Console/CacheClearCommand.php @@ -25,20 +25,12 @@ class CacheClearCommand extends AbstractCommand protected $cache; /** -<<<<<<< HEAD:src/Foundation/Console/CacheClearCommand.php - * @var \Flarum\Forum\Frontend -======= * @var ForumWebApp ->>>>>>> master:src/Debug/Console/CacheClearCommand.php */ protected $forum; /** -<<<<<<< HEAD:src/Foundation/Console/CacheClearCommand.php - * @var \Flarum\Admin\Frontend -======= * @var AdminWebApp ->>>>>>> master:src/Debug/Console/CacheClearCommand.php */ protected $admin; diff --git a/framework/core/src/Http/Middleware/ShareErrorsFromSession.php b/framework/core/src/Http/Middleware/ShareErrorsFromSession.php index 5d0a5ed9b..87c2b845a 100644 --- a/framework/core/src/Http/Middleware/ShareErrorsFromSession.php +++ b/framework/core/src/Http/Middleware/ShareErrorsFromSession.php @@ -59,4 +59,3 @@ class ShareErrorsFromSession implements MiddlewareInterface return $out ? $out($request, $response) : $response; } } - diff --git a/framework/core/src/Core/AvatarUploader.php b/framework/core/src/User/AvatarUploader.php similarity index 96% rename from framework/core/src/Core/AvatarUploader.php rename to framework/core/src/User/AvatarUploader.php index 180bae93c..29f1e9e2e 100755 --- a/framework/core/src/Core/AvatarUploader.php +++ b/framework/core/src/User/AvatarUploader.php @@ -9,9 +9,8 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\User; -use Flarum\User\User; use Illuminate\Support\Str; use Intervention\Image\Image; use League\Flysystem\FilesystemInterface; diff --git a/framework/core/src/User/Command/DeleteAvatarHandler.php b/framework/core/src/User/Command/DeleteAvatarHandler.php index a5ee526a1..91b0dd50d 100644 --- a/framework/core/src/User/Command/DeleteAvatarHandler.php +++ b/framework/core/src/User/Command/DeleteAvatarHandler.php @@ -13,9 +13,9 @@ namespace Flarum\User\Command; use Flarum\Foundation\DispatchEventsTrait; use Flarum\User\AssertPermissionTrait; +use Flarum\User\AvatarUploader; use Flarum\User\Event\AvatarDeleting; use Flarum\User\UserRepository; -use Flarum\Core\AvatarUploader; use Flarum\Event\AvatarWillBeDeleted; use Illuminate\Contracts\Events\Dispatcher; diff --git a/framework/core/src/User/Command/EditUserHandler.php b/framework/core/src/User/Command/EditUserHandler.php index 4c2d887f6..7dd0cd3dc 100644 --- a/framework/core/src/User/Command/EditUserHandler.php +++ b/framework/core/src/User/Command/EditUserHandler.php @@ -12,7 +12,7 @@ namespace Flarum\User\Command; use Exception; -use Flarum\Core\AvatarUploader; +use Flarum\User\AvatarUploader; use Flarum\Foundation\DispatchEventsTrait; use Flarum\User\AssertPermissionTrait; use Flarum\User\Event\GroupsChanged; diff --git a/framework/core/src/User/Command/RegisterUserHandler.php b/framework/core/src/User/Command/RegisterUserHandler.php index 91d628810..977766fce 100644 --- a/framework/core/src/User/Command/RegisterUserHandler.php +++ b/framework/core/src/User/Command/RegisterUserHandler.php @@ -12,7 +12,7 @@ namespace Flarum\User\Command; use Exception; -use Flarum\Core\AvatarUploader; +use Flarum\User\AvatarUploader; use Flarum\Foundation\DispatchEventsTrait; use Flarum\Settings\SettingsRepositoryInterface; use Flarum\User\AssertPermissionTrait; diff --git a/framework/core/src/User/Command/UploadAvatarHandler.php b/framework/core/src/User/Command/UploadAvatarHandler.php index 9e50a192c..b0dc60b6d 100644 --- a/framework/core/src/User/Command/UploadAvatarHandler.php +++ b/framework/core/src/User/Command/UploadAvatarHandler.php @@ -11,11 +11,10 @@ namespace Flarum\User\Command; -use Exception; -use Flarum\Core\AvatarUploader; 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; diff --git a/framework/core/src/Core/Listener/SelfDemotionGuard.php b/framework/core/src/User/Listener/SelfDemotionGuard.php similarity index 82% rename from framework/core/src/Core/Listener/SelfDemotionGuard.php rename to framework/core/src/User/Listener/SelfDemotionGuard.php index 1fbfe3e89..d45d8ccb8 100644 --- a/framework/core/src/Core/Listener/SelfDemotionGuard.php +++ b/framework/core/src/User/Listener/SelfDemotionGuard.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Listener; +namespace Flarum\User\Listener; -use Flarum\Core\Exception\PermissionDeniedException; -use Flarum\Core\Group; -use Flarum\Event\UserWillBeSaved; +use Flarum\User\Exception\PermissionDeniedException; +use Flarum\Group\Group; +use Flarum\User\Event\Saving; 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/User/User.php b/framework/core/src/User/User.php index b5f6824c7..38a9f6900 100755 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -18,14 +18,6 @@ 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\Foundation\Application; use Flarum\Foundation\EventGeneratorTrait; use Flarum\Group\Group; diff --git a/framework/core/src/User/UserServiceProvider.php b/framework/core/src/User/UserServiceProvider.php index 7c17943c6..be6da2d8a 100644 --- a/framework/core/src/User/UserServiceProvider.php +++ b/framework/core/src/User/UserServiceProvider.php @@ -30,7 +30,7 @@ class UserServiceProvider extends AbstractServiceProvider }); $this->app->alias('flarum.gate', 'Illuminate\Contracts\Auth\Access\Gate'); - $this->app->alias('flarum.gate', 'Flarum\User\Gate'); + $this->app->alias('flarum.gate', Gate::class); $this->registerAvatarsFilesystem(); } @@ -45,11 +45,11 @@ class UserServiceProvider extends AbstractServiceProvider ->needs('League\Flysystem\FilesystemInterface') ->give($avatarsFilesystem); - $this->app->when('Flarum\User\Command\DeleteAvatarHandler') + $this->app->when(Command\DeleteAvatarHandler::class) ->needs('League\Flysystem\FilesystemInterface') ->give($avatarsFilesystem); - $this->app->when('Flarum\User\Command\RegisterUserHandler') + $this->app->when(Command\RegisterUserHandler::class) ->needs('League\Flysystem\FilesystemInterface') ->give($avatarsFilesystem); } @@ -86,10 +86,10 @@ class UserServiceProvider extends AbstractServiceProvider $events = $this->app->make('events'); - $events->subscribe('Flarum\Core\Listener\SelfDemotionGuard'); - $events->subscribe('Flarum\User\EmailConfirmationMailer'); - $events->subscribe('Flarum\User\UserMetadataUpdater'); - $events->subscribe('Flarum\User\UserPolicy'); + $events->subscribe(Listener\SelfDemotionGuard::class); + $events->subscribe(EmailConfirmationMailer::class); + $events->subscribe(UserMetadataUpdater::class); + $events->subscribe(UserPolicy::class); $events->listen(ConfigureUserPreferences::class, [$this, 'configureUserPreferences']); } From b0974d72f5efa0e771d43ddd6523afc337f57da5 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Fri, 15 Dec 2017 08:14:15 +0100 Subject: [PATCH 116/172] satisfying sci isnt enough for it, lets please it further --- framework/core/src/Http/Middleware/ShareErrorsFromSession.php | 1 + framework/core/src/User/Command/DeleteAvatarHandler.php | 1 - framework/core/src/User/Command/EditUserHandler.php | 2 +- framework/core/src/User/Command/RegisterUserHandler.php | 2 +- framework/core/src/User/Listener/SelfDemotionGuard.php | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/core/src/Http/Middleware/ShareErrorsFromSession.php b/framework/core/src/Http/Middleware/ShareErrorsFromSession.php index 87c2b845a..6f03c6215 100644 --- a/framework/core/src/Http/Middleware/ShareErrorsFromSession.php +++ b/framework/core/src/Http/Middleware/ShareErrorsFromSession.php @@ -1,4 +1,5 @@ Date: Fri, 15 Dec 2017 08:15:08 +0100 Subject: [PATCH 117/172] and another.. --- framework/core/src/User/Listener/SelfDemotionGuard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/User/Listener/SelfDemotionGuard.php b/framework/core/src/User/Listener/SelfDemotionGuard.php index f4aaf4276..9c015ed83 100644 --- a/framework/core/src/User/Listener/SelfDemotionGuard.php +++ b/framework/core/src/User/Listener/SelfDemotionGuard.php @@ -11,9 +11,9 @@ namespace Flarum\User\Listener; +use Flarum\Group\Group; use Flarum\User\Event\Saving; use Flarum\User\Exception\PermissionDeniedException; -use Flarum\Group\Group; use Illuminate\Contracts\Events\Dispatcher; class SelfDemotionGuard From 3f7b51cf2447776114ba7507c3c3514eedb9cbb9 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Fri, 15 Dec 2017 08:29:07 +0100 Subject: [PATCH 118/172] fixed the BasicFoo vs FooBasic serializer definition issue, prevented for future using ::class --- framework/core/src/Api/ApiServiceProvider.php | 3 ++- .../Api/Serializer/BasicDiscussionSerializer.php | 14 +++++++------- .../src/Api/Serializer/BasicPostSerializer.php | 4 ++-- .../src/Api/Serializer/BasicUserSerializer.php | 2 +- .../core/src/Api/Serializer/ForumSerializer.php | 2 +- .../core/src/Api/Serializer/GroupSerializer.php | 2 +- .../src/Api/Serializer/NotificationSerializer.php | 4 ++-- .../core/src/Api/Serializer/PostSerializer.php | 8 ++++---- 8 files changed, 20 insertions(+), 19 deletions(-) diff --git a/framework/core/src/Api/ApiServiceProvider.php b/framework/core/src/Api/ApiServiceProvider.php index 7360358a3..f0bdf6659 100644 --- a/framework/core/src/Api/ApiServiceProvider.php +++ b/framework/core/src/Api/ApiServiceProvider.php @@ -15,6 +15,7 @@ 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; @@ -114,7 +115,7 @@ class ApiServiceProvider extends AbstractServiceProvider { $blueprints = []; $serializers = [ - 'discussionRenamed' => 'Flarum\Api\Serializer\DiscussionBasicSerializer' + 'discussionRenamed' => BasicDiscussionSerializer::class ]; $this->app->make('events')->fire( diff --git a/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php b/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php index b0f39b2fe..b03d6d002 100644 --- a/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php +++ b/framework/core/src/Api/Serializer/BasicDiscussionSerializer.php @@ -46,7 +46,7 @@ class BasicDiscussionSerializer extends AbstractSerializer */ protected function startUser($discussion) { - return $this->hasOne($discussion, 'Flarum\Api\Serializer\BasicUserSerializer'); + return $this->hasOne($discussion, BasicUserSerializer::class); } /** @@ -54,7 +54,7 @@ class BasicDiscussionSerializer extends AbstractSerializer */ protected function startPost($discussion) { - return $this->hasOne($discussion, 'Flarum\Api\Serializer\BasicPostSerializer'); + return $this->hasOne($discussion, BasicPostSerializer::class); } /** @@ -62,7 +62,7 @@ class BasicDiscussionSerializer extends AbstractSerializer */ protected function lastUser($discussion) { - return $this->hasOne($discussion, 'Flarum\Api\Serializer\BasicUserSerializer'); + return $this->hasOne($discussion, BasicUserSerializer::class); } /** @@ -70,7 +70,7 @@ class BasicDiscussionSerializer extends AbstractSerializer */ protected function lastPost($discussion) { - return $this->hasOne($discussion, 'Flarum\Api\Serializer\BasicPostSerializer'); + return $this->hasOne($discussion, BasicPostSerializer::class); } /** @@ -78,7 +78,7 @@ class BasicDiscussionSerializer 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 BasicDiscussionSerializer extends AbstractSerializer */ protected function relevantPosts($discussion) { - return $this->hasMany($discussion, 'Flarum\Api\Serializer\BasicPostSerializer'); + return $this->hasMany($discussion, BasicPostSerializer::class); } /** @@ -94,6 +94,6 @@ class BasicDiscussionSerializer 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/BasicPostSerializer.php b/framework/core/src/Api/Serializer/BasicPostSerializer.php index a2a10feeb..103bd8a06 100644 --- a/framework/core/src/Api/Serializer/BasicPostSerializer.php +++ b/framework/core/src/Api/Serializer/BasicPostSerializer.php @@ -57,7 +57,7 @@ class BasicPostSerializer extends AbstractSerializer */ protected function user($post) { - return $this->hasOne($post, 'Flarum\Api\Serializer\BasicUserSerializer'); + return $this->hasOne($post, BasicUserSerializer::class); } /** @@ -65,6 +65,6 @@ class BasicPostSerializer extends AbstractSerializer */ protected function discussion($post) { - return $this->hasOne($post, 'Flarum\Api\Serializer\BasicDiscussionSerializer'); + return $this->hasOne($post, BasicDiscussionSerializer::class); } } diff --git a/framework/core/src/Api/Serializer/BasicUserSerializer.php b/framework/core/src/Api/Serializer/BasicUserSerializer.php index 5e84273d5..3a6b3d46d 100644 --- a/framework/core/src/Api/Serializer/BasicUserSerializer.php +++ b/framework/core/src/Api/Serializer/BasicUserSerializer.php @@ -47,6 +47,6 @@ class BasicUserSerializer 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/ForumSerializer.php b/framework/core/src/Api/Serializer/ForumSerializer.php index 399fcfd83..02dcdd6d6 100644 --- a/framework/core/src/Api/Serializer/ForumSerializer.php +++ b/framework/core/src/Api/Serializer/ForumSerializer.php @@ -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); } /** diff --git a/framework/core/src/Api/Serializer/GroupSerializer.php b/framework/core/src/Api/Serializer/GroupSerializer.php index 7cd1eb989..7511329cc 100644 --- a/framework/core/src/Api/Serializer/GroupSerializer.php +++ b/framework/core/src/Api/Serializer/GroupSerializer.php @@ -62,7 +62,7 @@ class GroupSerializer extends AbstractSerializer */ protected function permissions($group) { - return $this->hasMany($group, 'Flarum\Api\Serializers\PermissionSerializer'); + return $this->hasMany($group, PermissionSerializer::class); } /** diff --git a/framework/core/src/Api/Serializer/NotificationSerializer.php b/framework/core/src/Api/Serializer/NotificationSerializer.php index 9159445a3..55b809079 100644 --- a/framework/core/src/Api/Serializer/NotificationSerializer.php +++ b/framework/core/src/Api/Serializer/NotificationSerializer.php @@ -57,7 +57,7 @@ class NotificationSerializer extends AbstractSerializer */ protected function user($notification) { - return $this->hasOne($notification, 'Flarum\Api\Serializer\BasicUserSerializer'); + 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\BasicUserSerializer'); + 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 7843e43ce..ee807374b 100644 --- a/framework/core/src/Api/Serializer/PostSerializer.php +++ b/framework/core/src/Api/Serializer/PostSerializer.php @@ -77,7 +77,7 @@ class PostSerializer extends BasicPostSerializer */ 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 BasicPostSerializer */ 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 BasicPostSerializer */ 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 BasicPostSerializer */ protected function hideUser($post) { - return $this->hasOne($post, 'Flarum\Api\Serializer\UserBasicSerializer'); + return $this->hasOne($post, BasicUserSerializer::class); } } From 033961844dda7e74ff2f9a268483dca4e34c294c Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Fri, 15 Dec 2017 09:29:20 +0100 Subject: [PATCH 119/172] - FilesystemInterface no longer needed in User related handlers - FilesystemInterface conditional ioc binding moved to AvatarUploader - User::getAvatarAtribute failed to use the UrlGenerator properly --- .../core/src/User/Command/UploadAvatarHandler.php | 2 +- framework/core/src/User/User.php | 2 +- framework/core/src/User/UserServiceProvider.php | 10 +--------- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/framework/core/src/User/Command/UploadAvatarHandler.php b/framework/core/src/User/Command/UploadAvatarHandler.php index b0dc60b6d..18fa84c00 100644 --- a/framework/core/src/User/Command/UploadAvatarHandler.php +++ b/framework/core/src/User/Command/UploadAvatarHandler.php @@ -98,7 +98,7 @@ class UploadAvatarHandler $image = (new ImageManager)->make($tmpFile); $this->events->fire( - new AvatarSaving($user, $actor, $tmpFile) + new AvatarSaving($user, $actor, $image) ); $this->uploader->upload($user, $image); diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 38a9f6900..577ab1dcb 100755 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -316,7 +316,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); } } diff --git a/framework/core/src/User/UserServiceProvider.php b/framework/core/src/User/UserServiceProvider.php index be6da2d8a..1b1a52954 100644 --- a/framework/core/src/User/UserServiceProvider.php +++ b/framework/core/src/User/UserServiceProvider.php @@ -41,15 +41,7 @@ class UserServiceProvider extends AbstractServiceProvider return $app->make('Illuminate\Contracts\Filesystem\Factory')->disk('flarum-avatars')->getDriver(); }; - $this->app->when('Flarum\User\Command\UploadAvatarHandler') - ->needs('League\Flysystem\FilesystemInterface') - ->give($avatarsFilesystem); - - $this->app->when(Command\DeleteAvatarHandler::class) - ->needs('League\Flysystem\FilesystemInterface') - ->give($avatarsFilesystem); - - $this->app->when(Command\RegisterUserHandler::class) + $this->app->when(AvatarUploader::class) ->needs('League\Flysystem\FilesystemInterface') ->give($avatarsFilesystem); } From 29ab5b83b1243ae776979d04f05994c55ad46db8 Mon Sep 17 00:00:00 2001 From: Daniel Klabbers Date: Fri, 15 Dec 2017 09:35:02 +0100 Subject: [PATCH 120/172] the admin service provider also has to use the new HandleError logic --- framework/core/src/Admin/AdminServiceProvider.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/framework/core/src/Admin/AdminServiceProvider.php b/framework/core/src/Admin/AdminServiceProvider.php index d517f1fe6..ccdf4fc62 100644 --- a/framework/core/src/Admin/AdminServiceProvider.php +++ b/framework/core/src/Admin/AdminServiceProvider.php @@ -51,8 +51,7 @@ class AdminServiceProvider extends AbstractServiceProvider // All requests should first be piped through our global error handler $debugMode = ! $app->isUpToDate() || $app->inDebugMode(); - $errorDir = __DIR__.'/../../error'; - $pipe->pipe(new HandleErrors($errorDir, $app->make('log'), $debugMode)); + $pipe->pipe($app->make(HandleErrors::class, ['debug' => $debugMode])); $pipe->pipe($app->make(ParseJsonBody::class)); $pipe->pipe($app->make(StartSession::class)); From 1ba7ba0ad7c58051db8b1dbecbcfca375c210930 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 19 Dec 2017 18:38:00 +1030 Subject: [PATCH 121/172] Pick up config when setting a new base path --- framework/core/src/Foundation/Site.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/framework/core/src/Foundation/Site.php b/framework/core/src/Foundation/Site.php index 904e403de..e069366e8 100644 --- a/framework/core/src/Foundation/Site.php +++ b/framework/core/src/Foundation/Site.php @@ -95,6 +95,10 @@ class Site { $this->basePath = $basePath; + if (file_exists($file = $this->basePath.'/config.php')) { + $this->config = include $file; + } + return $this; } From 37f7e7fa67ecbc6efd1660baae455f2abccdbece Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 19 Dec 2017 18:52:27 +1030 Subject: [PATCH 122/172] Fix usage of UrlGenerator in notifications --- .../core/src/Api/Controller/ListNotificationsController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Api/Controller/ListNotificationsController.php b/framework/core/src/Api/Controller/ListNotificationsController.php index ceb9a2a6f..f5f360309 100644 --- a/framework/core/src/Api/Controller/ListNotificationsController.php +++ b/framework/core/src/Api/Controller/ListNotificationsController.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Controller; -use Flarum\Api\UrlGenerator; +use Flarum\Http\UrlGenerator; use Flarum\Discussion\Discussion; use Flarum\Notification\NotificationRepository; use Flarum\User\Exception\PermissionDeniedException; @@ -92,7 +92,7 @@ class ListNotificationsController extends AbstractListController } $document->addPaginationLinks( - $this->url->toRoute('notifications.index'), + $this->url->to('api')->route('notifications.index'), $request->getQueryParams(), $offset, $limit, From 58ead0e16bc5aa56a917c82906a67b002d91c628 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 19 Dec 2017 08:24:06 +0000 Subject: [PATCH 123/172] Apply fixes from StyleCI [ci skip] [skip ci] --- .../core/src/Api/Controller/ListNotificationsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Api/Controller/ListNotificationsController.php b/framework/core/src/Api/Controller/ListNotificationsController.php index f5f360309..f09dd7ca9 100644 --- a/framework/core/src/Api/Controller/ListNotificationsController.php +++ b/framework/core/src/Api/Controller/ListNotificationsController.php @@ -11,8 +11,8 @@ namespace Flarum\Api\Controller; -use Flarum\Http\UrlGenerator; use Flarum\Discussion\Discussion; +use Flarum\Http\UrlGenerator; use Flarum\Notification\NotificationRepository; use Flarum\User\Exception\PermissionDeniedException; use Psr\Http\Message\ServerRequestInterface; From 1ea421482a852f2c834526cbbe9551b174683b33 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 19 Dec 2017 18:58:45 +1030 Subject: [PATCH 124/172] Remove Listener namespace We may reverse this in the future, but for now just going for consistency between domains (the majority do not use a Listener namespace) --- framework/core/src/Admin/AdminServiceProvider.php | 1 - .../core/src/Admin/{Listener => }/CheckCustomLessFormat.php | 2 +- framework/core/src/User/{Listener => }/SelfDemotionGuard.php | 2 +- framework/core/src/User/UserServiceProvider.php | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) rename framework/core/src/Admin/{Listener => }/CheckCustomLessFormat.php (97%) rename framework/core/src/User/{Listener => }/SelfDemotionGuard.php (98%) diff --git a/framework/core/src/Admin/AdminServiceProvider.php b/framework/core/src/Admin/AdminServiceProvider.php index ccdf4fc62..d0ca1975f 100644 --- a/framework/core/src/Admin/AdminServiceProvider.php +++ b/framework/core/src/Admin/AdminServiceProvider.php @@ -11,7 +11,6 @@ namespace Flarum\Admin; -use Flarum\Admin\Listener\CheckCustomLessFormat; use Flarum\Admin\Middleware\RequireAdministrateAbility; use Flarum\Event\ConfigureMiddleware; use Flarum\Extension\Event\Disabled; diff --git a/framework/core/src/Admin/Listener/CheckCustomLessFormat.php b/framework/core/src/Admin/CheckCustomLessFormat.php similarity index 97% rename from framework/core/src/Admin/Listener/CheckCustomLessFormat.php rename to framework/core/src/Admin/CheckCustomLessFormat.php index c8d80d2b0..a2644945f 100644 --- a/framework/core/src/Admin/Listener/CheckCustomLessFormat.php +++ b/framework/core/src/Admin/CheckCustomLessFormat.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Admin\Listener; +namespace Flarum\Admin; use Flarum\Foundation\ValidationException; use Flarum\Settings\Event\Serializing; diff --git a/framework/core/src/User/Listener/SelfDemotionGuard.php b/framework/core/src/User/SelfDemotionGuard.php similarity index 98% rename from framework/core/src/User/Listener/SelfDemotionGuard.php rename to framework/core/src/User/SelfDemotionGuard.php index 9c015ed83..1aec59e6c 100644 --- a/framework/core/src/User/Listener/SelfDemotionGuard.php +++ b/framework/core/src/User/SelfDemotionGuard.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\User\Listener; +namespace Flarum\User; use Flarum\Group\Group; use Flarum\User\Event\Saving; diff --git a/framework/core/src/User/UserServiceProvider.php b/framework/core/src/User/UserServiceProvider.php index 1b1a52954..dc7774e2e 100644 --- a/framework/core/src/User/UserServiceProvider.php +++ b/framework/core/src/User/UserServiceProvider.php @@ -78,7 +78,7 @@ class UserServiceProvider extends AbstractServiceProvider $events = $this->app->make('events'); - $events->subscribe(Listener\SelfDemotionGuard::class); + $events->subscribe(SelfDemotionGuard::class); $events->subscribe(EmailConfirmationMailer::class); $events->subscribe(UserMetadataUpdater::class); $events->subscribe(UserPolicy::class); From d8035374bef02255920a7f8fe97378da8448449a Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 19 Dec 2017 23:16:06 +0100 Subject: [PATCH 125/172] DRY up loading of config --- framework/core/src/Foundation/Site.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/framework/core/src/Foundation/Site.php b/framework/core/src/Foundation/Site.php index e069366e8..3c73b643a 100644 --- a/framework/core/src/Foundation/Site.php +++ b/framework/core/src/Foundation/Site.php @@ -65,7 +65,7 @@ class Site /** * @var array */ - protected $config; + protected $config = []; protected $extenders = []; @@ -73,10 +73,6 @@ class Site { $this->basePath = getcwd(); $this->publicPath = $this->basePath; - - if (file_exists($file = $this->basePath.'/config.php')) { - $this->config = include $file; - } } /** @@ -95,10 +91,6 @@ class Site { $this->basePath = $basePath; - if (file_exists($file = $this->basePath.'/config.php')) { - $this->config = include $file; - } - return $this; } @@ -135,6 +127,15 @@ class Site 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 */ @@ -153,7 +154,7 @@ class Site } $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); From e779b89bfb9a07fe5c8d28f13debbe8ff3f969dc Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 19 Dec 2017 23:48:38 +0100 Subject: [PATCH 126/172] Fix previous commit Prevent `flarum.config` from being bound in the container when the software has not been installed yet. --- framework/core/src/Foundation/Site.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Foundation/Site.php b/framework/core/src/Foundation/Site.php index 3c73b643a..a86f7d6e1 100644 --- a/framework/core/src/Foundation/Site.php +++ b/framework/core/src/Foundation/Site.php @@ -65,7 +65,7 @@ class Site /** * @var array */ - protected $config = []; + protected $config; protected $extenders = []; From 54ecd48b722933c4bb0a32d81aeaecdc5699a8f6 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 20 Dec 2017 00:00:23 +0100 Subject: [PATCH 127/172] Disable HandleErrors middleware during installation Temporary measure until we have a real fix in place. --- framework/core/src/Http/Server.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Http/Server.php b/framework/core/src/Http/Server.php index 590a73a24..8c50cb3e2 100644 --- a/framework/core/src/Http/Server.php +++ b/framework/core/src/Http/Server.php @@ -67,6 +67,7 @@ class Server */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out) { + // FIXME: Only call this when app is installed. Do this via middleware? $this->collectGarbage(); $middleware = $this->getMiddleware($request->getUri()->getPath()); @@ -119,8 +120,10 @@ class Server { $this->app->register(InstallServiceProvider::class); - $pipe->pipe(new HandleErrors($this->getErrorDir(), $this->app->make('log'), true)); - + // 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')])); From b9f68921b701a009db9d930229333d53f54f3cb7 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 20 Dec 2017 00:20:23 +0100 Subject: [PATCH 128/172] Fix more incompatibilities with Laravel 5.5 --- .../migrations/2016_02_04_095452_add_slug_to_discussions.php | 2 +- framework/core/src/Database/DatabaseMigrationRepository.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) 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/Database/DatabaseMigrationRepository.php b/framework/core/src/Database/DatabaseMigrationRepository.php index fdce0f00e..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') - ->pluck('migration'); + ->pluck('migration') + ->toArray(); } /** From 2936b894d46977ac5699cd3a39486132b40a49ae Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 21 Dec 2017 12:23:34 +0100 Subject: [PATCH 129/172] Move garbage collection into middleware This prevents garbage collection to randomly break the installer: before installation, the models that are being accessed have no database connection. Now, the middleware is only mounted into the forum's middleware stack. I want API requests to have stable performance, and the forum middleware stack is only mounted when Flarum is installed. --- .../core/src/Forum/ForumServiceProvider.php | 2 + .../src/Http/Middleware/CollectGarbage.php | 55 +++++++++++++++++++ framework/core/src/Http/Server.php | 24 -------- 3 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 framework/core/src/Http/Middleware/CollectGarbage.php diff --git a/framework/core/src/Forum/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index 175346ad3..8e95b0072 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -17,6 +17,7 @@ use Flarum\Extension\Event\Disabled; use Flarum\Extension\Event\Enabled; use Flarum\Foundation\AbstractServiceProvider; 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; @@ -54,6 +55,7 @@ class ForumServiceProvider extends AbstractServiceProvider $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)); 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 @@ + + * + * 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/Server.php b/framework/core/src/Http/Server.php index 8c50cb3e2..80e507d43 100644 --- a/framework/core/src/Http/Server.php +++ b/framework/core/src/Http/Server.php @@ -18,9 +18,6 @@ use Flarum\Http\Middleware\HandleErrors; use Flarum\Http\Middleware\StartSession; use Flarum\Install\InstallServiceProvider; use Flarum\Update\UpdateServiceProvider; -use Flarum\User\AuthToken; -use Flarum\User\EmailToken; -use Flarum\User\PasswordToken; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Zend\Diactoros\Response\HtmlResponse; @@ -67,9 +64,6 @@ class Server */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out) { - // FIXME: Only call this when app is installed. Do this via middleware? - $this->collectGarbage(); - $middleware = $this->getMiddleware($request->getUri()->getPath()); return $middleware($request, $response, $out); @@ -152,24 +146,6 @@ class Server return $pipe; } - 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; - } - private function getErrorDir() { return __DIR__.'/../../error'; From ac0a9e05674399d72bb6b53cdd6156a3de662c43 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 26 Dec 2017 20:38:15 +1030 Subject: [PATCH 130/172] Fix order of array_first arguments As per https://laravel.com/docs/5.3/upgrade (under "Arrays") --- framework/core/src/Forum/Controller/DiscussionController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Forum/Controller/DiscussionController.php b/framework/core/src/Forum/Controller/DiscussionController.php index 931141561..1c16d4669 100644 --- a/framework/core/src/Forum/Controller/DiscussionController.php +++ b/framework/core/src/Forum/Controller/DiscussionController.php @@ -64,7 +64,7 @@ class DiscussionController extends FrontendController $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; }); }; From f846d5c5e43fca28940ae02f93ee7cbb2d7be503 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 27 Dec 2017 16:17:25 +1030 Subject: [PATCH 131/172] Fix some class names, clean up imports --- framework/core/src/Forum/Controller/ResetPasswordController.php | 1 - framework/core/src/Forum/Controller/SavePasswordController.php | 2 +- framework/core/src/Forum/ForumServiceProvider.php | 1 + framework/core/src/Foundation/AbstractValidator.php | 2 +- framework/core/src/User/User.php | 1 - framework/core/src/User/UserServiceProvider.php | 1 + 6 files changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/core/src/Forum/Controller/ResetPasswordController.php b/framework/core/src/Forum/Controller/ResetPasswordController.php index 2f3b025e2..3752ead21 100644 --- a/framework/core/src/Forum/Controller/ResetPasswordController.php +++ b/framework/core/src/Forum/Controller/ResetPasswordController.php @@ -27,7 +27,6 @@ class ResetPasswordController extends AbstractHtmlController /** * @param Factory $view - * @param TranslatorInterface $translator */ public function __construct(Factory $view) { diff --git a/framework/core/src/Forum/Controller/SavePasswordController.php b/framework/core/src/Forum/Controller/SavePasswordController.php index 0a1a25400..ea3257062 100644 --- a/framework/core/src/Forum/Controller/SavePasswordController.php +++ b/framework/core/src/Forum/Controller/SavePasswordController.php @@ -17,7 +17,7 @@ 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; diff --git a/framework/core/src/Forum/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index 8e95b0072..f0a68d342 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -27,6 +27,7 @@ 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; diff --git a/framework/core/src/Foundation/AbstractValidator.php b/framework/core/src/Foundation/AbstractValidator.php index ee1062af5..25108526f 100644 --- a/framework/core/src/Foundation/AbstractValidator.php +++ b/framework/core/src/Foundation/AbstractValidator.php @@ -13,8 +13,8 @@ namespace Flarum\Foundation; 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 diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index 577ab1dcb..7c02c882d 100755 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -16,7 +16,6 @@ use Flarum\Database\AbstractModel; use Flarum\Database\ScopeVisibilityTrait; use Flarum\Event\ConfigureUserPreferences; use Flarum\Event\GetDisplayName; -use Flarum\Event\PostWasDeleted; use Flarum\Event\PrepareUserGroups; use Flarum\Foundation\Application; use Flarum\Foundation\EventGeneratorTrait; diff --git a/framework/core/src/User/UserServiceProvider.php b/framework/core/src/User/UserServiceProvider.php index dc7774e2e..03f3cbf55 100644 --- a/framework/core/src/User/UserServiceProvider.php +++ b/framework/core/src/User/UserServiceProvider.php @@ -15,6 +15,7 @@ use Flarum\Event\ConfigureUserPreferences; use Flarum\Event\GetPermission; use Flarum\Foundation\AbstractServiceProvider; use Illuminate\Contracts\Container\Container; +use RuntimeException; class UserServiceProvider extends AbstractServiceProvider { From fa1e557e0a3af23442691ee0ed173596a16d8a5c Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 27 Dec 2017 16:17:35 +1030 Subject: [PATCH 132/172] Remove unused method --- framework/core/src/Api/Serializer/GroupSerializer.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/framework/core/src/Api/Serializer/GroupSerializer.php b/framework/core/src/Api/Serializer/GroupSerializer.php index 7511329cc..7207c0153 100644 --- a/framework/core/src/Api/Serializer/GroupSerializer.php +++ b/framework/core/src/Api/Serializer/GroupSerializer.php @@ -57,14 +57,6 @@ class GroupSerializer extends AbstractSerializer ]; } - /** - * @return \Tobscure\JsonApi\Relationship - */ - protected function permissions($group) - { - return $this->hasMany($group, PermissionSerializer::class); - } - /** * @param string $name * @return string From 8b157346dfc11b3b75801369ca965fd9139213e5 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 28 Dec 2017 22:47:13 +0100 Subject: [PATCH 133/172] Fix comment --- framework/core/src/Http/Middleware/CollectGarbage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Http/Middleware/CollectGarbage.php b/framework/core/src/Http/Middleware/CollectGarbage.php index 0a04da16e..5f67bdbd5 100644 --- a/framework/core/src/Http/Middleware/CollectGarbage.php +++ b/framework/core/src/Http/Middleware/CollectGarbage.php @@ -34,7 +34,7 @@ class CollectGarbage implements MiddlewareInterface private function collectGarbageSometimes() { // In order to save performance, we only execute this query - // from time to time (with 50% chance). + // from time to time (with 2% chance). if (! $this->hit()) { return; } From f57dffe4a27927a4a713363b4a968f6a7e636a1f Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 29 Dec 2017 18:42:31 +1030 Subject: [PATCH 134/172] Fix class reference --- framework/core/src/User/EmailToken.php | 2 +- framework/core/src/User/PasswordToken.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/src/User/EmailToken.php b/framework/core/src/User/EmailToken.php index ac143ea12..5de96e2e6 100644 --- a/framework/core/src/User/EmailToken.php +++ b/framework/core/src/User/EmailToken.php @@ -64,7 +64,7 @@ class EmailToken extends AbstractModel */ public function user() { - return $this->belongsTo('Flarum\User'); + return $this->belongsTo(User::class); } /** diff --git a/framework/core/src/User/PasswordToken.php b/framework/core/src/User/PasswordToken.php index 53b955eda..5c8070ead 100644 --- a/framework/core/src/User/PasswordToken.php +++ b/framework/core/src/User/PasswordToken.php @@ -59,6 +59,6 @@ class PasswordToken extends AbstractModel */ public function user() { - return $this->belongsTo('Flarum\User'); + return $this->belongsTo(User::class); } } From b491df89c2a5942f0dd39e5b6f6bea905e1483be Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 29 Dec 2017 21:28:53 +1030 Subject: [PATCH 135/172] Fix view paths --- framework/core/src/Forum/Controller/DiscussionController.php | 2 +- framework/core/src/Forum/Controller/IndexController.php | 2 +- framework/core/src/Forum/ForumServiceProvider.php | 2 +- framework/core/src/Frontend/AbstractFrontend.php | 2 +- framework/core/src/Frontend/FrontendView.php | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/framework/core/src/Forum/Controller/DiscussionController.php b/framework/core/src/Forum/Controller/DiscussionController.php index 1c16d4669..d39ec77c7 100644 --- a/framework/core/src/Forum/Controller/DiscussionController.php +++ b/framework/core/src/Forum/Controller/DiscussionController.php @@ -87,7 +87,7 @@ class DiscussionController extends FrontendController $view->title = $document->data->attributes->title; $view->document = $document; - $view->content = app('view')->make('flarum.forum::content.discussion', compact('document', 'page', 'getResource', 'posts', 'url')); + $view->content = app('view')->make('flarum.forum::frontend.content.discussion', compact('document', 'page', 'getResource', 'posts', 'url')); return $view; } diff --git a/framework/core/src/Forum/Controller/IndexController.php b/framework/core/src/Forum/Controller/IndexController.php index 62701be96..028b716e7 100644 --- a/framework/core/src/Forum/Controller/IndexController.php +++ b/framework/core/src/Forum/Controller/IndexController.php @@ -68,7 +68,7 @@ class IndexController extends FrontendController $document = $this->getDocument($request->getAttribute('actor'), $params); $view->document = $document; - $view->content = app('view')->make('flarum.forum::content.index', compact('document', 'page', 'forum')); + $view->content = app('view')->make('flarum.forum::frontend.content.index', compact('document', 'page', 'forum')); return $view; } diff --git a/framework/core/src/Forum/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index f0a68d342..92f5578fc 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -77,7 +77,7 @@ class ForumServiceProvider extends AbstractServiceProvider { $this->populateRoutes($this->app->make('flarum.forum.routes')); - $this->loadViewsFrom(__DIR__.'/../../views/frontend', 'flarum.forum'); + $this->loadViewsFrom(__DIR__.'/../../views', 'flarum.forum'); $this->app->make('view')->share([ 'translator' => $this->app->make(TranslatorInterface::class), diff --git a/framework/core/src/Frontend/AbstractFrontend.php b/framework/core/src/Frontend/AbstractFrontend.php index 94c480a9c..b20eaf806 100644 --- a/framework/core/src/Frontend/AbstractFrontend.php +++ b/framework/core/src/Frontend/AbstractFrontend.php @@ -86,7 +86,7 @@ abstract class AbstractFrontend */ protected function getLayout() { - return 'flarum.forum::'.$this->getName(); + return 'flarum.forum::frontend.'.$this->getName(); } /** diff --git a/framework/core/src/Frontend/FrontendView.php b/framework/core/src/Frontend/FrontendView.php index 05bd9f3e9..587850f8e 100644 --- a/framework/core/src/Frontend/FrontendView.php +++ b/framework/core/src/Frontend/FrontendView.php @@ -287,7 +287,7 @@ class FrontendView $this->view->share('forum', array_get($forum, 'data')); $this->view->share('debug', $this->app->inDebugMode()); - $view = $this->view->make('flarum.forum::app'); + $view = $this->view->make('flarum.forum::frontend.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 FrontendView protected function buildContent() { - $view = $this->view->make('flarum.forum::content'); + $view = $this->view->make('flarum.forum::frontend.content'); $view->content = $this->content; From 1176ca8a503148dcc8658b9f0543736f0e9dd303 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 29 Dec 2017 21:29:04 +1030 Subject: [PATCH 136/172] Fix URL generator usage --- framework/core/src/Forum/Controller/LogOutController.php | 2 +- framework/core/views/reset-password.blade.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Forum/Controller/LogOutController.php b/framework/core/src/Forum/Controller/LogOutController.php index d3473a068..cc71a20af 100644 --- a/framework/core/src/Forum/Controller/LogOutController.php +++ b/framework/core/src/Forum/Controller/LogOutController.php @@ -108,7 +108,7 @@ class LogOutController implements ControllerInterface $return = array_get($request->getQueryParams(), 'return'); $view = $this->view->make('flarum.forum::log-out') - ->with('url', $this->url->toRoute('logout').'?token='.$csrfToken.($return ? '&return='.urlencode($return) : '')); + ->with('url', $this->url->to('forum')->route('logout').'?token='.$csrfToken.($return ? '&return='.urlencode($return) : '')); return new HtmlResponse($view->render()); } diff --git a/framework/core/views/reset-password.blade.php b/framework/core/views/reset-password.blade.php index 11ac7020e..5c5a9d86b 100644 --- a/framework/core/views/reset-password.blade.php +++ b/framework/core/views/reset-password.blade.php @@ -14,7 +14,7 @@
@endif -
+ From 50a62a0395da61a554bb9b60994dbd345723ecaf Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Sun, 31 Dec 2017 20:48:23 +0100 Subject: [PATCH 137/172] Update year (#1328) --- framework/core/LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/LICENSE b/framework/core/LICENSE index 1e346ea06..e6288c67a 100644 --- a/framework/core/LICENSE +++ b/framework/core/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014-2017 Toby Zerner +Copyright (c) 2014-2018 Toby Zerner Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 47e4bce4da0a4c156d8a0de96dfb8c0ea0f1a4e1 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Mon, 1 Jan 2018 10:34:19 +1030 Subject: [PATCH 138/172] Fix class name --- framework/core/views/reset-password.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/views/reset-password.blade.php b/framework/core/views/reset-password.blade.php index 5c5a9d86b..2b389864d 100644 --- a/framework/core/views/reset-password.blade.php +++ b/framework/core/views/reset-password.blade.php @@ -1,5 +1,5 @@ @extends('flarum.forum::layouts.basic') -@inject('url', 'Flarum\Forum\UrlGenerator') +@inject('url', 'Flarum\Http\UrlGenerator') @section('title', $translator->trans('core.views.reset_password.title')) From 8c787cdd51dba03740aea49e20a28f8caf705bcb Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Mon, 1 Jan 2018 10:45:26 +1030 Subject: [PATCH 139/172] Re-add missing middleware --- framework/core/src/Forum/ForumServiceProvider.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/framework/core/src/Forum/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index 92f5578fc..48478d5f7 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -23,6 +23,7 @@ use Flarum\Http\Middleware\HandleErrors; use Flarum\Http\Middleware\ParseJsonBody; use Flarum\Http\Middleware\RememberFromCookie; use Flarum\Http\Middleware\SetLocale; +use Flarum\Http\Middleware\ShareErrorsFromSession; use Flarum\Http\Middleware\StartSession; use Flarum\Http\RouteCollection; use Flarum\Http\RouteHandlerFactory; @@ -61,6 +62,7 @@ class ForumServiceProvider extends AbstractServiceProvider $pipe->pipe($app->make(RememberFromCookie::class)); $pipe->pipe($app->make(AuthenticateWithSession::class)); $pipe->pipe($app->make(SetLocale::class)); + $pipe->pipe($app->make(ShareErrorsFromSession::class)); event(new ConfigureMiddleware($pipe, 'forum')); From 2a8545c389af4fc5bee26265ce143788c350306a Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 2 Jan 2018 09:48:50 +1030 Subject: [PATCH 140/172] Fix order of array_first arguments As per https://laravel.com/docs/5.3/upgrade (under "Arrays") --- framework/core/src/Notification/NotificationSyncer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/core/src/Notification/NotificationSyncer.php b/framework/core/src/Notification/NotificationSyncer.php index 5dc3a1843..b8cd39b48 100644 --- a/framework/core/src/Notification/NotificationSyncer.php +++ b/framework/core/src/Notification/NotificationSyncer.php @@ -89,7 +89,7 @@ class NotificationSyncer continue; } - $existing = $toDelete->first(function ($i, $notification) use ($user) { + $existing = $toDelete->first(function ($notification, $i) use ($user) { return $notification->user_id === $user->id; }); From 66a320398ef25b0039a596a72fdf570d896450e7 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 2 Jan 2018 19:25:20 +0100 Subject: [PATCH 141/172] Clean up code, use PHP 7 feature :) --- .../core/src/Http/Middleware/HandleErrors.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/framework/core/src/Http/Middleware/HandleErrors.php b/framework/core/src/Http/Middleware/HandleErrors.php index 0c8aa168f..5802adbfc 100644 --- a/framework/core/src/Http/Middleware/HandleErrors.php +++ b/framework/core/src/Http/Middleware/HandleErrors.php @@ -101,7 +101,7 @@ class HandleErrors // Log the exception (with trace) $this->logger->debug($error); - if (! $this->view->exists($name = 'flarum.forum::error.'.$status)) { + if (! $this->view->exists($name = "flarum.forum::error.$status")) { $name = 'flarum.forum::error.default'; } @@ -114,20 +114,16 @@ class HandleErrors private function getMessage($status) { - if (! $translation = $this->getTranslationIfExists($status)) { - if (! $translation = $this->getTranslationIfExists(500)) { - $translation = 'An error occurred while trying to load this page.'; - } - } - - return $translation; + return $this->getTranslationIfExists($status) + ?? $this->getTranslationIfExists(500) + ?? 'An error occurred while trying to load this page.'; } private function getTranslationIfExists($status) { - $key = 'core.views.error.'.$status.'_message'; + $key = "core.views.error.${status}_message"; $translation = $this->translator->trans($key, ['{forum}' => $this->settings->get('forum_title')]); - return $translation === $key ? false : $translation; + return $translation === $key ? null : $translation; } } From eb6453e9f449210168d51aeb3db7d822ec771a3c Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 2 Jan 2018 19:36:48 +0100 Subject: [PATCH 142/172] Use ::class instead of some hardcoded class names This gives us better refactoring functionality in IDEs like PhpStorm, and also more quickly surfaces typos through errors about undefined classes. :) --- .../core/src/Api/Controller/CreateDiscussionController.php | 3 ++- framework/core/src/Api/Controller/CreateGroupController.php | 3 ++- framework/core/src/Api/Controller/CreatePostController.php | 3 ++- framework/core/src/Api/Controller/CreateUserController.php | 3 ++- framework/core/src/Api/Controller/DeleteAvatarController.php | 3 ++- .../core/src/Api/Controller/ListDiscussionsController.php | 3 ++- framework/core/src/Api/Controller/ListGroupsController.php | 3 ++- .../core/src/Api/Controller/ListNotificationsController.php | 3 ++- framework/core/src/Api/Controller/ListPostsController.php | 3 ++- framework/core/src/Api/Controller/ListUsersController.php | 3 ++- framework/core/src/Api/Controller/ShowDiscussionController.php | 3 ++- framework/core/src/Api/Controller/ShowForumController.php | 3 ++- framework/core/src/Api/Controller/ShowPostController.php | 3 ++- framework/core/src/Api/Controller/ShowUserController.php | 3 ++- .../core/src/Api/Controller/UpdateDiscussionController.php | 3 ++- framework/core/src/Api/Controller/UpdateGroupController.php | 3 ++- .../core/src/Api/Controller/UpdateNotificationController.php | 3 ++- framework/core/src/Api/Controller/UpdatePostController.php | 3 ++- framework/core/src/Api/Controller/UpdateUserController.php | 3 ++- framework/core/src/Api/Controller/UploadAvatarController.php | 3 ++- 20 files changed, 40 insertions(+), 20 deletions(-) diff --git a/framework/core/src/Api/Controller/CreateDiscussionController.php b/framework/core/src/Api/Controller/CreateDiscussionController.php index 69f2afc15..a58418a1e 100644 --- a/framework/core/src/Api/Controller/CreateDiscussionController.php +++ b/framework/core/src/Api/Controller/CreateDiscussionController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\DiscussionSerializer; use Flarum\Discussion\Command\ReadDiscussion; use Flarum\Discussion\Command\StartDiscussion; use Flarum\Post\Floodgate; @@ -23,7 +24,7 @@ class CreateDiscussionController extends AbstractCreateController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\DiscussionSerializer'; + public $serializer = DiscussionSerializer::class; /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/CreateGroupController.php b/framework/core/src/Api/Controller/CreateGroupController.php index 9bf23052f..623815924 100644 --- a/framework/core/src/Api/Controller/CreateGroupController.php +++ b/framework/core/src/Api/Controller/CreateGroupController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\GroupSerializer; use Flarum\Group\Command\CreateGroup; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; @@ -21,7 +22,7 @@ class CreateGroupController extends AbstractCreateController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\GroupSerializer'; + public $serializer = GroupSerializer::class; /** * @var Dispatcher diff --git a/framework/core/src/Api/Controller/CreatePostController.php b/framework/core/src/Api/Controller/CreatePostController.php index 1d7e9f5c2..050314838 100644 --- a/framework/core/src/Api/Controller/CreatePostController.php +++ b/framework/core/src/Api/Controller/CreatePostController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\PostSerializer; use Flarum\Discussion\Command\ReadDiscussion; use Flarum\Post\Command\PostReply; use Flarum\Post\Floodgate; @@ -23,7 +24,7 @@ class CreatePostController extends AbstractCreateController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\PostSerializer'; + public $serializer = PostSerializer::class; /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/CreateUserController.php b/framework/core/src/Api/Controller/CreateUserController.php index 155f862ac..20bcda015 100644 --- a/framework/core/src/Api/Controller/CreateUserController.php +++ b/framework/core/src/Api/Controller/CreateUserController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\CurrentUserSerializer; use Flarum\User\Command\RegisterUser; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; @@ -21,7 +22,7 @@ class CreateUserController extends AbstractCreateController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\CurrentUserSerializer'; + public $serializer = CurrentUserSerializer::class; /** * @var Dispatcher diff --git a/framework/core/src/Api/Controller/DeleteAvatarController.php b/framework/core/src/Api/Controller/DeleteAvatarController.php index 61ab87109..c22d9a798 100644 --- a/framework/core/src/Api/Controller/DeleteAvatarController.php +++ b/framework/core/src/Api/Controller/DeleteAvatarController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\UserSerializer; use Flarum\User\Command\DeleteAvatar; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; @@ -21,7 +22,7 @@ class DeleteAvatarController extends AbstractShowController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\UserSerializer'; + public $serializer = UserSerializer::class; /** * @var Dispatcher diff --git a/framework/core/src/Api/Controller/ListDiscussionsController.php b/framework/core/src/Api/Controller/ListDiscussionsController.php index 7a90bf540..55cc4a4e9 100644 --- a/framework/core/src/Api/Controller/ListDiscussionsController.php +++ b/framework/core/src/Api/Controller/ListDiscussionsController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\DiscussionSerializer; use Flarum\Discussion\Search\DiscussionSearcher; use Flarum\Http\UrlGenerator; use Flarum\Search\SearchCriteria; @@ -22,7 +23,7 @@ class ListDiscussionsController extends AbstractListController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\DiscussionSerializer'; + public $serializer = DiscussionSerializer::class; /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/ListGroupsController.php b/framework/core/src/Api/Controller/ListGroupsController.php index f02253810..2ebc478b1 100644 --- a/framework/core/src/Api/Controller/ListGroupsController.php +++ b/framework/core/src/Api/Controller/ListGroupsController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\GroupSerializer; use Flarum\Group\Group; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; @@ -20,7 +21,7 @@ class ListGroupsController extends AbstractListController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\GroupSerializer'; + public $serializer = GroupSerializer::class; /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/ListNotificationsController.php b/framework/core/src/Api/Controller/ListNotificationsController.php index f09dd7ca9..b1bec9718 100644 --- a/framework/core/src/Api/Controller/ListNotificationsController.php +++ b/framework/core/src/Api/Controller/ListNotificationsController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\NotificationSerializer; use Flarum\Discussion\Discussion; use Flarum\Http\UrlGenerator; use Flarum\Notification\NotificationRepository; @@ -23,7 +24,7 @@ class ListNotificationsController extends AbstractListController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\NotificationSerializer'; + public $serializer = NotificationSerializer::class; /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/ListPostsController.php b/framework/core/src/Api/Controller/ListPostsController.php index 5c732bc6f..4818b54e9 100644 --- a/framework/core/src/Api/Controller/ListPostsController.php +++ b/framework/core/src/Api/Controller/ListPostsController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\PostSerializer; use Flarum\Event\ConfigurePostsQuery; use Flarum\Post\PostRepository; use Illuminate\Database\Eloquent\Builder; @@ -23,7 +24,7 @@ class ListPostsController extends AbstractListController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\PostSerializer'; + public $serializer = PostSerializer::class; /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/ListUsersController.php b/framework/core/src/Api/Controller/ListUsersController.php index 679230a98..b04b17233 100644 --- a/framework/core/src/Api/Controller/ListUsersController.php +++ b/framework/core/src/Api/Controller/ListUsersController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\UserSerializer; use Flarum\Http\UrlGenerator; use Flarum\Search\SearchCriteria; use Flarum\User\Exception\PermissionDeniedException; @@ -23,7 +24,7 @@ class ListUsersController extends AbstractListController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\UserSerializer'; + public $serializer = UserSerializer::class; /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/ShowDiscussionController.php b/framework/core/src/Api/Controller/ShowDiscussionController.php index a2930c15e..6321820f0 100644 --- a/framework/core/src/Api/Controller/ShowDiscussionController.php +++ b/framework/core/src/Api/Controller/ShowDiscussionController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\DiscussionSerializer; use Flarum\Discussion\Discussion; use Flarum\Discussion\DiscussionRepository; use Flarum\Post\PostRepository; @@ -33,7 +34,7 @@ class ShowDiscussionController extends AbstractShowController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\DiscussionSerializer'; + public $serializer = DiscussionSerializer::class; /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/ShowForumController.php b/framework/core/src/Api/Controller/ShowForumController.php index 2dd3cd369..427962b77 100644 --- a/framework/core/src/Api/Controller/ShowForumController.php +++ b/framework/core/src/Api/Controller/ShowForumController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\ForumSerializer; use Flarum\Group\Group; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; @@ -20,7 +21,7 @@ class ShowForumController extends AbstractShowController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\ForumSerializer'; + public $serializer = ForumSerializer::class; /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/ShowPostController.php b/framework/core/src/Api/Controller/ShowPostController.php index 49a5f2dec..f269b7ebc 100644 --- a/framework/core/src/Api/Controller/ShowPostController.php +++ b/framework/core/src/Api/Controller/ShowPostController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\PostSerializer; use Flarum\Post\PostRepository; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; @@ -20,7 +21,7 @@ class ShowPostController extends AbstractShowController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\PostSerializer'; + public $serializer = PostSerializer::class; /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/ShowUserController.php b/framework/core/src/Api/Controller/ShowUserController.php index f61d3a1b6..310643c3b 100644 --- a/framework/core/src/Api/Controller/ShowUserController.php +++ b/framework/core/src/Api/Controller/ShowUserController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\UserSerializer; use Flarum\User\UserRepository; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; @@ -20,7 +21,7 @@ class ShowUserController extends AbstractShowController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\UserSerializer'; + public $serializer = UserSerializer::class; /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/UpdateDiscussionController.php b/framework/core/src/Api/Controller/UpdateDiscussionController.php index 3fa1900f3..f8c8cd0b4 100644 --- a/framework/core/src/Api/Controller/UpdateDiscussionController.php +++ b/framework/core/src/Api/Controller/UpdateDiscussionController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\DiscussionSerializer; use Flarum\Discussion\Command\EditDiscussion; use Flarum\Discussion\Command\ReadDiscussion; use Illuminate\Contracts\Bus\Dispatcher; @@ -23,7 +24,7 @@ class UpdateDiscussionController extends AbstractShowController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\DiscussionSerializer'; + public $serializer = DiscussionSerializer::class; /** * @var Dispatcher diff --git a/framework/core/src/Api/Controller/UpdateGroupController.php b/framework/core/src/Api/Controller/UpdateGroupController.php index c4bd8f5dd..919ebcf53 100644 --- a/framework/core/src/Api/Controller/UpdateGroupController.php +++ b/framework/core/src/Api/Controller/UpdateGroupController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\GroupSerializer; use Flarum\Group\Command\EditGroup; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; @@ -21,7 +22,7 @@ class UpdateGroupController extends AbstractShowController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\GroupSerializer'; + public $serializer = GroupSerializer::class; /** * @var Dispatcher diff --git a/framework/core/src/Api/Controller/UpdateNotificationController.php b/framework/core/src/Api/Controller/UpdateNotificationController.php index f459e0338..fe9564838 100644 --- a/framework/core/src/Api/Controller/UpdateNotificationController.php +++ b/framework/core/src/Api/Controller/UpdateNotificationController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\NotificationSerializer; use Flarum\Notification\Command\ReadNotification; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; @@ -21,7 +22,7 @@ class UpdateNotificationController extends AbstractShowController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\NotificationSerializer'; + public $serializer = NotificationSerializer::class; /** * @var Dispatcher diff --git a/framework/core/src/Api/Controller/UpdatePostController.php b/framework/core/src/Api/Controller/UpdatePostController.php index 6f13e3371..fe2db5ed9 100644 --- a/framework/core/src/Api/Controller/UpdatePostController.php +++ b/framework/core/src/Api/Controller/UpdatePostController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\PostSerializer; use Flarum\Post\Command\EditPost; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; @@ -21,7 +22,7 @@ class UpdatePostController extends AbstractShowController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\PostSerializer'; + public $serializer = PostSerializer::class; /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/UpdateUserController.php b/framework/core/src/Api/Controller/UpdateUserController.php index 42a57754a..92781c85b 100644 --- a/framework/core/src/Api/Controller/UpdateUserController.php +++ b/framework/core/src/Api/Controller/UpdateUserController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\CurrentUserSerializer; use Flarum\User\Command\EditUser; use Flarum\User\Exception\PermissionDeniedException; use Illuminate\Contracts\Bus\Dispatcher; @@ -22,7 +23,7 @@ class UpdateUserController extends AbstractShowController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\CurrentUserSerializer'; + public $serializer = CurrentUserSerializer::class; /** * {@inheritdoc} diff --git a/framework/core/src/Api/Controller/UploadAvatarController.php b/framework/core/src/Api/Controller/UploadAvatarController.php index b2e23e33b..5ac1e1fdc 100644 --- a/framework/core/src/Api/Controller/UploadAvatarController.php +++ b/framework/core/src/Api/Controller/UploadAvatarController.php @@ -11,6 +11,7 @@ namespace Flarum\Api\Controller; +use Flarum\Api\Serializer\UserSerializer; use Flarum\User\Command\UploadAvatar; use Illuminate\Contracts\Bus\Dispatcher; use Psr\Http\Message\ServerRequestInterface; @@ -21,7 +22,7 @@ class UploadAvatarController extends AbstractShowController /** * {@inheritdoc} */ - public $serializer = 'Flarum\Api\Serializer\UserSerializer'; + public $serializer = UserSerializer::class; /** * @var Dispatcher From b56ebe57472c13141f0e865b869a650353b39a91 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 2 Jan 2018 21:22:17 +0100 Subject: [PATCH 143/172] Installation default data: Use more sensible defaults Using .dev as a TLD for local development is discouraged, as at least Chrome now enforces HTTPS for these domains. As far as I know, by default, the MySQL root user does not have a password on many platforms. I use it this way on my local machine, and this makes it convenient to setup a local copy. --- framework/core/src/Install/Console/DefaultsDataProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Install/Console/DefaultsDataProvider.php b/framework/core/src/Install/Console/DefaultsDataProvider.php index e34235404..c14d3aabd 100644 --- a/framework/core/src/Install/Console/DefaultsDataProvider.php +++ b/framework/core/src/Install/Console/DefaultsDataProvider.php @@ -18,12 +18,12 @@ class DefaultsDataProvider implements DataProviderInterface 'host' => 'localhost', 'database' => 'flarum', 'username' => 'root', - 'password' => 'root', + 'password' => '', 'prefix' => '', 'port' => '3306', ]; - protected $baseUrl = 'http://flarum.dev'; + protected $baseUrl = 'http://flarum.local'; protected $adminUser = [ 'username' => 'admin', From 167e4f3be8582b8ef4b0d10afeee6441fd43b328 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 3 Oct 2017 15:43:49 +0200 Subject: [PATCH 144/172] Deprecate remaining non-namespaced events These will be replaced by etenders soon. --- framework/core/src/Event/AbstractConfigureRoutes.php | 3 +++ framework/core/src/Event/ConfigureApiRoutes.php | 4 +--- framework/core/src/Event/ConfigureForumRoutes.php | 4 +--- framework/core/src/Event/ConfigureLocales.php | 3 +++ framework/core/src/Event/ConfigureMiddleware.php | 3 +++ 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/framework/core/src/Event/AbstractConfigureRoutes.php b/framework/core/src/Event/AbstractConfigureRoutes.php index 3ce06cf61..5474c40f1 100644 --- a/framework/core/src/Event/AbstractConfigureRoutes.php +++ b/framework/core/src/Event/AbstractConfigureRoutes.php @@ -14,6 +14,9 @@ namespace Flarum\Event; use Flarum\Http\RouteCollection; use Flarum\Http\RouteHandlerFactory; +/** + * @deprecated + */ abstract class AbstractConfigureRoutes { /** diff --git a/framework/core/src/Event/ConfigureApiRoutes.php b/framework/core/src/Event/ConfigureApiRoutes.php index 47727c913..1bcadbfb5 100644 --- a/framework/core/src/Event/ConfigureApiRoutes.php +++ b/framework/core/src/Event/ConfigureApiRoutes.php @@ -12,9 +12,7 @@ namespace Flarum\Event; /** - * Configure API routes. - * - * This event is fired when API routes are being registered. + * @deprecated */ class ConfigureApiRoutes extends AbstractConfigureRoutes { diff --git a/framework/core/src/Event/ConfigureForumRoutes.php b/framework/core/src/Event/ConfigureForumRoutes.php index 934f27a48..cc64464fd 100644 --- a/framework/core/src/Event/ConfigureForumRoutes.php +++ b/framework/core/src/Event/ConfigureForumRoutes.php @@ -14,9 +14,7 @@ namespace Flarum\Event; use Flarum\Forum\Controller\FrontendController; /** - * Configure forum routes. - * - * This event is fired when routes for the forum client are being registered. + * @deprecated */ class ConfigureForumRoutes extends AbstractConfigureRoutes { diff --git a/framework/core/src/Event/ConfigureLocales.php b/framework/core/src/Event/ConfigureLocales.php index 11a412537..1fb373155 100644 --- a/framework/core/src/Event/ConfigureLocales.php +++ b/framework/core/src/Event/ConfigureLocales.php @@ -15,6 +15,9 @@ use DirectoryIterator; use Flarum\Locale\LocaleManager; use RuntimeException; +/** + * @deprecated + */ class ConfigureLocales { /** diff --git a/framework/core/src/Event/ConfigureMiddleware.php b/framework/core/src/Event/ConfigureMiddleware.php index e602d5532..1581bfdbd 100644 --- a/framework/core/src/Event/ConfigureMiddleware.php +++ b/framework/core/src/Event/ConfigureMiddleware.php @@ -13,6 +13,9 @@ namespace Flarum\Event; use Zend\Stratigility\MiddlewarePipe; +/** + * @deprecated + */ class ConfigureMiddleware { /** From d38255e0489c0cba38f0439e60d7d6911bb0ef79 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 3 Oct 2017 16:15:12 +0200 Subject: [PATCH 145/172] Resolve extenders from ExtensionManager Loading the activated extensions now means retrieving an array of extenders (classes that implement a certain type of extension of a core feature in Flarum). For now, the only existing extender is the Compat extender which is used to handle old-style bootstrappers that simply return a closure that receives all of its dependencies via auto injection. In the future, extensions will be able to return an array of extender instances from their bootstrapper instead. These extender classes will be implemented in the next step. --- framework/core/src/Extend/Compat.php | 38 +++++++++++++++++++ framework/core/src/Extend/Extender.php | 19 ++++++++++ framework/core/src/Extension/Extension.php | 5 +++ .../core/src/Extension/ExtensionManager.php | 28 +++++++++----- .../Extension/ExtensionServiceProvider.php | 14 ++++--- 5 files changed, 89 insertions(+), 15 deletions(-) create mode 100644 framework/core/src/Extend/Compat.php create mode 100644 framework/core/src/Extend/Extender.php diff --git a/framework/core/src/Extend/Compat.php b/framework/core/src/Extend/Compat.php new file mode 100644 index 000000000..3678f2a84 --- /dev/null +++ b/framework/core/src/Extend/Compat.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Extend; + +use Illuminate\Contracts\Container\Container; + +/** + * This class is used to wrap old bootstrap.php closures (as used in versions up + * to 0.1.0-beta7) in the new Extender format. + * + * This gives extensions the chance to work with the new API without making any + * changes, and have some time to convert to the pure usage of extenders. + * + * @deprecated + */ +class Compat implements Extender +{ + protected $callback; + + public function __construct($callback) + { + $this->callback = $callback; + } + + public function apply(Container $container) + { + $container->call($this->callback); + } +} diff --git a/framework/core/src/Extend/Extender.php b/framework/core/src/Extend/Extender.php new file mode 100644 index 000000000..71274391e --- /dev/null +++ b/framework/core/src/Extend/Extender.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Extend; + +use Illuminate\Contracts\Container\Container; + +interface Extender +{ + public function apply(Container $container); +} diff --git a/framework/core/src/Extension/Extension.php b/framework/core/src/Extension/Extension.php index 1abb6febe..255a7c6df 100644 --- a/framework/core/src/Extension/Extension.php +++ b/framework/core/src/Extension/Extension.php @@ -231,6 +231,11 @@ class Extension implements Arrayable return $this->path; } + public function getBootstrapperPath() + { + return "{$this->path}/bootstrap.php"; + } + /** * Tests whether the extension has assets. * diff --git a/framework/core/src/Extension/ExtensionManager.php b/framework/core/src/Extension/ExtensionManager.php index 404638fd5..ad0df4278 100644 --- a/framework/core/src/Extension/ExtensionManager.php +++ b/framework/core/src/Extension/ExtensionManager.php @@ -12,6 +12,7 @@ namespace Flarum\Extension; use Flarum\Database\Migrator; +use Flarum\Extend\Compat; use Flarum\Extension\Event\Disabled; use Flarum\Extension\Event\Disabling; use Flarum\Extension\Event\Enabled; @@ -273,21 +274,30 @@ class ExtensionManager } /** - * Loads all bootstrap.php files of the enabled extensions. + * Retrieve all extender instances of all enabled extensions. * * @return Collection */ - public function getEnabledBootstrappers() + public function getActiveExtenders() { - $bootstrappers = new Collection; + return $this->getEnabledExtensions() + ->flatMap(function (Extension $extension) { + $bootstrapper = $extension->getBootstrapperPath(); + if ($this->filesystem->exists($bootstrapper)) { + $extenders = require $bootstrapper; - foreach ($this->getEnabledExtensions() as $extension) { - if ($this->filesystem->exists($file = $extension->getPath().'/bootstrap.php')) { - $bootstrappers->push($file); - } - } + if (is_array($extenders)) { + return $extenders; + } - return $bootstrappers; + // Assume that the extension has not yet switched to the new + // bootstrap.php format, and wrap the callback in a Compat + // extender. + return [new Compat($extenders)]; + } else { + return []; + } + }); } /** diff --git a/framework/core/src/Extension/ExtensionServiceProvider.php b/framework/core/src/Extension/ExtensionServiceProvider.php index 77b88d3e5..78b8be201 100644 --- a/framework/core/src/Extension/ExtensionServiceProvider.php +++ b/framework/core/src/Extension/ExtensionServiceProvider.php @@ -12,6 +12,7 @@ namespace Flarum\Extension; use Flarum\Foundation\AbstractServiceProvider; +use Illuminate\Contracts\Container\Container; class ExtensionServiceProvider extends AbstractServiceProvider { @@ -22,13 +23,14 @@ class ExtensionServiceProvider extends AbstractServiceProvider { $this->app->bind('flarum.extensions', ExtensionManager::class); - $bootstrappers = $this->app->make('flarum.extensions')->getEnabledBootstrappers(); + $this->app->booting(function (Container $app) { + /** @var \Flarum\Extend\Extender[] $extenders */ + $extenders = $app->make('flarum.extensions')->getActiveExtenders(); - foreach ($bootstrappers as $file) { - $bootstrapper = require $file; - - $this->app->call($bootstrapper); - } + foreach ($extenders as $extender) { + $extender->apply($app); + } + }); } /** From 5aead007304b88e9716e8d039560723524c8ce1f Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 2 Jan 2018 21:59:49 +0100 Subject: [PATCH 146/172] Add Locale extender for language pack extensions --- framework/core/src/Extend/Locale.php | 75 ++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 framework/core/src/Extend/Locale.php diff --git a/framework/core/src/Extend/Locale.php b/framework/core/src/Extend/Locale.php new file mode 100644 index 000000000..08e126b41 --- /dev/null +++ b/framework/core/src/Extend/Locale.php @@ -0,0 +1,75 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Extend; + +use DirectoryIterator; +use Flarum\Locale\LocaleManager; +use Illuminate\Contracts\Container\Container; +use RuntimeException; + +class Locale implements Extender +{ + protected $directory; + + public function __construct($directory) + { + $this->directory = $directory; + } + + public function apply(Container $container) + { + $this->loadLanguagePackFrom( + $this->directory, + $container->make(LocaleManager::class) + ); + } + + private function loadLanguagePackFrom($directory, LocaleManager $locales) + { + $name = $title = basename($directory); + + if (file_exists($manifest = $directory.'/composer.json')) { + $json = json_decode(file_get_contents($manifest), true); + + if (empty($json)) { + throw new RuntimeException("Error parsing composer.json in $name: ".json_last_error_msg()); + } + + $locale = array_get($json, 'extra.flarum-locale.code'); + $title = array_get($json, 'extra.flarum-locale.title', $title); + } + + if (! isset($locale)) { + throw new RuntimeException("Language pack $name must define \"extra.flarum-locale.code\" in composer.json."); + } + + $locales->addLocale($locale, $title); + + if (! is_dir($localeDir = $directory.'/locale')) { + throw new RuntimeException("Language pack $name must have a \"locale\" subdirectory."); + } + + if (file_exists($file = $localeDir.'/config.js')) { + $locales->addJsFile($locale, $file); + } + + if (file_exists($file = $localeDir.'/config.css')) { + $locales->addCssFile($locale, $file); + } + + foreach (new DirectoryIterator($localeDir) as $file) { + if ($file->isFile() && in_array($file->getExtension(), ['yml', 'yaml'])) { + $locales->addTranslations($locale, $file->getPathname()); + } + } + } +} From 95b80aecfeaeace64c75e4ffaf0165ccbb36b383 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 2 Jan 2018 22:50:39 +0100 Subject: [PATCH 147/172] Add Assets extender for frontend extensions --- framework/core/src/Extend/Assets.php | 81 ++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 framework/core/src/Extend/Assets.php diff --git a/framework/core/src/Extend/Assets.php b/framework/core/src/Extend/Assets.php new file mode 100644 index 000000000..6fb52dbd7 --- /dev/null +++ b/framework/core/src/Extend/Assets.php @@ -0,0 +1,81 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Extend; + +use Flarum\Frontend\Event\Rendering; +use Illuminate\Contracts\Container\Container; +use Illuminate\Events\Dispatcher; + +class Assets implements Extender +{ + protected $appName; + + protected $assets = []; + protected $bootstrapper; + + public function __construct($appName) + { + $this->appName = $appName; + } + + public function defaultAssets($baseDir) + { + $this->asset("$baseDir/js/{$this->appName}/dist/extension.js"); + $this->asset("$baseDir/less/{$this->appName}/extension.less"); + + return $this; + } + + public function asset($path) + { + $this->assets[] = $path; + + return $this; + } + + public function bootstrapper($name) + { + $this->bootstrapper = $name; + + return $this; + } + + public function apply(Container $container) + { + $container->make(Dispatcher::class)->listen( + Rendering::class, + function (Rendering $event) { + if (! $this->matches($event)) { + return; + } + + $event->addAssets($this->assets); + + if ($this->bootstrapper) { + $event->addBootstrapper($this->bootstrapper); + } + } + ); + } + + private function matches(Rendering $event) + { + switch ($this->appName) { + case 'admin': + return $event->isAdmin(); + case 'forum': + return $event->isForum(); + default: + return false; + } + } +} From f69579c4b03dfd848b14610247af5c232ade3fa8 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 2 Jan 2018 22:51:12 +0100 Subject: [PATCH 148/172] Add FormatterConfiguration extender for extensions working with TextFormatter --- .../src/Extend/FormatterConfiguration.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 framework/core/src/Extend/FormatterConfiguration.php diff --git a/framework/core/src/Extend/FormatterConfiguration.php b/framework/core/src/Extend/FormatterConfiguration.php new file mode 100644 index 000000000..1608a35fd --- /dev/null +++ b/framework/core/src/Extend/FormatterConfiguration.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Extend; + +use Flarum\Formatter\Event\Configuring; +use Illuminate\Contracts\Container\Container; +use Illuminate\Events\Dispatcher; + +class FormatterConfiguration implements Extender +{ + protected $callback; + + public function __construct(callable $callback) + { + $this->callback = $callback; + } + + public function apply(Container $container) + { + $container->make(Dispatcher::class)->listen( + Configuring::class, + function (Configuring $event) { + call_user_func($this->callback, $event->configurator); + } + ); + } +} From 629439a578cabbc860c553ac7674e9a47b812f10 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 3 Jan 2018 20:23:05 +0100 Subject: [PATCH 149/172] Admin: Set up all event listeners in one place See discussion in #1273. --- .../core/src/Admin/AdminServiceProvider.php | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/framework/core/src/Admin/AdminServiceProvider.php b/framework/core/src/Admin/AdminServiceProvider.php index d0ca1975f..44f597d6a 100644 --- a/framework/core/src/Admin/AdminServiceProvider.php +++ b/framework/core/src/Admin/AdminServiceProvider.php @@ -76,11 +76,7 @@ class AdminServiceProvider extends AbstractServiceProvider $this->loadViewsFrom(__DIR__.'/../../views', 'flarum.admin'); - $this->flushWebAppAssetsWhenThemeChanged(); - - $this->flushWebAppAssetsWhenExtensionsChanged(); - - $this->checkCustomLessFormat(); + $this->registerListeners(); } /** @@ -96,21 +92,23 @@ class AdminServiceProvider extends AbstractServiceProvider $callback($routes, $factory); } - protected function flushWebAppAssetsWhenThemeChanged() + protected function registerListeners() { - $this->app->make('events')->listen(Saved::class, function (Saved $event) { + $dispatcher = $this->app->make('events'); + + // Flush web app assets when the theme is changed + $dispatcher->listen(Saved::class, function (Saved $event) { if (preg_match('/^theme_|^custom_less$/i', $event->key)) { $this->getWebAppAssets()->flushCss(); } }); - } - protected function flushWebAppAssetsWhenExtensionsChanged() - { - $events = $this->app->make('events'); + // Flush web app assets when extensions are changed + $dispatcher->listen(Enabled::class, [$this, 'flushWebAppAssets']); + $dispatcher->listen(Disabled::class, [$this, 'flushWebAppAssets']); - $events->listen(Enabled::class, [$this, 'flushWebAppAssets']); - $events->listen(Disabled::class, [$this, 'flushWebAppAssets']); + // Check the format of custom LESS code + $dispatcher->subscribe(CheckCustomLessFormat::class); } public function flushWebAppAssets() @@ -125,11 +123,4 @@ class AdminServiceProvider extends AbstractServiceProvider { return $this->app->make(Frontend::class)->getAssets(); } - - protected function checkCustomLessFormat() - { - $events = $this->app->make('events'); - - $events->subscribe(CheckCustomLessFormat::class); - } } From e0f61d51c009cf7ca13ad2f9239516488dbf0723 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 3 Jan 2018 23:18:19 +0100 Subject: [PATCH 150/172] Add Route extender for registering routes with forum, admin or API --- framework/core/src/Extend/Route.php | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 framework/core/src/Extend/Route.php diff --git a/framework/core/src/Extend/Route.php b/framework/core/src/Extend/Route.php new file mode 100644 index 000000000..260bb37a5 --- /dev/null +++ b/framework/core/src/Extend/Route.php @@ -0,0 +1,49 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Extend; + +use Flarum\Http\RouteCollection; +use Flarum\Http\RouteHandlerFactory; +use Illuminate\Contracts\Container\Container; + +class Route implements Extender +{ + protected $appName; + protected $name; + protected $httpMethod; + protected $path; + protected $handler; + + public function __construct($appName, $name, $httpMethod, $path, $handler) + { + $this->appName = $appName; + $this->name = $name; + $this->httpMethod = $httpMethod; + $this->path = $path; + $this->handler = $handler; + } + + public function apply(Container $container) + { + /** @var RouteCollection $routes */ + $collection = $container->make("flarum.{$this->appName}.routes"); + + /** @var RouteHandlerFactory $factory */ + $factory = $container->make(RouteHandlerFactory::class); + + $collection->{$this->httpMethod}( + $this->path, + $this->name, + $factory->toController($this->handler) + ); + } +} From 41c7f26058a524dd5938b8c6f78002719b2ef37c Mon Sep 17 00:00:00 2001 From: Clark Winkelmann Date: Thu, 4 Jan 2018 00:09:06 +0100 Subject: [PATCH 151/172] Manage Composer height with overridable methods (#1272) * Manage Composer height in a separate class with overridable methods * Use a computed method * Keep everything in Composer.js * Drop usage of computed property for the Composer height Because the Composer height also depends on the page height and is rarely called without position, height or page height changing anyway --- .../core/js/forum/src/components/Composer.js | 108 ++++++++++++------ 1 file changed, 70 insertions(+), 38 deletions(-) diff --git a/framework/core/js/forum/src/components/Composer.js b/framework/core/js/forum/src/components/Composer.js index 93532d700..71738d3fc 100644 --- a/framework/core/js/forum/src/components/Composer.js +++ b/framework/core/js/forum/src/components/Composer.js @@ -3,7 +3,6 @@ import ItemList from 'flarum/utils/ItemList'; import ComposerButton from 'flarum/components/ComposerButton'; import listItems from 'flarum/helpers/listItems'; import classList from 'flarum/utils/classList'; -import computed from 'flarum/utils/computed'; /** * The `Composer` component displays the composer. It can be loaded with a @@ -33,28 +32,6 @@ class Composer extends Component { * @type {Boolean} */ this.active = false; - - /** - * Computed the composer's current height, based on the intended height, and - * the composer's current state. This will be applied to the composer's - * content's DOM element. - * - * @return {Integer} - */ - this.computedHeight = computed('height', 'position', (height, position) => { - // If the composer is minimized, then we don't want to set a height; we'll - // let the CSS decide how high it is. If it's fullscreen, then we need to - // make it as high as the window. - if (position === Composer.PositionEnum.MINIMIZED) { - return ''; - } else if (position === Composer.PositionEnum.FULLSCREEN) { - return $(window).height(); - } - - // Otherwise, if it's normal or hidden, then we use the intended height. - // We don't let the composer get too small or too big, though. - return Math.max(200, Math.min(height, $(window).height() - $('#header').outerHeight())); - }); } view() { @@ -85,12 +62,6 @@ class Composer extends Component { } config(isInitialized, context) { - let defaultHeight; - - if (!isInitialized) { - defaultHeight = this.$().height(); - } - // Set the height of the Composer element and its contents on each redraw, // so that they do not lose it if their DOM elements are recreated. this.updateHeight(); @@ -101,11 +72,8 @@ class Composer extends Component { // routes, we will flag the DOM to be retained across route changes. context.retain = true; - // Initialize the composer's intended height based on what the user has set - // it at previously, or otherwise the composer's default height. After that, - // we'll hide the composer. - this.height = localStorage.getItem('composerHeight') || defaultHeight; - this.$().hide().css('bottom', -this.height); + this.initializeHeight(); + this.$().hide().css('bottom', -this.computedHeight()); // Whenever any of the inputs inside the composer are have focus, we want to // add a class to the composer to draw attention to it. @@ -176,8 +144,7 @@ class Composer extends Component { // height so that it fills the height of the composer, and update the // body's padding. const deltaPixels = this.mouseStart - e.clientY; - this.height = this.heightStart + deltaPixels; - this.updateHeight(); + this.changeHeight(this.heightStart + deltaPixels); // Update the body's padding-bottom so that no content on the page will ever // get permanently hidden behind the composer. If the user is already @@ -186,8 +153,6 @@ class Composer extends Component { const scrollTop = $(window).scrollTop(); const anchorToBottom = scrollTop > 0 && scrollTop + $(window).height() >= $(document).height(); this.updateBodyPadding(anchorToBottom); - - localStorage.setItem('composerHeight', this.height); } /** @@ -486,6 +451,73 @@ class Composer extends Component { return items; } + + /** + * Initialize default Composer height. + */ + initializeHeight() { + this.height = localStorage.getItem('composerHeight'); + + if (!this.height) { + this.height = this.defaultHeight(); + } + } + + /** + * Default height of the Composer in case none is saved. + * @returns {Integer} + */ + defaultHeight() { + return this.$().height(); + } + + /** + * Minimum height of the Composer. + * @returns {Integer} + */ + minimumHeight() { + return 200; + } + + /** + * Maxmimum height of the Composer. + * @returns {Integer} + */ + maximumHeight() { + return $(window).height() - $('#header').outerHeight(); + } + + /** + * Computed the composer's current height, based on the intended height, and + * the composer's current state. This will be applied to the composer's + * content's DOM element. + * @returns {Integer|String} + */ + computedHeight() { + // If the composer is minimized, then we don't want to set a height; we'll + // let the CSS decide how high it is. If it's fullscreen, then we need to + // make it as high as the window. + if (this.position === Composer.PositionEnum.MINIMIZED) { + return ''; + } else if (this.position === Composer.PositionEnum.FULLSCREEN) { + return $(window).height(); + } + + // Otherwise, if it's normal or hidden, then we use the intended height. + // We don't let the composer get too small or too big, though. + return Math.max(this.minimumHeight(), Math.min(this.height, this.maximumHeight())); + } + + /** + * Save a new Composer height and update the DOM. + * @param {Integer} height + */ + changeHeight(height) { + this.height = height; + this.updateHeight(); + + localStorage.setItem('composerHeight', this.height); + } } Composer.PositionEnum = { From 0d8dfabbb3de7321dadd6a2ca55e92ae4de7f78a Mon Sep 17 00:00:00 2001 From: AFR Date: Sat, 6 Jan 2018 05:44:11 +0700 Subject: [PATCH 152/172] Add Custom Footer HTML (#1315) * Add Custom Footer HTML Straight copy from Custom Header HTML * Move Custom Footer HTML to exactly before `` tag. * Fix invalid class name * Append CustomFooterHTML when preparing the view. * Some consistency in placing the variable --- .../js/admin/src/components/AppearancePage.js | 13 ++++++++++ .../src/components/EditCustomFooterModal.js | 24 +++++++++++++++++++ .../src/Api/Serializer/ForumSerializer.php | 1 + framework/core/src/Frontend/FrontendView.php | 11 ++++++++- 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 framework/core/js/admin/src/components/EditCustomFooterModal.js diff --git a/framework/core/js/admin/src/components/AppearancePage.js b/framework/core/js/admin/src/components/AppearancePage.js index c59a039af..62ba8e52c 100644 --- a/framework/core/js/admin/src/components/AppearancePage.js +++ b/framework/core/js/admin/src/components/AppearancePage.js @@ -3,6 +3,7 @@ import Button from 'flarum/components/Button'; import Switch from 'flarum/components/Switch'; import EditCustomCssModal from 'flarum/components/EditCustomCssModal'; import EditCustomHeaderModal from 'flarum/components/EditCustomHeaderModal'; +import EditCustomFooterModal from 'flarum/components/EditCustomFooterModal'; import UploadImageButton from 'flarum/components/UploadImageButton'; import saveSettings from 'flarum/utils/saveSettings'; @@ -81,6 +82,18 @@ export default class AppearancePage extends Page { })} +
+ {app.translator.trans('core.admin.appearance.custom_footer_heading')} +
+ {app.translator.trans('core.admin.appearance.custom_footer_text')} +
+ {Button.component({ + className: 'Button', + children: app.translator.trans('core.admin.appearance.edit_footer_button'), + onclick: () => app.modal.show(new EditCustomFooterModal()) + })} +
+
{app.translator.trans('core.admin.appearance.custom_styles_heading')}
diff --git a/framework/core/js/admin/src/components/EditCustomFooterModal.js b/framework/core/js/admin/src/components/EditCustomFooterModal.js new file mode 100644 index 000000000..1cd02a012 --- /dev/null +++ b/framework/core/js/admin/src/components/EditCustomFooterModal.js @@ -0,0 +1,24 @@ +import SettingsModal from 'flarum/components/SettingsModal'; + +export default class EditCustomFooterModal extends SettingsModal { + className() { + return 'EditCustomFooterModal Modal--large'; + } + + title() { + return app.translator.trans('core.admin.edit_footer.title'); + } + + form() { + return [ +

{app.translator.trans('core.admin.edit_footer.customize_text')}

, +
+