From ceb503163e23851a0015b1ee63a4072ab0f2c677 Mon Sep 17 00:00:00 2001 From: Alfred Tchondjo Date: Sun, 23 Sep 2018 01:27:11 +0200 Subject: [PATCH 01/14] Update .travis.yml --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b5f0b08..3965164 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,12 @@ language: php php: + - 5.4 + - 5.5 + - 5.6 - 7.0 - 7.1 - 7.2 - - hhvm script: - echo 'Iriven PHP ConfigManager Library' From a6668f706e6c905e8e2624d37472bb3cb10a7547 Mon Sep 17 00:00:00 2001 From: Alfred Tchondjo Date: Sun, 23 Sep 2018 01:27:58 +0200 Subject: [PATCH 02/14] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bb3f115..7aeaef4 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ ] }, "require": { - "php": ">=7.0.0" + "php": ">=5.4.0" }, "require-dev": { "phpunit/phpunit": "~6.4.0" From 621ff66dfb2fa8131e672501818e12c12103ed83 Mon Sep 17 00:00:00 2001 From: Alfred Tchondjo Date: Sun, 23 Sep 2018 01:31:06 +0200 Subject: [PATCH 03/14] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7aeaef4..bb3f115 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ ] }, "require": { - "php": ">=5.4.0" + "php": ">=7.0.0" }, "require-dev": { "phpunit/phpunit": "~6.4.0" From 192a2700015828709eaa43f560447c86e2bca376 Mon Sep 17 00:00:00 2001 From: Alfred Tchondjo Date: Sun, 23 Sep 2018 01:31:28 +0200 Subject: [PATCH 04/14] Update .travis.yml --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3965164..941e037 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,6 @@ language: php php: - - 5.4 - - 5.5 - - 5.6 - 7.0 - 7.1 - 7.2 From dd5a3068bad24667733eb2e63649b983f3fecb82 Mon Sep 17 00:00:00 2001 From: Alfred Tchondjo Date: Sun, 23 Sep 2018 01:32:53 +0200 Subject: [PATCH 05/14] Update .travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 941e037..b5f0b08 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ php: - 7.0 - 7.1 - 7.2 + - hhvm script: - echo 'Iriven PHP ConfigManager Library' From 19f89761e1e3d9d6529e4c403c0e149145c296af Mon Sep 17 00:00:00 2001 From: Alfred Tchondjo Date: Sun, 23 Sep 2018 07:24:04 +0200 Subject: [PATCH 06/14] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cce24f0..ccb0c98 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ Iriven PHP ConfigManager ======= [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XDCFPNTKUC4TU) [![Build Status](https://travis-ci.org/iriven/ConfigManager.svg?branch=master)](https://travis-ci.org/iriven/ConfigManager) +[![Code Intelligence Status](https://scrutinizer-ci.com/g/iriven/ConfigManager/badges/code-intelligence.svg?b=master)](https://scrutinizer-ci.com/code-intelligence) >Iriven Php ConfigManager est un composant / package stand alone, developpé pour manipuler facilement les fichiers de configurations de toute application PHP. From 75f72104060034a46e9ef55d89c1966cce8de89e Mon Sep 17 00:00:00 2001 From: Alfred Tchondjo Date: Sun, 23 Sep 2018 07:27:31 +0200 Subject: [PATCH 07/14] Update ConfigManager.php --- ConfigManager.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ConfigManager.php b/ConfigManager.php index c87a008..6f12203 100644 --- a/ConfigManager.php +++ b/ConfigManager.php @@ -28,7 +28,7 @@ class ConfigManager /** * @param $filename - * @param null $location + * @param $location * @throws \Exception */ public function __construct( $filename, $location=null ) @@ -44,12 +44,12 @@ public function __construct( $filename, $location=null ) } catch(Exception $a) { - die($a->getMessage()); + trigger_error($a->getMessage(),E_USER_ERROR); } } /** - * @param null $section - * @param null $item + * @param $section + * @param $item * @return array|bool|mixed */ public function get($section=null, $item=null) @@ -81,9 +81,9 @@ public function get($section=null, $item=null) } /** - * @param null $section + * @param $section * @param $item - * @param null $value + * @param $value * @return bool */ public function set($section,$item=null,$value=null) @@ -142,7 +142,7 @@ public function set($section,$item=null,$value=null) } /** * @param $section - * @param null $item + * @param $item * @return bool */ public function del($section, $item=null) @@ -192,7 +192,7 @@ public function del($section, $item=null) } /** * @param $file - * @param null $location + * @param $location * @return array|bool */ private function configureOptions($file,$location=null){ @@ -222,7 +222,7 @@ private function configureOptions($file,$location=null){ } /** * @param $path - * @param null $relativeTo + * @param $relativeTo * @return string */ private function normalize($path, $relativeTo = null) { From 5146cabff76e58abeb13adbb1bb35c18fea933fc Mon Sep 17 00:00:00 2001 From: Alfred Tchondjo Date: Sun, 23 Sep 2018 07:31:41 +0200 Subject: [PATCH 08/14] Update ConfigManager.php --- ConfigManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ConfigManager.php b/ConfigManager.php index 6f12203..9d93904 100644 --- a/ConfigManager.php +++ b/ConfigManager.php @@ -279,7 +279,7 @@ private function parseConfiguration($options=[]) } catch(Exception $b) { - die( $b->getMessage()); + trigger_error($b->getMessage(),E_USER_ERROR); } return $this->Config; } From a1b16fb0d9049a8e45ed9a245519b3b085dee617 Mon Sep 17 00:00:00 2001 From: Alfred Tchondjo Date: Sun, 23 Sep 2018 07:41:02 +0200 Subject: [PATCH 09/14] Update exemple.php --- exemple.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exemple.php b/exemple.php index 6deb2e6..b807cb8 100644 --- a/exemple.php +++ b/exemple.php @@ -14,7 +14,7 @@ 'salt'=>pack('H*', md5(time())), 'lastvalidation' => 98745612 // default: time(), execution du script pour la 1ere fois ); -$ini = new IrivenConfigManager('./licence.ini'); +$ini = new Iriven\ConfigManager('./licence.ini'); $ini->set('licence',$licence); //with section $test = array('test1'=>'my tester1','test2'=>'my tester2','test3'=>'my tester3'); $ini->set($test); //no section From 4c6299843042f2e06205aeaa17089b76954ebe0a Mon Sep 17 00:00:00 2001 From: Alfred Tchondjo Date: Sun, 23 Sep 2018 07:52:24 +0200 Subject: [PATCH 10/14] Update ConfigManager.php --- ConfigManager.php | 1 + 1 file changed, 1 insertion(+) diff --git a/ConfigManager.php b/ConfigManager.php index 9d93904..b3d1cf6 100644 --- a/ConfigManager.php +++ b/ConfigManager.php @@ -9,6 +9,7 @@ */ class ConfigManager { + const PHP_TAB = "\t"; /** * Chemin complet du fichier de configuration */ From fd2762d6ef7289ae00a6e2d174d94c4190859400 Mon Sep 17 00:00:00 2001 From: Alfred Tchondjo Date: Sun, 23 Sep 2018 07:58:54 +0200 Subject: [PATCH 11/14] Update ConfigManager.php --- ConfigManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ConfigManager.php b/ConfigManager.php index b3d1cf6..b86ec9b 100644 --- a/ConfigManager.php +++ b/ConfigManager.php @@ -216,7 +216,7 @@ private function configureOptions($file,$location=null){ $Options['driver'] = strtoupper(pathinfo($Options['filename'], PATHINFO_EXTENSION)); else $Options['filename']= $Options['filename'].'.'.strtolower($default['driver']); - if(!in_array($Options['driver'],$this->$availableDrivers)) + if(!in_array($Options['driver'],$this->availableDrivers)) throw new Exception('ERROR: driver "'.$Options['driver'].'" not supported'); $this->Options = array_merge($default,$Options); return $this->Options; From 73d5e0ec03a26d371a4031870040e7a63bd7ca8e Mon Sep 17 00:00:00 2001 From: Alfred Tchondjo Date: Sun, 23 Sep 2018 09:54:46 +0200 Subject: [PATCH 12/14] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ccb0c98..76f189c 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ Iriven PHP ConfigManager ======= [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XDCFPNTKUC4TU) [![Build Status](https://travis-ci.org/iriven/ConfigManager.svg?branch=master)](https://travis-ci.org/iriven/ConfigManager) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/iriven/ConfigManager/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/iriven/ConfigManager/?branch=master) [![Code Intelligence Status](https://scrutinizer-ci.com/g/iriven/ConfigManager/badges/code-intelligence.svg?b=master)](https://scrutinizer-ci.com/code-intelligence) >Iriven Php ConfigManager est un composant / package stand alone, developpé pour manipuler facilement From 549bf7eee47fc35ee0ee5d809f47d56c582495b7 Mon Sep 17 00:00:00 2001 From: Alfred Tchondjo Date: Sun, 23 Sep 2018 09:56:18 +0200 Subject: [PATCH 13/14] Update ConfigManager.php --- ConfigManager.php | 128 ++++++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 61 deletions(-) diff --git a/ConfigManager.php b/ConfigManager.php index b86ec9b..0a965fa 100644 --- a/ConfigManager.php +++ b/ConfigManager.php @@ -1,36 +1,36 @@ configureOptions($filename,$location); $this->parseConfiguration($this->Options); - return $this; } catch(Exception $a) { trigger_error($a->getMessage(),E_USER_ERROR); } + return $this; } - /** + + /** * @param $section * @param $item * @return array|bool|mixed @@ -80,15 +81,14 @@ public function get($section=null, $item=null) if(!isset($this->Config[$section][$item])) return false; return $this->Config[$section][$item]; } - - /** + /** * @param $section * @param $item * @param $value * @return bool */ public function set($section,$item=null,$value=null) - { + { ob_start(); $numarg = func_num_args(); $arguments=func_get_args(); @@ -96,8 +96,8 @@ public function set($section,$item=null,$value=null) { case 1: if(!is_array($arguments[0])) return false; - $item=array_change_key_case($arguments[0], CASE_LOWER); $section=null; $value=null; - break; + $item=array_change_key_case($arguments[0], CASE_LOWER); $section=null; $value=null; + break; case 2: if(is_array($arguments[0])) return false; $_arg = strtolower(trim($arguments[0])); @@ -141,7 +141,7 @@ public function set($section,$item=null,$value=null) ob_end_clean(); return $re; } -/** + /** * @param $section * @param $item * @return bool @@ -172,7 +172,7 @@ public function del($section, $item=null) if($sectionSize>1) unset($this->Config[$section][$item]); else unset($this->Config[$section]); } - } + } } else { @@ -191,10 +191,12 @@ public function del($section, $item=null) } return $this->Save(); } + /** * @param $file * @param $location - * @return array|bool + * @return array + * @throws Exception */ private function configureOptions($file,$location=null){ if(!is_string($file) or ($location and !is_string($location))) @@ -216,15 +218,16 @@ private function configureOptions($file,$location=null){ $Options['driver'] = strtoupper(pathinfo($Options['filename'], PATHINFO_EXTENSION)); else $Options['filename']= $Options['filename'].'.'.strtolower($default['driver']); - if(!in_array($Options['driver'],$this->availableDrivers)) + if(!in_array($Options['driver'],$this->availableDrivers)) throw new Exception('ERROR: driver "'.$Options['driver'].'" not supported'); - $this->Options = array_merge($default,$Options); + $this->Options = array_merge($default,$Options); return $this->Options; } + /** * @param $path * @param $relativeTo - * @return string + * @return bool|string */ private function normalize($path, $relativeTo = null) { $path = rtrim(preg_replace('#[/\\\\]+#', DIRECTORY_SEPARATOR, $path), DIRECTORY_SEPARATOR); @@ -250,13 +253,14 @@ private function normalize($path, $relativeTo = null) { } return $path; } - /** + + /** * @param array $options - * @return mixed + * @return array|bool|mixed */ + private function parseConfiguration($options=[]) { - try { $this->targetFile = $this->normalize($options['directory'].DIRECTORY_SEPARATOR.$options['filename']); if(!file_exists($this->targetFile)) @@ -284,48 +288,50 @@ private function parseConfiguration($options=[]) } return $this->Config; } -/** + + /** * @return bool */ - private function Save() + private function Save() { - if( !is_writeable( $this->targetFile ) ) @chmod($this->targetFile,0775); - $content = null; - switch($this->Options['driver']) - { - case 'JSON': - $content .= json_encode(serialize($this->Config)); - break; - case 'INI': - $content .= '; @file generator: Iriven France Php "'.get_class($this).'" Class'.PHP_EOL; - $content .= '; @Last Update: '.date('Y-m-d H:i:s').PHP_EOL; - $content .= PHP_EOL; - foreach($this->Config as $section => $array) - { - is_array($array) or $array = array($array); - $content .= '[' . $section . ']'.PHP_EOL; - foreach( $array as $key => $value ) - $content .= PHP_TAB.$key.' = '.$value.PHP_EOL; + try { + $content = null; + switch($this->Options['driver']) + { + case 'JSON': + $content .= json_encode(serialize($this->Config)); + break; + case 'INI': + $content .= '; @file generator: Iriven France Php "'.get_class($this).'" Class'.PHP_EOL; + $content .= '; @Last Update: '.date('Y-m-d H:i:s').PHP_EOL; $content .= PHP_EOL; - } - break; - case 'YML': - $content .= yaml_emit ($this->Config, YAML_UTF8_ENCODING , YAML_LN_BREAK ); - break; - default: - $content .= 'Config, true) . ';'; - $content = preg_replace('/array\s+\(/', '[', $content); - $content = preg_replace('/,(\s+)\)/', '$1]', $content); - break; + foreach($this->Config as $section => $array) + { + is_array($array) or $array = array($array); + $content .= '[' . $section . ']'.PHP_EOL; + foreach( $array as $key => $value ) + $content .= $key.' = '.$value.PHP_EOL; + $content .= PHP_EOL; + } + break; + case 'YML': + $content .= yaml_emit ($this->Config, YAML_UTF8_ENCODING , YAML_LN_BREAK ); + break; + default: + $content .= 'Config, true) . ';'; + $content = preg_replace('/array\s+\(/', '[', $content); + $content = preg_replace('/,(\s+)\)/', '$1]', $content); + break; + } + file_put_contents($this->targetFile, $content, LOCK_EX); } - file_put_contents($this->targetFile, $content, LOCK_EX); - @chmod($this->targetFile,0644); + catch (Exception $e) + { trigger_error($e->getMessage(),E_USER_ERROR);} return true; } /** * fin de la classe */ - } From 92c3b96918a0a1c48b0ff4dc1f7b7358f75b37fb Mon Sep 17 00:00:00 2001 From: Alfred Tchondjo Date: Sun, 23 Sep 2018 10:00:38 +0200 Subject: [PATCH 14/14] Create .scrutinizer.yml --- .scrutinizer.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .scrutinizer.yml diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..eac82c5 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,21 @@ +build: + nodes: + analysis: + project_setup: + override: + - 'true' + tests: + override: + - php-scrutinizer-run + - + command: phpcs-run + use_website_config: true + tests: true +checks: + php: true +coding_style: + php: + indentation: + general: + size: 2 +filter: { }