Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Commit

Permalink
Get and set php's options
Browse files Browse the repository at this point in the history
  • Loading branch information
jawira committed Jun 14, 2019
1 parent 934f782 commit 250381f
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 7 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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

9 changes: 4 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Changelog
=========

All notable changes to this project will be documented in this file.

<!--
### Added
### Changed
### Deprecated
### Removed
### Fixed
### Security
-->

Unreleased
----------

### Added

- Set and get php's options



<!---
Guiding Principles
Changelogs are for humans, not machines.
There should be an entry for every single version.
The same types of changes should be grouped.
Versions and sections should be linkable.
The latest version comes first.
The release date of each versions is displayed.
Mention whether you follow Semantic Versioning.
Types of changes
### Added for new features.
### Changed for changes in existing functionality.
### Deprecated for soon-to-be removed features.
### Removed for now removed features.
### Fixed for any bug fixes.
### Security in case of vulnerabilities.
-->
1 change: 1 addition & 0 deletions LICENSE → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
MIT License
===========

Copyright (c) 2019 Jawira Portugal

Expand Down
49 changes: 47 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,47 @@
# php-ini-settings
Manage your php settings
@todo Project name
==================

<!--
BADGES:
https://github.com/php-pds/badges
https://poser.pugx.org/
https://php-eye.com/about#badges
https://phppackages.org/p/jawira/case-converter
-->

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).
50 changes: 50 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" ?>

<project name="PHP ini settings" description="Manage php settings" default="diagnostics">

<defaultexcludes default="true"/><!--Initializing default excludes-->
<defaultexcludes add="**/.idea"/>
<defaultexcludes add="**/.idea/**"/>

<property name="phing.http.proxy" value="${env.http_proxy}"/>

<target name="diagnostics">
<diagnostics/>
</target>

<target name="git:tags" description="List all git tags">
<!--https://stackoverflow.com/a/34239190/4345061-->
<exec executable="git" passthru="true">
<arg value="log"/>
<arg line="--graph --all --decorate --oneline --simplify-by-decoration"/>
</exec>
</target>

<target name="changelog:links" description="Update links in composer.json">
<composer command="require">
<arg value="symplify/changelog-linker"/>
</composer>
<exec executable="vendor/bin/changelog-linker">
<arg value="link"/>
</exec>
<composer command="remove">
<arg value="symplify/changelog-linker"/>
</composer>
</target>

<target name="php:version" description="Get current PHP version">
<exec executable="${php.interpreter}" passthru="true" checkreturn="true">
<arg value="--version"/>
</exec>
</target>

<target name="php:lint" description="Check PHP syntax">
<property name="phplint.dir" value="src" description="Based on pds/skeleton dirs"/>
<phplint haltonfailure="true">
<fileset dir="${phplint.dir}">
<include name="**/*.php"/>
</fileset>
</phplint>
</target>

</project>
21 changes: 21 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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/"
}
}
}
11 changes: 11 additions & 0 deletions phive.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<configuration>
<targetDirectory>bin</targetDirectory>
</configuration>
<phar name="phpunit" version="^7.4.4" installed="7.5.8" location="./bin/phpunit" copy="false"/>
<phar name="phpstan" version="^0.10.5" installed="0.11.5" location="./bin/phpstan" copy="false"/>
<phar name="phing" version="^3.0.0-alpha2" installed="3.0.0-alpha2" location="./bin/phing" copy="false"/>
<phar name="behat/behat" version="^3.3.0" installed="3.3.0" location="./bin/behat" copy="false"/>
<phar name="phpbench" version="^0.16.9" installed="0.16.9" location="./bin/phpbench" copy="false"/>
</phive>
55 changes: 55 additions & 0 deletions src/Settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php declare(strict_types=1);

namespace Jawira\PhpIniSettings;

/**
* Class Settings
*
* This is a wrapper Class to manage `ini` related functions:
*
* - ini_​alter
* - ini_​get_​all
* - ini_​get
* - ini_​restore
* - ini_​set
* - php_​ini_​loaded_​file
* - php_​ini_​scanned_​files
*
* @package Jawira\PhpIniSettings
* @author Jawira Portugal <dev@tugal.be>
*/
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;
}
}

0 comments on commit 250381f

Please sign in to comment.