Download the PHP package azjezz/typed without Composer
On this page you can find all versions of the php package azjezz/typed. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package typed
Typed
This library allows you to create typed variables in PHP 7.4 +
Composer installation :
Usage Example :
callable => func
, array => { arr
, keyset
, vector
, set
}
Since callable
and array
cant be used for function names, instead i have used func
for callable and arr
for array.
keyset
, vector
and set
are just helper to help you create an array of keys ( keyset = arr(array_keys($value))
), an array of values ( vector = arr(array_values($value))
) and an array of unique values ( set = arr(array_unique($value))
).
typed
typed()
is a function to help you create a typed variables based on the type of the passed variable, currently it supports string
, int
, float
, bool
, object
and iterable
. it was suggested by @mikesherov on twitter.
purge
, clean
, delete
and c
As mentioned here and here, memory leak is a huge issue here, if a specific function created a typed variable, the variable will still exist inside the repository even after execution, for this i made some helper functions that allow you to remove variables from the repository.
Typed\purge()
will delete every reference registered in the repository, you can call this function at the end of every request/response cycle in a web application per example.Typed\clean(string $namespace = 'default')
this function will delete every reference to a typed variable in a specific namespace as shown in the example above, its recommended to use a unique namespace every time you use typed variables and callclean()
to ensure there's no memory leak.Typed\filter(mixed $value, string $namespace = 'default')
this function will delete the every created reference to a typed variable with the given value in a specific namespace.-
Typed\delete(mixed $value, string $namespace = 'default')
similar to whatTyped\filter
does, this function allows you to delete the last created reference to a typed variable with the given value in a specific namespace. example : Typed\c
this function accepted a callable that take no arguments, the callable will be called insidec
( container ) and all the assigned typed variables in the time of the call would be deleted afterward, this makes it easier to ensure that function calls don't cause any memory leak. example :
More :
A cool PSR-15 Middleware to delete all typed variables created inside the next middleware/handler
TODO :
- add
nullable*
functions.