Symfnoy4 using Flex with ReactPHP supported.
We didn't re-invent the wheel here, we are just coming up with the latest updates from Symfony4 with some customizations to make it fit your usage in your microservices architecture.
- Symfony with Flex module.
- Add ReactPHP.
- Restful support (Simple).
- Custom
ControllerTrait
. - Middleware.
- CORS NelmioCorsBundle.
- GWT LexikJWT.
- Add Debug via parameters (like sending
_profile
as a param). - Basic Authentication.
- Basic AccessControl.
- Unify the response body/add a pattern.
- Add
ExceptionalTrait
. - Use PSR-7 Bridge with ReactPHP.
- Clean the code.
- Integrate blackfire.io.
- Add tests.
- Why.
- Why Symfony.
- How to setup.
- Run the app.
- Installing new packages.
- Profiling.
- How to integrate JWT with Symfony security system.
- How to create a new endpoint.
- References for Symfony4.
Add the minimal amount of components and services that serve the needs of having Restful API following the standards.
Wait for it.
- Clone the repo:
git clone https://github.com/MustafaMagdi/Symfony4.git
- Install packages:
cd Symfony4 && composer install
- Configure
.env
file:
cp .env.dist .env
- Generate SSH keys for LexikJWT:
$ mkdir -p var/jwt
$ openssl genrsa -out var/jwt/private.pem -aes256 4096
$ openssl rsa -pubout -in var/jwt/private.pem -out var/jwt/public.pem
It might asks you for passphrase, provide it and add it to your .env
file:
JWT_PASSPHRASE=whatever
- Configure NelmioCorsBundle, check your
config/packages/nelmio_cors.yaml
file.
And now, you run the application:
- For the regular setup:
./bin/console server:run
- For ReactPHP:
php public/index.react.php
Before you start searching in Packagist, have a look at Symfony.sh which is a hub for Symfony services configuration. It is playing with Symfony flex and Symfony recipes a really nice role in Symfony4.
I am going to provide more details about it soon.
Symfony is already coming up with a really nice Profiler Component,
to see the nice profiler bar in browser, just send _profiler
param in your request, it even dumps the response body.
On development env, you still can open the profiler url form the response header, just check the X-Debug-Token-Link
.
In order to understand how Symfony security system is working, check the documentation here. We have two steps to configure JWT with Symfony security system:
One second, if you are not aware about JWT, just check jwt.io.
You need to generate the token for the user:
Controller/AuthController.php:generateToken
By defining the authenticator class in config/packages/security.yaml
:
guard:
authenticators:
- App\Security\JwtTokenAuthenticator
Check App\Security\JwtTokenAuthenticator:getUser
, which you decode the token and match with your DB user record,
then, you return the Symfony\Component\Security\Core\User
object with a dummy user role that should match what we
have in security.yaml
:
access_control:
- { path: ^/profile, roles: ROLE_USER }
It is very simple, you will notice at the docblock of the controller functions:
/**
* @Route("/auth") // where you provide the route
* @Method({"POST"}) // where you provide the HTTP method
* ...
*/
In order to involve in Symfony:
- For sure, it is Symfony's website.
- Symfony's blog, they have "A week of Symfony" is being release in a weekly basis with all the updates.
- KNP Symfony there are some courses introduced by weaverryan, I really like the way he is introducing them. Thanks you @weaverryan.