From 250381f0c7f251fe82116631b00f7a4710f4b256 Mon Sep 17 00:00:00 2001 From: Jawira Date: Fri, 14 Jun 2019 11:22:02 +0200 Subject: [PATCH] Get and set php's options --- .editorconfig | 11 +++++++++ .gitattributes | 13 ++++++++++ .gitignore | 9 ++++--- CHANGELOG.md | 43 +++++++++++++++++++++++++++++++++ LICENSE => LICENSE.md | 1 + README.md | 49 ++++++++++++++++++++++++++++++++++++-- build.xml | 50 +++++++++++++++++++++++++++++++++++++++ composer.json | 21 +++++++++++++++++ phive.xml | 11 +++++++++ src/Settings.php | 55 +++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 256 insertions(+), 7 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 CHANGELOG.md rename LICENSE => LICENSE.md (98%) create mode 100644 build.xml create mode 100644 composer.json create mode 100644 phive.xml create mode 100644 src/Settings.php diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..e950a54 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +;https://EditorConfig.org +;https://github.com/editorconfig/editorconfig/wiki + +root = true + +[*.{yml,yaml,neon,xml,md,json}] +charset = utf-8 +indent_size = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8222a1b --- /dev/null +++ b/.gitattributes @@ -0,0 +1,13 @@ +# https://madewithlove.be/gitattributes/ + +/.editorconfig export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.idea export-ignore +/build.xml export-ignore +/docs export-ignore +/phive.xml export-ignore +/phpunit.xml export-ignore +/phpunit.xml.dist export-ignore +/tests export-ignore + diff --git a/.gitignore b/.gitignore index a67d42b..e429c63 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ -composer.phar +/.idea/ +!/.idea/dictionaries/jawira.xml +/composer.phar /vendor/ - -# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control -# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file -# composer.lock +/composer.lock diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..32d76c9 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,43 @@ +Changelog +========= + +All notable changes to this project will be documented in this file. + + + +Unreleased +---------- + +### Added + +- Set and get php's options + + + + diff --git a/LICENSE b/LICENSE.md similarity index 98% rename from LICENSE rename to LICENSE.md index a41105d..dc1ffc7 100644 --- a/LICENSE +++ b/LICENSE.md @@ -1,4 +1,5 @@ MIT License +=========== Copyright (c) 2019 Jawira Portugal diff --git a/README.md b/README.md index 1dfbf21..a50899d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,47 @@ -# php-ini-settings -Manage your php settings +@todo Project name +================== + + + +Usage +----- + +Set values: + +```php +$ini = new Settings(); +$oldValue = $ini->set('option-name','value'); +``` + +Get values: + +```php +$ini = new Settings(); +$oldValue = $ini->get('option-name'); +``` + +How to install +-------------- + +@todo + +Requirements +------------ + +@todo + +Contributing +------------ + +To contribute to this project please read [CONTRIBUTING.md](./CONTRIBUTING.md) + +License +------- + +This library is licensed under the [MIT license](LICENSE.md). diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..31cd102 --- /dev/null +++ b/build.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..969a4ad --- /dev/null +++ b/composer.json @@ -0,0 +1,21 @@ +{ + "name": "jawira/php-ini-settings", + "description": "Manage your PHP settings", + "type": "library", + "require": { + "php": ">=7.1", + "jawira/skeleton": "^1.9" + }, + "license": "MIT", + "authors": [ + { + "name": "Jawira Portugal", + "email": "dev@tugal.be" + } + ], + "autoload": { + "psr-4": { + "Jawira\\PhpIniSettings\\": "src/" + } + } +} diff --git a/phive.xml b/phive.xml new file mode 100644 index 0000000..26b01f2 --- /dev/null +++ b/phive.xml @@ -0,0 +1,11 @@ + + + + bin + + + + + + + diff --git a/src/Settings.php b/src/Settings.php new file mode 100644 index 0000000..40da29f --- /dev/null +++ b/src/Settings.php @@ -0,0 +1,55 @@ + + */ +class Settings +{ + /** + * Sets the value of a configuration option + * + * Returns the old value on success and null on failure + * + * @see https://www.php.net/manual/en/function.ini-set.php + * + * @param string $varName + * @param string $newValue + * + * @return null|string + */ + public function set(string $varName, string $newValue): ?string + { + $oldValue = ini_set($varName, $newValue); + + return (false === $oldValue) ? $oldValue : null; + } + + /** + * Gets the value of a configuration option + * + * @param string $varName + * + * @return null|string + */ + public function get(string $varName): ?string + { + $value = ini_get($varName); + + return (false === $value) ? $value : null; + } +}