feat: init project

This commit is contained in:
Aymeric GUERACAGUE 2025-05-19 13:50:19 +02:00
commit 3b915384f0
Signed by: Superkooka
GPG Key ID: F78F2B172E894865
29 changed files with 4413 additions and 0 deletions

4
.env.dev Normal file
View File

@ -0,0 +1,4 @@
###> symfony/framework-bundle ###
APP_SECRET=d45bc10fbd2ddcc480e49401526a6e7f
###< symfony/framework-bundle ###

17
.env.example Normal file
View File

@ -0,0 +1,17 @@
###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=79e3e28a27aa752548962c961aee5324
###< 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="postgres://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8&charset=utf8mb4"
DB_DATABASE=stat_an
DB_HOST=postgres
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=postgres
###< doctrine/doctrine-bundle ###

23
.gitignore vendored Normal file
View File

@ -0,0 +1,23 @@
.env
/.idea/
/sample/
/docker/php-fpm/ini/xdebug.ini
###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###
###> friendsofphp/php-cs-fixer ###
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###
.DS_Store
###> phpstan/phpstan ###
phpstan.neon
###< phpstan/phpstan ###

22
.php-cs-fixer.php Normal file
View File

@ -0,0 +1,22 @@
<?php
$finder = PhpCsFixer\Finder::create()
->in([
__DIR__ . '/src',
])
;
$config = new PhpCsFixer\Config();
return $config
->setRiskyAllowed(true)
->setRules([
'@PER' => true,
'@PER:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP80Migration:risky' => true,
'@PHP83Migration' => true,
'concat_space' => ['spacing' => 'one'],
])
->setFinder($finder);

67
Makefile Normal file
View File

@ -0,0 +1,67 @@
TARGET_APP=stat-an:dev
## To init project
.PHONY: init
init:
$(MAKE) build
cp .env.example .env
cp docker/php-fpm/xdebug.ini.example docker/php-fpm/xdebug.ini
$(MAKE) install db-init
## Build docker image
.PHONY: build
build:
DOCKER_BUILDKIT=1 docker build \
-f docker/php-fpm/Dockerfile \
--target dev \
-t $(TARGET_APP) \
.
## Install dependencies
.PHONY: install
install:
docker-compose -f docker-compose.yaml run --rm stat-an-api composer install
## Init database
.PHONY: db-init
db-init:
docker-compose run --rm stat-an-api sh -c "php bin/console doctrine:migrations:migrate -n"
## Start containers
.PHONY: start
start:
docker-compose -f docker-compose.yaml up -d
## Stop containers
.PHONY: stop
stop:
docker-compose -f docker-compose.yaml down
.PHONY: shell
shell:
docker-compose -f docker-compose.yaml exec stat-an-api sh
## Display container status
.PHONY: status
status:
docker-compose -f docker-compose.yaml ps
## Display logs of all containers
.PHONY: logs
logs:
docker-compose -f docker-compose.yaml logs -f
## Run static code analyses with phpstan
.PHONY: static-check
static-check:
docker-compose -f docker-compose.yaml run --rm stat-an-api php -d memory_limit=4G vendor/bin/phpstan analyse -c phpstan.neon
## Run linter analyses with php-cs-fixer
.PHONY: style-check
style-check:
docker-compose -f docker-compose.yaml run -e PHP_CS_FIXER_IGNORE_ENV=1 --rm stat-an-api php -d memory_limit=4G vendor/bin/php-cs-fixer fix --dry-run --diff --show-progress=dots
## Run linter automatic fix with php-cs-fixer
.PHONY: style-fix
style-fix:
docker-compose -f docker-compose.yaml run -e PHP_CS_FIXER_IGNORE_ENV=1 --rm stat-an-api php -d memory_limit=4G vendor/bin/php-cs-fixer fix --diff --show-progress=dots

21
bin/console Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env php
<?php
use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
if (!is_dir(dirname(__DIR__).'/vendor')) {
throw new LogicException('Dependencies are missing. Try running "composer install".');
}
if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
return new Application($kernel);
};

71
composer.json Normal file
View File

@ -0,0 +1,71 @@
{
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": ">=8.4",
"ext-ctype": "*",
"ext-iconv": "*",
"symfony/console": "7.2.*",
"symfony/dotenv": "7.2.*",
"symfony/flex": "^2",
"symfony/framework-bundle": "7.2.*",
"symfony/runtime": "7.2.*",
"symfony/yaml": "7.2.*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.75",
"phpstan/phpstan": "^2.1"
},
"config": {
"allow-plugins": {
"php-http/discovery": true,
"symfony/flex": true,
"symfony/runtime": true
},
"bump-after-update": true,
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*",
"symfony/polyfill-php73": "*",
"symfony/polyfill-php74": "*",
"symfony/polyfill-php80": "*",
"symfony/polyfill-php81": "*",
"symfony/polyfill-php82": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "7.2.*"
}
}
}

3780
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

5
config/bundles.php Normal file
View File

@ -0,0 +1,5 @@
<?php
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
];

View File

@ -0,0 +1,19 @@
framework:
cache:
# Unique name of your app: used to compute stable namespaces for cache keys.
#prefix_seed: your_vendor_name/app_name
# The "app" cache stores to the filesystem by default.
# The data in this cache should persist between deploys.
# Other options include:
# Redis
#app: cache.adapter.redis
#default_redis_provider: redis://localhost
# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
#app: cache.adapter.apcu
# Namespaced pools use the above "app" backend by default
#pools:
#my.dedicated.cache: null

View File

@ -0,0 +1,15 @@
# see https://symfony.com/doc/current/reference/configuration/framework.html
framework:
secret: '%env(APP_SECRET)%'
# Note that the session will be started ONLY if you read or write from it.
session: true
#esi: true
#fragments: true
when@test:
framework:
test: true
session:
storage_factory_id: session.storage.factory.mock_file

View File

@ -0,0 +1,10 @@
framework:
router:
# Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
# See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
#default_uri: http://localhost
when@prod:
framework:
router:
strict_requirements: null

5
config/preload.php Normal file
View File

@ -0,0 +1,5 @@
<?php
if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php';
}

5
config/routes.yaml Normal file
View File

@ -0,0 +1,5 @@
controllers:
resource:
path: ../src/Controller/
namespace: App\Controller
type: attribute

View File

@ -0,0 +1,4 @@
when@dev:
_errors:
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
prefix: /_error

24
config/services.yaml Normal file
View File

@ -0,0 +1,24 @@
# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones

41
docker-compose.yaml Normal file
View File

@ -0,0 +1,41 @@
services:
stat-an-nginx:
image: nginx:1.27.5
ports:
- '8080:80'
links:
- stat-an-api
volumes:
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:rw,cached
- ./docker/nginx/bucket-size.conf:/etc/nginx/conf.d/bucket-size.conf:rw,cached
- ./public:/var/www/public:rw,cached
networks:
- stat-an
stat-an-api:
image: stat-an:dev
user: 1000:1000
env_file:
- .env
volumes:
- ./:/var/www:rw,cached
- ./docker/php-fpm/ini/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini:rw,cached
- ./docker/php-fpm/ini/local.ini:/usr/local/etc/php/conf.d/local.ini:rw,cached
networks:
- stat-an
extra_hosts:
- host.docker.internal:host-gateway
stat-an-postgres:
image: postgres:17.5
volumes:
- ./docker/docker-entrypoint-initdb.d/:/docker-entrypoint-initdb.d:rw,cached
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
networks:
- stat-an
networks:
stat-an:
driver: bridge

View File

@ -0,0 +1 @@
server_names_hash_bucket_size 128;

28
docker/nginx/default.conf Normal file
View File

@ -0,0 +1,28 @@
server {
listen 80;
server_name local.services.stat-an.com;
client_max_body_size 100M;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/public;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass stat-an-api:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}

View File

@ -0,0 +1,2 @@
[www]
pm.max_children = 10

128
docker/php-fpm/Dockerfile Normal file
View File

@ -0,0 +1,128 @@
ARG PHP_VERSION=8.4
FROM php:${PHP_VERSION}-fpm-alpine AS prod
ARG UID=1000
ARG GID=1000
ENV UID=${UID}
ENV GID=${GID}
ARG STABILITY="stable"
ENV STABILITY=${STABILITY}
ARG SYMFONY_VERSION=""
ENV SYMFONY_VERSION=${SYMFONY_VERSION}
ENV APP_ENV=prod
WORKDIR /var/www
RUN apk add postgresql postgresql-dev \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install pdo pdo_pgsql pgsql
RUN apk add --no-cache \
acl \
fcgi \
file \
gettext \
git \
;
RUN set -eux; \
apk update; \
apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
linux-headers \
icu-data-full \
icu-dev \
libzip-dev \
zlib-dev \
; \
\
docker-php-ext-configure zip; \
docker-php-ext-install -j$(nproc) \
intl \
zip \
sockets \
; \
pecl install \
apcu \
excimer \
; \
pecl clear-cache; \
docker-php-ext-enable \
apcu \
excimer \
opcache \
; \
\
runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)"; \
apk add --no-cache --virtual .app-phpexts-rundeps $runDeps; \
\
apk del .build-deps
COPY docker/php-fpm/ini/prod.ini /usr/local/etc/php/conf.d/local.ini
COPY docker/php-fpm/99-www-override.conf /usr/local/etc/php-fpm.d/99-www-override.conf
CMD ["php-fpm", "--nodaemonize"]
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV PATH="${PATH}:/root/.composer/vendor/bin"
COPY --from=composer:2.8.9 /usr/bin/composer /usr/bin/composer
COPY composer.* symfony.* ./
RUN set -eux; \
if [ -f composer.json ]; then \
composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress; \
composer clear-cache; \
fi
COPY src /var/www/src
COPY bin /var/www/bin
COPY migrations /var/www/migrations
COPY config /var/www/config
COPY public /var/www/public
COPY .env.example /var/www/.env
RUN addgroup -g ${GID} www
RUN adduser -u ${UID} -s /bin/sh -D -G www www
RUN chown -R www:www /var/www
USER www
RUN set -eux; \
mkdir -p var/cache var/log; \
if [ -f composer.json ]; then \
composer dump-autoload --classmap-authoritative --no-dev; \
composer dump-env prod; \
composer run-script --no-dev post-install-cmd; \
chmod +x bin/console; sync; \
fi
FROM prod AS dev
USER root
RUN apk --no-cache add linux-headers pcre-dev ${PHPIZE_DEPS}
RUN pecl install xdebug-3.4.3
RUN docker-php-ext-enable xdebug
RUN apk del linux-headers pcre-dev ${PHPIZE_DEPS}
USER www
#COPY .php-cs-fixer.php /var/www/.php-cs-fixer.php
#COPY phpstan.neon /var/www/phpstan.neon
#COPY phpstan.stub /var/www/phpstan.stub
RUN composer install

View File

@ -0,0 +1,6 @@
; PHP MEMORY LIMIT
memory_limit = -1
; PHP MAX UPLOAD SIZE
upload_max_filesize = 20M
post_max_size = 20M

View File

@ -0,0 +1,3 @@
; PHP MAX UPLOAD SIZE
upload_max_filesize = 20M
post_max_size = 20M

View File

@ -0,0 +1,6 @@
zend_extension=xdebug
xdebug.mode=debug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.idekey=idekey
xdebug.log=/dev/null

View File

@ -0,0 +1 @@
CREATE DATABASE stat_an;

9
public/index.php Normal file
View File

@ -0,0 +1,9 @@
<?php
use App\Kernel;
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};

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

13
src/Kernel.php Normal file
View File

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace App;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
class Kernel extends BaseKernel
{
use MicroKernelTrait;
}

83
symfony.lock Normal file
View File

@ -0,0 +1,83 @@
{
"friendsofphp/php-cs-fixer": {
"version": "3.75",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "3.0",
"ref": "be2103eb4a20942e28a6dd87736669b757132435"
},
"files": [
".php-cs-fixer.dist.php"
]
},
"phpstan/phpstan": {
"version": "2.1",
"recipe": {
"repo": "github.com/symfony/recipes-contrib",
"branch": "main",
"version": "1.0",
"ref": "5e490cc197fb6bb1ae22e5abbc531ddc633b6767"
},
"files": [
"phpstan.dist.neon"
]
},
"symfony/console": {
"version": "7.2",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "5.3",
"ref": "1781ff40d8a17d87cf53f8d4cf0c8346ed2bb461"
},
"files": [
"bin/console"
]
},
"symfony/flex": {
"version": "2.5",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "2.4",
"ref": "52e9754527a15e2b79d9a610f98185a1fe46622a"
},
"files": [
".env",
".env.dev"
]
},
"symfony/framework-bundle": {
"version": "7.2",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "7.2",
"ref": "87bcf6f7c55201f345d8895deda46d2adbdbaa89"
},
"files": [
"config/packages/cache.yaml",
"config/packages/framework.yaml",
"config/preload.php",
"config/routes/framework.yaml",
"config/services.yaml",
"public/index.php",
"src/Controller/.gitignore",
"src/Kernel.php"
]
},
"symfony/routing": {
"version": "7.2",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "7.0",
"ref": "21b72649d5622d8f7da329ffb5afb232a023619d"
},
"files": [
"config/packages/routing.yaml",
"config/routes.yaml"
]
}
}