mirror of
https://codeberg.org/vlw/php-globalsnapshot.git
synced 2025-09-13 20:03:41 +02:00
Compare commits
2 commits
80cb5d17b2
...
4bb9e4a08c
Author | SHA1 | Date | |
---|---|---|---|
4bb9e4a08c | |||
0db14c2d0b |
3 changed files with 17 additions and 15 deletions
|
@ -1,6 +1,8 @@
|
||||||
# php-globalsnapshot
|
# php-globalsnapshot
|
||||||
|
|
||||||
Capture the current state of all [PHP superglobal variables](https://www.php.net/manual/en/language.variables.superglobals.php); which can then be restored to that state at a later time.
|
Capture the current state of all [PHP superglobal variables](https://www.php.net/manual/en/language.variables.superglobals.php) - which can then be restored to the state of capture at a later time.
|
||||||
|
|
||||||
|
**Supports PHP 8.1+**
|
||||||
|
|
||||||
Example use:
|
Example use:
|
||||||
```php
|
```php
|
||||||
|
@ -24,12 +26,12 @@ echo $_ENV["hello"]; // echo: "world"
|
||||||
|
|
||||||
1. Install with composer
|
1. Install with composer
|
||||||
```
|
```
|
||||||
composer install victorwesterlund/globalsnapshot
|
composer install vlw/globalsnapshot
|
||||||
```
|
```
|
||||||
|
|
||||||
2. `use` in your project
|
2. `use` in your project
|
||||||
```php
|
```php
|
||||||
use victorwesterlund\GlobalSnapshot;
|
use vlw\GlobalSnapshot;
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Capture current superglobals with `capture()`
|
3. Capture current superglobals with `capture()`
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
{
|
{
|
||||||
"name": "victorwesterlund/globalsnapshot",
|
"name": "vlw/globalsnapshot",
|
||||||
"description": "Capture and restore the state of all PHP superglobals.",
|
"description": "Capture and restore the state of all PHP superglobals.",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"license": "Unlicense",
|
"license": "Unlicense",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Victor Westerlund",
|
"name": "Victor Westerlund",
|
||||||
"email": "victor.vesterlund@gmail.com"
|
"email": "victor@vlw.se"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"victorwesterlund\\": "src/"
|
"vlw\\": "src/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace victorwesterlund;
|
namespace vlw;
|
||||||
|
|
||||||
// Capture the current state of all superglobals.
|
// Capture the current state of all superglobals.
|
||||||
// This will save a copy of all keys and values and any changes made to the superglobals
|
// This will save a copy of all keys and values and any changes made to the superglobals
|
||||||
// can be restored to this point in time by calling $this->restore();
|
// can be restored to this point in time by calling $this->restore();
|
||||||
class GlobalSnapshot {
|
class GlobalSnapshot {
|
||||||
// Declare all PHP superglobals
|
// Declare all PHP superglobals
|
||||||
private array $_ENV;
|
private readonly array $_ENV;
|
||||||
private array $_GET;
|
private readonly array $_GET;
|
||||||
private array $_POST;
|
private readonly array $_POST;
|
||||||
private array $_FILES;
|
private readonly array $_FILES;
|
||||||
private array $_SERVER;
|
private readonly array $_SERVER;
|
||||||
private array $_COOKIE;
|
private readonly array $_COOKIE;
|
||||||
private array $_REQUEST;
|
private readonly array $_REQUEST;
|
||||||
private array $_SESSION;
|
private readonly array $_SESSION;
|
||||||
|
|
||||||
// Declare additional PHP globals (for PHP 8.0+ compatability)
|
// Declare additional PHP globals (for PHP 8.0+ compatability)
|
||||||
// These will not be captured, or altered by GlobalSnapshot
|
// These will not be captured, or altered by GlobalSnapshot
|
||||||
|
|
Loading…
Add table
Reference in a new issue