CodeCanyon PHP Configuration System 7199251

CodeCanyon PHP Configuration System 7199251

CodeCanyon PHP Configuration System 7199251
PHP Script \ Miscellaneous
Class \ Configuration \ Oriented \ Options \ Object \ Notation \ Config \ Array


PHP Script - PHP Configuration System 7199251 by afflicto @ CodeCanyon

PHP Script \ Miscellaneous

Last Update: 20 March 14; Software Version: PHP 5.3, PHP 5.4, PHP 5.5; Files Included: PHP.

Features

Introducing NeatConfig – The simple way to manage the configuration of your application. Supports multiple environments!

- Store your configurations as simple .php arrays

- Manage multiple environments with ease

- Use array dot-notation to get nested config values

- Includes an example of a static facade

- Well-documented, clean object-oriented code!

Installation & Basic use

This script is one single class, in 1 file. So it should be fairly easy to get started. However, here’s a basic introduction.

Also, I recommend you read through the two example files located in the ‘examples’ directory of the ZIP File, they should get you going pretty quickly.

I assume your application has a file structure similar to this.

MyApplication
index.php
classes
lib

To integrate NeatConfig, simply place the Config class somewhere.

MyApplication
index.php
classes
lib
Afflicto
NeatConfig
Config.php

Now, create a config directory.

MyApplication
index.php
classes
lib
Afflicto
NeatConfig
Config.php
config

Now, probably the most common kind of configuration is database information, like host, database, password etc. Let’s create a “database.php” file in our new ‘config’ directory.

config
database.php

Now, in your index.php, instantiate (create) a new instance of the Config class. It takes two parameters, the path to our config directory, and the ‘environment’ we’re in. You can leave out the second parameter if you don’t use multiple environments (Like one for production and one for local development).

The path to the config directory can be either a relative path of the script or a full path.

$config = new AfflictoNeatConfigConfig('config');

Remember our database.php configuration file? let’s put some stuff in there. Each config file must return an array. Perhaps our database config looks like this.

<?php
return array(
'driver' => 'mysql',
'connection' => array(
'host' => 'localhost',
'username' => 'affy',
'database' => 'somedb',
'password' => 'secret',
),
);

Now, to get the values from our database.php config, we can do this.

$databaseConfig = $config->get('database');

Note that you can also use array dot-notation to get nested values of the config array, like so.

$password = $config->get('database.connection.password');

Also, if you’re using multiple environments, you can (if you need to) specify that you want a specific environment like so.

$developmentDatabase = $config->get('database', 'development');

That concludes this short introduction to NeatConfig, I hope you like it. If you have any questions or feature requests, be sure to give me a comment.

Multiple Environments

Most often, some of the configuration is different depending on what environment you’re in, whether on a local development machine, or on a live server somewhere, where some values might be different (like the URL or database).

You should probably keep all your configs in the root of your ‘config’ directory, and override them by creating a folder for each environment in the ‘config’ directory.

Let’s say, for our application, we’re using a different database driver or a different database name/password, let’s create a new folder called ‘local’ in our ‘config’ directory, and create a ‘database.php’ file there as well.

MyApplication
index.php
classes
lib
Afflicto
NeatConfig
Config.php
config
database.php
local
database.php

Now, when we initialize $config, we set our current environment in the second parameter.

$config = new AfflictoNeatConfigConfig('config', 'local');

Now, when we request the database config, it will first search for one defined in our ‘local’ directory, then fall-back to the root ‘config’ directory if that specific environment does not override it.

PHP Datatables & jQuery Plugin; Form Class - AJAX, Validation, jQuery & Bootstrap; Class Mutations - Dynamically Add Methods; HTML Layout & Utility Class; Event/Hook class.

Keywords: array, class, config, configuration, configuration class, dot-notation, environment, object-oriented, oop, options, php.



Tags: Configuration, Class, Oriented, Object, Options

Premium CodeCanyon PHP Configuration System 7199251 WordPress Themes, Website Templates, Mobile Themes, Flash Templates & Scripts from creative professional designers. Full details of CodeCanyon PHP Configuration System 7199251 for digital design and education. CodeCanyon PHP Configuration System 7199251 desigen style information or anything related.

Comments:

Name:*
E-Mail:*
Add Comments:
Enter Code: *