zenigata / utility
Requires
- php: ^8.2 || ^8.3 || ^8.4
- psr/cache: ^3.0
- psr/container: ^2.0
- psr/http-factory: ^1.1
- psr/http-server-middleware: ^1.0
- psr/log: ^3.0
- psr/simple-cache: ^3.0
Requires (Dev)
- mikey179/vfsstream: ^1.6
- nyholm/psr7: ^1.8
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5 || ^12.0
- symfony/cache: ^7.3
README
⚠️ This project is in an early development stage. Feedback and contributions are welcome!
Lightweight collection of PHP utility classes to simplify common development tasks.
The library provides small, focused helpers and traits that reduce boilerplate when working with PSR standards, configuration files, reflection, and more. Each component is designed to be framework-agnostic, minimal, and easy to integrate into any PHP project.
Requirements
- PHP >= 8.2
- Composer
Installation
composer require zenigata/utility
Overview
Awareness
Traits that provide awareness for common dependencies, allowing classes to receive services such as containers, factories, or debug state without requiring dependency injection.
ContainerAwareTraitprovides access to a PSR-11 container and helper methods for retrieving services.DebugAwareTraitadds a configurable debug flag to enable or disable development features.ResponseFactoryAwareTraitprovides access to a PSR-17 response factory for creating HTTP responses.StreamFactoryAwareTraitprovides access to a PSR-17 stream factory for creating HTTP streams.
Helper
Collection of small utilities that simplify common tasks such as configuration loading, caching interoperability, file generation, and more.
CacheHelperfor interacting with both PSR-6 and PSR-16 caches with a unified API. It hides the differences between the two standards, so you can use the same methods regardless of the underlying cache implementation.ConfigLoaderfor lazily loading PHP configuration files using generators, ensuring minimal memory usage when working with multiple config files.ReflectionResolverfor instantiating classes with empty constructors using PHP reflection, useful when no dependency injection container is available.StubRendererfor generating files from stub templates with placeholder replacement and automatic directory creation.
Testing
Simple test doubles designed to simplify unit testing when full implementations are unnecessary.
FakeContainer: in-memory implementation of PSR-11ContainerInterface, useful for testing container-aware classes and manually registering dependencies.FakeLogger: lightweight PSR-3 logger that records log messages in memory, allowing tests to inspect and assert logged output.FakeMiddleware: configurable PSR-15 middleware that can optionally return a predefined response or execute a callback during processing, making it easy to test middleware pipelines.FakeRequestHandler: simple PSR-15 request handler returning a predefined response, with optional callback execution to observe request handling during tests.
Contributing
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
Keep the implementation minimal, focused, and well-documented, making sure to update tests accordingly.
See CONTRIBUTING for more information.
License
This library is licensed under the MIT license. See LICENSE for more information.