Skip to content

Commit 76424a1

Browse files
init
0 parents  commit 76424a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+6625
-0
lines changed

Diff for: .dockerignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
vendor
2+
var
3+
.git
4+
Makefile

Diff for: .env

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# In all environments, the following files are loaded if they exist,
2+
# the latter taking precedence over the former:
3+
#
4+
# * .env contains default values for the environment variables needed by the app
5+
# * .env.local uncommitted file with local overrides
6+
# * .env.$APP_ENV committed environment-specific defaults
7+
# * .env.$APP_ENV.local uncommitted environment-specific overrides
8+
#
9+
# Real environment variables win over .env files.
10+
#
11+
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
12+
#
13+
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
14+
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
15+
16+
###> symfony/framework-bundle ###
17+
APP_ENV=dev
18+
APP_SECRET=03f6994ac87aecede000de1509cb1af1
19+
###< symfony/framework-bundle ###
20+
21+
###> doctrine/doctrine-bundle ###
22+
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
23+
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
24+
#
25+
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
26+
# DATABASE_URL="mysql://db_user:[email protected]:3306/db_name?serverVersion=5.7"
27+
DATABASE_URL="postgresql://db_user:[email protected]:5432/db_name?serverVersion=13&charset=utf8"
28+
###< doctrine/doctrine-bundle ###

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/var/
2+
/vendor/
3+
.idea

Diff for: Dockerfile

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
ARG PHP_VERSION=8.0
2+
ARG NGINX_VERSION=1.18
3+
4+
FROM php:${PHP_VERSION}-fpm-alpine AS app_php
5+
6+
ARG WORKDIR=/app
7+
8+
RUN docker-php-source extract \
9+
&& apk add --update --virtual .build-deps autoconf g++ make pcre-dev icu-dev openssl-dev libxml2-dev libmcrypt-dev git libpng-dev \
10+
# Instaling pecl modules
11+
&& pecl install apcu xdebug \
12+
# Enable pecl modules
13+
&& docker-php-ext-enable apcu opcache \
14+
# Installing intl
15+
&& apk add icu-libs icu \
16+
&& docker-php-ext-install intl \
17+
# Post run
18+
&& runDeps="$( \
19+
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
20+
| tr ',' '\n' \
21+
| sort -u \
22+
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
23+
)" \
24+
&& apk add --no-cache --virtual .app-phpexts-rundeps $runDeps \
25+
&& pecl clear-cache \
26+
&& docker-php-source delete \
27+
&& apk del --purge .build-deps \
28+
&& rm -rf /tmp/pear \
29+
&& rm -rf /var/cache/apk/*
30+
31+
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
32+
COPY docker/php/php.ini $PHP_INI_DIR/conf.d/php.ini
33+
COPY docker/php/php-cli.ini $PHP_INI_DIR/conf.d/php-cli.ini
34+
COPY docker/php/xdebug.ini $PHP_INI_DIR/conf.d/xdebug.ini
35+
36+
RUN mkdir -p ${WORKDIR}
37+
WORKDIR ${WORKDIR}
38+
39+
# prevent the reinstallation of vendors at every changes in the source code
40+
COPY composer.json composer.lock symfony.lock ./
41+
RUN set -eux; \
42+
composer install --prefer-dist --no-autoloader --no-scripts --no-progress --no-suggest; \
43+
composer clear-cache
44+
45+
RUN set -eux \
46+
&& mkdir -p var/cache var/log \
47+
&& composer dump-autoload --classmap-authoritative
48+
49+
VOLUME ${WORKDIR}/var
50+
51+
COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
52+
RUN chmod +x /usr/local/bin/docker-entrypoint
53+
54+
ENTRYPOINT ["docker-entrypoint"]
55+
CMD ["php-fpm"]
56+
57+
58+
FROM nginx:${NGINX_VERSION}-alpine AS app_nginx
59+
60+
COPY docker/nginx/conf.d/default.conf /etc/nginx/conf.d/
61+
62+
WORKDIR /app/public

Diff for: Makefile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
up:
2+
docker-compose up -d
3+
4+
down:
5+
docker-compose down -v
6+
7+
rebuild:
8+
docker-compose down -v --remove-orphans
9+
docker-compose rm -vsf
10+
docker-compose up -d --build

Diff for: README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Design pattern "Chain of responsibility" (Symfony implementation)
2+
3+
Watch full tutorial [here](https://youtu.be/3KQlubIv684)
4+
5+
# Launch project
6+
7+
Run in terminal `make up`
8+
9+
Sample API request:
10+
11+
```
12+
curl --location --request POST 'http://localhost:8080/api/locations/resolve' \
13+
--header 'content-type: application/json' \
14+
--data-raw '{
15+
"name": "My closest gym"
16+
}'
17+
```
18+
19+
# Other video tutorials
20+
21+
## Create Symfony 5 project with Docker and Postgres
22+
23+
Watch full tutorial [here](https://youtu.be/69wjRPQ0A_U)
24+
25+
## How to use data transfer objects (DTO) in Symfony API application
26+
27+
There is a [branch](https://github.com/Cap-Coding/symfony_api/tree/data_transfer_objects) and here is a [video](https://youtu.be/XxIhzgGv214)
28+
29+
## How to build simple CRUD API service with Symfony 5 (for beginners)
30+
31+
There is a [branch](https://github.com/Cap-Coding/symfony_api/tree/crud_api) and here is a [video](https://youtu.be/tbXpX4dAqjg)
32+
33+
## How to use Symfony Form Events in API service
34+
35+
There is a [video](https://youtu.be/lLwx96DA_Ww)
36+
37+
## How to use object factories with Symfony Forms
38+
39+
There is a [video](https://youtu.be/chgvsi6TWM8)

Diff for: bin/console

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
use App\Kernel;
5+
use Symfony\Bundle\FrameworkBundle\Console\Application;
6+
use Symfony\Component\Console\Input\ArgvInput;
7+
use Symfony\Component\Dotenv\Dotenv;
8+
use Symfony\Component\ErrorHandler\Debug;
9+
10+
if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
11+
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL;
12+
}
13+
14+
set_time_limit(0);
15+
16+
require dirname(__DIR__).'/vendor/autoload.php';
17+
18+
if (!class_exists(Application::class) || !class_exists(Dotenv::class)) {
19+
throw new LogicException('You need to add "symfony/framework-bundle" and "symfony/dotenv" as Composer dependencies.');
20+
}
21+
22+
$input = new ArgvInput();
23+
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
24+
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
25+
}
26+
27+
if ($input->hasParameterOption('--no-debug', true)) {
28+
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
29+
}
30+
31+
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
32+
33+
if ($_SERVER['APP_DEBUG']) {
34+
umask(0000);
35+
36+
if (class_exists(Debug::class)) {
37+
Debug::enable();
38+
}
39+
}
40+
41+
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
42+
$application = new Application($kernel);
43+
$application->run($input);

Diff for: composer.json

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"type": "project",
3+
"name": "cap-coding/symfony_delay_tasks",
4+
"description": "Tutorial about how to delay heavy tasks in Symfony application",
5+
"license": "proprietary",
6+
"minimum-stability": "dev",
7+
"prefer-stable": true,
8+
"require": {
9+
"php": ">=8.0",
10+
"ext-ctype": "*",
11+
"ext-iconv": "*",
12+
"ext-json": "*",
13+
"composer/package-versions-deprecated": "1.11.99.1",
14+
"doctrine/annotations": "^1.0",
15+
"doctrine/doctrine-bundle": "^2.2",
16+
"doctrine/doctrine-migrations-bundle": "^3.0",
17+
"doctrine/orm": "^2.8",
18+
"friendsofsymfony/rest-bundle": "^3.0",
19+
"phpdocumentor/reflection-docblock": "^5.2",
20+
"symfony/console": "5.2.*",
21+
"symfony/dotenv": "5.2.*",
22+
"symfony/flex": "^1.3.1",
23+
"symfony/form": "5.2.*",
24+
"symfony/framework-bundle": "5.2.*",
25+
"symfony/property-access": "5.2.*",
26+
"symfony/property-info": "5.2.*",
27+
"symfony/proxy-manager-bridge": "5.2.*",
28+
"symfony/serializer": "5.2.*",
29+
"symfony/yaml": "5.2.*"
30+
},
31+
"require-dev": {
32+
},
33+
"config": {
34+
"optimize-autoloader": true,
35+
"preferred-install": {
36+
"*": "dist"
37+
},
38+
"sort-packages": true
39+
},
40+
"autoload": {
41+
"psr-4": {
42+
"App\\": "src/"
43+
}
44+
},
45+
"autoload-dev": {
46+
"psr-4": {
47+
"App\\Tests\\": "tests/"
48+
}
49+
},
50+
"replace": {
51+
"symfony/polyfill-ctype": "*",
52+
"symfony/polyfill-iconv": "*",
53+
"symfony/polyfill-php72": "*"
54+
},
55+
"scripts": {
56+
"auto-scripts": {
57+
"cache:clear": "symfony-cmd",
58+
"assets:install %PUBLIC_DIR%": "symfony-cmd"
59+
},
60+
"post-install-cmd": [
61+
"@auto-scripts"
62+
],
63+
"post-update-cmd": [
64+
"@auto-scripts"
65+
]
66+
},
67+
"conflict": {
68+
"symfony/symfony": "*"
69+
},
70+
"extra": {
71+
"symfony": {
72+
"allow-contrib": false,
73+
"require": "5.2.*"
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)