├── .env.dist
├── .gitignore
├── assets
└── .gitignore
├── bin
├── console
└── phpunit
├── composer.json
├── composer.lock
├── config
├── bundles.php
├── packages
│ ├── dev
│ │ ├── easy_log_handler.yaml
│ │ ├── monolog.yaml
│ │ ├── routing.yaml
│ │ ├── swiftmailer.yaml
│ │ └── web_profiler.yaml
│ ├── doctrine.yaml
│ ├── doctrine_migrations.yaml
│ ├── fos_rest.yaml
│ ├── framework.yaml
│ ├── prod
│ │ ├── doctrine.yaml
│ │ └── monolog.yaml
│ ├── routing.yaml
│ ├── security.yaml
│ ├── swiftmailer.yaml
│ ├── test
│ │ ├── framework.yaml
│ │ ├── monolog.yaml
│ │ ├── swiftmailer.yaml
│ │ └── web_profiler.yaml
│ ├── translation.yaml
│ └── twig.yaml
├── routes.yaml
├── routes
│ ├── annotations.yaml
│ └── dev
│ │ ├── twig.yaml
│ │ └── web_profiler.yaml
├── services.yaml
└── services_test.yaml
├── package.json
├── phpunit.xml.dist
├── public
└── index.php
├── readme.txt
├── src
├── Application
│ ├── DTO
│ │ ├── ArticleAssembler.php
│ │ └── ArticleDTO.php
│ └── Service
│ │ ├── .gitignore
│ │ └── ArticleService.php
├── Domain
│ └── Model
│ │ ├── .gitignore
│ │ └── Article
│ │ ├── Article.php
│ │ └── ArticleRepositoryInterface.php
├── Infrastructure
│ ├── Http
│ │ ├── Rest
│ │ │ └── Controller
│ │ │ │ ├── .gitignore
│ │ │ │ └── ArticleController.php
│ │ └── Web
│ │ │ └── Controller
│ │ │ └── .gitignore
│ ├── Migrations
│ │ └── .gitignore
│ └── Repository
│ │ ├── .gitignore
│ │ └── ArticleRepository.php
└── Kernel.php
├── symfony.lock
├── templates
└── base.html.twig
├── tests
└── .gitignore
├── translations
└── .gitignore
└── webpack.config.js
/.env.dist:
--------------------------------------------------------------------------------
1 | # This file is a "template" of which env vars need to be defined for your application
2 | # Copy this file to .env file for development, create environment variables when deploying to production
3 | # https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
4 |
5 | ###> symfony/framework-bundle ###
6 | APP_ENV=dev
7 | APP_SECRET=dcec9205a79267e18a6a65fb24ce97e0
8 | #TRUSTED_PROXIES=127.0.0.1,127.0.0.2
9 | #TRUSTED_HOSTS=localhost,example.com
10 | ###< symfony/framework-bundle ###
11 |
12 | ###> symfony/swiftmailer-bundle ###
13 | # For Gmail as a transport, use: "gmail://username:password@localhost"
14 | # For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
15 | # Delivery is disabled by default via "null://localhost"
16 | MAILER_URL=null://localhost
17 | ###< symfony/swiftmailer-bundle ###
18 |
19 | ###> doctrine/doctrine-bundle ###
20 | # Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
21 | # For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
22 | # Configure your db driver and server_version in config/packages/doctrine.yaml
23 | DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name
24 | ###< doctrine/doctrine-bundle ###
25 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | ###> symfony/framework-bundle ###
3 | /.env
4 | /public/bundles/
5 | /var/
6 | /vendor/
7 | ###< symfony/framework-bundle ###
8 |
9 | ###> symfony/webpack-encore-pack ###
10 | /node_modules/
11 | /public/build/
12 | ###< symfony/webpack-encore-pack ###
13 |
14 | ###> symfony/phpunit-bridge ###
15 | .phpunit
16 | /phpunit.xml
17 | ###< symfony/phpunit-bridge ###
18 |
19 | ###> symfony/web-server-bundle ###
20 | /.web-server-pid
21 | ###< symfony/web-server-bundle ###
22 | .idea/
23 | phpdocker/
24 | docker-compose.yml
25 |
--------------------------------------------------------------------------------
/assets/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JeffreyVerreckt/Symfony4-REST-API/56f798f0e838858b526f3102d669cda2df1f1f06/assets/.gitignore
--------------------------------------------------------------------------------
/bin/console:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | load(__DIR__.'/../.env');
23 | }
24 |
25 | $input = new ArgvInput();
26 | $env = $input->getParameterOption(['--env', '-e'], $_SERVER['APP_ENV'] ?? 'dev', true);
27 | $debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env)) && !$input->hasParameterOption('--no-debug', true);
28 |
29 | if ($debug) {
30 | umask(0000);
31 |
32 | if (class_exists(Debug::class)) {
33 | Debug::enable();
34 | }
35 | }
36 |
37 | $kernel = new Kernel($env, $debug);
38 | $application = new Application($kernel);
39 | $application->run($input);
40 |
--------------------------------------------------------------------------------
/bin/phpunit:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | ['all' => true],
5 | Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
6 | Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
7 | Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true],
8 | Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
9 | Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
10 | Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
11 | Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
12 | Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
13 | Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
14 | Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true],
15 | Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
16 | Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => true],
17 | FOS\RestBundle\FOSRestBundle::class => ['all' => true],
18 | ];
19 |
--------------------------------------------------------------------------------
/config/packages/dev/easy_log_handler.yaml:
--------------------------------------------------------------------------------
1 | services:
2 | EasyCorp\EasyLog\EasyLogHandler:
3 | public: false
4 | arguments: ['%kernel.logs_dir%/%kernel.environment%.log']
5 |
6 | #// FIXME: How to add this configuration automatically without messing up with the monolog configuration?
7 | #monolog:
8 | # handlers:
9 | # buffered:
10 | # type: buffer
11 | # handler: easylog
12 | # channels: ['!event']
13 | # level: debug
14 | # easylog:
15 | # type: service
16 | # id: EasyCorp\EasyLog\EasyLogHandler
17 |
--------------------------------------------------------------------------------
/config/packages/dev/monolog.yaml:
--------------------------------------------------------------------------------
1 | monolog:
2 | handlers:
3 | main:
4 | type: stream
5 | path: "%kernel.logs_dir%/%kernel.environment%.log"
6 | level: debug
7 | channels: ["!event"]
8 | # uncomment to get logging in your browser
9 | # you may have to allow bigger header sizes in your Web server configuration
10 | #firephp:
11 | # type: firephp
12 | # level: info
13 | #chromephp:
14 | # type: chromephp
15 | # level: info
16 | console:
17 | type: console
18 | process_psr_3_messages: false
19 | channels: ["!event", "!doctrine", "!console"]
20 |
--------------------------------------------------------------------------------
/config/packages/dev/routing.yaml:
--------------------------------------------------------------------------------
1 | framework:
2 | router:
3 | strict_requirements: true
4 |
--------------------------------------------------------------------------------
/config/packages/dev/swiftmailer.yaml:
--------------------------------------------------------------------------------
1 | # See https://symfony.com/doc/current/email/dev_environment.html
2 | swiftmailer:
3 | # send all emails to a specific address
4 | #delivery_addresses: ['me@example.com']
5 |
--------------------------------------------------------------------------------
/config/packages/dev/web_profiler.yaml:
--------------------------------------------------------------------------------
1 | web_profiler:
2 | toolbar: true
3 | intercept_redirects: false
4 |
5 | framework:
6 | profiler: { only_exceptions: false }
7 |
--------------------------------------------------------------------------------
/config/packages/doctrine.yaml:
--------------------------------------------------------------------------------
1 | parameters:
2 | # Adds a fallback DATABASE_URL if the env var is not set.
3 | # This allows you to run cache:warmup even if your
4 | # environment variables are not available yet.
5 | # You should not need to change this value.
6 | env(DATABASE_URL): ''
7 |
8 | doctrine:
9 | dbal:
10 | # configure these for your database server
11 | driver: 'pdo_mysql'
12 | server_version: '5.7'
13 | charset: utf8mb4
14 | default_table_options:
15 | charset: utf8mb4
16 | collate: utf8mb4_unicode_ci
17 |
18 | # With Symfony 3.3, remove the `resolve:` prefix
19 | url: '%env(resolve:DATABASE_URL)%'
20 | orm:
21 | auto_generate_proxy_classes: '%kernel.debug%'
22 | naming_strategy: doctrine.orm.naming_strategy.underscore
23 | auto_mapping: true
24 | mappings:
25 | Domain:
26 | is_bundle: false
27 | type: annotation
28 | dir: '%kernel.project_dir%/src/Domain/Model'
29 | prefix: 'App\Domain\Model'
30 | alias: Domain\Model
31 |
--------------------------------------------------------------------------------
/config/packages/doctrine_migrations.yaml:
--------------------------------------------------------------------------------
1 | doctrine_migrations:
2 | dir_name: '%kernel.project_dir%/src/Infrastructure/Migrations'
3 | # namespace is arbitrary but should be different from App\Migrations
4 | # as migrations classes should NOT be autoloaded
5 | namespace: DoctrineMigrations
6 |
--------------------------------------------------------------------------------
/config/packages/fos_rest.yaml:
--------------------------------------------------------------------------------
1 | fos_rest:
2 | view:
3 | view_response_listener: true
4 | exception:
5 | exception_controller: 'fos_rest.exception.controller:showAction'
6 | codes:
7 | Doctrine\ORM\EntityNotFoundException: 404
8 | format_listener:
9 | rules:
10 | - { path: ^/api, prefer_extension: true, fallback_format: json, priorities: [ json ] }
11 | body_converter:
12 | enabled: true
--------------------------------------------------------------------------------
/config/packages/framework.yaml:
--------------------------------------------------------------------------------
1 | framework:
2 | secret: '%env(APP_SECRET)%'
3 | #default_locale: en
4 | #csrf_protection: true
5 | #http_method_override: true
6 |
7 | # Enables session support. Note that the session will ONLY be started if you read or write from it.
8 | # Remove or comment this section to explicitly disable session support.
9 | session:
10 | handler_id: ~
11 |
12 | #esi: true
13 | #fragments: true
14 | php_errors:
15 | log: true
16 |
17 | cache:
18 | # Put the unique name of your app here: the prefix seed
19 | # is used to compute stable namespaces for cache keys.
20 | #prefix_seed: your_vendor_name/app_name
21 |
22 | # The app cache caches to the filesystem by default.
23 | # Other options include:
24 |
25 | # Redis
26 | #app: cache.adapter.redis
27 | #default_redis_provider: redis://localhost
28 |
29 | # APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
30 | #app: cache.adapter.apcu
31 |
--------------------------------------------------------------------------------
/config/packages/prod/doctrine.yaml:
--------------------------------------------------------------------------------
1 | doctrine:
2 | orm:
3 | metadata_cache_driver:
4 | type: service
5 | id: doctrine.system_cache_provider
6 | query_cache_driver:
7 | type: service
8 | id: doctrine.system_cache_provider
9 | result_cache_driver:
10 | type: service
11 | id: doctrine.result_cache_provider
12 |
13 | services:
14 | doctrine.result_cache_provider:
15 | class: Symfony\Component\Cache\DoctrineProvider
16 | public: false
17 | arguments:
18 | - '@doctrine.result_cache_pool'
19 | doctrine.system_cache_provider:
20 | class: Symfony\Component\Cache\DoctrineProvider
21 | public: false
22 | arguments:
23 | - '@doctrine.system_cache_pool'
24 |
25 | framework:
26 | cache:
27 | pools:
28 | doctrine.result_cache_pool:
29 | adapter: cache.app
30 | doctrine.system_cache_pool:
31 | adapter: cache.system
32 |
--------------------------------------------------------------------------------
/config/packages/prod/monolog.yaml:
--------------------------------------------------------------------------------
1 | monolog:
2 | handlers:
3 | main:
4 | type: fingers_crossed
5 | action_level: error
6 | handler: nested
7 | excluded_404s:
8 | # regex: exclude all 404 errors from the logs
9 | - ^/
10 | nested:
11 | type: stream
12 | path: "%kernel.logs_dir%/%kernel.environment%.log"
13 | level: debug
14 | console:
15 | type: console
16 | process_psr_3_messages: false
17 | channels: ["!event", "!doctrine"]
18 |
--------------------------------------------------------------------------------
/config/packages/routing.yaml:
--------------------------------------------------------------------------------
1 | framework:
2 | router:
3 | strict_requirements: ~
4 |
--------------------------------------------------------------------------------
/config/packages/security.yaml:
--------------------------------------------------------------------------------
1 | security:
2 | # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
3 | providers:
4 | in_memory: { memory: ~ }
5 | firewalls:
6 | dev:
7 | pattern: ^/(_(profiler|wdt)|css|images|js)/
8 | security: false
9 | main:
10 | anonymous: true
11 |
12 | # activate different ways to authenticate
13 |
14 | # http_basic: true
15 | # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
16 |
17 | # form_login: true
18 | # https://symfony.com/doc/current/security/form_login_setup.html
19 |
20 | # Easy way to control access for large sections of your site
21 | # Note: Only the *first* access control that matches will be used
22 | access_control:
23 | # - { path: ^/admin, roles: ROLE_ADMIN }
24 | # - { path: ^/profile, roles: ROLE_USER }
25 |
--------------------------------------------------------------------------------
/config/packages/swiftmailer.yaml:
--------------------------------------------------------------------------------
1 | swiftmailer:
2 | url: '%env(MAILER_URL)%'
3 | spool: { type: 'memory' }
4 |
--------------------------------------------------------------------------------
/config/packages/test/framework.yaml:
--------------------------------------------------------------------------------
1 | framework:
2 | test: true
3 | session:
4 | storage_id: session.storage.mock_file
5 |
--------------------------------------------------------------------------------
/config/packages/test/monolog.yaml:
--------------------------------------------------------------------------------
1 | monolog:
2 | handlers:
3 | main:
4 | type: stream
5 | path: "%kernel.logs_dir%/%kernel.environment%.log"
6 | level: debug
7 | channels: ["!event"]
8 |
--------------------------------------------------------------------------------
/config/packages/test/swiftmailer.yaml:
--------------------------------------------------------------------------------
1 | swiftmailer:
2 | disable_delivery: true
3 |
--------------------------------------------------------------------------------
/config/packages/test/web_profiler.yaml:
--------------------------------------------------------------------------------
1 | web_profiler:
2 | toolbar: false
3 | intercept_redirects: false
4 |
5 | framework:
6 | profiler: { collect: false }
7 |
--------------------------------------------------------------------------------
/config/packages/translation.yaml:
--------------------------------------------------------------------------------
1 | framework:
2 | default_locale: '%locale%'
3 | translator:
4 | paths:
5 | - '%kernel.project_dir%/translations'
6 | fallbacks:
7 | - '%locale%'
8 |
--------------------------------------------------------------------------------
/config/packages/twig.yaml:
--------------------------------------------------------------------------------
1 | twig:
2 | paths: ['%kernel.project_dir%/templates']
3 | debug: '%kernel.debug%'
4 | strict_variables: '%kernel.debug%'
5 |
--------------------------------------------------------------------------------
/config/routes.yaml:
--------------------------------------------------------------------------------
1 | #index:
2 | # path: /
3 | # controller: App\Controller\DefaultController::index
4 |
--------------------------------------------------------------------------------
/config/routes/annotations.yaml:
--------------------------------------------------------------------------------
1 | web_controller:
2 | resource: ../../src/Infrastructure/Http/Web/Controller/
3 | type: annotation
4 |
5 | rest_controller:
6 | resource: ../../src/Infrastructure/Http/Rest/Controller/
7 | type: annotation
8 | prefix: /api
--------------------------------------------------------------------------------
/config/routes/dev/twig.yaml:
--------------------------------------------------------------------------------
1 | _errors:
2 | resource: '@TwigBundle/Resources/config/routing/errors.xml'
3 | prefix: /_error
4 |
--------------------------------------------------------------------------------
/config/routes/dev/web_profiler.yaml:
--------------------------------------------------------------------------------
1 | web_profiler_wdt:
2 | resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
3 | prefix: /_wdt
4 |
5 | web_profiler_profiler:
6 | resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
7 | prefix: /_profiler
8 |
--------------------------------------------------------------------------------
/config/services.yaml:
--------------------------------------------------------------------------------
1 | # Put parameters here that don't need to change on each machine where the app is deployed
2 | # https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
3 | parameters:
4 | locale: 'en'
5 |
6 | services:
7 | # default configuration for services in *this* file
8 | _defaults:
9 | autowire: true # Automatically injects dependencies in your services.
10 | autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
11 | public: false # Allows optimizing the container by removing unused services; this also means
12 | # fetching services directly from the container via $container->get() won't work.
13 | # The best practice is to be explicit about your dependencies anyway.
14 |
15 | # makes classes in src/ available to be used as services
16 | # this creates a service per class whose id is the fully-qualified class name
17 | App\:
18 | resource: '../src/*'
19 | exclude: '../src/{Entity,Infrastructure/Migrations,Application/DTO/*DTO.php,Tests,Kernel.php}'
20 |
21 | # controllers are imported separately to make sure services can be injected
22 | # as action arguments even if you don't extend any base controller class
23 | App\Infrastructure\Http\Web\Controller\:
24 | resource: '../src/Infrastructure/Http/Web/Controller'
25 | tags: ['controller.service_arguments']
26 |
27 | App\Infrastructure\Http\Rest\Controller\:
28 | resource: '../src/Infrastructure/Http/Rest/Controller'
29 | tags: ['controller.service_arguments']
30 | # add more service definitions when explicit configuration is needed
31 | # please note that last definitions always *replace* previous ones
32 |
--------------------------------------------------------------------------------
/config/services_test.yaml:
--------------------------------------------------------------------------------
1 | services:
2 | _defaults:
3 | public: true
4 |
5 | # If you need to access services in a test, create an alias
6 | # and then fetch that alias from the container. As a convention,
7 | # aliases are prefixed with test. For example:
8 | #
9 | # test.App\Service\MyService: '@App\Service\MyService'
10 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "devDependencies": {
3 | "@symfony/webpack-encore": "^0.17.0"
4 | },
5 | "license": "UNLICENSED",
6 | "private": true,
7 | "scripts": {
8 | "dev-server": "encore dev-server",
9 | "dev": "encore dev",
10 | "watch": "encore dev --watch",
11 | "build": "encore production"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/phpunit.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |