Skip to main content

Speed Up Configuration in Aura v2

·322 words·2 mins
Hari KT
Author
Hari KT
Freelancer | Founder of Tripti and Tanvish | Maintainer of Aura for PHP, created by Paul M Jones

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<?php
// src/Vendor/World.php
namespace Vendor;

class World
{
    public function __construct(Baz $baz)
    {
    }
}
1
2
3
4
5
6
7
<?php
// src/Vendor/Baz.php
namespace Vendor;

class Baz
{
}

Now you can make use of

1
vendor/bin/di-config-dump src/Vendor/World.php

will output

1
2
<?php
$di->params['Vendor\World']['baz'] = $di->lazyNew('Vendor\Baz');

You can also pass directory path instead of file. It will read the files and display the configuration.

Example 2
#

Let us look into another example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<?php
// src/Vendor/Hello.php
namespace Vendor;

class Hello
{
    public function __construct(
        \Aura\Web\Response $response,
        \Aura\Web\Request $request,
        \Aura\Router\Router $router,
        World $word
    ) {
    }
}
1
vendor/bin/di-config-dump src/Vendor/Hello.php

will output

1
2
3
4
$di->params['Vendor\Hello']['response'] = $di->lazyGet('aura/web-kernel:response');
$di->params['Vendor\Hello']['request'] = $di->lazyGet('aura/web-kernel:request');
$di->params['Vendor\Hello']['router'] = $di->lazyGet('aura/web-kernel:router');
$di->params['Vendor\Hello']['word'] = $di->lazyNew('Vendor\World');

If you look carefully the Aura\Web\Response, Aura\Web\Request and Aura\Router\Router are making use of lazyGet which gets the shared instance of the Aura.Web_Kernel .

If you are not using inside the framework just pass something as 2nd argument.

1
2
3
4
5
vendor/bin/di-config-dump src/Vendor/Hello.php h
$di->params['Vendor\Hello']['response'] = $di->lazyNew('Aura\Web\Response');
$di->params['Vendor\Hello']['request'] = $di->lazyNew('Aura\Web\Request');
$di->params['Vendor\Hello']['router'] = $di->lazyNew('Aura\Router\Router');
$di->params['Vendor\Hello']['word'] = $di->lazyNew('Vendor\World');

Please make sure all the files need to be autoloadable in-order to generate this.

If you like to improve something fork and contribute.

I have purposefully left not to make use of Aura.Cli in this library. Not sure if we need to integrate or not.

Related

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 .

Aura Framework v2: The Missing Manual

·543 words·3 mins
Aura has an awesome collection of libraries for different purpose. It has components for authentication, cli, request and response, router, dependency injection container, dispatcher, html, view, event handlers, validation, extended pdo, query builders, sql schema, marshal, build and modify uri, http, internationalization, session, forms, includer. If you are new to aura, there is probably something you may want to figure out yourself. Some of the components have version 1 and version 2 releases. There is a question of which branch corresponds to which version. The v1 packages are in develop branch and v2 over develop-2 branch.