1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace hiqdev\billing\hiapi\repositories; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use hiapi\components\ConnectionInterface; |
7
|
|
|
use hiqdev\php\billing\Type; |
8
|
|
|
use hiqdev\php\billing\customer\Customer; |
9
|
|
|
use hiqdev\php\billing\target\Target; |
10
|
|
|
use hiqdev\php\billing\BillFactoryInterface; |
11
|
|
|
use hiqdev\php\units\Quantity; |
12
|
|
|
use Money\Money; |
13
|
|
|
|
14
|
|
|
class BillRepository extends \hiapi\repositories\BaseRepository |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var BillFactoryInterface |
18
|
|
|
*/ |
19
|
|
|
protected $factory; |
20
|
|
|
|
21
|
|
|
public function __construct( |
22
|
|
|
ConnectionInterface $db, |
23
|
|
|
BillFactoryInterface $factory, |
24
|
|
|
array $config = [] |
25
|
|
|
) { |
26
|
|
|
parent::__construct($config); |
27
|
|
|
|
28
|
|
|
$this->db = $db; |
|
|
|
|
29
|
|
|
$this->factory = $factory; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function create(array $row) |
33
|
|
|
{ |
34
|
|
|
$row = $this->split($row); |
35
|
|
|
$row['type'] = $this->createEntity(Type::class, $row['type']); |
|
|
|
|
36
|
|
|
$row['time'] = new DateTime($row['time']); |
37
|
|
|
$row['quantity'] = Quantity::create('megabyte', $row['quantity']['quantity']); |
38
|
|
|
$row['sum'] = Money::USD($row['sum.amount']); |
39
|
|
|
$row['customer'] = $this->createEntity(Customer::class, $row['customer']); |
|
|
|
|
40
|
|
|
$row['target'] = $this->createEntity(Target::class, $row['target']); |
|
|
|
|
41
|
|
|
|
42
|
|
|
return parent::create($row); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function split(array $row) |
46
|
|
|
{ |
47
|
|
|
foreach ($row as $key => $value) { |
48
|
|
|
$parts = explode('.', $key, 2); |
49
|
|
|
if (count($parts)>1) { |
50
|
|
|
$row[$parts[0]][$parts[1]] = $value; |
51
|
|
|
unset($row[$key]); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $row; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.