diff --git a/.env.example b/.env.example deleted file mode 100644 index 0ae08cd..0000000 --- a/.env.example +++ /dev/null @@ -1,13 +0,0 @@ -DB_DRIVER=pdo_mysql -DB_HOSTNAME=localhost -DB_DBNAME=scotchbox -DB_USERNAME=root -DB_PASSWORD=root - -MAIL_HOST=localhost -MAIL_PORT=25 -MAIL_USERNAME= -MAIL_PASSWORD= - -GITHUB_API_KEY=changeme -GITHUB_API_SECRET=changeme \ No newline at end of file diff --git a/.gitignore b/.gitignore index d4a6796..ff59c78 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ data/logs/* data/sessions/* !data/sessions/.gitkeep /vendor/ -.env +/app/config/parameters.yml composer.phar phinx.yml .DS_Store diff --git a/README.md b/README.md index 1c75387..cc482e9 100644 --- a/README.md +++ b/README.md @@ -29,28 +29,10 @@ You should have [Composer](http://getcomposer.org) installed and available. If y You will need to navigate to the URL in a browser, authenticate with GitHub, and generate the access token. -6. From the same directory, run `vendor/bin/phinx init` to generate a `phinx.yml` file. -7. Edit `/var/www/phinx.yml`: - - In the `paths` section, set the `migrations` value to: - - ```{.yaml} - migrations: %%PHINX_CONFIG_DIR%%/data/migrations - ``` - - In the `development` section, set the following MySQL credentials: - - ```{.yaml} - name: scotchbox - user: root - pass: root - ``` - +6. [Configure Phinx](#phinx-configuration) 9. Run `vendor/bin/phinx migrate` to run the database migrations. -10. Copy `.env.example` to `.env` -11. Create a new Github Application at - - Set the **Homepage** and **Authorization callback URL** to -10. Update your `.env` file and set the `GITHUB_API_KEY` and `GITHUB_API_SECRET` to the Client ID and Client Secret for your app. +10. Copy `app/config/parameters.yml.dist` to `app/config/parameters.yml` and configure for your setup +11. [Configure Github](#github) 13. Visit in your browser! #### Running Without Vagrant @@ -67,11 +49,24 @@ Steps: 127.0.0.1 www.mentoring.dev mentoring.dev - 3. Change directory to the directory where you cloned the project in step 1 and run `composer install` -4. Copy `.env.example` to `.env` -5. From the same directory, run `vendor/bin/phinx init` to generate a `phinx.yml` file. -6. Edit `./phinx.yml`'s development section (lines 19-21) with the following values for MySQL. +4. Copy `app/config/parameters.yml.dist` to `app/config/parameters.yml` and configure for your setup +5. [Configure Phinx](#phinx-configuration) +8. Run `vendor/bin/phinx migrate` to run the database migrations. +9. [Configure Github](#github) +11. To run using PHP's built-in server, navigate to the root of the project and run: + + php -S mentoring.dev:8080 -t public public/index.php + +12. Visit in your browser! + +### Phinx Configuration + +We use [Phinx](https://phinx.org/) for managing our database migrations. It provides a programmatic way for handling +table and data changes. It does require some initial setup however. + +1. From the root project directory, run `vendor/bin/phinx init` to generate a `phinx.yml` file. +2. Edit `./phinx.yml`'s development section (lines 19-21) with the following values for MySQL. ```{.yaml} name: mentoring @@ -79,31 +74,46 @@ Steps: pass: vagrant ``` - To use sqlite, in `./phinx.yml` change change the adapter to `sqlite` (line 17) the name (line 19) to `data/mentoring.db`. In `.env` change `DB_DRIVER` to `pdo_sqlite` on line 1. + To use sqlite, in `./phinx.yml` change change the adapter to `sqlite` (line 17) the name (line 19) to `data/mentoring.db`. -7. Edit `./phinx.yml`'s `paths.migrations` value (line 2) to: +3. Edit `./phinx.yml`'s `paths.migrations` value (line 2) to: ``` %%PHINX_CONFIG_DIR%%/data/migrations ``` -8. Run `vendor/bin/phinx migrate` to run the database migrations. -9. Create a new Github Application at - - Set the **Homepage** and **Authorization callback URL** to -10. Update your `.env` file and set the `GITHUB_API_KEY` and `GITHUB_API_SECRET` to the Client ID and Client Secret for your app. -11 To run using PHP's built-in server, navigate to the root of the project and run: - - php -S mentoring.dev:8080 -t public public/index.php - -12. Visit in your browser! +### App Configuration + +All configuration is store in `app/config/parameters.yml`. The app ships with a `.dist` version that you will need to +copy/paste into the above path. You can then edit it to your needs. + +#### Github +The application uses Github for authentication. If you are developing or working +on features that require a user login, you will need to set up a new Github Application +to generate a secret and a key. -### Email in Development +Instructions for doing this are available at . -Before you start the VM, you need to change your .env file. To use mailcatcher, you'll want the following config: +Set the **Homepage** and **Authorization callback URL** to or , depending on how you set up your `hosts` file. -MAIL_HOST=0.0.0.0 -MAIL_PORT=1025 +Once you have that completed, you will need to add them to the `parameters.yml` file, like this: + +```{.yaml} +github: + api_key: 'keyfromgithub' + api_secret: 'secretfromgithub' +``` + +#### Email in Development + +Before you start the VM, you need to change your `parameters.yml` file. To use mailcatcher, you'll want the following config: + +```{.yaml} +mail: + host: '0.0.0.0' + port: 1025 +``` Mailcatcher is installed in the VM, but to use it you need to ssh into the VM and execute the following command to start the mail server: @@ -112,3 +122,13 @@ Mailcatcher is installed in the VM, but to use it you need to ssh into the VM an You can then view all emails being sent out by the app in your host machine's browser at the following address: `http://192.168.56.101:1080` + +#### Database Configuration + +This app uses the [Doctrine DBAL](http://silex.sensiolabs.org/doc/master/providers/doctrine.html) as it's underlying +database layer, so you can configure the database using the options in the Silex documentation. + +Explicitly, we support MySQL and it's dialect of SQL. Others may work, like SQLite for development environments, but +most of the code is written with MySQL in mind. + +You can configure the database settings under the `database:` key. \ No newline at end of file diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist new file mode 100644 index 0000000..3e56e9c --- /dev/null +++ b/app/config/parameters.yml.dist @@ -0,0 +1,16 @@ +database: + driver: 'pdo_mysql' + host: 'localhost' + dbname: 'scotchbox' + user: 'root' + password: 'root' + +mail: + host: 'localhost' + port: 25 + username: '' + password: '' + +github: + api_key: 'changeme' + api_secret: 'changeme' \ No newline at end of file diff --git a/composer.json b/composer.json index 6b79943..d991283 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "swiftmailer/swiftmailer": "^5.4", "symfony/config": "^3.1", "symfony/security-csrf": "^3.1", - "mockery/mockery": "^0.9.5" + "mockery/mockery": "^0.9.5", + "rpodwika/yaml-config-service-provider": "^1.0" }, "require-dev": { "phpunit/phpunit": "4.6.*", diff --git a/composer.lock b/composer.lock index 871af60..67d03b7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "449148b5ea68d029f64346059bcdcd35", - "content-hash": "5ed956dbf93a3951840b335098d91fd3", + "hash": "ef16f15fb468a4ad7683a7b6a0f623f0", + "content-hash": "120bd4a7c5cadb7fb41540fa1a35f135", "packages": [ { "name": "doctrine/annotations", @@ -1395,6 +1395,45 @@ ], "time": "2016-10-27 10:16:12" }, + { + "name": "rpodwika/yaml-config-service-provider", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/rpodwika/yaml-config-service-provider.git", + "reference": "0c62c9c37ccdd67c68dbe72e133e6e4509ba3cbf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rpodwika/yaml-config-service-provider/zipball/0c62c9c37ccdd67c68dbe72e133e6e4509ba3cbf", + "reference": "0c62c9c37ccdd67c68dbe72e133e6e4509ba3cbf", + "shasum": "" + }, + "require": { + "silex/silex": "^2.0", + "symfony/yaml": "^3.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Rpodwika\\Silex\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-3.0+" + ], + "authors": [ + { + "name": "Robert Podwika", + "email": "hello@rpodwika.pl", + "homepage": "http://www.rpodwika.pl", + "role": "developer" + } + ], + "description": "Based on deralex/YamlConfigServiceProvider YAML service provider for silex ~2.0 and symfony/yaml 3.~", + "time": "2016-09-15 13:14:21" + }, { "name": "silex/silex", "version": "v2.0.3", diff --git a/public/index.php b/public/index.php index fdb2477..d392013 100644 --- a/public/index.php +++ b/public/index.php @@ -9,40 +9,17 @@ use Silex\Application; use Silex\Provider; -use Dotenv\Dotenv; - -$dotenv = new Dotenv(__DIR__ . '/../'); -$dotenv->load(); - -$mySqlOptions = [ - 'driver' => 'pdo_mysql', - 'host' => getenv('DB_HOSTNAME'), - 'dbname' => getenv('DB_DBNAME'), - 'user' => getenv('DB_USERNAME'), - 'password' => getenv('DB_PASSWORD'), -]; - -$sqliteOptions = [ - 'driver' => 'pdo_sqlite', - 'path' => 'data/mentoring.db', -]; - -$dbOptions = (getenv('DB_DRIVER') == 'pdo_mysql' ? $mySqlOptions : $sqliteOptions); $app = new Application(); $app['debug'] = true; +$app->register(new \Rpodwika\Silex\YamlConfigServiceProvider(__DIR__ . '/../app/config/parameters.yml')); $app->register(new Provider\SessionServiceProvider()); $app->register(new Provider\ServiceControllerServiceProvider()); $app->register(new Provider\RoutingServiceProvider()); $app->register(new Provider\SwiftmailerServiceProvider(), [ - 'swiftmailer.options' => [ - 'host' => getenv('MAIL_HOST') ?: 'localhost', - 'port' => getenv('MAIL_PORT') ?: 25, - 'username' => getenv('MAIL_USERNAME') ?: '', - 'password' => getenv('MAIL_PASSWORD') ?: '', - ], + 'swiftmailer.options' => $app['config']['mail'], 'swiftmailer.use_spool' => false ]); @@ -70,7 +47,7 @@ ]); $app->register(new Silex\Provider\DoctrineServiceProvider(), [ - 'db.options' => $dbOptions + 'db.options' => $app['config']['database'], ]); $taxonomyServiceProvider = new \Mentoring\Taxonomy\ServiceProvider\TaxonomyServiceProvider(); diff --git a/src/Mentoring/Auth/Controller/AuthController.php b/src/Mentoring/Auth/Controller/AuthController.php index aacc4a4..0b1fc50 100644 --- a/src/Mentoring/Auth/Controller/AuthController.php +++ b/src/Mentoring/Auth/Controller/AuthController.php @@ -27,8 +27,8 @@ protected function getUserEmails(Github $provider, AccessToken $token) public function githubAction(Application $app, Request $request) { - $clientID = getenv('GITHUB_API_KEY'); - $clientSecret = getenv('GITHUB_API_SECRET'); + $clientID = $app['config']['github']['api_key']; + $clientSecret = $app['config']['github']['api_secret']; $code = $request->query->get('code'); $redirectUri = $request->getScheme() . '://' .$request->getHost();