Download the PHP package parable-php/getset without Composer
On this page you can find all versions of the php package parable-php/getset. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download parable-php/getset
More information about parable-php/getset
Files in parable-php/getset
Package getset
Short Description Parable GetSet helps with easily building value sets
License MIT
Homepage https://github.com/parable-php/getset
Informations about the package getset
Parable GetSet
Parable GetSet allows for clean and intuitive handling of global variables such as $_GET
and $_SERVER
using value
collections, in addition to resource objects with their own scope.
The major benefit is dot-notation (key.string
) for nested values, such as $getCollection->get('this.is.nested');
, which will
look in the GetCollection
's stored values for ['this']['is']['nested']
.
Collections always return the requested value or null
by default, allowing the predictable use of null coalescing.
Install
Php 8.0+ and composer are required.
Usage
Assuming a query string like: ?id=345&user[name]=username
:
Would output 345:username
Obviously you can also set values directly:
The Collections
Global Collections
These correspond to their $_NAME
global variables, also found in the super-global $GLOBALS
variable.
CookieCollection
, handles$_COOKIE
data.FilesCollection
, handles$_FILES
data.GetCollection
, handles$_GET
data.PostCollection
, handles$_POST
data.ServerCollection
, handles$_SERVER
data.SessionCollection
, handles$_SESSION
data.
Local Resource Collections
DataCollection
, a generic collection using only a local resource, useful for passing data throughout an application. Think configuration.InputStreamCollection
, to read out an input stream. Can import/parsejson
or query string data.
Your own custom Collections!
You can easily build your own collections by extending the BaseCollection
class and co-opting the easy
dot-notation get/set logic.
API
getAll(): array
- returns all values currently storedgetAllAndClear(): array
- returns all values currently stored and then clears themget(string $key, $default = null): mixed
- returns value by key or$default
if not foundgetAndRemove(string $key): mixed
- returns value by key and then removes it, or throw exception if it doesn't existset(string $key, $value): void
- set a value by keysetMany(array $values): void
- set all values passed one-by-one, overwriting pre-existing valuessetAll(array $values): void
- set all values, overwriting any pre-existing onesremove(string $key): void
- remove by key, if already removed, throwsclear(): void
- removes all valueshas(string $key): bool
- returns whether the passed key (orkey.string
) currently existscount(): int
- returns number of root value items (not all nested values)
Contributing
Any suggestions, bug reports or general feedback is welcome. Use github issues and pull requests, or find me over at devvoh.com.
License
All Parable components are open-source software, licensed under the MIT license.
All versions of getset with dependencies
ext-json Version *