1 | <?php |
||
14 | class Manager |
||
15 | { |
||
16 | /** @var string Entity identifier */ |
||
17 | protected $entityName; |
||
18 | |||
19 | /** @var string Entity primary field name */ |
||
20 | protected $primaryFieldName; |
||
21 | |||
22 | /** @var array Collection of entity field names and their types */ |
||
23 | protected $attributes = array(); |
||
24 | |||
25 | /** |
||
26 | * Manager constructor. |
||
27 | * |
||
28 | * @param string $entityName Entity name |
||
29 | * @param array $attributes Key-value collection with field name => type |
||
30 | * @param \PDO $driver database low-level driver |
||
31 | */ |
||
32 | public function __construct($entityName, $attributes, $driver) |
||
38 | |||
39 | /** |
||
40 | * Get new entity instance. |
||
41 | * |
||
42 | * @return RecordInterface New database manager entity instance |
||
43 | */ |
||
44 | public function instance() |
||
48 | |||
49 | /** |
||
50 | * Convert RecordInterface instance to collection of its field name => value. |
||
51 | * |
||
52 | * @param RecordInterface $object Database record instance to convert |
||
53 | * @return array Collection of key => value with SQL fields statements |
||
54 | */ |
||
55 | protected function &getFields(RecordInterface &$object = null) |
||
70 | |||
71 | /** |
||
72 | * Create new database entity record. |
||
73 | * @param RecordInterface $entity Entity record for creation |
||
74 | * @return RecordInterface Created database entity record with new primary identifier |
||
75 | */ |
||
76 | public function create(RecordInterface $entity) |
||
84 | |||
85 | /** |
||
86 | * Read database entity records from QueryInterface. |
||
87 | * |
||
88 | * @param QueryInterface $query For retrieving records |
||
89 | * @return RecordInterface[] Collection of read database entity records |
||
90 | */ |
||
91 | public function read(QueryInterface $query) |
||
95 | |||
96 | /** |
||
97 | * Update database entity record. |
||
98 | * |
||
99 | * @param RecordInterface $entity Entity record for updating |
||
100 | */ |
||
101 | public function update(RecordInterface $entity) |
||
114 | |||
115 | /** |
||
116 | * Delete database record from database. |
||
117 | * |
||
118 | * @param RecordInterface $entity Entity record for removing |
||
119 | */ |
||
120 | public function delete(RecordInterface $entity) |
||
126 | } |
||
127 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: