Compare commits

...

2 commits

Author SHA1 Message Date
André Lubian
0c1cf45137 fix style 2024-10-21 18:55:01 +02:00
André Lubian
1537b157b5 addapi 2024-10-21 18:45:21 +02:00
17 changed files with 2716 additions and 392 deletions

4
.env
View file

@ -28,3 +28,7 @@ DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
# DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
###< doctrine/doctrine-bundle ###
###> nelmio/cors-bundle ###
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
###< nelmio/cors-bundle ###

View file

@ -7,18 +7,29 @@
"php": ">=8.3",
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/doctrine-orm": "^4.0",
"api-platform/symfony": "^4.0",
"doctrine/dbal": "^4.1",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/doctrine-migrations-bundle": "^3.3.1",
"doctrine/orm": "^3.2.1",
"nelmio/cors-bundle": "^2.5",
"phpdocumentor/reflection-docblock": "^5.4",
"phpstan/phpdoc-parser": "^1.30",
"psr/clock": "^1.0",
"symfony/asset": "7.1.*",
"symfony/console": "7.1.*",
"symfony/dotenv": "7.1.*",
"symfony/expression-language": "7.1.*",
"symfony/flex": "^2.4.6",
"symfony/form": "7.1.*",
"symfony/framework-bundle": "7.1.*",
"symfony/property-access": "7.1.*",
"symfony/property-info": "7.1.*",
"symfony/runtime": "7.1.*",
"symfony/security-bundle": "7.1.*",
"symfony/security-csrf": "7.1.*",
"symfony/serializer": "7.1.*",
"symfony/twig-bundle": "7.1.*",
"symfony/uid": "7.1.*",
"symfony/validator": "7.1.*",

2900
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,12 @@
<?php declare(strict_types=1);
use ApiPlatform\Symfony\Bundle\ApiPlatformBundle;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle;
use Nelmio\CorsBundle\NelmioCorsBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\MakerBundle\MakerBundle;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Bundle\TwigBundle\TwigBundle;
return [
@ -22,4 +25,13 @@ return [
TwigBundle::class => [
'all' => true,
],
SecurityBundle::class => [
'all' => true,
],
NelmioCorsBundle::class => [
'all' => true,
],
ApiPlatformBundle::class => [
'all' => true,
],
];

View file

@ -0,0 +1,20 @@
<?php declare(strict_types=1);
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->extension('api_platform', [
'title' => 'Hello API Platform',
'version' => '1.0.0',
'defaults' => [
'stateless' => true,
'cache_headers' => [
'vary' => [
'Content-Type',
'Authorization',
'Origin',
],
],
],
]);
};

View file

@ -0,0 +1,33 @@
<?php declare(strict_types=1);
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->extension('nelmio_cors', [
'defaults' => [
'origin_regex' => true,
'allow_origin' => [
'%env(CORS_ALLOW_ORIGIN)%',
],
'allow_methods' => [
'GET',
'OPTIONS',
'POST',
'PUT',
'PATCH',
'DELETE',
],
'allow_headers' => [
'Content-Type',
'Authorization',
],
'expose_headers' => [
'Link',
],
'max_age' => 3600,
],
'paths' => [
'^/' => null,
],
]);
};

View file

@ -0,0 +1,40 @@
<?php declare(strict_types=1);
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->extension('security', [
'password_hashers' => [
PasswordAuthenticatedUserInterface::class => 'auto',
],
'providers' => [
'users_in_memory' => [
'memory' => null,
],
],
'firewalls' => [
'dev' => [
'pattern' => '^/(_(profiler|wdt)|css|images|js)/',
'security' => false,
],
'main' => [
'lazy' => true,
'provider' => 'users_in_memory',
],
],
'access_control' => null,
]);
if ($containerConfigurator->env() === 'test') {
$containerConfigurator->extension('security', [
'password_hashers' => [
PasswordAuthenticatedUserInterface::class => [
'algorithm' => 'auto',
'cost' => 4,
'time_cost' => 3,
'memory_cost' => 10,
],
],
]);
}
};

View file

@ -0,0 +1,8 @@
<?php declare(strict_types=1);
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
return static function (RoutingConfigurator $routingConfigurator): void {
$routingConfigurator->import('.', 'api_platform')
->prefix('/api');
};

View file

@ -0,0 +1,7 @@
<?php declare(strict_types=1);
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
return static function (RoutingConfigurator $routingConfigurator): void {
$routingConfigurator->import('security.route_loader.logout', 'service');
};

View file

@ -14,7 +14,9 @@
"@default": true,
"global-ignore": [
"App\\Service\\Favicon::__toString",
"ORM\\Column.*"
],
"global-ignoreSourceCodeByRegex": [
"#\\[ORM\\\\Column.*"
]
}
}

0
src/ApiResource/.gitignore vendored Normal file
View file

View file

@ -2,6 +2,7 @@
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\FoodOrderRepository;
use DateInterval;
use DateTimeImmutable;
@ -14,6 +15,8 @@ use Symfony\Component\Uid\Ulid;
use function iterator_to_array;
#[ORM\Entity(repositoryClass: FoodOrderRepository::class)]
#[ApiResource(
)]
class FoodOrder
{
#[ORM\Column(nullable: true)]

View file

@ -2,6 +2,7 @@
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\FoodVendorRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
@ -9,11 +10,15 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid;
use Symfony\Component\Validator\Constraints\NotBlank;
#[ORM\Entity(repositoryClass: FoodVendorRepository::class)]
#[ApiResource(
)]
class FoodVendor
{
#[ORM\Column(length: 50)]
#[NotBlank]
private string|null $name = null;
/**
@ -31,13 +36,17 @@ class FoodVendor
#[ORM\Column(length: 255, nullable: true)]
private string|null $menuLink = null;
public function __construct(
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private Ulid|null $id = new Ulid
private Ulid|null $id = null;
public function __construct(
) {
if (! $this->id instanceof Ulid) {
$this->id = new Ulid;
}
$this->foodOrders = new ArrayCollection;
$this->menuItems = new ArrayCollection;
}

View file

@ -2,6 +2,7 @@
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\MenuItemRepository;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
@ -10,6 +11,8 @@ use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: MenuItemRepository::class)]
#[ApiResource(
)]
class MenuItem
{
#[ORM\Column(length: 255)]

View file

@ -2,6 +2,7 @@
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\OrderItemRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
@ -9,6 +10,8 @@ use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: OrderItemRepository::class)]
#[ApiResource(
)]
class OrderItem
{
#[ORM\Id]

View file

@ -1,4 +1,18 @@
{
"api-platform/symfony": {
"version": "4.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "4.0",
"ref": "e9952e9f393c2d048f10a78f272cd35e807d972b"
},
"files": [
"config/packages/api_platform.yaml",
"config/routes/api_platform.yaml",
"src/ApiResource/.gitignore"
]
},
"doctrine/doctrine-bundle": {
"version": "2.12",
"recipe": {
@ -26,6 +40,18 @@
"migrations/.gitignore"
]
},
"nelmio/cors-bundle": {
"version": "2.5",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "1.5",
"ref": "6bea22e6c564fba3a1391615cada1437d0bde39c"
},
"files": [
"config/packages/nelmio_cors.yaml"
]
},
"phpstan/phpstan": {
"version": "1.11",
"recipe": {
@ -138,6 +164,19 @@
"config/routes.yaml"
]
},
"symfony/security-bundle": {
"version": "7.1",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "6.4",
"ref": "2ae08430db28c8eb4476605894296c82a642028f"
},
"files": [
"config/packages/security.yaml",
"config/routes/security.yaml"
]
},
"symfony/twig-bundle": {
"version": "7.1",
"recipe": {