Download the PHP package mention/kebab without Composer
On this page you can find all versions of the php package mention/kebab. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mention/kebab
More information about mention/kebab
Files in mention/kebab
Package kebab
Short Description Wrappers around the PHP standard library focused on safety and testability
License MIT
Informations about the package kebab
Kebab 🌮
Kebab is a collection of safety wrappers and testing utilities around a few functions of the PHP standard library. It's so useful that we wanted to use it everywhere, including our personal projects. So we couldn't keep it for ourselves.
Install
Goals
The goals of this package are to:
- Provide wrappers that are safe by default (by throwing exceptions on error)
- Provide wrappers with better APIs
- Make static analyzers happy
- Make testing easier
Some functions in the PHP standard library have a notoriously bad API. Take for example json_decode()
: If returns null
if there was an error, or if the JSON string was the NULL
literal. The package provides sane wrappers that automatically check for errors and throw exceptions on failure. The package also provides a wrapper for less broken functions like file_get_contents()
, because throwing exceptions on errors is useful.
The wrappers do not only check for errors, they also try to improve the API. For instance, json_decode()
is declined in two variants: JsonUtils::decodeArray()
and JsonUtils::decodeObject()
.
All wrappers have static, single return types, to make static analyzers happy. For example, there is Clock::microtimeFloat()
and Clock::microtimeString()
instead of a single function returning one of two possible types.
Finally, the package provides some tools to make testing easier, such as the Clock
class that allows to fake the system time during tests.
Overview
Clock
Clock wraps time()
, microtime()
, sleep()
, usleep()
in a way that allows these functions to return a fake time during tests (and the system time otherwise).
Example:
Before calling enableMocking()
, Clock
methods return the true system time, and sleep functions actually pause the program, as expected. After calling enableMocking()
, a fake time is returned instead, and sleep functions advance the fake time without actually pausing the program.
This is heavily inspired by Symfony's ClockMock
class.
Date\DateUtils
DateUtils
provides a few date creation methods. The class uses Clock
to get the system time, so its results can be controlled and predicted in tests.
File\FileUtils
This class provides a few file functions that throw an exception in case of failure.
Json\JsonUtils
This class provides a few JSON functions that throw an exception in case of failure, with a slightly improved interface.
Log\LogUtils
The method LogUtils::truncate()
can be used to prevent logging excessively long values. By default, it truncates the given string to 255 bytes. Truncating can be disabled by setting the NO_TRUNCATE_LOG
environment variable to 1
.
Pcre\PcreUtils
This class provides PCRE/preg wrappers with a better API:
- Throws exceptions in case of error (invalid argument, invalid regex, ...)
- Return static, single types
String replacement
Callback replacement
Filter replacement
Other methods
Authors
The Mention team and contributors