1: <?php
2:
3: namespace PHPixie\ORM\Conditions\Condition;
4:
5: class In extends \PHPixie\ORM\Conditions\Condition\Implementation
6: {
7: protected $modelName;
8: protected $items = array();
9:
10: public function __construct($modelName, $items)
11: {
12: $this->modelName = $modelName;
13: $this->add($items);
14: }
15:
16: public function add($items)
17: {
18: if(!is_array($items)) {
19: $items = array($items);
20: }
21:
22: foreach($items as $item) {
23: if(is_scalar($item)) {
24: continue;
25: }
26:
27: if($item->modelName() !== $this->modelName) {
28: throw new \PHPixie\ORM\Exception\Builder("Model {$item->modelName()} does not match {$this->modelName}");
29: }
30:
31: if($item instanceof \PHPixie\ORM\Models\Type\Database\Entity && $item->isNew()) {
32: throw new \PHPixie\ORM\Exception\Builder("Only saved entities can be used");
33: }
34:
35: }
36:
37: foreach($items as $item) {
38: $this->items[] = $item;
39: }
40: }
41:
42: public function items()
43: {
44: return $this->items;
45: }
46:
47: public function modelName()
48: {
49: return $this->modelName;
50: }
51: }
52: