2017 © Pedro Peláez
 

library builder

a generic builder for PHP application based on environment.

image

tuum/builder

a generic builder for PHP application based on environment.

  • Monday, November 6, 2017
  • by asaokamei
  • Repository
  • 1 Watchers
  • 0 Stars
  • 33 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 18 Versions
  • 0 % Grown

The README.md

Application Builder

A generic builder for application construction based on various server environment., (*1)

Licence

MIT License, (*2)

PSR

PSR-1, PSR-2, and PSR-4., (*3)

Installation

composer require "tuum/builder: ^1.0.0"

Sample Code

use WScore\Builder\Builder;

$builder  = Builder::forge(
    __DIR__ . '/config,  // app directory
    __DIR__ . '/var',    // var directory
    true                 // debug
);
$builder->loadEnv();
$builder->load('setup');
$builder->load('routes');
if ($builder->isEnv('local')) {
    $builder->load('extra.local');
}

$app = $builder->getApp(); // <- must set an app using setApp()!

Basic Usage

Directory Structure

Tuum/Builder assumes there are two directories to build an application:, (*4)

  • APP_DIR: directory for application settings, and
  • VAR_DIR: directory for files not under version control.

For instance,, (*5)

+ config/          // <- APP_DIR
   + setup.php
   + routes.php
+ var/             // <- VAR_DIR
   + .env
   + cache/

Construction

Construct the application builder with two directories:, (*6)

use WScore\Builder\Builder;

$builder  = new Builder([
    Builder::APP_DIR => __DIR__ . '/config,  // app directory
    Builder::VAR_DIR => __DIR__ . '/var',    // var directory
    Builder::DEBUG   => true                 // debug
]);

Or, simply use forge method as shown in the Sample Code Section., (*7)

Loading PHP File

To load configuration files under the APP_DIR, use load method as;, (*8)

$builder->load('setup');

In setup.php file, set up the application, such as:, (*9)

/** @var Tuum\Builder\Builder $builder */
$builder->set(Builder::APP_KEY, 'ENV');  // set value
$builder->setApp(new YourApp()); // set your application

return [
    'db-name' => $builder->get('DB_NAME', 'demo'),
]; // may return some value
  • The builder has has, get, and set methods as expected.
  • There are setApp() and getApp() methods to store your application.
  • The returned value from the PHP files are stored in the builder using its load name, which can be accessed by: $builder->get('setup');.

Getting Values

The get method tries to get value from:, (*10)

  1. environment value,
  2. $builder's internal value
  3. default value.
$builder->get('DB_NAME', 'my_db');

Environment File

Loads .env file using vlucas's dotenv component. The default location of the .env file is at VAR_DIR., (*11)

The .env file contains APP_ENV key to specify the environment as such;, (*12)

APP_ENV = local

Then, you can access the environment as,, (*13)

$builder->loadEnv(); // load the .env file

$builder->isEnv('local');
$builder->isEnvProd();
$env = $builder->getEnv();

The builder considers the environment as prod if no environment is set, or no environment file to load., (*14)

To change the key string used to specify the environment, set Builder::APP_KEY value to the new key name, such as;, (*15)

$builder->set(Builder::APP_KEY, 'ENV');  // set value

The Versions

06/11 2017

dev-master

9999999-dev

a generic builder for PHP application based on environment.

  Sources   Download

MIT

The Requires

 

by Asao Kamei

06/11 2017

1.0.0

1.0.0.0

a generic builder for PHP application based on environment.

  Sources   Download

MIT

The Requires

 

by Asao Kamei

02/11 2017

0.3.2

0.3.2.0

a generic builder for PHP application based on environment.

  Sources   Download

MIT

The Requires

 

by Asao Kamei

27/10 2017

0.3.1

0.3.1.0

a generic builder for PHP application based on environment.

  Sources   Download

MIT

The Requires

 

by Asao Kamei

16/10 2017

0.3.0

0.3.0.0

a generic builder for PHP application based on environment.

  Sources   Download

MIT

The Requires

 

by Asao Kamei

15/10 2017

0.2.7

0.2.7.0

a generic builder for PHP application based on environment.

  Sources   Download

MIT

The Requires

 

by Asao Kamei

15/10 2017

0.2.6

0.2.6.0

a generic builder for PHP application based on environment.

  Sources   Download

MIT

The Requires

 

by Asao Kamei

14/10 2017

0.2.5

0.2.5.0

a generic builder for PHP application based on environment.

  Sources   Download

MIT

The Requires

 

by Asao Kamei

14/10 2017

0.2.4

0.2.4.0

a generic builder for PHP application based on environment.

  Sources   Download

MIT

The Requires

 

by Asao Kamei

10/09 2017

0.2.3

0.2.3.0

a generic builder for PHP application based on environment.

  Sources   Download

MIT

The Requires

 

by Asao Kamei

31/08 2017

0.2.1

0.2.1.0

a generic builder for PHP application based on environment.

  Sources   Download

MIT

The Requires

 

by Asao Kamei

31/08 2017

0.2.2

0.2.2.0

a generic builder for PHP application based on environment.

  Sources   Download

MIT

The Requires

 

by Asao Kamei

30/08 2017

0.2.0

0.2.0.0

a generic builder for PHP application based on environment.

  Sources   Download

MIT

The Requires

 

by Asao Kamei

31/08 2016

0.1.0

0.1.0.0

a generic builder for PHP application based on environment.

  Sources   Download

MIT

by Asao Kamei

12/03 2016

1.0.0-RC2

1.0.0.0-RC2

a generic builder for PHP application based on environment.

  Sources   Download

MIT

by Asao Kamei

11/03 2016

dev-feature/simpleApi

dev-feature/simpleApi

a generic builder for PHP application based on environment.

  Sources   Download

MIT

by Asao Kamei

07/11 2015

1.0.0alpha1

1.0.0.0-alpha1

a generic builder for PHP application based on environment.

  Sources   Download

MIT

by Asao Kamei

07/11 2015

1.0.0-RC1

1.0.0.0-RC1

a generic builder for PHP application based on environment.

  Sources   Download

MIT

by Asao Kamei