https://github.com/petrknap/php-shorts
Set of short helpers
https://github.com/petrknap/php-shorts
array helper markdown php php-library phpunit
Last synced: 28 days ago
JSON representation
Set of short helpers
- Host: GitHub
- URL: https://github.com/petrknap/php-shorts
- Owner: petrknap
- License: lgpl-3.0
- Created: 2023-10-14T09:34:50.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-05T18:02:30.000Z (6 months ago)
- Last Synced: 2025-04-12T08:05:33.191Z (28 days ago)
- Topics: array, helper, markdown, php, php-library, phpunit
- Language: PHP
- Homepage:
- Size: 49.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING
- Authors: AUTHORS
Awesome Lists containing this project
README
# Set of short PHP helpers
* `Exception`s
* [`CouldNotProcessData` template](#exceptioncouldnotprocessdata-template)
* [`NotImplemented`](#exceptionnotimplemented)
* [`HasRequirements` trait](#hasrequirements-trait)## [`Exception\CouldNotProcessData` template](./src/Exception/CouldNotProcessData.php)
Template for an exception that indicates that the data could not be processed.
```php
namespace PetrKnap\Shorts;interface ImageResizerException extends \Throwable {}
/** @extends Exception\CouldNotProcessData */
final class ImageResizerCouldNotResizeImage extends Exception\CouldNotProcessData implements ImageResizerException {}final class ImageResizer {
public function resize(string $image) {
throw new ImageResizerCouldNotResizeImage(__METHOD__, $image);
}
}
```## [`Exception\NotImplemented`](./src/Exception/NotImplemented.php)
Simple exception for prototyping purposes.
```php
namespace PetrKnap\Shorts;final class StringablePrototype implements \Stringable {
public function __toString(): string {
Exception\NotImplemented::throw(__METHOD__);
}
}
```## [`HasRequirements` trait](./src/HasRequirements.php)
Simple trait to check if requirements of your code are fulfilled.
```php
namespace PetrKnap\Shorts;final class ServiceWithRequirements {
use HasRequirements;
public function __construct() {
self::checkRequirements(functions: ['required_function']);
}public function do(): void {
required_function();
}
}
```It should not replace [Composers](https://getcomposer.org/) [`require`s](https://getcomposer.org/doc/04-schema.md#require),
but it could improve them and check [`suggest`s](https://getcomposer.org/doc/04-schema.md#suggest).---
Run `composer require petrknap/shorts` to install it.
You can [support this project via donation](https://petrknap.github.io/donate.html).
The project is licensed under [the terms of the `LGPL-3.0-or-later`](./COPYING.LESSER).