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

PoC No driver #297

Draft
wants to merge 2 commits into
base: 1.13
Choose a base branch
from
Draft
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
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"phpstan/phpstan-webmozart-assert": "^1.2",
"phpunit/phpunit": "^9.5",
"sylius-labs/coding-standard": "^4.0",
"sylius/resource-bundle": "^1.10",
"sylius/resource-bundle": "dev-poc-new-resource-metadata",
"symfony/console": "^5.4 || ^6.0",
"symfony/dotenv": "^5.4 || ^6.0",
"symfony/maker-bundle": "^1.36",
Expand All @@ -79,7 +79,9 @@
"twig/extensions": "^1.5",
"twig/twig": "^2.12 || ^3.0",
"vimeo/psalm": "^4.26",
"rector/rector": "^0.13"
"rector/rector": "^0.13",
"symfony/uid": "^5.4 || ^6.0",
"symfony/messenger": "^5.4 || ^6.0"
},
"suggest": {
"sylius/currency-bundle": "^1.7"
Expand Down
4 changes: 3 additions & 1 deletion ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer;
use PhpCsFixer\Fixer\Comment\HeaderCommentFixer;
use PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer;
use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer;
use SlevomatCodingStandard\Sniffs\Commenting\InlineDocCommentDeclarationSniff;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
Expand All @@ -26,9 +27,10 @@
->set(NoSuperfluousPhpdocTagsFixer::class)->call('configure', [['allow_mixed' => true]])
;

$containerConfigurator->parameters()->set(Option::SKIP, [
$containerConfigurator->parameters()->set(Option::SKIP, value: [
InlineDocCommentDeclarationSniff::class . '.MissingVariable',
VisibilityRequiredFixer::class => ['*Spec.php'],
MethodArgumentSpaceFixer::class => ['*/BoardGameBlog/*'],
'**/var/*',
]);
};
17 changes: 17 additions & 0 deletions src/Bundle/Builder/GridBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ final class GridBuilder implements GridBuilderInterface

private array $driverConfiguration = [];

/** @var string|callable|null */
private $provider;

/** @var FieldInterface[] */
private array $fields = [];

Expand Down Expand Up @@ -72,6 +75,18 @@ public function setDriver(string $driver): GridBuilderInterface
return $this;
}

public function getProvider(): callable|string|null
{
return $this->provider;
}

public function setProvider(callable|string|null $provider): GridBuilderInterface
{
$this->provider = $provider;

return $this;
}

/**
* @param mixed $value
*/
Expand Down Expand Up @@ -225,6 +240,8 @@ public function toArray(): array
$output['extends'] = $this->extends;
}

$output['provider'] = $this->provider ?? 'sylius.grid.data_provider.default';

return $output;
}
}
7 changes: 7 additions & 0 deletions src/Bundle/Builder/GridBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
use Sylius\Bundle\GridBundle\Builder\Field\FieldInterface;
use Sylius\Bundle\GridBundle\Builder\Filter\FilterInterface;

/**
* @method string|callable|null getProvider
* @method GridBuilderInterface setProvider(string|callable|null $provider)
*
* @psalm-method string|callable|null getProvider
* @psalm-method GridBuilderInterface setProvider(string|callable|null $provider)
*/
interface GridBuilderInterface
{
public static function create(string $name, ?string $resourceClass = null): self;
Expand Down
5 changes: 5 additions & 0 deletions src/Bundle/DependencyInjection/SyliusGridExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle;
use Sylius\Bundle\GridBundle\Grid\GridInterface;
use Sylius\Bundle\GridBundle\SyliusGridBundle;
use Sylius\Component\Grid\Data\DataProviderInterface;
use Sylius\Component\Grid\Filtering\FilterInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -62,6 +63,10 @@ public function load(array $configs, ContainerBuilder $container): void
$container->registerForAutoconfiguration(FilterInterface::class)
->addTag('sylius.grid_filter')
;

$container->registerForAutoconfiguration(DataProviderInterface::class)
->addTag('sylius.grid_data_provider')
;
}

public function getConfiguration(array $config, ContainerBuilder $container): Configuration
Expand Down
9 changes: 7 additions & 2 deletions src/Bundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,17 @@
</service>
<service id="sylius.grid.view_factory" alias="Sylius\Component\Grid\View\GridViewFactoryInterface" />

<service id="Sylius\Component\Grid\Data\DataProviderInterface" class="Sylius\Component\Grid\Data\DataProvider">
<service id="sylius.grid.data_provider" class="Sylius\Component\Grid\Data\Provider">
<argument type="tagged_locator" tag="sylius.grid_data_provider" />
</service>
<service id="Sylius\Component\Grid\Data\DataProviderInterface" alias="sylius.grid.data_provider" />

<service id="sylius.grid.data_provider.default" class="Sylius\Component\Grid\Data\DataProvider">
<argument type="service" id="sylius.grid.data_source_provider" />
<argument type="service" id="sylius.grid.filters_applicator" />
<argument type="service" id="sylius.grid.sorter" />
<tag name="sylius.grid_data_provider" />
</service>
<service id="sylius.grid.data_provider" alias="Sylius\Component\Grid\Data\DataProviderInterface" />

<service id="Sylius\Component\Grid\Filtering\FiltersCriteriaResolverInterface" class="Sylius\Component\Grid\Filtering\FiltersCriteriaResolver" />
<service id="sylius.grid.filters_criteria_resolver" alias="Sylius\Component\Grid\Filtering\FiltersCriteriaResolverInterface" />
Expand Down
12 changes: 12 additions & 0 deletions src/Bundle/Tests/DataFixtures/ORM/fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,15 @@ App\Entity\Price:
price_2:
amount: 1000
currencyCode: "GBP"

App\BoardGameBlog\Domain\ValueObject\BoardGameName:
stone_age_name:
__construct: ['Stone Age']
ticket_to_ride_name:
__construct: ['Ticket to Ride']

App\BoardGameBlog\Domain\Model\BoardGame:
stone_age:
__construct: ['@stone_age_name']
ticket_to_ride:
__construct: ['@ticket_to_ride_name']
49 changes: 49 additions & 0 deletions src/Bundle/Tests/Functional/BoardGameUiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Functional;

use ApiTestCase\ApiTestCase;
use Coduo\PHPMatcher\Backtrace\VoidBacktrace;
use Coduo\PHPMatcher\Matcher;
use Symfony\Component\HttpFoundation\Response;

final class BoardGameUiTest extends ApiTestCase
{
/** @test */
public function it_allows_browsing_board_games(): void
{
$boardGames = $this->loadFixturesFromFile('fixtures.yml');

$this->client->request('GET', '/admin/board-games');
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_OK);
$content = $response->getContent();

$this->assertStringContainsString('<td>Stone Age</td>', $content);
$this->assertStringContainsString(sprintf('<a href="/admin/board-games/%s">Show</a>', $boardGames['stone_age']->id()), $content);
$this->assertStringContainsString(sprintf('<a href="/admin/board-games/%s/edit">Edit</a>', $boardGames['stone_age']->id()), $content);
$this->assertStringContainsString(sprintf('<form action="/admin/board-games/%s" method="post">', $boardGames['stone_age']->id()), $content);

$this->assertStringContainsString('<td>Ticket to Ride</td>', $content);
$this->assertStringContainsString(sprintf('<a href="/admin/board-games/%s">Show</a>', $boardGames['ticket_to_ride']->id()), $content);
$this->assertStringContainsString(sprintf('<a href="/admin/board-games/%s/edit">Edit</a>', $boardGames['ticket_to_ride']->id()), $content);
$this->assertStringContainsString(sprintf('<form action="/admin/board-games/%s" method="post">', $boardGames['ticket_to_ride']->id()), $content);
}

protected function buildMatcher(): Matcher
{
return $this->matcherFactory->createMatcher(new VoidBacktrace());
}
}
Binary file modified src/Bundle/test/config/db.sql
Binary file not shown.
5 changes: 5 additions & 0 deletions src/Bundle/test/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ doctrine:
dir: '%kernel.project_dir%/config/doctrine'
prefix: 'App\Entity'
alias: App
BoardGameBlog:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/BoardGameBlog/Domain'
prefix: 'App\BoardGameBlog\Domain'
1 change: 1 addition & 0 deletions src/Bundle/test/config/packages/fos_rest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ fos_rest:
empty_content: 204
format_listener:
rules:
- { path: '^/admin/*', priorities: ['html'], fallback_format: html }
- { path: '^/', priorities: ['json'], fallback_format: json, prefer_extension: true }
11 changes: 11 additions & 0 deletions src/Bundle/test/config/packages/messenger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
framework:
messenger:
default_bus: command.bus
buses:
command.bus: ~
query.bus: ~
transports:
sync: 'sync://'
routing:
'App\Shared\Application\Query\QueryInterface': 'sync'
'App\Shared\Application\Command\CommandInterface': 'sync'
6 changes: 6 additions & 0 deletions src/Bundle/test/config/packages/sylius_grid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sylius_grid:
templates:
action:
delete: 'grid/action/delete.html.twig'
show: 'grid/action/show.html.twig'
update: 'grid/action/update.html.twig'
7 changes: 7 additions & 0 deletions src/Bundle/test/config/routes/sylius_resource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sylius_crud_routes:
resource: 'sylius.routing.loader.crud_routes_attributes'
type: service

sylius_routes:
resource: 'sylius.routing.loader.routes_attributes'
type: service
6 changes: 6 additions & 0 deletions src/Bundle/test/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ services:
public: true

App\Filter\NationalityFilter: null

App\Shared\:
resource: '../src/Shared'

App\BoardGameBlog\:
resource: '../src/BoardGameBlog'
9 changes: 9 additions & 0 deletions src/Bundle/test/config/sylius/resources.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
sylius_resource:
mapping:
paths:
- '%kernel.project_dir%/src/BoardGameBlog/Infrastructure/Sylius/Resource'

resources:
app.board_game:
driver: false
classes:
model: App\BoardGameBlog\Infrastructure\Sylius\Resource\BoardGameResource

app.book:
classes:
model: App\Entity\Book
Expand Down
49 changes: 49 additions & 0 deletions src/Bundle/test/public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;

require __DIR__ . '/../../../../vendor/autoload.php';

if (!class_exists(Application::class)) {
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
}

$input = new ArgvInput();
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
putenv('APP_ENV=' . $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
}

if ($input->hasParameterOption('--no-debug', true)) {
putenv('APP_DEBUG=' . $_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}

require dirname(__DIR__) . '/config/bootstrap.php';

if ($_SERVER['APP_DEBUG']) {
umask(0000);

if (class_exists(Debug::class)) {
Debug::enable();
}
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\BoardGameBlog\Application\Command;

use App\BoardGameBlog\Domain\ValueObject\BoardGameName;
use App\Shared\Application\Command\CommandInterface;

final class CreateBoardGameCommand implements CommandInterface
{
public function __construct(
public BoardGameName $name,
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\BoardGameBlog\Application\Command;

use App\BoardGameBlog\Domain\Model\BoardGame;
use App\BoardGameBlog\Domain\Repository\BoardGameRepositoryInterface;
use App\Shared\Application\Command\CommandHandlerInterface;

final class CreateBoardGameCommandHandler implements CommandHandlerInterface
{
public function __construct(private BoardGameRepositoryInterface $boardGameRepository)
{
}

public function __invoke(CreateBoardGameCommand $command): BoardGame
{
$boardGame = new BoardGame(
$command->name,
);

$this->boardGameRepository->save($boardGame);

return $boardGame;
}
}
Loading