Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shirokovnv/psr-ex
PSR example implementations
https://github.com/shirokovnv/psr-ex
psr-11 psr-14 psr-3
Last synced: 1 day ago
JSON representation
PSR example implementations
- Host: GitHub
- URL: https://github.com/shirokovnv/psr-ex
- Owner: shirokovnv
- License: mit
- Created: 2023-09-11T07:11:02.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2023-10-15T23:11:19.000Z (about 1 year ago)
- Last Synced: 2023-10-17T03:39:36.900Z (about 1 year ago)
- Topics: psr-11, psr-14, psr-3
- Language: PHP
- Homepage:
- Size: 40 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# PSR Examples
![ci.yml][link-ci]
[PSR-3][link-psr3] logger implementation
[PSR-11][link-psr11] container implementation
[PSR-14][link-psr14] event dispatcher implementation
## Usage
### Logger
```php
use Shirokovnv\PsrEx\Log\Formatter\BaseFormatter;
use Shirokovnv\PsrEx\Log\Handler\FileHandler;
use Shirokovnv\PsrEx\Log\Logger;// Example logging to the file
$logger = new Logger(new FileHandler('log.txt'), new BaseFormatter());
$logger->log(\Psr\Log\LogLevel::DEBUG, 'debug message', [ 'context' => 'some context' ]);
```### Container
```php
use Shirokovnv\PsrEx\Container\Container;
$container = new Container();
// Put into the container
$container->set(ServiceInterface::class, Service::class);// Get from the container
// assert instanceOf Service::class
$instance = $container->get(ServiceInterface::class);// Check existence
if ($container->has(ServiceInterface::class)) {
// do stuff
}
```### Events
```php
use Shirokovnv\PsrEx\Event\EventDispatcher;
use Shirokovnv\PsrEx\Event\ListenerProvider;$event = new MyEvent();
$listener = new MyEventListener();$listenerProvider = new ListenerProvider();
$eventDispatcher = new EventDispatcher($listenerProvider);// Bind event and listener
$listenerProvider->addListener($event::class, $listener);// Dispatch
$eventDispatcher->dispatch($event);// Clear
$listenerProvider->clearListeners();
```## Testing
``` bash
$ composer test
```## License
MIT. Please see the [license file](LICENSE.md) for more information.
[link-ci]: https://github.com/shirokovnv/psr-ex/actions/workflows/ci.yml/badge.svg
[link-psr3]: https://www.php-fig.org/psr/psr-3/
[link-psr11]: https://www.php-fig.org/psr/psr-11/
[link-psr14]: https://www.php-fig.org/psr/psr-14/
[link-author]: https://github.com/shirokovnv