mael / symfony-api-template
Preconfigured template to create an API based on the Symfony framework
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^7.2.5
- ext-ctype: *
- ext-iconv: *
- ext-json: *
- api-platform/api-pack: ^1.2
- gesdinet/jwt-refresh-token-bundle: ^0.9.1
- lexik/jwt-authentication-bundle: ^2.8
- sensio/framework-extra-bundle: ^5.1
- symfony/asset: 5.1.*
- symfony/console: 5.1.*
- symfony/dotenv: 5.1.*
- symfony/expression-language: 5.1.*
- symfony/flex: ^1.3.1
- symfony/form: 5.1.*
- symfony/framework-bundle: 5.1.*
- symfony/http-client: 5.1.*
- symfony/intl: 5.1.*
- symfony/mailer: 5.1.*
- symfony/mime: 5.1.*
- symfony/monolog-bundle: ^3.1
- symfony/notifier: 5.1.*
- symfony/orm-pack: *
- symfony/process: 5.1.*
- symfony/security-bundle: 5.1.*
- symfony/serializer-pack: *
- symfony/string: 5.1.*
- symfony/translation: 5.1.*
- symfony/twig-pack: *
- symfony/validator: 5.1.*
- symfony/web-link: 5.1.*
- symfony/yaml: 5.1.*
Requires (Dev)
- doctrine/doctrine-fixtures-bundle: ^3.3
- fzaninotto/faker: ^1.9
- liip/test-fixtures-bundle: ^1.9
- nelmio/alice: ^3.7
- phpstan/phpstan: ^0.12.32
- phpstan/phpstan-doctrine: ^0.12.17
- phpstan/phpstan-mockery: ^0.12.5
- phpstan/phpstan-phpunit: ^0.12.11
- spatie/phpunit-watcher: ^1.22
- symfony/debug-pack: *
- symfony/maker-bundle: ^1.0
- symfony/profiler-pack: *
- symfony/test-pack: *
- theofidry/alice-data-fixtures: ^1.2
Suggests
- mael/intervention-image-bundle: Simple intervention/image integration for symfony projects. This bundle allows you to manipulate images (crop, resize, and many other features).
- mael/recaptcha-bundle: Google Recaptcha integration for Symfony and Twig (easy integration with Symfony Form)
Conflicts
This package is auto-updated.
Last update: 2024-11-08 22:47:18 UTC
README
- Synfony version : 5.1.2
Table of content
- Getting started
- Configuration
- Doctrine
- unit tests
- PHPStan
- JWT Configuration
- First Functional test
- Contributing
- License
Getting Started
Requirements :
PHP 7.2.5
ext-ctype
ext-iconv
ext-json
First create a new project with composer
$ composer create-project mael/symfony-api-template
In the composer.json file, change the name of the project by yours as well as the description and the license.
Configuration
Before you can start your project, you need to do some basic configuration
Doctrine
In the .env
file, modify the DATABASE_URL
by filling in your identifiers (see the Symfony documentation)
Unit tests
Our template provides you with a lot of tools for unit testing, you'll have to configure some things to suit your project
First, in the files WebTestCase.php
and ApiTestCase.php
you need to modify the login information that will be used to log in to a user.
You need to fill in the following variables $username
, $password
and $route
Ex :
public function login(string $username = 'test', string $password = 'test', string $route = '/api/login')
PHPStan
We also added PHPStan which allows you to detect errors in your code, you can change the level of detection in the phpstan.neon
file.
You will find PHPStan's documentation via this link https://phpstan.org/
JWT Configuration
We assume that your api will use the LexikJWTAuthenticationBundle
. You will find the configuration in config/packages
First, in the .env
file, modify JWT_PASSPHRAS
E by a string that you will choose
When you do the following two commands, it will ask you to enter the passphrase you previously selected
For JWT authentication to work, you need to generate two :
$ openssl genpkey -out config/jwt/private.pem -aes256 -algorithm rsa -pkeyopt rsa_keygen_bits:4096 $ openssl pkey -in config/jwt/private.pem -out config/jwt/public.pem -pubout
We have also added a bundle to refresh the JWT token, you will find the documentation here https://github.com/markitosgv/JWTRefreshTokenBundle#readme
You can also configure the route in the config/route.yaml
file.
Be careful, you have to configure the authentication system yourself via JWT, in the security.yaml file (see the bundle documentation https://github.com/lexik/LexikJWTAuthenticationBundle/blob/master/Resources/doc/index.md).
First Functional test
During your first functional tests you will have to generate the sqlite database using the command
$ php bin/console doctrine:database:create --env test
Contributing
If you want to contribute to the improvement of the template, you can :
- Fork this repo
- Make your change
- Create pull request
License
This repository is under MIT License