From f9e6e3f95e8476212b26ae40fc71ae5700642618 Mon Sep 17 00:00:00 2001 From: rustamwin Date: Fri, 15 Nov 2019 17:13:15 +0500 Subject: [PATCH 01/10] use `auth` package --- composer.json | 3 ++- config/web.php | 2 +- src/Controller/AuthController.php | 2 +- src/Entity/User.php | 2 +- src/Repository/UserRepository.php | 4 ++-- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 04af7d62..4a3fd17a 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,8 @@ "yiisoft/mailer": "^3.0@dev", "yiisoft/mailer-swiftmailer": "^3.0@dev", "yiisoft/html": "^3.0@dev", - "yiisoft/security": "^3.0@dev" + "yiisoft/security": "^3.0@dev", + "yiisoft/auth": "^3.0@dev" }, "require-dev": { "hiqdev/composer-config-plugin": "^1.0@dev" diff --git a/config/web.php b/config/web.php index 9a28bb93..7828d965 100644 --- a/config/web.php +++ b/config/web.php @@ -26,7 +26,7 @@ use App\Factory\AppRouterFactory; use Yiisoft\Yii\Web\Session\Session; use Yiisoft\Yii\Web\Session\SessionInterface; -use Yiisoft\Yii\Web\User\IdentityRepositoryInterface; +use Yiisoft\Auth\IdentityRepositoryInterface; use Yiisoft\Yii\Web\User\User; /** diff --git a/src/Controller/AuthController.php b/src/Controller/AuthController.php index cd4108fc..55861a1b 100644 --- a/src/Controller/AuthController.php +++ b/src/Controller/AuthController.php @@ -9,7 +9,7 @@ use Yiisoft\Aliases\Aliases; use Yiisoft\Router\Method; use Yiisoft\View\WebView; -use Yiisoft\Yii\Web\User\IdentityRepositoryInterface; +use Yiisoft\Auth\IdentityRepositoryInterface; use Yiisoft\Yii\Web\User\User; class AuthController extends Controller diff --git a/src/Entity/User.php b/src/Entity/User.php index 8874c21f..488bc1d6 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -2,7 +2,7 @@ namespace App\Entity; use Yiisoft\Security\PasswordHasher; -use Yiisoft\Yii\Web\User\IdentityInterface; +use Yiisoft\Auth\IdentityInterface; class User implements IdentityInterface { diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index 39ea7322..f1cc8a7c 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -3,8 +3,8 @@ namespace App\Repository; use App\Entity\User; -use Yiisoft\Yii\Web\User\IdentityInterface; -use Yiisoft\Yii\Web\User\IdentityRepositoryInterface; +use Yiisoft\Auth\IdentityInterface; +use Yiisoft\Auth\IdentityRepositoryInterface; class UserRepository implements IdentityRepositoryInterface { From 72013f4b9b1a9c62db1b4984168ad8766315062f Mon Sep 17 00:00:00 2001 From: Ehsan Rezaei Date: Mon, 30 Dec 2019 13:57:05 +0330 Subject: [PATCH 02/10] Update Docker container to PHP 7.4 --- docker-compose.yml.local | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml.local b/docker-compose.yml.local index e9c3b423..2f2135d4 100644 --- a/docker-compose.yml.local +++ b/docker-compose.yml.local @@ -3,7 +3,7 @@ version: '3' services: php: - image: yiisoftware/yii2-php:7.2-apache + image: yiisoftware/yii-php:7.4-apache working_dir: /app volumes: - ./:/app From 3d444f6c2aebe9fd52d5d0c4f95a8deb8594f4d7 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Tue, 31 Dec 2019 17:08:37 +0300 Subject: [PATCH 03/10] Subfolder Middleware Renamed (#38) --- config/web.php | 8 ++++---- src/Factory/MiddlewareDispatcherFactory.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/web.php b/config/web.php index 9b84f2b9..89466c11 100644 --- a/config/web.php +++ b/config/web.php @@ -61,10 +61,10 @@ ], ], - \Yiisoft\Yii\Web\Middleware\SubFolderMiddleware::class => [ - '__construct()' => [Reference::to(UrlGeneratorInterface::class), Reference::to(Aliases::class)], - // 'prefix' => '', - ], + // here you can configure custom prefix of the web path + // \Yiisoft\Yii\Web\Middleware\SubFolder::class => [ + // 'prefix' => '', + // ], // event dispatcher ListenerProviderInterface::class => Provider::class, diff --git a/src/Factory/MiddlewareDispatcherFactory.php b/src/Factory/MiddlewareDispatcherFactory.php index d86d2da4..e4c45d2d 100644 --- a/src/Factory/MiddlewareDispatcherFactory.php +++ b/src/Factory/MiddlewareDispatcherFactory.php @@ -5,7 +5,7 @@ use Yiisoft\Router\Middleware\Router; use Yiisoft\Yii\Web\ErrorHandler\ErrorCatcher; use Yiisoft\Yii\Web\MiddlewareDispatcher; -use Yiisoft\Yii\Web\Middleware\SubFolderMiddleware; +use Yiisoft\Yii\Web\Middleware\SubFolder; use Yiisoft\Yii\Web\Session\SessionMiddleware; class MiddlewareDispatcherFactory @@ -15,7 +15,7 @@ public function __invoke(ContainerInterface $container) $session = $container->get(SessionMiddleware::class); $router = $container->get(Router::class); $errorCatcher = $container->get(ErrorCatcher::class); - $subFolder = $container->get(SubFolderMiddleware::class); + $subFolder = $container->get(SubFolder::class); return new MiddlewareDispatcher([ $errorCatcher, From a0f359b91e9cbb0e6fb1146d7466b1840d0670e7 Mon Sep 17 00:00:00 2001 From: Rustam Mamadaminov Date: Thu, 7 May 2020 12:15:45 +0500 Subject: [PATCH 04/10] Add route/list command --- config/common.php | 12 ++++++ config/params.php | 1 + config/web.php | 5 --- src/Command/Route/ListCommand.php | 67 +++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 src/Command/Route/ListCommand.php diff --git a/config/common.php b/config/common.php index cdea5e75..ae1b3597 100644 --- a/config/common.php +++ b/config/common.php @@ -1,5 +1,6 @@ [$params['mailer']['username']], 'setPassword()' => [$params['mailer']['password']], ], + + // Router: + RouteCollectorInterface::class => Group::create(), + UrlMatcherInterface::class => new AppRouterFactory(), + UrlGeneratorInterface::class => UrlGenerator::class, + MailerInterface::class => new MailerFactory($params['mailer']['writeToFiles']), Timer::class => $timer, ]; diff --git a/config/params.php b/config/params.php index 1d819d47..41dd10ef 100644 --- a/config/params.php +++ b/config/params.php @@ -31,6 +31,7 @@ 'commands' => [ 'user/create' => Command\User\CreateCommand::class, 'fixture/add' => Command\Fixture\AddCommand::class, + 'route/list' => Command\Route\ListCommand::class, ], ], diff --git a/config/web.php b/config/web.php index 7a02ce77..2ddd8a5e 100644 --- a/config/web.php +++ b/config/web.php @@ -52,11 +52,6 @@ DataResponseFormatterInterface::class => HtmlDataResponseFormatter::class, DataResponseFactoryInterface::class => DataResponseFactory::class, - // Router: - RouteCollectorInterface::class => Group::create(), - UrlMatcherInterface::class => new AppRouterFactory(), - UrlGeneratorInterface::class => UrlGenerator::class, - MiddlewareDispatcher::class => new MiddlewareDispatcherFactory(), SessionInterface::class => [ '__class' => Session::class, diff --git a/src/Command/Route/ListCommand.php b/src/Command/Route/ListCommand.php new file mode 100644 index 00000000..0ac428cd --- /dev/null +++ b/src/Command/Route/ListCommand.php @@ -0,0 +1,67 @@ +urlMatcher = $urlMatcher; + parent::__construct(); + } + + protected function configure() + { + $this + ->setDescription('List all registered routes') + ->setHelp('This command displays a list of registered routes.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $table = new Table($output); + $io = new SymfonyStyle($input, $output); + /** @var Route[] $routes */ + $routes = $this->urlMatcher->getRouteCollection()->getRoutes(); + $table->setHeaders(['Host', 'Methods', 'Name', 'Pattern', 'Defaults']); + foreach ($routes as $key => $route) { + $table->addRow( + [ + $route->getHost(), + implode(',', $route->getMethods()), + $route->getName(), + $route->getPattern(), + implode(',', $route->getDefaults()) + ] + ); + if (next($routes) !== false) { + $table->addRow(new TableSeparator()); + } + } + + try { + $table->render(); + } catch (\Throwable $exception) { + $io->error($exception->getMessage()); + return $exception->getCode() ?: ExitCode::UNSPECIFIED_ERROR; + } + return ExitCode::OK; + } +} From c5319f483df3094a47c44a0305bffef282ee03dc Mon Sep 17 00:00:00 2001 From: Rustam Mamadaminov Date: Thu, 7 May 2020 12:31:10 +0500 Subject: [PATCH 05/10] fix --- src/Command/Route/ListCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Command/Route/ListCommand.php b/src/Command/Route/ListCommand.php index 0ac428cd..9186c9ca 100644 --- a/src/Command/Route/ListCommand.php +++ b/src/Command/Route/ListCommand.php @@ -4,7 +4,6 @@ namespace App\Command\Route; - use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Helper\TableSeparator; From b4939b22aeacd62b4d91993b319ee4e6e3b00492 Mon Sep 17 00:00:00 2001 From: Rustam Mamadaminov Date: Thu, 7 May 2020 12:32:43 +0500 Subject: [PATCH 06/10] type hints --- src/Command/Route/ListCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Command/Route/ListCommand.php b/src/Command/Route/ListCommand.php index 9186c9ca..7caa01f0 100644 --- a/src/Command/Route/ListCommand.php +++ b/src/Command/Route/ListCommand.php @@ -26,14 +26,14 @@ public function __construct(UrlMatcherInterface $urlMatcher) parent::__construct(); } - protected function configure() + protected function configure(): void { $this ->setDescription('List all registered routes') ->setHelp('This command displays a list of registered routes.'); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $table = new Table($output); $io = new SymfonyStyle($input, $output); From 9a3a2478218d979f0193fb9c8dd858e11301bc4c Mon Sep 17 00:00:00 2001 From: Rustam Mamadaminov Date: Tue, 12 May 2020 18:32:46 +0500 Subject: [PATCH 07/10] fixes --- src/Command/Route/ListCommand.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Command/Route/ListCommand.php b/src/Command/Route/ListCommand.php index 7caa01f0..b880d5b6 100644 --- a/src/Command/Route/ListCommand.php +++ b/src/Command/Route/ListCommand.php @@ -9,8 +9,6 @@ use Symfony\Component\Console\Helper\TableSeparator; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; -use Yiisoft\Router\Route; use Yiisoft\Router\UrlMatcherInterface; use Yiisoft\Yii\Console\ExitCode; @@ -36,9 +34,13 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { $table = new Table($output); - $io = new SymfonyStyle($input, $output); - /** @var Route[] $routes */ $routes = $this->urlMatcher->getRouteCollection()->getRoutes(); + uasort( + $routes, + static function ($a, $b) { + return ($a->getHost() <=> $b->getHost()) ?: ($a->getName() <=> $b->getName()); + } + ); $table->setHeaders(['Host', 'Methods', 'Name', 'Pattern', 'Defaults']); foreach ($routes as $key => $route) { $table->addRow( @@ -55,12 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } - try { - $table->render(); - } catch (\Throwable $exception) { - $io->error($exception->getMessage()); - return $exception->getCode() ?: ExitCode::UNSPECIFIED_ERROR; - } + $table->render(); return ExitCode::OK; } } From 04acd4927d5d2cccfafaad92839c00c703151bfe Mon Sep 17 00:00:00 2001 From: Rustam Mamadaminov Date: Tue, 12 May 2020 18:35:42 +0500 Subject: [PATCH 08/10] fixes --- src/Command/Route/ListCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/Route/ListCommand.php b/src/Command/Route/ListCommand.php index b880d5b6..1ad4eb2e 100644 --- a/src/Command/Route/ListCommand.php +++ b/src/Command/Route/ListCommand.php @@ -42,7 +42,7 @@ static function ($a, $b) { } ); $table->setHeaders(['Host', 'Methods', 'Name', 'Pattern', 'Defaults']); - foreach ($routes as $key => $route) { + foreach ($routes as $route) { $table->addRow( [ $route->getHost(), From a57b4b39b2313439f763292dd72d8d589500b287 Mon Sep 17 00:00:00 2001 From: Rustam Mamadaminov Date: Thu, 14 May 2020 11:56:17 +0500 Subject: [PATCH 09/10] fix naming --- config/params.php | 2 +- src/Command/{Route => Router}/ListCommand.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/Command/{Route => Router}/ListCommand.php (95%) diff --git a/config/params.php b/config/params.php index 41dd10ef..2aca9154 100644 --- a/config/params.php +++ b/config/params.php @@ -31,7 +31,7 @@ 'commands' => [ 'user/create' => Command\User\CreateCommand::class, 'fixture/add' => Command\Fixture\AddCommand::class, - 'route/list' => Command\Route\ListCommand::class, + 'router/list' => Command\Router\ListCommand::class, ], ], diff --git a/src/Command/Route/ListCommand.php b/src/Command/Router/ListCommand.php similarity index 95% rename from src/Command/Route/ListCommand.php rename to src/Command/Router/ListCommand.php index 1ad4eb2e..68913411 100644 --- a/src/Command/Route/ListCommand.php +++ b/src/Command/Router/ListCommand.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Command\Route; +namespace App\Command\Router; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\Table; @@ -16,7 +16,7 @@ class ListCommand extends Command { private UrlMatcherInterface $urlMatcher; - protected static $defaultName = 'route/list'; + protected static $defaultName = 'router/list'; public function __construct(UrlMatcherInterface $urlMatcher) { From 1c410a1a452eea58f0d5f8d98ff5119de970b8a4 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Mon, 18 May 2020 15:11:33 +0300 Subject: [PATCH 10/10] Minor formatting fixes --- src/Factory/AppRouterFactory.php | 3 +-- views/blog/archive/monthly-archive.php | 2 +- views/layout/main.php | 5 ++++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Factory/AppRouterFactory.php b/src/Factory/AppRouterFactory.php index bc558b2e..aba37355 100644 --- a/src/Factory/AppRouterFactory.php +++ b/src/Factory/AppRouterFactory.php @@ -91,8 +91,7 @@ public function __invoke(ContainerInterface $container) // Monthly page Route::get('/{year:\d+}-{month:\d+}[/page{page:\d+}]', [ArchiveController::class, 'monthlyArchive']) ->name('blog/archive/month') - ] - ), + ]), // comments Route::get('/comments/[next/{next}]', [CommentController::class, 'index']) ->name('blog/comment/index'), diff --git a/views/blog/archive/monthly-archive.php b/views/blog/archive/monthly-archive.php index 6bf058c7..8e1132bc 100644 --- a/views/blog/archive/monthly-archive.php +++ b/views/blog/archive/monthly-archive.php @@ -3,7 +3,7 @@ /** * @var int $year * @var int $month - * @var \Yiisoft\Data\Paginator\OffsetPaginator $paginator; + * @var \Yiisoft\Data\Paginator\OffsetPaginator $paginator * @var \Yiisoft\Router\UrlGeneratorInterface $urlGenerator * @var \Yiisoft\View\WebView $this */ diff --git a/views/layout/main.php b/views/layout/main.php index fe292c4e..812d7d6c 100644 --- a/views/layout/main.php +++ b/views/layout/main.php @@ -1,6 +1,9 @@