Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blog: Fix locale, routes and npm dependencies #597

Merged
merged 10 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/blog-api_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
- 'blog-api/psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'blog-api/docs/**'
- 'blog-api/README.md'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/blog-api_dependency.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
- 'blog-api/psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'blog-api/docs/**'
- 'blog-api/README.md'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/blog-api_static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
- 'blog-api/phpunit.xml.dist'

push:
branches: ['master']
paths-ignore:
- 'blog-api/docs/**'
- 'blog-api/README.md'
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/blog_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
- 'blog/psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'blog/docs/**'
- 'blog/README.md'
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/blog_dependency.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
- 'blog/psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'blog/docs/**'
- 'blog/README.md'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/blog_static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
- 'blog/phpunit.xml.dist'

push:
branches: ['master']
paths-ignore:
- 'blog/docs/**'
- 'blog/README.md'
Expand Down
4 changes: 4 additions & 0 deletions blog/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions blog/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ phpunit.phar
/vendor
/composer.lock
/node_modules
/package-lock.json

# Codeception
c3.php
20 changes: 20 additions & 0 deletions blog/Makefile
Original file line number Diff line number Diff line change
@@ -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 [email protected]

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))
22 changes: 20 additions & 2 deletions blog/config/common/di/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
7 changes: 6 additions & 1 deletion blog/config/web/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
],
];
2 changes: 1 addition & 1 deletion blog/configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
'$events',
'console/events.php',
],
'routes' => [
'app-routes' => [
'common/routes/*.php',
],
'bootstrap' => [
Expand Down
10 changes: 10 additions & 0 deletions blog/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion blog/src/User/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading