Skip to content

Commit 63a76f2

Browse files
author
Marco Bunge
committed
Prepare release
1 parent 79a2434 commit 63a76f2

File tree

8 files changed

+114
-103
lines changed

8 files changed

+114
-103
lines changed

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
# Hawkbit Persistence Changelog
1+
# Hawkbit Database Changelog
22

33
## 1.0.0
44

55
### Added
66

7-
- Add persistence service, service provider and documentation
7+
- Add mapper
8+
- Add connection service
9+
- Add gateway
10+
- Add hydrator
11+
- Add mapper
12+
- Add identity map
13+
- Add data mapper
14+
- Add unit of work
15+
816

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Contributions are **welcome** and will be fully **credited**.
44

5-
We accept contributions via Pull Requests on [Github](https://github.com/HawkBitPhP/persistence).
5+
We accept contributions via Pull Requests on [Github](https://github.com/HawkBitPhP/database).
66

77
## Pull Requests
88

README.md

Lines changed: 10 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
# Hawkbit Persistence
1+
# Hawkbit Database
22

33
[![Latest Version on Packagist][ico-version]][link-packagist]
44
[![Software License][ico-license]](LICENSE.md)
55
[![Build Status][ico-travis]][link-travis]
66
[![Total Downloads][ico-downloads]][link-downloads]
77
[![Coverage Status][ico-coveralls]][link-coveralls]
88

9-
Persistence layer for Hawkbit PSR-7 Micro PHP framework.
10-
Features unit of work, identity map, object graph, popo's and mapper.
9+
Object orientated database handling with POPO's, unit of work, identity map and data mapper.
1110

1211
## Install
1312

@@ -39,7 +38,7 @@ require __DIR__ . '/vendor/autoload.php';
3938

4039
### Downloading .zip file
4140

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.
41+
This project is also available for download as a `.zip` file on GitHub. Visit the [releases page](https://github.com/hawkbit/database/releases), select the version you want, and click the "Source code (zip)" download button.
4342

4443
### Requirements
4544

@@ -50,91 +49,9 @@ The following versions of PHP are supported by this version.
5049
* PHP 7.0
5150
* HHVM
5251

53-
## Setup
52+
## Usage
5453

55-
Create a Mapper and an entity. See
56-
57-
Create a Connection and register mappers
58-
59-
```php
60-
<?php
61-
62-
use Hawkbit\Database\ConnectionManager;
63-
use Application\Persistence\Mappers\PostMapper;
64-
65-
$connection = ConnectionManager::create([
66-
'url' => 'sqlite:///:memory:',
67-
'memory' => 'true'
68-
]);
69-
70-
$connection->getMapperLocator()->register(PostMapper::class);
71-
```
72-
73-
Load Mapper by mapper class or entity class
74-
75-
```php
76-
<?php
77-
78-
use Application\Persistence\Mappers\PostMapper;
79-
use Application\Persistence\Entities\Post;
80-
81-
// load by mapper
82-
$mapper = $connection->loadMapper(PostMapper::class);
83-
84-
// load by entity
85-
$mapper = $connection->loadMapper(Post::class);
86-
87-
```
88-
89-
## Data manipulation
90-
91-
### Create entity
92-
93-
```php
94-
<?php
95-
96-
use Application\Persistence\Entities\Post;
97-
98-
$entity = new Post();
99-
100-
$entity->setContent('cnt');
101-
102-
/** @var Post $createdEntity */
103-
$mapper->create($entity);
104-
105-
```
106-
107-
108-
### Load entity
109-
110-
```php
111-
<?php
112-
113-
$entity = $mapper->find(['id' => 1]);
114-
115-
```
116-
117-
118-
### Update entity
119-
120-
```php
121-
<?php
122-
123-
$entity->setContent('FOO');
124-
$mapper->update($entity);
125-
126-
```
127-
128-
### Delete entity
129-
130-
```php
131-
<?php
132-
133-
$mapper->delete($entity);
134-
135-
```
136-
137-
## Transactions
54+
View [Examples](examples) for usage.
13855

13956
## Change log
14057

@@ -157,17 +74,17 @@ If you discover any security related issues, please email <[email protected]> instead
15774
## Credits
15875

15976
- [Marco Bunge](https://github.com/mbunge)
160-
- [All contributors](https://github.com/hawkbit/persistence/graphs/contributors)
77+
- [All contributors](https://github.com/hawkbit/database/graphs/contributors)
16178

16279
## License
16380

16481
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
16582

166-
[ico-version]: https://img.shields.io/packagist/v/hawkbit/persistence.svg?style=flat-square
83+
[ico-version]: https://img.shields.io/packagist/v/hawkbit/database.svg?style=flat-square
16784
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
168-
[ico-travis]: https://img.shields.io/travis/HawkBitPhp/hawkbit-persistence/master.svg?style=flat-square
169-
[ico-downloads]: https://img.shields.io/packagist/dt/hawkbit/persistence.svg?style=flat-square
170-
[ico-coveralls]: https://img.shields.io/coveralls/HawkBitPhp/hawkbit-persistence/master.svg?style=flat-square
85+
[ico-travis]: https://img.shields.io/travis/HawkBitPhp/hawkbit-database/master.svg?style=flat-square
86+
[ico-downloads]: https://img.shields.io/packagist/dt/hawkbit/database.svg?style=flat-square
87+
[ico-coveralls]: https://img.shields.io/coveralls/HawkBitPhp/hawkbit-database/master.svg?style=flat-square
17188

17289
[link-packagist]: https://packagist.org/packages/hawkbit/hawkbit
17390
[link-travis]: https://travis-ci.org/HawkBitPhp/hawkbit

composer.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
2-
"name": "hawkbit/persistence",
3-
"type": "hawkbit-component",
4-
"description": "Persistence layer for Hawkbit PSR-7 Micro PHP framework",
2+
"name": "hawkbit/database",
3+
"description": "Object orientated database handling",
54
"keywords": [
65
"doctrine",
76
"orm",
@@ -18,13 +17,11 @@
1817
],
1918
"require": {
2019
"php": ">=5.5.0",
21-
"doctrine/collections": "~1.3",
2220
"doctrine/dbal": "~2.5",
2321
"doctrine/inflector": "~1.1"
2422
},
2523
"require-dev": {
26-
"phpunit/phpunit": "~4.8",
27-
"hawkbit/hawkbit": "~2.0"
24+
"phpunit/phpunit": "~4.8"
2825
},
2926
"autoload": {
3027
"psr-4": {

example/bootstrap.php renamed to example/mapper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
$entity = new Post();
2727
$mapper = $connection->loadMapper($entity);
2828

29+
// or create entity from mapper
30+
//$entity = $mapper->createEntity();
31+
2932
// create entity
3033
$entity->setContent('cnt');
3134
$mapper->create($entity);

example/unitOfWork.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
use Application\Persistence\Entities\Post;
4+
use Application\Persistence\Mappers\PostMapper;
5+
use Hawkbit\Database\ConnectionManager;
6+
7+
require_once __DIR__ . '/../vendor/autoload.php';
8+
9+
/*
10+
* Tis is only an example. All steps are separated in their specific logic
11+
*/
12+
13+
// setup connection
14+
$connection = ConnectionManager::create([
15+
'url' => 'sqlite:///:memory:',
16+
'memory' => 'true'
17+
]);
18+
19+
// setup schema
20+
$connection->exec('CREATE TABLE post (id int, title VARCHAR(255), content TEXT, date DATETIME DEFAULT CURRENT_DATE )');
21+
22+
// register mappers
23+
$connection->getMapperLocator()->register(PostMapper::class);
24+
25+
// load mapper
26+
$mapper = $connection->loadMapper(Post::class);
27+
$unitOfWork = $connection->createUnitOfWork();
28+
$entity = new Post();
29+
30+
// or create entity from mapper
31+
//$entity = $mapper->createEntity();
32+
33+
// create entity
34+
$entity->setContent('cnt');
35+
$unitOfWork->create($entity);
36+
37+
// commit transaction
38+
if(false === $unitOfWork->commit()){
39+
//handle exception
40+
$unitOfWork->getException();
41+
42+
// get last processed entity
43+
$unitOfWork->getLastProcessed();
44+
}
45+
46+
// get all modified entities
47+
$unitOfWork->getModified();
48+
49+
// get a list of all entities by state
50+
$unitOfWork->getProcessed();
51+
52+
// find entity by primary key or compound key
53+
$mapper->find(['id' => 1]);
54+
55+
// update entity
56+
$entity->setContent('FOO');
57+
$unitOfWork->update($entity);
58+
59+
// delete entity
60+
$unitOfWork->delete($entity);
61+
62+
// commit transaction
63+
$unitOfWork->commit();

src/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function setPrefix($prefix)
5656

5757
/**
5858
* @param $entityOrMapper
59-
* @return Mapper
59+
* @return Mapper|AbstractMapper
6060
*/
6161
public function loadMapper($entityOrMapper){
6262

src/UnitOfWork.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ final class UnitOfWork
3737
*/
3838
private $processed = [];
3939

40+
/**
41+
* @var
42+
*/
43+
private $lastProcessed = null;
44+
4045
/**
4146
* @var Connection
4247
*/
@@ -81,6 +86,22 @@ public function getException()
8186
return $this->exception;
8287
}
8388

89+
/**
90+
* @return mixed
91+
*/
92+
public function getLastProcessed()
93+
{
94+
return $this->lastProcessed;
95+
}
96+
97+
/**
98+
* @return array
99+
*/
100+
public function getProcessed()
101+
{
102+
return $this->processed;
103+
}
104+
84105
/**
85106
* @param $object
86107
*/
@@ -184,6 +205,7 @@ public function commit()
184205
$connection = $this->connection;
185206
$this->processed = [];
186207
$this->modified = [];
208+
$this->lastProcessed = null;
187209

188210
try {
189211
$connection->beginTransaction();
@@ -220,6 +242,7 @@ protected function process($label, &$entities, callable $task)
220242
{
221243
foreach ($entities as $key => $entity) {
222244
$task($entity);
245+
$this->lastProcessed = $entity;
223246
$this->processed[$label][] = $entity;
224247
if(IdentityMap::REMOVED !== $label){
225248
$this->modified[] = $entity;

0 commit comments

Comments
 (0)