2017 © Pedro PelĂĄez
 

library config

Include php array files

image

alius/config

Include php array files

  • Sunday, January 17, 2016
  • by Romeo Vegvari
  • Repository
  • 1 Watchers
  • 0 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Build Status, (*1)

Alius Config

Alius Config is just a simple composer package, all it can do is include php array files., (*2)

Never commit any sensitive information into your version control!, (*3)

Basic usage:

<?php

return [
    'test' => 'this is a test',
];
$config = new \Alius\Config\Config('path_to_file.php');
print $config->get('test'); // => this is a test

Multiple files, directories

You can include multiple files:, (*4)

$config = new \Alius\Config\Config([
    'path_to_file1.php',
    'path_to_file2.php',
]);

One or more directories (includes the subdirectories and files recursively):, (*5)

$config = new \Alius\Config\Config([
    'path_to_directory',
    'path_to_directory2',
]);

All of the files must use php as extension and they must return array., (*6)

Last file wins

If you include two files with the same variable, the last file always wins:, (*7)

<?php
// file1.php
return [
    'test' => 'one',
];
<?php
// file2.php
return [
    'test' => 'two',
];
$config = new \Alius\Config\Config(['file1.php', 'file2.php']);
print $config->get('test'); // => two

It's a good idea to name your files starting with numbers:, (*8)

10-something.php
20-something_more.php

Get the source file of a variable

Including lots of files could be confusing so you can get the source file of a variable:, (*9)

print $config->getOrigin('test'); // => file2.php

Required variables

You can mark a variables required, if none of the included files has this variable then an exception will be thrown:, (*10)

$config = new \Alius\Config\Config('path_to_file.php', ['test']);
var_dump($config->isRequired('test')); // => true
var_dump($config->isRequired('test2')); // => false

Get the variables in one array

You can get an array with all the variables:, (*11)

$config->compile();

Error thrown, if:

  • any of the files doesn't exist or not readable or has extension other than php
  • if you try to get a non-existing variable ($config->get('not_there'); or $config->getOrigin('not_there');)
  • when a required variable is not found in any of the included files

The point is that it should fail fast so you can fix everything before you commit your changes or deploy., (*12)

Never commit any sensitive information into your version control!, (*13)

You should create a directory for all of your non-sensitive data, and another one for sensitive data (and exclude that one from version control)., (*14)

For example:, (*15)

config/non-sensitive-data1.php
config/non-sensitive-data2.php
exclude_this_dir_from_vc/database.php

Or you can still use dotenv or similar for sensitive data, for example Laravel’s env function with defaults:, (*16)

return [
    'db_host' => env('db_host', 'localhost'),
    'db_user' => env('db_user', 'homestead'),
    'db_pass' => env('db_pass', 'secret'),
    'db_name' => env('db_name', 'homestead'),
];

What’s wrong with dotenv?

Nothing, but sometimes it’s just not enough., (*17)

With this package you can include files conditionally, override variables, you can use bool, int, float, arrays, constants, Closures, even objects or resources., (*18)

Or you can extend it, create your DatabaseConfig class so you can inject it as a dependency., (*19)

The Versions

17/01 2016

1.0.x-dev

1.0.9999999.9999999-dev

Include php array files

  Sources   Download

GPL-2.0

The Requires

  • php >=5.5

 

by Avatar Romeo Vegvari

17/01 2016

dev-master

9999999-dev

Include php array files

  Sources   Download

GPL-2.0

The Requires

  • php >=5.5

 

by Avatar Romeo Vegvari

17/01 2016

1.0

1.0.0.0

Include php array files

  Sources   Download

GPL-2.0

The Requires

  • php >=5.5

 

by Avatar Romeo Vegvari