first commit

This commit is contained in:
Sergio Álvarez 2022-05-21 12:32:17 +02:00
parent 7043b0900e
commit 98e1f085c0
No known key found for this signature in database
GPG Key ID: BD711A37FE7DD77E
22 changed files with 3431 additions and 2 deletions

9
.env
View File

@ -17,3 +17,12 @@
APP_ENV=dev
APP_SECRET=927b6476c39dc61a41e55ee144b865f2
###< 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://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7&charset=utf8mb4"
DATABASE_URL="sqlite:///%kernel.project_dir%/var/app.db"
###< doctrine/doctrine-bundle ###

View File

@ -7,14 +7,24 @@
"php": ">=8.0.2",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/doctrine-bundle": "^2.6",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.12",
"symfony/console": "6.0.*",
"symfony/dotenv": "6.0.*",
"symfony/flex": "^2",
"symfony/framework-bundle": "6.0.*",
"symfony/proxy-manager-bridge": "6.0.*",
"symfony/runtime": "6.0.*",
"symfony/yaml": "6.0.*"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4",
"symfony/debug-bundle": "6.0.*",
"symfony/maker-bundle": "^1.43",
"symfony/monolog-bundle": "^3.0",
"symfony/stopwatch": "6.0.*",
"symfony/web-profiler-bundle": "6.0.*"
},
"config": {
"allow-plugins": {

2863
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -2,4 +2,12 @@
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
];

View File

@ -0,0 +1,5 @@
when@dev:
debug:
# Forwards VarDumper Data clones to a centralized server allowing to inspect dumps on CLI or in your browser.
# See the "server:dump" command to start a new server.
dump_destination: "tcp://%env(VAR_DUMPER_SERVER)%"

View File

@ -0,0 +1,42 @@
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: '13'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
dir: '%kernel.project_dir%/src/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
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

View File

@ -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: '%kernel.debug%'

View File

@ -0,0 +1,61 @@
monolog:
channels:
- deprecation # Deprecations are logged in the dedicated "deprecation" channel when it exists
when@dev:
monolog:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: ["!event"]
# uncomment to get logging in your browser
# you may have to allow bigger header sizes in your Web server configuration
#firephp:
# type: firephp
# level: info
#chromephp:
# type: chromephp
# level: info
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine", "!console"]
when@test:
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
excluded_http_codes: [404, 405]
channels: ["!event"]
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
when@prod:
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
excluded_http_codes: [404, 405]
buffer_size: 50 # How many messages should be saved? Prevent memory leaks
nested:
type: stream
path: php://stderr
level: debug
formatter: monolog.formatter.json
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine"]
deprecation:
type: stream
channels: [deprecation]
path: php://stderr

View File

@ -0,0 +1,6 @@
twig:
default_path: '%kernel.project_dir%/templates'
when@test:
twig:
strict_variables: true

View File

@ -0,0 +1,15 @@
when@dev:
web_profiler:
toolbar: true
intercept_redirects: false
framework:
profiler: { only_exceptions: false }
when@test:
web_profiler:
toolbar: false
intercept_redirects: false
framework:
profiler: { collect: false }

View File

@ -0,0 +1,8 @@
when@dev:
web_profiler_wdt:
resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
prefix: /_wdt
web_profiler_profiler:
resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
prefix: /_profiler

0
migrations/.gitignore vendored Normal file
View File

View File

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220520203412 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE entity1 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(255) NOT NULL)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE entity1');
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Repository\Entity1Repository;
class IndexController extends AbstractController
{
#[Route('/', name: 'app_index')]
public function index(Entity1Repository $repo): Response
{
$entity8 = $repo->findOneByName('entity 8');
return $this->render('index/index.html.twig', [
'controller_name' => 'IndexController',
'entity8' => $entity8
]);
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace App\DataFixtures;
use App\Entity\Entity1;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
class AppFixtures extends Fixture
{
public function load(ObjectManager $manager): void
{
for ($i = 0; $i < 20; $i++) {
$e = new Entity1();
$e->setName('entity '.$i);
$manager->persist($e);
}
$manager->flush();
}
}
// symfony console doctrine:fixtures:load

0
src/Entity/.gitignore vendored Normal file
View File

35
src/Entity/Entity1.php Normal file
View File

@ -0,0 +1,35 @@
<?php
namespace App\Entity;
use App\Repository\Entity1Repository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: Entity1Repository::class)]
class Entity1
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private $name;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
}

0
src/Repository/.gitignore vendored Normal file
View File

View File

@ -0,0 +1,66 @@
<?php
namespace App\Repository;
use App\Entity\Entity1;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Entity1>
*
* @method Entity1|null find($id, $lockMode = null, $lockVersion = null)
* @method Entity1|null findOneBy(array $criteria, array $orderBy = null)
* @method Entity1[] findAll()
* @method Entity1[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class Entity1Repository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Entity1::class);
}
public function add(Entity1 $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Entity1 $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return Entity1[] Returns an array of Entity1 objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('e')
// ->andWhere('e.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('e.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
public function findOneByName($value): ?Entity1
{
return $this->createQueryBuilder('e')
->andWhere('e.name = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
}

View File

@ -1,4 +1,106 @@
{
"doctrine/annotations": {
"version": "1.13",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "1.10",
"ref": "64d8583af5ea57b7afa4aba4b159907f3a148b05"
}
},
"doctrine/cache": {
"version": "2.2.0"
},
"doctrine/collections": {
"version": "1.6.8"
},
"doctrine/common": {
"version": "3.3.0"
},
"doctrine/data-fixtures": {
"version": "1.5.3"
},
"doctrine/dbal": {
"version": "3.3.6"
},
"doctrine/deprecations": {
"version": "v1.0.0"
},
"doctrine/doctrine-bundle": {
"version": "2.6",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "2.4",
"ref": "ddddd8249dd55bbda16fa7a45bb7499ef6f8e90e"
},
"files": [
"config/packages/doctrine.yaml",
"src/Entity/.gitignore",
"src/Repository/.gitignore"
]
},
"doctrine/doctrine-fixtures-bundle": {
"version": "3.4",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "3.0",
"ref": "1f5514cfa15b947298df4d771e694e578d4c204d"
},
"files": [
"src/DataFixtures/AppFixtures.php"
]
},
"doctrine/doctrine-migrations-bundle": {
"version": "3.2",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "3.1",
"ref": "ee609429c9ee23e22d6fa5728211768f51ed2818"
},
"files": [
"config/packages/doctrine_migrations.yaml",
"migrations/.gitignore"
]
},
"doctrine/event-manager": {
"version": "1.1.1"
},
"doctrine/inflector": {
"version": "2.0.4"
},
"doctrine/instantiator": {
"version": "1.4.1"
},
"doctrine/lexer": {
"version": "1.2.3"
},
"doctrine/migrations": {
"version": "3.5.1"
},
"doctrine/orm": {
"version": "2.12.2"
},
"doctrine/persistence": {
"version": "3.0.2"
},
"doctrine/sql-formatter": {
"version": "1.1.2"
},
"friendsofphp/proxy-manager-lts": {
"version": "v1.0.12"
},
"laminas/laminas-code": {
"version": "4.5.1"
},
"monolog/monolog": {
"version": "2.6.0"
},
"nikic/php-parser": {
"version": "v4.13.2"
},
"psr/cache": {
"version": "3.0.0"
},
@ -32,12 +134,27 @@
"bin/console"
]
},
"symfony/debug-bundle": {
"version": "6.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "5.3",
"ref": "5aa8aa48234c8eb6dbdd7b3cd5d791485d2cec4b"
},
"files": [
"config/packages/debug.yaml"
]
},
"symfony/dependency-injection": {
"version": "v6.0.8"
},
"symfony/deprecation-contracts": {
"version": "v3.0.1"
},
"symfony/doctrine-bridge": {
"version": "v6.0.8"
},
"symfony/dotenv": {
"version": "v6.0.5"
},
@ -93,6 +210,30 @@
"symfony/http-kernel": {
"version": "v6.0.8"
},
"symfony/maker-bundle": {
"version": "1.43",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "1.0",
"ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f"
}
},
"symfony/monolog-bridge": {
"version": "v6.0.3"
},
"symfony/monolog-bundle": {
"version": "3.8",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "3.7",
"ref": "213676c4ec929f046dfde5ea8e97625b81bc0578"
},
"files": [
"config/packages/monolog.yaml"
]
},
"symfony/polyfill-intl-grapheme": {
"version": "v1.25.0"
},
@ -105,6 +246,9 @@
"symfony/polyfill-php81": {
"version": "v1.25.0"
},
"symfony/proxy-manager-bridge": {
"version": "v6.0.6"
},
"symfony/routing": {
"version": "6.0",
"recipe": {
@ -124,16 +268,54 @@
"symfony/service-contracts": {
"version": "v3.0.1"
},
"symfony/stopwatch": {
"version": "v6.0.5"
},
"symfony/string": {
"version": "v6.0.8"
},
"symfony/translation-contracts": {
"version": "v3.0.1"
},
"symfony/twig-bridge": {
"version": "v6.0.8"
},
"symfony/twig-bundle": {
"version": "6.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "5.4",
"ref": "bb2178c57eee79e6be0b297aa96fc0c0def81387"
},
"files": [
"config/packages/twig.yaml",
"templates/base.html.twig"
]
},
"symfony/var-dumper": {
"version": "v6.0.8"
},
"symfony/var-exporter": {
"version": "v6.0.8"
},
"symfony/web-profiler-bundle": {
"version": "6.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "5.3",
"ref": "24bbc3d84ef2f427f82104f766014e799eefcc3e"
},
"files": [
"config/packages/web_profiler.yaml",
"config/routes/web_profiler.yaml"
]
},
"symfony/yaml": {
"version": "v6.0.3"
},
"twig/twig": {
"version": "v3.4.1"
}
}

19
templates/base.html.twig Normal file
View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>{% block title %}Welcome!{% endblock %}</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 128 128%22><text y=%221.2em%22 font-size=%2296%22>⚫️</text></svg>">
{# Run `composer require symfony/webpack-encore-bundle` to start using Symfony UX #}
{% block stylesheets %}
{{ encore_entry_link_tags('app') }}
{% endblock %}
{% block javascripts %}
{{ encore_entry_script_tags('app') }}
{% endblock %}
</head>
<body>
{% block body %}{% endblock %}
</body>
</html>

View File

@ -0,0 +1,22 @@
{% extends 'base.html.twig' %}
{% block title %}Hello IndexController!{% endblock %}
{% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
</style>
<div class="example-wrapper">
<h1>Hello {{ controller_name }}! ✅</h1>
This friendly message is coming from:
<ul>
<li>Your controller at <code><a href="{{ '/home/xergio/dev/symfony-playground/src/Controller/IndexController.php'|file_link(0) }}">src/Controller/IndexController.php</a></code></li>
<li>Your template at <code><a href="{{ '/home/xergio/dev/symfony-playground/templates/index/index.html.twig'|file_link(0) }}">templates/index/index.html.twig</a></code></li>
</ul>
</div>
<p>entity8: {{ entity8.id }}</p>
{% endblock %}