Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Adding support for environment variables
Browse files Browse the repository at this point in the history
To satisfy issue #39, I'm adding support for dotenv file. I also has set
up the PHPunit for doing unit test and functional test.
  • Loading branch information
bepitulaz committed Aug 13, 2017
1 parent 01dced4 commit 6f40f10
Show file tree
Hide file tree
Showing 14 changed files with 1,405 additions and 204 deletions.
19 changes: 19 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#use 'en' for English and 'id' for Indonesia
SYMFONY_LOCALE=en

SYMFONY_SECRET=changewithyoursecretkey

#use '' instead of null if you want to empty the value
SYMFONY_DB_HOST=127.0.0.1
SYMFONY_DB_PORT=3306
SYMFONY_DB_NAME=yourdatabasename
SYMFONY_DB_USERNAME=yourdatabaseusername
SYMFONY_DB_PASSWORD=yourdatabasepassword

#use this default value if you don't have any mailer system
SYMFONY_MAILER_TRANSPORT=smtp
SYMFONY_MAILER_HOST=127.0.0.1
SYMFONY_MAILER_USERNAME=admin
SYMFONY_MAILER_PASSWORD=admin
SYMFONY_MAILER_FROM_ADDRESS=youremail@yourdomain.com
SYMFONY_MAILER_SENDER_NAME=yourname
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
/web/uploads/seeds/*.JPG
/web/uploads/seeds/*.GIF
/web/vendor/*
.env
5 changes: 5 additions & 0 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Dotenv\Dotenv;

class AppKernel extends Kernel
{
public function registerBundles()
{
// load the environment variables
$dotenv = new Dotenv();
$dotenv->load(dirname(__DIR__).'/.env');

$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
Expand Down
30 changes: 15 additions & 15 deletions app/config/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
imports:
- { resource: parameters.yml }
#- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: repository.yml }
Expand All @@ -11,8 +11,8 @@ imports:

framework:
#esi: ~
translator: { fallbacks: ['%locale%'] }
secret: '%secret%'
translator: { fallbacks: ['%env(SYMFONY_LOCALE)%'] }
secret: '%env(SYMFONY_SECRET)%'
router:
resource: '%kernel.project_dir%/app/config/routing.yml'
strict_requirements: ~
Expand All @@ -22,7 +22,7 @@ framework:
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: '%locale%'
default_locale: '%env(SYMFONY_LOCALE)%'
trusted_hosts: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
Expand All @@ -43,11 +43,11 @@ twig:
doctrine:
dbal:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
host: '%env(SYMFONY_DB_HOST)%'
port: '%env(SYMFONY_DB_PORT)%'
dbname: '%env(SYMFONY_DB_NAME)%'
user: '%env(SYMFONY_DB_USERNAME)%'
password: '%env(SYMFONY_DB_PASSWORD)%'
charset: utf8mb4
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
Expand Down Expand Up @@ -77,19 +77,19 @@ doctrine_migrations:

# Swiftmailer Configuration
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
transport: '%env(SYMFONY_MAILER_TRANSPORT)%'
host: '%env(SYMFONY_MAILER_HOST)%'
username: '%env(SYMFONY_MAILER_USERNAME)%'
password: '%env(SYMFONY_MAILER_PASSWORD)%'
spool: { type: memory }

fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: AppBundle\Entity\User
from_email:
address: "%mailer_user%"
sender_name: "%mailer_user%"
address: "%env(SYMFONY_MAILER_FROM_ADDRESS)%"
sender_name: "%env(SYMFONY_MAILER_SENDER_NAME)%"
registration:
form:
type: AppBundle\Form\RegistrationFormType
Expand Down
2 changes: 1 addition & 1 deletion app/config/config_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ monolog:
handlers:
main:
type: stream
path: '%kernel.logs_dir%/%kernel.environment%.log'
path: '/tmp/stdout'
level: debug
channels: ['!event']
console:
Expand Down
2 changes: 1 addition & 1 deletion app/config/config_prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ monolog:
handler: nested
nested:
type: stream
path: '%kernel.logs_dir%/%kernel.environment%.log'
path: '/tmp/stdout'
level: debug
console:
type: console
Expand Down
5 changes: 5 additions & 0 deletions app/config/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ framework:
profiler:
collect: false

security:
firewalls:
main:
http_basic: ~

web_profiler:
toolbar: false
intercept_redirects: false
Expand Down
22 changes: 0 additions & 22 deletions app/config/parameters.yml.dist

This file was deleted.

6 changes: 1 addition & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@
"vich/uploader-bundle": "^1.4"
},
"require-dev": {
"behat/behat": "^3.3",
"phpunit/phpunit": "6.2",
"sensio/generator-bundle": "^3.0",
"symfony/phpunit-bridge": "^3.0"
},
"scripts": {
"symfony-scripts": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
Expand All @@ -69,9 +68,6 @@
"symfony-web-dir": "web",
"symfony-tests-dir": "tests",
"symfony-assets-install": "relative",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": "NULL"
}
}
Loading

0 comments on commit 6f40f10

Please sign in to comment.