diff --git a/.github/workflows/blog-api_build.yml b/.github/workflows/blog-api_build.yml index 9ad9ca26..2e9e3a62 100644 --- a/.github/workflows/blog-api_build.yml +++ b/.github/workflows/blog-api_build.yml @@ -14,6 +14,7 @@ on: - 'blog-api/psalm.xml' push: + branches: ['master'] paths-ignore: - 'blog-api/docs/**' - 'blog-api/README.md' diff --git a/.github/workflows/blog-api_dependency.yml b/.github/workflows/blog-api_dependency.yml index ed73b9d8..47f52377 100644 --- a/.github/workflows/blog-api_dependency.yml +++ b/.github/workflows/blog-api_dependency.yml @@ -14,6 +14,7 @@ on: - 'blog-api/psalm.xml' push: + branches: ['master'] paths-ignore: - 'blog-api/docs/**' - 'blog-api/README.md' diff --git a/.github/workflows/blog-api_static.yml b/.github/workflows/blog-api_static.yml index 84059dd2..047577c9 100644 --- a/.github/workflows/blog-api_static.yml +++ b/.github/workflows/blog-api_static.yml @@ -14,6 +14,7 @@ on: - 'blog-api/phpunit.xml.dist' push: + branches: ['master'] paths-ignore: - 'blog-api/docs/**' - 'blog-api/README.md' diff --git a/.github/workflows/blog_build.yml b/.github/workflows/blog_build.yml index 4a010ae6..5bbfbdc0 100644 --- a/.github/workflows/blog_build.yml +++ b/.github/workflows/blog_build.yml @@ -14,6 +14,7 @@ on: - 'blog/psalm.xml' push: + branches: ['master'] paths-ignore: - 'blog/docs/**' - 'blog/README.md' @@ -94,6 +95,10 @@ jobs: run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi working-directory: ${{ env.working_directory }} + - name: Install dependencies with npm + run: npm update + working-directory: ${{ env.working_directory }} + - name: Run tests codeception if: matrix.os != 'ubuntu-latest' || matrix.php != '8.0' run: vendor/bin/codecept run diff --git a/.github/workflows/blog_dependency.yml b/.github/workflows/blog_dependency.yml index 3a2c9afd..08c7d574 100644 --- a/.github/workflows/blog_dependency.yml +++ b/.github/workflows/blog_dependency.yml @@ -14,6 +14,7 @@ on: - 'blog/psalm.xml' push: + branches: ['master'] paths-ignore: - 'blog/docs/**' - 'blog/README.md' diff --git a/.github/workflows/blog_static.yml b/.github/workflows/blog_static.yml index d0ab289a..6e5c3a32 100644 --- a/.github/workflows/blog_static.yml +++ b/.github/workflows/blog_static.yml @@ -14,6 +14,7 @@ on: - 'blog/phpunit.xml.dist' push: + branches: ['master'] paths-ignore: - 'blog/docs/**' - 'blog/README.md' diff --git a/blog/.editorconfig b/blog/.editorconfig index 5e9a93ea..8802775b 100644 --- a/blog/.editorconfig +++ b/blog/.editorconfig @@ -10,6 +10,10 @@ indent_style = space indent_size = 4 trim_trailing_whitespace = true +[*.php] +ij_php_space_before_short_closure_left_parenthesis = false +ij_php_space_after_type_cast = true + [*.md] trim_trailing_whitespace = false diff --git a/blog/.gitignore b/blog/.gitignore index 94819d1f..e1bda997 100644 --- a/blog/.gitignore +++ b/blog/.gitignore @@ -25,6 +25,7 @@ phpunit.phar /vendor /composer.lock /node_modules +/package-lock.json # Codeception c3.php diff --git a/blog/Makefile b/blog/Makefile new file mode 100644 index 00000000..5cc895d7 --- /dev/null +++ b/blog/Makefile @@ -0,0 +1,20 @@ +init: composer-update npm-update up + +up: + docker-compose up -d +down: + docker-compose down + +composer: + docker-compose run php composer $(filter-out $@, $(MAKECMDGOALS)) +composer-update: + docker-compose run php composer update + npm i bootstrap@5.3.1 + +npm: + docker-compose run php npm $(filter-out $@, $(MAKECMDGOALS)) +npm-update: + docker-compose run php npm update + +yii3: + docker-compose run php ./yii $(filter-out $@, $(MAKECMDGOALS)) diff --git a/blog/config/common/di/router.php b/blog/config/common/di/router.php index d192a6d1..3cbc1147 100644 --- a/blog/config/common/di/router.php +++ b/blog/config/common/di/router.php @@ -5,22 +5,40 @@ use Yiisoft\Config\Config; use Yiisoft\Csrf\CsrfMiddleware; use Yiisoft\DataResponse\Middleware\FormatDataResponse; +use Yiisoft\Router\FastRoute\UrlGenerator; use Yiisoft\Router\Group; use Yiisoft\Router\RouteCollection; use Yiisoft\Router\RouteCollectionInterface; use Yiisoft\Router\RouteCollectorInterface; +use Yiisoft\Router\UrlGeneratorInterface; use Yiisoft\Yii\Debug\Viewer\Middleware\ToolbarMiddleware; -/** @var Config $config */ +/** + * @var Config $config + * @var array $params + */ return [ + UrlGeneratorInterface::class => [ + 'class' => UrlGenerator::class, + 'setEncodeRaw()' => [$params['yiisoft/router-fastroute']['encodeRaw']], + 'setDefaultArgument()' => ['_language', 'en'], + 'reset' => function () { + $this->defaultArguments = ['_language', 'en']; + }, + ], + RouteCollectionInterface::class => static function (RouteCollectorInterface $collector) use ($config) { $collector ->middleware(CsrfMiddleware::class) ->middleware(FormatDataResponse::class) ->addGroup( - Group::create('/{_language}') + Group::create() ->routes(...$config->get('routes')) + ) + ->addGroup( + Group::create('/{_language}') + ->routes(...$config->get('app-routes')) ); if (!str_starts_with(getenv('YII_ENV') ?: '', 'prod')) { diff --git a/blog/config/web/events.php b/blog/config/web/events.php index fffb00e9..c8373efd 100644 --- a/blog/config/web/events.php +++ b/blog/config/web/events.php @@ -3,10 +3,15 @@ declare(strict_types=1); use App\Timer; +use Yiisoft\Translator\TranslatorInterface; use Yiisoft\Yii\Http\Event\ApplicationStartup; +use Yiisoft\Yii\Middleware\Event\SetLocaleEvent; return [ ApplicationStartup::class => [ - static fn (Timer $timer) => $timer->start('overall'), + static fn(Timer $timer) => $timer->start('overall'), + ], + SetLocaleEvent::class => [ + static fn(TranslatorInterface $translator, SetLocaleEvent $event) => $translator->setLocale($event->getLocale()), ], ]; diff --git a/blog/configuration.php b/blog/configuration.php index 20520fe0..918ce8a4 100644 --- a/blog/configuration.php +++ b/blog/configuration.php @@ -44,7 +44,7 @@ '$events', 'console/events.php', ], - 'routes' => [ + 'app-routes' => [ 'common/routes/*.php', ], 'bootstrap' => [ diff --git a/blog/package.json b/blog/package.json new file mode 100644 index 00000000..ec1ad179 --- /dev/null +++ b/blog/package.json @@ -0,0 +1,10 @@ +{ + "name": "yii3-demo-blog", + "version": "1.0.0", + "description": "Yii3 Demo Blog", + "dependencies": { + "bootstrap": "^5.3.1" + }, + "devDependencies": {}, + "license": "BSD-3-Clause" +} diff --git a/blog/src/User/Controller/UserController.php b/blog/src/User/Controller/UserController.php index 3174bb79..60d9a292 100644 --- a/blog/src/User/Controller/UserController.php +++ b/blog/src/User/Controller/UserController.php @@ -25,7 +25,7 @@ public function __construct(private ViewRenderer $viewRenderer) public function index( UserRepository $userRepository, - #[Body] array $body, + #[Body] ?array $body, #[Query] array $sortOrder, #[Route('page')] int $page = 1, #[Route('pagesize')] int $pageSize = null,