1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rougin\Windstorm\Relation; |
4
|
|
|
|
5
|
|
|
use Rougin\Windstorm\ChildInterface; |
6
|
|
|
use Rougin\Windstorm\MixedInterface; |
7
|
|
|
use Rougin\Windstorm\QueryInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Mixed |
11
|
|
|
* |
12
|
|
|
* @package Windstorm |
13
|
|
|
* @author Rougin Gutib <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class Mixed extends Wrappable implements MixedInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var \Rougin\Windstorm\ChildInterface[] |
19
|
|
|
*/ |
20
|
|
|
protected $children = array(); |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Initializes the mixed instance. |
24
|
|
|
* |
25
|
|
|
* @param \Rougin\Windstorm\QueryInterface $query |
26
|
|
|
* @param \Rougin\Windstorm\ChildInterface[] $children |
27
|
|
|
*/ |
28
|
6 |
|
public function __construct(QueryInterface $query, array $children = array()) |
29
|
|
|
{ |
30
|
6 |
|
parent::__construct($query); |
31
|
|
|
|
32
|
6 |
|
$this->children = $children; |
33
|
6 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Creates a new child instance and adds it to children. |
37
|
|
|
* |
38
|
|
|
* @param string $column |
39
|
|
|
* @param \Rougin\Windstorm\QueryInterface $query |
40
|
|
|
* @param string $primary |
41
|
|
|
* @param string $foreign |
42
|
|
|
* @return self |
43
|
|
|
*/ |
44
|
6 |
|
public function add($column, QueryInterface $query, $primary, $foreign) |
45
|
|
|
{ |
46
|
6 |
|
$child = new Child($column, $query, $primary, $foreign); |
47
|
|
|
|
48
|
6 |
|
return $this->child($child); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Returns all added child instances. |
53
|
|
|
* |
54
|
|
|
* @return \Rougin\Windstorm\ChildInterface[] |
55
|
|
|
*/ |
56
|
6 |
|
public function children() |
57
|
|
|
{ |
58
|
6 |
|
return $this->children; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Adds a new child instance directly to children. |
63
|
|
|
* |
64
|
|
|
* @param \Rougin\Windstorm\ChildInterface $child |
65
|
|
|
* @return self |
66
|
|
|
*/ |
67
|
6 |
|
public function child(ChildInterface $child) |
68
|
|
|
{ |
69
|
6 |
|
$this->children[] = $child; |
70
|
|
|
|
71
|
6 |
|
return $this; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|