Skip to main content

Improving Environment Values in Aura v2

·208 words·1 min
Hari KT
Author
Hari KT
Freelancer | Founder of Tripti and Tanvish | Maintainer of Aura for PHP, created by Paul M Jones

Aura v2 framework probably have missed a better way to handle environment variables. But that doesn’t make you stall. Things can be improved ;-).

Assume you are already using aura framework and is at root of the project.

We are going to make use of vlucas/phpdotenv , alternatives are there if you are interested to experiment.

1
composer require vlucas/phpdotenv

Edit the file config/_env.php and add Dotenv::load(/path/to/.env); to the first line. If you have not modified anything it will look as below

1
2
3
4
5
6
7
8
<?php
// {PROJECT_PATH}/config/_env.php
Dotenv::load(__DIR__);
// set the mode here only if it is not already set.
// this allows for setting via web server, shell script, etc.
if (! isset($_ENV['AURA_CONFIG_MODE'])) {
    $_ENV['AURA_CONFIG_MODE'] = 'dev';
}

Don’t forget to create the .env file.

You are done!

Now you can easily make use of environment variables easily from the configuration files.

Below is an example.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<?php
namespace Aura\Framework_Project\_Config;
// config/Common.php

use Aura\Di\Config;
use Aura\Di\Container;

class Common extends Config
{
    public function define(Container $di)
    {
        $di->params['Aura\Sql\ExtendedPdo'] = array(
            'dsn' => getenv('dsn'),
            'username' => getenv('username'),
            'password' => getenv('password'),
        );
    }

    // more code

Related

Speed Up Configuration in Aura v2

·322 words·2 mins
Aura v2 added auto resolution in-order to help lazy people writing configuration manually. Even though it was introduced to help, it introduced a few issues. So auto resolution will be disabled in the future. Some of the complains/suggestions are how to easily write the di configuration. So introducing you FOA.DiConfig Installation # 1 composer require foa/di-config Usage # 1 2 3 vendor/bin/di-config-dump Usage : vendor/bin/di-config-dump /real/path/to/file.php Usage : vendor/bin/di-config-dump /real/path/to/directory Example 1 # Let’s assume you have

Getting Started With Aura v2

·438 words·3 mins
Yesterday aura framework v2 stable released. Lots of complains about documentation or missing documentation. So this is a quick start. Probably a five minutes walk through. Learn and change to make it better. Creating your project # Create the project using composer. 1 2 composer create-project aura/web-project quick-start cd quick-start The minimal framework don’t come with any sort of view integrated. Let us use aura/view, the two step templating with the help of foa/html-view-bundle.

Using Aura.Input Forms Inside Slim Framework

·738 words·4 mins
Rob Allen wrote about Integrating ZF2 forms into Slim. I did write how you can use Aura.Input and Aura.Html to create standalone form for PHP. This time I felt I should write about integrating aura input inside Slim. Let us install a few dependencies aura/input for building the form and aura/html for the html helpers. You of-course can skip not to use aura/html and build your own helper. I also purposefully left not integrating the powerful Aura.Filter , but you are not limited to integrate any validator you love inside Aura.Input .