Skip to content

Commit cde2528

Browse files
authored
Merge pull request #3 from p-chess/improve-readme
🎨 improve Twig extension
2 parents 5668477 + 8dfbb94 commit cde2528

15 files changed

Lines changed: 81 additions & 48 deletions

.github/workflows/build.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,44 @@ on:
66

77
jobs:
88
phpstan:
9-
runs-on: ubuntu-22.04
9+
runs-on: ubuntu-24.04
1010
name: PHPStan
1111
steps:
1212
- name: Checkout
1313
uses: actions/checkout@v3
1414
- name: PHPStan
15-
uses: docker://oskarstark/phpstan-ga
15+
uses: docker://oskarstark/phpstan-ga:1.8.0
1616
env:
1717
REQUIRE_DEV: true
1818
with:
1919
args: analyse
2020
cs-fixer:
21-
runs-on: ubuntu-22.04
21+
runs-on: ubuntu-24.04
2222
name: PHP-CS-Fixer
2323
steps:
2424
- name: Checkout
2525
uses: actions/checkout@v3
2626
- name: Fix CS
2727
uses: docker://oskarstark/php-cs-fixer-ga
2828
tests:
29-
runs-on: ubuntu-22.04
29+
runs-on: ubuntu-24.04
3030
strategy:
3131
matrix:
3232
php:
33-
- '8.0'
3433
- '8.1'
3534
- '8.2'
3635
- '8.3'
36+
- '8.4'
3737
include:
3838
- description: 'Symfony 6.4'
39-
php: '8.0'
39+
php: '8.1'
4040
composer_option: '--prefer-lowest'
4141
- description: 'Symfony 6.4'
42-
php: '8.2'
43-
symfony: 6.4.*
44-
- description: 'Symfony 7.0'
4542
php: '8.3'
46-
symfony: 7.0.*
43+
symfony: 6.4.*
44+
- description: 'Symfony 7.2'
45+
php: '8.4'
46+
symfony: 7.2.*
4747
name: PHP ${{ matrix.php }} tests (${{ matrix.description }})
4848
steps:
4949
- name: Checkout

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ Run `composer require p-chess/chess-bundle`
77
## Configuration
88

99
Create a service that extends `PChess\ChessBundle\HtmlOutput` and
10-
implements required methods.
11-
You probably want to inject Symfony's router service here, and use it
12-
to return required URLs.
10+
implement the required methods.
11+
You probably want to inject Symfony's router service here and use it
12+
to return the required URLs.
1313
Note that each route can be provided with an identifier for your game.
1414

15-
Create a configuration file, and use a content like the following:
15+
Create a configuration file, and use content like the following:
1616

1717
```yaml
1818
# config/packages/chess.yaml
1919
chess:
2020
output_service: App\YourOutputService
2121
```
2222
23-
This is an example of how routes can be defined (using an "id" parameter as identifier):
23+
This is an example of how routes can be defined (using an "id" parameter as an identifier):
2424
2525
```yaml
2626
# config/routes.yaml
@@ -52,11 +52,11 @@ move_end:
5252
You can inject a service implementing `\PChess\ChessBundle\ChessProviderInterface` in your controller, then
5353
implement different actions, using provided `\PChess\Chess\Chess` object.
5454

55-
In your template, you can use Twig function `chess_render(chess)` to render the board.
55+
In your template, you can use the Twig function `chess_render(chess)` to render the board.
5656
If you need to pass an identifier, use `chess_render(chess, identifier)` instead.
5757

5858
The main service you can use is `\PChess\ChessBundle\SessionChessProvider`.
59-
This service allows you to keep chess games in session, providing following methods:
59+
This service allows you to keep chess games in session, providing the following methods:
6060

6161
* `getChess($identifier, $fen)` to get main `\PChess\Chess\Chess` instance (as provided by interface)
6262
* `restart($identifier)` to restart the game
@@ -68,7 +68,7 @@ Using `$identifier` is not mandatory.
6868

6969
### Styling
7070

71-
You can use provided `_board.scss` file to style the board:
71+
You can use the provided `_board.scss` file to style the board:
7272

7373
`@import '~@p-chess/chess-bundle/scss/board';`
7474

composer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
}
2020
],
2121
"require": {
22-
"php": "^8.0",
23-
"p-chess/chess": "^0.4",
24-
"symfony/config": "^5.4 || ^6.4 || ^7.0",
25-
"symfony/dependency-injection": "^5.4 || ^6.4 || ^7.0",
26-
"symfony/http-kernel": "^5.4 || ^6.4 || ^7.0",
27-
"symfony/routing": "^5.4 || ^6.4 || ^7.0",
28-
"twig/twig": "^3.0"
22+
"php": "^8.1",
23+
"p-chess/chess": "^0.6",
24+
"symfony/config": "^6.4 || ^7.0",
25+
"symfony/dependency-injection": "^6.4 || ^7.0",
26+
"symfony/http-kernel": "^6.4 || ^7.0",
27+
"symfony/routing": "^6.4 || ^7.0",
28+
"twig/twig": "^3.18"
2929
},
3030
"require-dev": {
31-
"dg/bypass-finals": "^1.3",
31+
"dg/bypass-finals": "^1.6",
3232
"phpunit/phpunit": "^9.6",
33-
"symfony/phpunit-bridge": "^7.0"
33+
"symfony/phpunit-bridge": "^7.2"
3434
},
3535
"config": {
3636
"sort-packages": true

config/services.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
</service>
1212
<service id="PChess\ChessBundle\SimpleChessProvider"/>
1313
<service id="PChess\ChessBundle\Twig\ChessExtension">
14-
<argument type="abstract" key="$output"/>
1514
<tag name="twig.extension"/>
1615
</service>
16+
<service id="PChess\ChessBundle\Twig\ChessRuntime">
17+
<argument type="abstract" key="$output"/>
18+
<tag name="twig.runtime"/>
19+
</service>
1720
</services>
1821
</container>

src/ChessProviderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
interface ChessProviderInterface
88
{
9-
public function getChess(mixed $identifier = null, string $fen = null): Chess;
9+
public function getChess(mixed $identifier = null, ?string $fen = null): Chess;
1010
}

src/DependencyInjection/CompilerPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace PChess\ChessBundle\DependencyInjection;
44

5-
use PChess\ChessBundle\Twig\ChessExtension as TwigExtension;
5+
use PChess\ChessBundle\Twig\ChessRuntime;
66
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
77
use Symfony\Component\DependencyInjection\ContainerBuilder;
88

@@ -13,6 +13,6 @@ public function process(ContainerBuilder $container): void
1313
/** @var string $service */
1414
$service = $container->getParameter('chess.output_service');
1515
$output = $container->getDefinition($service);
16-
$container->getDefinition(TwigExtension::class)->replaceArgument(0, $output);
16+
$container->getDefinition(ChessRuntime::class)->replaceArgument(0, $output);
1717
}
1818
}

src/HtmlOutput.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ abstract public function getCancelUrl(mixed $identifier = null): string;
1818

1919
abstract public function getPromotionUrl(string $from, string $to, mixed $identifier = null): string;
2020

21-
public function generateLinks(Chess $chess, string $from = null, mixed $identifier = null): array
21+
public function generateLinks(Chess $chess, ?string $from = null, mixed $identifier = null): array
2222
{
2323
$links = [];
2424
$allowedMoves = self::getAllowedMoves($chess, $from);
@@ -58,7 +58,7 @@ public function generateLinks(Chess $chess, string $from = null, mixed $identifi
5858
/**
5959
* @return array<string, array<int, string>>
6060
*/
61-
private static function getAllowedMoves(Chess $chess, string $from = null): array
61+
private static function getAllowedMoves(Chess $chess, ?string $from = null): array
6262
{
6363
$moves = $chess->moves($from ? Board::SQUARES[$from] : null);
6464
$return = [];

src/Mover.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class Mover
1616
*
1717
* @return array<string, array<int, string>>
1818
*/
19-
public static function getAllowedMoves(Chess $chess, string $from = null): array
19+
public static function getAllowedMoves(Chess $chess, ?string $from = null): array
2020
{
2121
$moves = $chess->moves($from ? Board::SQUARES[$from] : null);
2222
$return = [];

src/SessionChessProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function __construct(private RequestStack $requestStack, private string $
1515
{
1616
}
1717

18-
public function getChess(mixed $identifier = null, string $fen = null, History $history = null): Chess
18+
public function getChess(mixed $identifier = null, ?string $fen = null, ?History $history = null): Chess
1919
{
2020
$name = $this->name.$identifier;
2121
$chess = $this->getSession()->has($name) ? $this->getSession()->get($name) : new Chess($fen, $history);

src/SimpleChessProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
final class SimpleChessProvider implements ChessProviderInterface
88
{
9-
public function getChess(mixed $identifier = null, string $fen = null): Chess
9+
public function getChess(mixed $identifier = null, ?string $fen = null): Chess
1010
{
1111
return new Chess($fen);
1212
}

0 commit comments

Comments
 (0)