-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriterInterface.php
More file actions
76 lines (71 loc) · 2.04 KB
/
WriterInterface.php
File metadata and controls
76 lines (71 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace Bdf\Prime\Repository\Write;
use Bdf\Prime\Exception\PrimeException;
use Bdf\Prime\Query\Contract\WriteOperation;
/**
* Handle write operations on repository
*
* @template E as object
*/
interface WriterInterface
{
/**
* Insert an entity into the repository
*
* Available options :
* - ignore (bool) : Ignore the insert if the entity is already created. By default set to false
*
* <code>
* // Perform a simple insert operation
* $writer->insert($myEntity);
*
* // Insert ignore operation, and check if the entity is successfully inserted
* $inserted = $writer->insert($otherEntity, ['ignore' => true]) === 1;
* </code>
*
* @param E $entity The entity
* @param array $options Insert options
*
* @return int The number of affected rows
* @throws PrimeException When insert fail
*/
#[WriteOperation]
public function insert($entity, array $options = []): int;
/**
* Update an entity to the repository
*
* Available options :
* - attributes (array) : List of attributes to update. If not provided all attributes will be updated
*
* <code>
* // Update all values of the entity
* $writer->update($entity);
*
* // Update only the "name" attributes
* $writer->update($entity, ['attributes' => ['name']]);
* </code>
*
* @param E $entity The entity
* @param array $options Update options
*
* @return int The number of affected rows
* @throws PrimeException When update fail
*/
#[WriteOperation]
public function update($entity, array $options = []): int;
/**
* Delete an entity from the repository
*
* <code>
* $writer->delete($entity);
* </code>
*
* @param E $entity The entity
* @param array $options Delete options
*
* @return int The number of affected rows
* @throws PrimeException When delete fail
*/
#[WriteOperation]
public function delete($entity, array $options = []): int;
}