What is this?
Simple JSON API which is build on top of Symfony framework.
Table of Contents
- What is this?
- Table of contents
- Main points
- Requirements
- Installation
- Development
- Useful resources + tips
- Contributing & issues & questions
- Authors
- LICENSE
Main points
- This is just an API, nothing else
- Only JSON responses from API
- Easy REST API configuration and customization, see examples here and here
- JWT authentication
- API documentation
TODO - update this list
- And everything else...
Requirements
- PHP 7.0+
- Apache / nginx see configuration information here
Installation
- Use your favorite IDE and get checkout from git OR just use command
git clone https://github.com/tarlepp/symfony-backend.git
- Open terminal, go to folder where you make that checkout and run following commands
JWT SSH keys generation
$ openssl genrsa -out app/var/jwt/private.pem -aes256 4096
$ openssl rsa -pubout -in app/var/jwt/private.pem -out app/var/jwt/public.pem
Fetch all dependencies
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar install
Note that this will also ask you some environment settings; db, mail, secrets, jwt, etc.
Environment checks
$ HTTPDUSER=`ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
$ setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var
$ setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var
CLI
Open terminal and go to project root directory and run following command.
$ ./bin/symfony_requirements
Check the output from your console.
WEB
Open terminal and go to project root directory and run following command to start standalone server.
$ ./bin/console server:run
Open your favorite browser with http://127.0.0.1:8000/config.php
url and check it for any errors.
And if you get just blank page double check your permissions.
Configuration
Application will ask your configuration settings when you first time run php composer.phar install
command.
All those parameters that you should change are in /app/config/parameters.yml
file, so just open that and
made necessary changes to it.
If you want to answer those parameter values again, you can just delete /app/config/parameters.yml
file and
then run php composer.phar update
command.
Database initialization
At start you have just empty database which you have configured in previous topic. To initialize your database just run following command:
$ ./bin/console doctrine:schema:update
Development
PHP Code Sniffer
It's highly recommended that you use this tool while doing actual development to application. PHP Code Sniffer is added to project dev
dependencies, so all you need to do is just configure it to your favorite IDE. So the phpcs
command is available via following example command.
$ ./vendor/bin/phpcs -i
If you're using PhpStorm following links will help you to get things rolling.
Database changes
Generally you will need to generate migration files from each database change that you're doing. Easiest way to handle these are just following workflow:
- Made your changes to Entity (
/src/App/Entity/
) - Run diff command to create new migration file;
$ ./bin/console doctrine:migrations:diff
With this you won't need to write those migration files by yourself, just let doctrine handle those - although remember to really look what those generated migration files really contains...
Tests
Project contains bunch of tests (unit, functional, integration, etc.) which you can run simply by following commands:
# PHPUnit
$ ./vendor/bin/phpunit
# PHPSpec
$ ./vendor/bin/phpspec run
Or you could easily configure your IDE to run these for you.
XDebug
Add following lines to your xdebug.ini
file to get XDebug work:
xdebug.remote_enable=on
xdebug.remote_autostart=off
Useful resources + tips
- Symfony Development using PhpStorm - Guide to configure your PhpStorm for Symfony development
- PHP Annotations plugin for PhpStorm - PhpStorm plugin to make annotations really work
- Php Inspections (EA Extended) for IntelliJ IDEA - Static Code Analysis tool for PHP
- Use 1.1-dev version of composer, so that you can use
php composer.phar outdated
command to check package versions
Contributing & issues & questions
Please see the CONTRIBUTING.md file for guidelines.
Authors
Tarmo Leppänen Antti Nevala Tuomo Moilanen
LICENSE
Copyright (c) 2017 Protacon Solutions