first commit
This commit is contained in:
commit
6070adcae1
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
docker-compose.override.yml
|
||||||
|
docker-compose.override.yaml
|
1
.php-version
Normal file
1
.php-version
Normal file
@ -0,0 +1 @@
|
|||||||
|
8.2
|
3
Dockerfile
Normal file
3
Dockerfile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
FROM larueli/php-symfony-base-image:8.2
|
||||||
|
|
||||||
|
RUN echo 'cd /var/www/html && /usr/local/bin/php -d memory_limit=-1 bin/console messenger:consume async &' > /docker-entrypoint-init.d/messenger_queue.sh
|
75
README.md
Normal file
75
README.md
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
php -v
|
||||||
|
|
||||||
|
composer --version
|
||||||
|
|
||||||
|
composer selfupdate
|
||||||
|
|
||||||
|
sudo update-alternatives --set php /usr/bin/php8.2
|
||||||
|
|
||||||
|
symfony new gift_manager_api '--version=6.2.*' --webapp
|
||||||
|
|
||||||
|
composer require api
|
||||||
|
|
||||||
|
composer require symfony/apache-pack
|
||||||
|
|
||||||
|
composer require gedmo/doctrine-extensions "^3.10"
|
||||||
|
|
||||||
|
dans config/services.yaml
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
parameters:
|
||||||
|
app.from_email.address: "%env(APP_FROM_EMAIL_ADDRESS)%"
|
||||||
|
app.from_email.name: "%env(APP_FROM_EMAIL_NAME)%"
|
||||||
|
|
||||||
|
services:
|
||||||
|
App\Service\MailSender:
|
||||||
|
arguments:
|
||||||
|
$fromEmailAddress: "%app.from_email.address%"
|
||||||
|
$fromEmailName: "%app.from_email.name%"
|
||||||
|
|
||||||
|
gedmo.listener.timestampable:
|
||||||
|
class: Gedmo\Timestampable\TimestampableListener
|
||||||
|
tags:
|
||||||
|
- { name: doctrine.event_subscriber, connection: default }
|
||||||
|
calls:
|
||||||
|
- [ setAnnotationReader, [ "@annotation_reader" ] ]
|
||||||
|
```
|
||||||
|
|
||||||
|
Dans le .env
|
||||||
|
|
||||||
|
```
|
||||||
|
APP_FROM_EMAIL_ADDRESS=noreply@noreply.com
|
||||||
|
APP_FROM_EMAIL_NAME="NO REPLY"
|
||||||
|
MESSENGER_TRANSPORT_DSN=doctrine://default
|
||||||
|
```
|
||||||
|
|
||||||
|
APP_SECRET à changer
|
||||||
|
|
||||||
|
Paquets
|
||||||
|
|
||||||
|
```
|
||||||
|
"require-dev": {
|
||||||
|
"roave/security-advisories": "dev-latest",
|
||||||
|
"captainhook/captainhook": "^5.10",
|
||||||
|
"marcocesarato/php-conventional-changelog": "^1.15",
|
||||||
|
"ramsey/conventional-commits": "^1.3",
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
# Exposition reverse proxy
|
||||||
|
|
||||||
|
S'assurer que le reverse proxy renvoie bien `http-forwarded-prefix`
|
||||||
|
|
||||||
|
Configurer les trusted proxies
|
||||||
|
|
||||||
|
```
|
||||||
|
# config/packages/framework.yml
|
||||||
|
|
||||||
|
framework:
|
||||||
|
trusted_proxies: '%env(TRUSTED_PROXIES)%'
|
||||||
|
trusted_headers: ['x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto', 'x-forwarded-port', 'x-forwarded-prefix']
|
||||||
|
```
|
||||||
|
|
||||||
|
définir la variable d'env TRUSTED_PROXIES avec le/les réseaux ou IP spécfiques (séparés par des virgules, réseaux en notation CIDR)
|
52
captainhook.json
Normal file
52
captainhook.json
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
{
|
||||||
|
"commit-msg": {
|
||||||
|
"enabled": true,
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"action": "\\Ramsey\\CaptainHook\\ValidateConventionalCommit",
|
||||||
|
"options": {
|
||||||
|
"configFile": "./conventional-commits.json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"pre-push": {
|
||||||
|
"enabled": false,
|
||||||
|
"actions": []
|
||||||
|
},
|
||||||
|
"pre-commit": {
|
||||||
|
"enabled": false,
|
||||||
|
"actions": []
|
||||||
|
},
|
||||||
|
"prepare-commit-msg": {
|
||||||
|
"enabled": true,
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"action": "\\Ramsey\\CaptainHook\\ValidateConventionalCommit",
|
||||||
|
"options": {
|
||||||
|
"configFile": "./conventional-commits.json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"post-commit": {
|
||||||
|
"enabled": false,
|
||||||
|
"actions": []
|
||||||
|
},
|
||||||
|
"post-merge": {
|
||||||
|
"enabled": false,
|
||||||
|
"actions": []
|
||||||
|
},
|
||||||
|
"post-checkout": {
|
||||||
|
"enabled": false,
|
||||||
|
"actions": []
|
||||||
|
},
|
||||||
|
"post-rewrite": {
|
||||||
|
"enabled": false,
|
||||||
|
"actions": []
|
||||||
|
},
|
||||||
|
"post-change": {
|
||||||
|
"enabled": false,
|
||||||
|
"actions": []
|
||||||
|
}
|
||||||
|
}
|
22
conventional-commits.json
Normal file
22
conventional-commits.json
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"typeCase": "kebab",
|
||||||
|
"types": [
|
||||||
|
"chore",
|
||||||
|
"ci",
|
||||||
|
"docs",
|
||||||
|
"feat",
|
||||||
|
"fix",
|
||||||
|
"refactor",
|
||||||
|
"security",
|
||||||
|
"style",
|
||||||
|
"test"
|
||||||
|
],
|
||||||
|
"scopeCase": "kebab",
|
||||||
|
"scopeRequired": false,
|
||||||
|
"scopes": [],
|
||||||
|
"descriptionCase": null,
|
||||||
|
"descriptionEndMark": "",
|
||||||
|
"bodyRequired": false,
|
||||||
|
"bodyWrapWidth": 72,
|
||||||
|
"requiredFooters": []
|
||||||
|
}
|
57
docker-compose.dev.yml
Normal file
57
docker-compose.dev.yml
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
application:
|
||||||
|
image: larueli/php-symfony-base-image:8.2
|
||||||
|
user: "1000:0"
|
||||||
|
environment:
|
||||||
|
DATABASE_URL: "postgresql://app:app@database:5432/app?serverVersion=14&charset=utf8"
|
||||||
|
MAILER_DSN: "smtp://mailer:1025"
|
||||||
|
PHP_IDE_CONFIG: "serverName=docker"
|
||||||
|
XDEBUG_MODE: "develop,debug" # profile,coverage
|
||||||
|
XDEBUG_CONFIG: "client_host=host.docker.internal"
|
||||||
|
XDEBUG_TRIGGER: "yes"
|
||||||
|
volumes:
|
||||||
|
- ./:/var/www/html
|
||||||
|
#ports:
|
||||||
|
# - "8000:8080"
|
||||||
|
#extra_hosts:
|
||||||
|
# - host.docker.internal:${HOST_IP:-172.17.0.1}
|
||||||
|
|
||||||
|
#database:
|
||||||
|
# ports:
|
||||||
|
# - "5432:5432"
|
||||||
|
|
||||||
|
adminer:
|
||||||
|
image: adminer
|
||||||
|
networks:
|
||||||
|
- traefik
|
||||||
|
environment:
|
||||||
|
ADMINER_DEFAULT_DB_HOST: database
|
||||||
|
ADMINER_DEFAULT_DB_NAME: app
|
||||||
|
ADMINER_DESIGN: lucas-sandery
|
||||||
|
#ports:
|
||||||
|
# - "8080:8080"
|
||||||
|
labels:
|
||||||
|
- "traefik.http.routers.app_adminer.rule=Host(`localhost`) && PathPrefix(`/adminer/`)"
|
||||||
|
- "traefik.http.services.app_adminer.loadbalancer.server.port=8080"
|
||||||
|
- "traefik.http.routers.app_adminer.middlewares=app_adminer_strip"
|
||||||
|
- "traefik.http.middlewares.app_adminer_strip.stripprefix.prefixes=/adminer"
|
||||||
|
- "traefik.http.middlewares.app_adminer_strip.stripprefix.forceslash=false"
|
||||||
|
|
||||||
|
mailer:
|
||||||
|
image: sj26/mailcatcher
|
||||||
|
environment:
|
||||||
|
HTTPPATH: "mailer"
|
||||||
|
networks:
|
||||||
|
- traefik
|
||||||
|
command:
|
||||||
|
- "--ip"
|
||||||
|
- "0.0.0.0"
|
||||||
|
- "--http-path"
|
||||||
|
- "mailer"
|
||||||
|
#ports:
|
||||||
|
# - "8081:1080"
|
||||||
|
labels:
|
||||||
|
- "traefik.http.routers.app_mailer.rule=Host(`localhost`) && PathPrefix(`/mailer`)"
|
||||||
|
- "traefik.http.services.app_mailer.loadbalancer.server.port=1080"
|
8
docker-compose.prod.yml
Normal file
8
docker-compose.prod.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
application:
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
database:
|
||||||
|
restart: always
|
36
docker-compose.yml
Normal file
36
docker-compose.yml
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
application:
|
||||||
|
image: larueli/app
|
||||||
|
networks:
|
||||||
|
- traefik
|
||||||
|
environment:
|
||||||
|
APACHE_DOCUMENT_ROOT: /var/www/html/public
|
||||||
|
TZ: Europe/Paris
|
||||||
|
depends_on:
|
||||||
|
database:
|
||||||
|
condition: service_healthy
|
||||||
|
labels:
|
||||||
|
- "traefik.http.routers.app.rule=Host(`localhost`) && PathPrefix(`/api`)"
|
||||||
|
- "traefik.http.services.app.loadbalancer.server.port=8080"
|
||||||
|
- "traefik.http.routers.app.middlewares=app_strip"
|
||||||
|
- "traefik.http.middlewares.app.stripprefix.prefixes=/api"
|
||||||
|
- "traefik.http.middlewares.app.stripprefix.forceslash=false"
|
||||||
|
|
||||||
|
database:
|
||||||
|
image: postgres:15.1
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: app
|
||||||
|
POSTGRES_PASSWORD: app
|
||||||
|
POSTGRES_USER: app
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
volumes:
|
||||||
|
- db-data:/var/lib/postgresql/data:rw
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db-data:
|
34
src/Service/MailSender.php
Normal file
34
src/Service/MailSender.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Component\Mailer\MailerInterface;
|
||||||
|
use Symfony\Component\Mime\Address;
|
||||||
|
use Symfony\Component\Mime\Email;
|
||||||
|
|
||||||
|
class MailSender
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private MailerInterface $mailer,
|
||||||
|
private LoggerInterface $logger,
|
||||||
|
private string $fromEmailAddress,
|
||||||
|
private string $fromEmailName
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function sendMail(string $subject, array $to, string $content) {
|
||||||
|
$message = ( new Email())
|
||||||
|
->subject($subject)
|
||||||
|
->to(...$to)
|
||||||
|
->from(new Address($this->fromEmail, $this->fromEmailName))
|
||||||
|
->html($content);
|
||||||
|
try {
|
||||||
|
$this->mailer->send($message);
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
$this->logger->critical($exception->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
76
src/Trait/TimestampableEntity.php
Normal file
76
src/Trait/TimestampableEntity.php
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Doctrine Behavioral Extensions package.
|
||||||
|
* (c) Gediminas Morkevicius <gediminas.morkevicius@gmail.com> http://www.gediminasm.org
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Trait;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Types\Types;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Gedmo\Mapping\Annotation as Gedmo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Timestampable Trait, usable with PHP >= 5.4
|
||||||
|
*
|
||||||
|
* @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
|
||||||
|
*/
|
||||||
|
trait TimestampableEntity
|
||||||
|
{
|
||||||
|
|
||||||
|
#[Gedmo\Timestampable(on: 'create')]
|
||||||
|
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
|
||||||
|
private ?\DateTimeImmutable $createdAt = null;
|
||||||
|
|
||||||
|
|
||||||
|
#[Gedmo\Timestampable(on: 'update')]
|
||||||
|
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
|
||||||
|
private ?\DateTimeImmutable $updatedAt = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets createdAt.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setCreatedAt(\DateTimeImmutable $createdAt)
|
||||||
|
{
|
||||||
|
$this->createdAt = $createdAt;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns createdAt.
|
||||||
|
*
|
||||||
|
* @return \DateTimeImmutable
|
||||||
|
*/
|
||||||
|
public function getCreatedAt()
|
||||||
|
{
|
||||||
|
return $this->createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets updatedAt.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setUpdatedAt(\DateTimeImmutable $updatedAt)
|
||||||
|
{
|
||||||
|
$this->updatedAt = $updatedAt;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns updatedAt.
|
||||||
|
*
|
||||||
|
* @return \DateTimeImmutable
|
||||||
|
*/
|
||||||
|
public function getUpdatedAt()
|
||||||
|
{
|
||||||
|
return $this->updatedAt;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user