Skip to content

Commit

Permalink
Init Admin UI component
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Jun 28, 2024
1 parent 3c7ec7a commit 1423df4
Show file tree
Hide file tree
Showing 48 changed files with 1,376 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@
APP_ENV=dev
APP_SECRET=28de35e787e86cb435f0312627623283
###< symfony/framework-bundle ###

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=8.0.32&charset=utf8mb4"
# DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
DATABASE_URL="postgresql://sylius_stack:[email protected]:5432/sylius_stack?serverVersion=16&charset=utf8"
###< doctrine/doctrine-bundle ###
26 changes: 26 additions & 0 deletions app/DataFixtures/AppFixtures.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* This file is part of SyliusUi.
*
* (c) Monofony
*
* 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\DataFixtures;

use App\Story\DefaultBooksStory;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;

class AppFixtures extends Fixture
{
public function load(ObjectManager $manager): void
{
DefaultBooksStory::load();
}
}
Empty file added app/Entity/.gitignore
Empty file.
87 changes: 87 additions & 0 deletions app/Entity/Book.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

declare(strict_types=1);

namespace App\Entity;

use App\Repository\BookRepository;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Resource\Annotation\SyliusCrudRoutes;
use Sylius\Component\Resource\Model\ResourceInterface;

#[ORM\Entity(repositoryClass: BookRepository::class)]
#[SyliusCrudRoutes(
alias: 'app.book',
path: '/admin/books',
section: 'admin',
redirect: 'update',
templates: '@SyliusAdminUi/crud',
grid: 'app_book',
vars: [
'all' => [
'subheader' => 'app.ui.manage_your_books',
],
],
)]
class Book implements ResourceInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;

#[ORM\Column(type: 'string', length: 255)]
private ?string $title = null;

#[ORM\Column(type: 'string', length: 255)]
private ?string $authorName = null;

#[ORM\Column(type: 'datetime_immutable')]
private \DateTimeImmutable $createdAt;

public function __construct()
{
$this->createdAt = new \DateTimeImmutable();
}

public function getId(): ?int
{
return $this->id;
}

public function getTitle(): ?string
{
return $this->title;
}

public function setTitle(string $title): self
{
$this->title = $title;

return $this;
}

public function getAuthorName(): ?string
{
return $this->authorName;
}

public function setAuthorName(string $authorName): self
{
$this->authorName = $authorName;

return $this;
}

public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}

public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;

return $this;
}
}
61 changes: 61 additions & 0 deletions app/Factory/BookFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace App\Factory;

use App\Entity\Book;
use App\Repository\BookRepository;
use Doctrine\Persistence\Proxy;
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
use \Zenstruck\Foundry\Persistence\ProxyRepositoryDecorator;

/**
* @template TModel of Book
* @template-extends PersistentObjectFactory<TModel>
*
* @method static Book|Proxy createOne(array $attributes = [])
* @method static Book[]|Proxy[] createMany(int $number, array|callable $attributes = [])
* @method static Book[]|Proxy[] createSequence(array|callable $sequence)
* @method static Book|Proxy find(object|array|mixed $criteria)
* @method static Book|Proxy findOrCreate(array $attributes)
* @method static Book|Proxy first(string $sortedField = 'id')
* @method static Book|Proxy last(string $sortedField = 'id')
* @method static Book|Proxy random(array $attributes = [])
* @method static Book|Proxy randomOrCreate(array $attributes = [])
* @method static Book[]|Proxy[] all()
* @method static Book[]|Proxy[] findBy(array $attributes)
* @method static Book[]|Proxy[] randomSet(int $number, array $attributes = [])
* @method static Book[]|Proxy[] randomRange(int $min, int $max, array $attributes = [])
* @method static BookRepository|ProxyRepositoryDecorator repository()
* @method Book|Proxy create(array|callable $attributes = [])
*/
final class BookFactory extends PersistentProxyObjectFactory
{
public function withTitle(string $title): self
{
return $this->with(['title' => $title]);
}

public function withAuthorName(string $authorName): self
{
return $this->with(['authorName' => $authorName]);
}

public static function class(): string
{
return Book::class;
}

/**
* @return array<string, mixed>|callable
*/
protected function defaults(): array|callable
{
return [
'title' => ucfirst(self::faker()->words(3, true)),
'authorName' => self::faker()->firstName() . ' ' . self::faker()->lastName(),
];
}
}
Empty file added app/Repository/.gitignore
Empty file.
29 changes: 29 additions & 0 deletions app/Repository/BookRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace App\Repository;

use App\Entity\Book;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\ResourceRepositoryTrait;
use Sylius\Component\Resource\Repository\RepositoryInterface;

/**
* @extends ServiceEntityRepository<Book>
*
* @method Book|null find($id, $lockMode = null, $lockVersion = null)
* @method Book|null findOneBy(array $criteria, array $orderBy = null)
* @method Book[] findAll()
* @method Book[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class BookRepository extends ServiceEntityRepository implements RepositoryInterface
{
use ResourceRepositoryTrait;

public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Book::class);
}
}
21 changes: 21 additions & 0 deletions app/Story/DefaultBooksStory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Story;

use App\Factory\BookFactory;
use Zenstruck\Foundry\Story;

final class DefaultBooksStory extends Story
{
public function build(): void
{
BookFactory::new()
->withTitle('1984')
->withAuthorName('George Orwell')
;

BookFactory::createMany(20);
}
}
6 changes: 6 additions & 0 deletions compose.override.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
###> doctrine/doctrine-bundle ###
database:
ports:
- "${POSTGRES_PORT:-5432}:5432"
###< doctrine/doctrine-bundle ###
19 changes: 19 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
###> doctrine/doctrine-bundle ###
database:
image: postgres:${POSTGRES_VERSION:-16}-alpine
environment:
POSTGRES_DB: ${POSTGRES_DB:-sylius_stack}
# You should definitely change the password in production
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-sylius_stack}
POSTGRES_USER: ${POSTGRES_USER:-sylius_stack}
volumes:
- database_data:/var/lib/postgresql/data:rw
# You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
# - ./docker/db/data:/var/lib/postgresql/data:rw
###< doctrine/doctrine-bundle ###

volumes:
###> doctrine/doctrine-bundle ###
database_data:
###< doctrine/doctrine-bundle ###
19 changes: 18 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,34 @@
],
"require": {
"php": "^8.1",
"doctrine/dbal": "^3",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/doctrine-migrations-bundle": "^3.3",
"doctrine/orm": "^2.19",
"knplabs/knp-menu-bundle": "^3.0",
"laminas/laminas-stdlib": "^3.18",
"symfony/config": "^6.4 || ^7.0",
"symfony/dependency-injection": "^6.4 || ^7.0",
"symfony/expression-language": "^6.4 || ^7.0",
"symfony/http-kernel": "^6.4 || ^7.0",
"symfony/stopwatch": "^6.4 || ^7.0",
"symfony/twig-bundle": "^6.4 || ^7.0",
"pagerfanta/doctrine-orm-adapter": "^4.6",
"sylius/resource-bundle": "dev-symfony-7",
"symfony/config": "^6.4",
"symfony/dependency-injection": "^6.4",
"symfony/expression-language": "^6.4",
"symfony/http-kernel": "^6.4",
"symfony/stopwatch": "^6.4",
"symfony/twig-bundle": "^6.4",
"symfony/ux-live-component": "^2.17",
"symfony/ux-twig-component": "^2.17",
"twig/twig": "^2.15 || ^3.0"
},
"require-dev": {
"matthiasnoback/symfony-config-test": "^5.1",
"matthiasnoback/symfony-dependency-injection-test": "^5.1",
"doctrine/doctrine-fixtures-bundle": "^3.6",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-symfony": "^1.3",
"phpunit/phpunit": "^9.6",
Expand All @@ -42,10 +56,13 @@
"symfony/translation": "^6.4 || ^7.0",
"symfony/web-profiler-bundle": "^6.4 || ^7.0",
"symfony/yaml": "^6.4 || ^7.0",
"symplify/monorepo-builder": "11.2.*"
"symplify/monorepo-builder": "11.2.*",
"zenstruck/foundry": "^2.0"
},
"autoload": {
"psr-4": {
"Sylius\\AdminUi\\": "src/AdminUi/src/",
"Sylius\\TwigExtra\\": "src/TwigExtra/src/",
"Sylius\\TwigHooks\\": "src/TwigHooks/src/"
}
},
Expand Down
10 changes: 10 additions & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\UX\TwigComponent\TwigComponentBundle::class => ['all' => true],
Sylius\TwigHooks\TwigHooksBundle::class => ['all' => true],
Sylius\TwigExtra\Symfony\TwigExtraBundle::class => ['all' => true],
Sylius\AdminUi\Symfony\AdminUiBundle::class => ['all' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true],
Symfony\UX\LiveComponent\LiveComponentBundle::class => ['all' => true],
Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true],
winzou\Bundle\StateMachineBundle\winzouStateMachineBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true],
Sylius\Bundle\ResourceBundle\SyliusResourceBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Zenstruck\Foundry\ZenstruckFoundryBundle::class => ['dev' => true, 'test' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
];
50 changes: 50 additions & 0 deletions config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'

# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '16'

profiling_collect_backtrace: '%kernel.debug%'
use_savepoints: true
orm:
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true
report_fields_where_declared: true
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
type: attribute
is_bundle: false
dir: '%kernel.project_dir%/app/Entity'
prefix: 'App\Entity'
alias: App

when@test:
doctrine:
dbal:
# "TEST_TOKEN" is typically set by ParaTest
dbname_suffix: '_test%env(default::TEST_TOKEN)%'

when@prod:
doctrine:
orm:
auto_generate_proxy_classes: false
proxy_dir: '%kernel.build_dir%/doctrine/orm/Proxies'
query_cache_driver:
type: pool
pool: doctrine.system_cache_pool
result_cache_driver:
type: pool
pool: doctrine.result_cache_pool

framework:
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.app
doctrine.system_cache_pool:
adapter: cache.system
6 changes: 6 additions & 0 deletions config/packages/doctrine_migrations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
doctrine_migrations:
migrations_paths:
# namespace is arbitrary but should be different from App\Migrations
# as migrations classes should NOT be autoloaded
'DoctrineMigrations': '%kernel.project_dir%/migrations'
enable_profiler: false
Loading

0 comments on commit 1423df4

Please sign in to comment.