Compare commits

...

2 commits

Author SHA1 Message Date
vlw
4bb9e4a08c chore: add PHP 8.1 readonly properties (#4)
Reviewed-on: https://codeberg.org/vlw/php-globalsnapshot/pulls/4
Co-authored-by: vlw <victor@vlw.se>
Co-committed-by: vlw <victor@vlw.se>
2024-11-23 09:23:42 +00:00
vlw
0db14c2d0b chore: change project namespace (#3)
Change namespace from `victorwesterlund/globalsnapshot` to `vlw/globalsnapshot`.

I will also deprecate the [existing Packagist listing](https://packagist.org/packages/victorwesterlund/globalsnapshot) in favor of a new one using the new namespace.

Reviewed-on: https://codeberg.org/vlw/php-globalsnapshot/pulls/3
Co-authored-by: vlw <victor@vlw.se>
Co-committed-by: vlw <victor@vlw.se>
2024-11-23 09:23:17 +00:00
3 changed files with 17 additions and 15 deletions

View file

@ -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()`

View file

@ -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/"
} }
} }
} }

View file

@ -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