1 | <?php |
||
21 | trait SourceTrait |
||
22 | { |
||
23 | /** |
||
24 | * Get record selector for a given query. |
||
25 | * |
||
26 | * Example: |
||
27 | * User::find(['status' => 'active']; |
||
28 | * |
||
29 | * @param array $query Selection WHERE statement. |
||
30 | * |
||
31 | * @return RecordSelector |
||
32 | * |
||
33 | * @throws ScopeException |
||
34 | */ |
||
35 | public static function find(array $query = []): RecordSelector |
||
39 | |||
40 | /** |
||
41 | * Fetch one record based on provided query or return null. Make sure to specify sort by in |
||
42 | * order to stabilize selection |
||
43 | * |
||
44 | * Example: |
||
45 | * User::findOne(['name' => 'Wolfy-J'], ['id' => 'DESC'], ['profile']); |
||
46 | * |
||
47 | * |
||
48 | * @param array $where Selection WHERE statement. |
||
49 | * @param array $sortBy Sort by. |
||
50 | * @param array $load Relations to pre-load. |
||
51 | * |
||
52 | * @return \Spiral\ORM\RecordEntity|null * |
||
53 | * @throws ScopeException |
||
54 | */ |
||
55 | public static function findOne($where = [], array $sortBy = [], array $load = []) |
||
59 | |||
60 | /** |
||
61 | * Find record using it's primary key and load children. |
||
62 | * |
||
63 | * Example: |
||
64 | * User::findByPK(1, ['profile']); |
||
65 | * |
||
66 | * @param mixed $primaryKey Primary key. |
||
67 | * @param array $load Relations to pre-load. |
||
68 | * |
||
69 | * @return \Spiral\ORM\RecordEntity|null |
||
70 | * |
||
71 | * @throws ScopeException |
||
72 | */ |
||
73 | public static function findByPK($primaryKey, array $load = []) |
||
77 | |||
78 | /** |
||
79 | * Instance of RecordSource associated with specific model. |
||
80 | * |
||
81 | * @see Component::staticContainer() |
||
82 | ** |
||
83 | * @return RecordSource |
||
84 | * |
||
85 | * @throws ScopeException |
||
86 | */ |
||
87 | public static function source(): RecordSource |
||
107 | |||
108 | /** |
||
109 | * Trait can ONLY be added to components. |
||
110 | * |
||
111 | * @see Component |
||
112 | * |
||
113 | * @param ContainerInterface|null $container |
||
114 | * |
||
115 | * @return ContainerInterface|null |
||
116 | */ |
||
117 | abstract protected static function staticContainer(ContainerInterface $container = null); |
||
118 | } |