Compare commits

..

No commits in common. "4bb9e4a08cccc3a64f5a2be2ff1c646b10975ce3" and "80cb5d17b2f6228e174edb0853b2c39c5d6dac21" have entirely different histories.

3 changed files with 15 additions and 17 deletions

View file

@ -1,8 +1,6 @@
# 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 the state of capture at a later time.
**Supports PHP 8.1+**
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.
Example use:
```php
@ -26,12 +24,12 @@ echo $_ENV["hello"]; // echo: "world"
1. Install with composer
```
composer install vlw/globalsnapshot
composer install victorwesterlund/globalsnapshot
```
2. `use` in your project
```php
use vlw\GlobalSnapshot;
use victorwesterlund\GlobalSnapshot;
```
3. Capture current superglobals with `capture()`

View file

@ -1,18 +1,18 @@
{
"name": "vlw/globalsnapshot",
"name": "victorwesterlund/globalsnapshot",
"description": "Capture and restore the state of all PHP superglobals.",
"type": "library",
"license": "Unlicense",
"authors": [
{
"name": "Victor Westerlund",
"email": "victor@vlw.se"
"email": "victor.vesterlund@gmail.com"
}
],
"minimum-stability": "dev",
"autoload": {
"psr-4": {
"vlw\\": "src/"
"victorwesterlund\\": "src/"
}
}
}

View file

@ -1,20 +1,20 @@
<?php
namespace vlw;
namespace victorwesterlund;
// Capture the current state of all 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();
class GlobalSnapshot {
// Declare all PHP superglobals
private readonly array $_ENV;
private readonly array $_GET;
private readonly array $_POST;
private readonly array $_FILES;
private readonly array $_SERVER;
private readonly array $_COOKIE;
private readonly array $_REQUEST;
private readonly array $_SESSION;
private array $_ENV;
private array $_GET;
private array $_POST;
private array $_FILES;
private array $_SERVER;
private array $_COOKIE;
private array $_REQUEST;
private array $_SESSION;
// Declare additional PHP globals (for PHP 8.0+ compatability)
// These will not be captured, or altered by GlobalSnapshot