-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQuery.php
86 lines (74 loc) · 1.4 KB
/
Query.php
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
77
78
79
80
81
82
83
84
85
86
<?php
namespace Darya\ORM;
use Darya\Storage;
/**
* Darya's ORM query.
*
* @property-read Mapper $mapper
* @property-read string[]|callable[] $has
* @property-read string[]|callable[] $with
*
* @author Chris Andrew <[email protected]>
*/
class Query extends Storage\Query
{
/**
* The mapper used for this ORM query.
*
* @var Mapper
*/
protected Mapper $mapper;
/**
* Relationships to check existence for.
*
* @var callable[]|string[]
*/
protected array $has = [];
/**
* Relationships to load entities with.
*
* @var callable[]|string[]
*/
protected array $with = [];
/**
* Create a new ORM query.
*
* @param Mapper $mapper
*/
public function __construct(Mapper $mapper)
{
parent::__construct($mapper->getEntityMap()->getResource());
$this->mapper = $mapper;
}
/**
* Set the relationships to check existence for.
*
* @param callable[]|string[]|string $relationships
* @return $this
*/
public function has($relationships): Query
{
$this->has = (array) $relationships;
return $this;
}
/**
* Set the relationships to load entities with.
*
* @param callable[]|string[]|string $relationships
* @return $this
*/
public function with($relationships): Query
{
$this->with = (array) $relationships;
return $this;
}
/**
* Run the query.
*
* @return object[]
*/
public function run()
{
return $this->mapper->run($this);
}
}