|
| 1 | +# Hawkbit Persistence |
| 2 | + |
| 3 | +[![Latest Version on Packagist][ico-version]][link-packagist] |
| 4 | +[![Software License][ico-license]](LICENSE.md) |
| 5 | +[![Build Status][ico-travis]][link-travis] |
| 6 | +[![Total Downloads][ico-downloads]][link-downloads] |
| 7 | +[![Coverage Status][ico-coveralls]][link-coveralls] |
| 8 | + |
| 9 | +Persistence layer for Hawkbit PSR-7 Micro PHP framework. |
| 10 | +Hawkbit Persitence uses factories of `dasprid/container-interop-doctrine` and wraps them with in a PersistenceService |
| 11 | + |
| 12 | +## Install |
| 13 | + |
| 14 | +### Using Composer |
| 15 | + |
| 16 | +Hawkbit Persistence is available on [Packagist][link-packagist] and can be installed using [Composer](https://getcomposer.org/). This can be done by running the following command or by updating your `composer.json` file. |
| 17 | + |
| 18 | +```bash |
| 19 | +composer require hawkbit/persistence |
| 20 | +``` |
| 21 | + |
| 22 | +composer.json |
| 23 | + |
| 24 | +```javascript |
| 25 | +{ |
| 26 | + "require": { |
| 27 | + "hawkbit/persistence": "~1.0" |
| 28 | + } |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +Be sure to also include your Composer autoload file in your project: |
| 33 | + |
| 34 | +```php |
| 35 | +<?php |
| 36 | + |
| 37 | +require __DIR__ . '/vendor/autoload.php'; |
| 38 | +``` |
| 39 | + |
| 40 | +### Downloading .zip file |
| 41 | + |
| 42 | +This project is also available for download as a `.zip` file on GitHub. Visit the [releases page](https://github.com/hawkbit/persistence/releases), select the version you want, and click the "Source code (zip)" download button. |
| 43 | + |
| 44 | +### Requirements |
| 45 | + |
| 46 | +The following versions of PHP are supported by this version. |
| 47 | + |
| 48 | +* PHP 5.5 |
| 49 | +* PHP 5.6 |
| 50 | +* PHP 7.0 |
| 51 | +* HHVM |
| 52 | + |
| 53 | +## Setup |
| 54 | + |
| 55 | +Setup with an existing application configuration (we refer to [tests/assets/config.php](tests/assets/config.php)) |
| 56 | + |
| 57 | +```php |
| 58 | +<?php |
| 59 | + |
| 60 | +use \Hawkbit\Application; |
| 61 | +use \Hawkbit\Persistence\PersistenceService; |
| 62 | +use \Hawkbit\Persistence\PersistenceServiceProvider; |
| 63 | + |
| 64 | +$app = new Application(require_once __DIR__ . '/config.php'); |
| 65 | + |
| 66 | +$entityFactoryClass = \ContainerInteropDoctrine\EntityManagerFactory::class; |
| 67 | + |
| 68 | +$persistenceService = new PersistenceService([ |
| 69 | + PersistenceService::resolveFactoryAlias($entityFactoryClass) => [$entityFactoryClass] |
| 70 | +], $app); |
| 71 | + |
| 72 | +$app->register(new PersistenceServiceProvider($persistenceService)); |
| 73 | +``` |
| 74 | + |
| 75 | +## Examples |
| 76 | + |
| 77 | +### Full configuration |
| 78 | + |
| 79 | +A full configuration is available on [DASPRiD/container-interop-doctrine/example/full-config.php](https://github.com/DASPRiD/container-interop-doctrine/blob/master/example/full-config.php). |
| 80 | +Refer to [container-interop-doctrine Documentation](https://github.com/DASPRiD/container-interop-doctrine) for further instructions on factories. |
| 81 | + |
| 82 | +### Persistence from Hawbit Application |
| 83 | + |
| 84 | +```php |
| 85 | +<?php |
| 86 | + |
| 87 | +/** @var \Hawkbit\Persistence\PersistenceServiceInterface $persistence */ |
| 88 | +$persistence = $app[\Hawkbit\Persistence\PersistenceServiceInterface::class]; |
| 89 | + |
| 90 | +$em = $persistence->getEntityManager(); |
| 91 | + |
| 92 | +// or with from specific connection |
| 93 | +$em = $persistence->getEntityManager('connectionname'); |
| 94 | + |
| 95 | +``` |
| 96 | + |
| 97 | +### Persistence in a Hawkbit controller |
| 98 | + |
| 99 | +Access persistence service in controller. Hawbit is inject classes to controllers by default. |
| 100 | + |
| 101 | +```php |
| 102 | +<?php |
| 103 | + |
| 104 | +use \Hawkbit\Persistence\PersistenceServiceInterface; |
| 105 | + |
| 106 | +class MyController{ |
| 107 | + |
| 108 | + /** |
| 109 | + * @var \Hawkbit\Persistence\PersistenceServiceInterface |
| 110 | + */ |
| 111 | + private $persistence = null; |
| 112 | + |
| 113 | + public function __construct(PersistenceServiceInterface $persistence){ |
| 114 | + $this->persistence = $persistence; |
| 115 | + } |
| 116 | + |
| 117 | + public function index(){ |
| 118 | + $em = $this->persistence->getEntityManager(); |
| 119 | + |
| 120 | + // or with from specific connection |
| 121 | + $em = $this->persistence->getEntityManager('connectionname'); |
| 122 | + } |
| 123 | +} |
| 124 | +``` |
| 125 | + |
| 126 | +## Change log |
| 127 | + |
| 128 | +Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. |
| 129 | + |
| 130 | +## Testing |
| 131 | + |
| 132 | +``` bash |
| 133 | +$ composer test |
| 134 | +``` |
| 135 | + |
| 136 | +## Contributing |
| 137 | + |
| 138 | +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. |
| 139 | + |
| 140 | +## Security |
| 141 | + |
| 142 | +If you discover any security related issues, please email <[email protected]> instead of using the issue tracker. |
| 143 | + |
| 144 | +## Credits |
| 145 | + |
| 146 | +- [Marco Bunge](https://github.com/mbunge) |
| 147 | +- [All contributors](https://github.com/hawkbit/persistence/graphs/contributors) |
| 148 | + |
| 149 | +## License |
| 150 | + |
| 151 | +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
| 152 | + |
| 153 | +[ico-version]: https://img.shields.io/packagist/v/hawkbit/persistence.svg?style=flat-square |
| 154 | +[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square |
| 155 | +[ico-travis]: https://img.shields.io/travis/HawkBitPhp/hawkbit-persistence/master.svg?style=flat-square |
| 156 | +[ico-downloads]: https://img.shields.io/packagist/dt/hawkbit/persistence.svg?style=flat-square |
| 157 | +[ico-coveralls]: https://img.shields.io/coveralls/HawkBitPhp/hawkbit-persistence/master.svg?style=flat-square |
| 158 | + |
| 159 | +[link-packagist]: https://packagist.org/packages/hawkbit/hawkbit |
| 160 | +[link-travis]: https://travis-ci.org/HawkBitPhp/hawkbit |
| 161 | +[link-downloads]: https://packagist.org/packages/hawkbit/hawkbit |
| 162 | +[link-author]: https://github.com/mbunge |
| 163 | +[link-contributors]: ../../contributors |
| 164 | +[link-coveralls]: https://coveralls.io/github/HawkBitPhp/hawkbit |
0 commit comments