Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yulonghu/sg
A Simple PHP Superglobals Management
https://github.com/yulonghu/sg
c php php5 php5-extension php7 php7-extension phpextension
Last synced: 26 days ago
JSON representation
A Simple PHP Superglobals Management
- Host: GitHub
- URL: https://github.com/yulonghu/sg
- Owner: yulonghu
- License: other
- Created: 2019-03-19T06:47:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-08-22T10:29:38.000Z (about 5 years ago)
- Last Synced: 2024-09-29T19:21:22.375Z (about 1 month ago)
- Topics: c, php, php5, php5-extension, php7, php7-extension, phpextension
- Language: C
- Homepage:
- Size: 81.1 KB
- Stars: 124
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SG - PHP Syntax Sugar Extension
[![Build Status](https://travis-ci.org/yulonghu/sg.svg?branch=master)](https://travis-ci.org/yulonghu/sg)
[中文文档](https://github.com/yulonghu/sg/blob/master/README_ZH.md) | English Document
### Table of Contents
* [Introduction](#introduction)
* [Features](#features)
* [Install](#install)
* [Supported Version](#supported-version)
* [DownLoad](#download)
* [Compile SG in Linux](#compile-sg-in-linux)
* [Add the follow information to your php.ini](#add-the-follow-information-to-your-phpini)
* [Help Manual](#help-manual)
* [API](#api)
* [global $variable](#global-variable)
* [Static Methods](#static-methods)
* [Inis(php.ini)](#inisphpini)
* [Hash Map](#hash-map)
* [Example](#example)
* [global $variable](#global-variable-1)
* [sg.global_level = 1](#sgglobal_level--1)
* [sg.global_level = 0](#sgglobal_level--0)
* [sg.func_name](#sgfunc_name)
* [Static Methods](#static-methods-1)
* [sg::get/set/has/del()](#sggetsethasdel)
* [array sg::all(void)](#array-sgallvoid)
* [sg.func_name](#sgfunc_name-1)
* [License](#license)### Introduction
[SG](https://github.com/yulonghu/sg) Full name [Superglobals](http://php.net/manual/en/language.variables.superglobals.php), References all variables available in global scope, SG has extended a new way to manage PHP superglobals variables, Make the management of PHP superglobals variables simple and unified.
These superglobal variables managed by SG are: $_SERVER, $_GET, $_POST, $_FILES, $_COOKIE, $_SESSION, $_REQUEST, $_ENV.
The version v3.0.1 support read raw data from the request body. In the case of POST requests.
Very important point: it is very simple.
### Features
- Simple, Fast, Lightweight
- Access PHP superglobals zero-copy, Synchronously update PHP Superglobals variables
- Support custom call function name, Default call [PHP trim](http://php.net/manual/en/function.trim.php)
- Solve the problem of undefined series when using PHP Superglobals variables (Undefined variable, Undefined offset)
- Use static function method, Replace the PHP array dimension with a decimal point
- Use global statement, Replace the PHP array dimension with a underline
- Support for global $variable the option configuration, Default level one lookup
- Support for read raw data from the POST requests## Install
### Supported Version
- PHP 5.4 +
- PHP 7.0 +### DownLoad
```
git clone https://github.com/yulonghu/sg.git
```### Compile SG in Linux
```
$ /path/to/php/bin/phpize
$ ./configure --with-php-config=/path/to/php/bin/php-config
$ make && make install
```#### Add the follow information to your php.ini
```ini
extension=sg.so[sg]
sg.enable = On
```Restart the php-fpm.
## Help Manual
### API
#### global $variable
```php
global $g_key, $p_key, $c_key, $s_key, $f_key, $n_key, $e_key, $r_key
```#### Static Methods
```php
array sg::all(void)
mixed sg::get(string $key [, mixed $default_value = null])
bool sg::set(string $key, mixed $value)
bool sg::has(string $key)
bool sg::del(string $key [, mixed $... ])
mixed sg::getRaw([mixed $default_value = null [, int $maxlen]])
mixed sg::getCache(string $key [, mixed $default_value = null])
```### Inis(php.ini)
| Options | Permission | Type | Default | Desc |
|---|---|---|---|---|
|sg.enable|PHP_INI_SYSTEM|bool|0| 0 Trun-Off 1 Turn-On|
|sg.global_level|PHP_INI_SYSTEM|bool|1| 1 Limit Level 0 Unlimited Level|
|sg.func_name|PHP_INI_ALL|char|trim| [PHP trim](http://php.net/manual/en/function.trim.php), Support for custom function|### Hash Map
- When management PHP sessions (MapKey = n), First call the function session_start()|PHP Predefined Superglobals|SG Key|global statement| Method Example|
| ------ | ------ | ------ | ------ |
|$GLOBALS|-|-|sg::all()|
|$_SERVER|s|global $s|sg::get/set/has/del('s')|
|$_GET|g|global $g|sg::get/set/has/del('g')|
|$_POST|p|global $p|sg::get/set/has/del('p')|
|$_FILES|f|global $f|sg::get/set/has/del('f')|
|$_COOKIE|c|global $c|sg::get/set/has/del('c')|
|$_SESSION|n|global $n|sg::get/set/has/del('n')|
|$_REQUEST|r|global $r|sg::get/set/has/del('r')|
|$_ENV|e|global $e|sg::get/set/has/del('e')|### Example
#### global $variable
##### sg.global_level = 1```php