diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ac1350f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.swp +*~ +~* diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0d946df --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 Zach Queal + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..5b39da8 --- /dev/null +++ b/README.md @@ -0,0 +1,157 @@ +About +============== + +A simple configuration script to store values in an array, and return them using public static functions! + +Got an email recently about this repository--its all but defunct and no longer necessary. A better approach would be to use `.env` variables. [Check out this project here](https://github.com/vlucas/phpdotenv)--and be sure to include `.env` to your `.gitignore`. + +#### Index +* [Usage](#usage) +* [Classes](#classes) + * [Set](#set) + * [Get](#get) + * [Return](#return) + * [Init](#init) + * [Update](#update) +* [Pull Requests and Support](#pulls-and-support) + +Usage +============== + +Ensure you have at least PHP version `5.4`; + +Require or include the class file: + +```php +require 'vendor/Config.php'; +``` + +Create your configuration array: + +```php +Config::init([ + 'username' => 'user', + 'password' => 'password', + 'hostname' => 'localhost', + 'dbname' => 'test', + 'database' => [ + 'hostname' => 'localhost', + 'username' => 'username', + 'password' => 'test', + 'port' => 3306 + ] +]); +``` + +Then do stuff with your values: + +```php +Config::get('username'); // contains 'user' +``` + +Or for multidimensional (init) arrays: + +```php +Config::$instance->database{'password'}; // contains 'password' +``` + +Classes +============== + +There are `5` classes of note, they are: `set`, `get`, `ret`, `init`, and `update`. + +---------- + +#### Set +```php +public static function set($key, $val) { + self::$config[$key] = $val; +} +``` + +Enables you to set a single key value pair. + +```php +Config::set('username', 'zQueal'); +``` + +---------- + +#### Get +```php +public static function get($key) { + self::$config[$key]; +} +``` + +Enables you to 'test' a single key pair value. `Config::get()` will not longer return a value. See [Config::ret()](#ret). + +```php +if(Config::get('username') == $value){ + doStuff(); +} +``` + +---------- + +#### Return +```php +public static function ret($key) { + print self::$config[$key]; +} +``` + +Returns (print) a single key pair value. + +```php +Config::ret('username'); // returns stored value +``` + +---------- + +#### Init +```php +public static function init($a) { + self::$config = $a; + self::$instance = new Config(); +} +``` + +Enables you to set multiple key value pairs in a single function, and create multidimensional values. + +```php +Config::init([ + 'username' => 'username', + 'password' => 'password', + 'directory' => '/home/zqueal', + 'about' => [ + 'name' => 'Zach Q', + 'email' => 'zach.queal@gmail.com', + 'color' = 'blue' + ] +]); +``` + +Once your function call has been executed, all the variables will be able to be used in the rest of your script / application. To call a single (top nested) key value pair, use the `Config::get('directory'); // contains /home/zqueal` static function call. If you're trying to access a nested key value pair, then you need to use the static object method `Config::$instance->about{'name'} // returns 'Zach Q'`. + +---------- + +#### Update +```php +public static function update($a) { + self::$config = array_merge(self::$config, $a); +} +``` + +A function to update already created values. + +```php +Config::set('name', 'Zach Q'); +Config::ret('name'); // returns 'Zach Q' +Config::update('name', 'Other Name'); +Config::ret('name'); // returns 'Other Name' +``` + +Pulls and Support +================== +I do not maintain this repository. If you have an improvement I'm open to pull requests, but I do not offer support. \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..3fdf6e1 --- /dev/null +++ b/composer.json @@ -0,0 +1,17 @@ +{ + "name": "zqueal/phpconfigure", + "description": "Simple PHP configure library that adds a key => value relationship for configuration data callable via variables.", + "keywords": ["php", "configure"], + "homepage": "https://github.com/zQueal/php-configure.git", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Zach Queal", + "email": "zach.queal@gmail.com" + } + ], + "require": { + "php": ">=5.4" + } +} diff --git a/index.php b/index.php new file mode 100644 index 0000000..a0a4bb6 --- /dev/null +++ b/index.php @@ -0,0 +1,19 @@ + 'user', + 'password' => 'password', + 'hostname' => 'localhost', + 'dbname' => 'test', + 'database' => [ + 'hostname' => 'localhost', + 'username' => 'username', + 'password' => 'test', + 'port' => 3306 + ] +]); + +print Config::$instance->database{'password'}; // returns 'password' +Config::get('username'); // contains 'user' \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..76207f5 --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "PHP-Config", + "description": "A simple tool to help with PHP configuration", + "keywords": [ + "php", + "configure" + ], + "repository": { + "type": "git", + "url": "git@github.com:zqueal/php-configure.git" + }, + "author": { + "name": "Zach Q", + "email": "zach.queal@gmail.com" + }, + "license": "MIT", + "dependencies": { + "php": "~5.4" + } +} diff --git a/vendor/Config.php b/vendor/Config.php new file mode 100644 index 0000000..698940f --- /dev/null +++ b/vendor/Config.php @@ -0,0 +1,39 @@ +