Skip to content
This repository has been archived by the owner on Dec 22, 2020. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zQueal committed Jun 9, 2017
0 parents commit 7f4ebf9
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.swp
*~
~*
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
157 changes: 157 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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' => '[email protected]',
'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.
17 changes: 17 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]"
}
],
"require": {
"php": ">=5.4"
}
}
19 changes: 19 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

require 'vendor/Config.php';

Config::init([
'username' => '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'
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "PHP-Config",
"description": "A simple tool to help with PHP configuration",
"keywords": [
"php",
"configure"
],
"repository": {
"type": "git",
"url": "[email protected]:zqueal/php-configure.git"
},
"author": {
"name": "Zach Q",
"email": "[email protected]"
},
"license": "MIT",
"dependencies": {
"php": "~5.4"
}
}
39 changes: 39 additions & 0 deletions vendor/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

class Config {
private static $config = [];
public static $instance = "";
private function __construct() {}
public static function set($key, $val) {
self::$config[$key] = $val;
}
public static function get($key) {
self::$config[$key];
}
public static function ret($key) {
print self::$config[$key];
}
public static function init($a) {
self::$config = $a;
self::$instance = new Config();
}
public static function update($a) {
self::$config = array_merge(self::$config, $a);
}
public function __get($param) {
if(isset(self::$config[$param])) {
return self::$config[$param];
}
}
public function __ret($param) {
if(isset(self::$config[$param])) {
return self::$config[$param];
}
}
public function __isset($param) {
if(isset(self::$config[$param])) {
return true;
}
return false;
}
}

0 comments on commit 7f4ebf9

Please sign in to comment.