1 | <?php |
||
22 | trait SourceTrait |
||
23 | { |
||
24 | /** |
||
25 | * Find multiple records based on provided query. |
||
26 | * |
||
27 | * Example: |
||
28 | * User::find(['status' => 'active'], ['profile']); |
||
29 | * |
||
30 | * @param array $query Selection WHERE statement. |
||
31 | * |
||
32 | * @return DocumentSelector |
||
33 | * |
||
34 | * @throws ScopeException |
||
35 | */ |
||
36 | public static function find(array $query = []): DocumentSelector |
||
40 | |||
41 | /** |
||
42 | * Fetch one record based on provided query or return null. Use second argument to specify |
||
43 | * relations to be loaded. |
||
44 | * |
||
45 | * Example: |
||
46 | * User::findOne(['name' => 'Wolfy-J'], ['profile'], ['id' => 'DESC']); |
||
47 | * |
||
48 | * @param array $where Selection WHERE statement. |
||
49 | * @param array $sortBy Sort by. |
||
50 | * |
||
51 | * @return CompositableInterface|Document|null |
||
52 | * |
||
53 | * @throws ScopeException |
||
54 | */ |
||
55 | public static function findOne($where = [], array $sortBy = []) |
||
59 | |||
60 | /** |
||
61 | * Find record using it's primary key. Relation data can be preloaded with found record. |
||
62 | * |
||
63 | * Example: |
||
64 | * User::findByID(1, ['profile']); |
||
65 | * |
||
66 | * @param mixed $primaryKey Primary key. |
||
67 | * |
||
68 | * @return CompositableInterface|Document|null |
||
69 | * |
||
70 | * @throws ScopeException |
||
71 | */ |
||
72 | public static function findByPK($primaryKey) |
||
76 | |||
77 | /** |
||
78 | * Instance of ORM Selector associated with specific document. |
||
79 | * |
||
80 | * @see Component::staticContainer() |
||
81 | ** |
||
82 | * @return DocumentSource |
||
83 | * |
||
84 | * @throws ScopeException |
||
85 | */ |
||
86 | public static function source(): DocumentSource |
||
106 | |||
107 | /** |
||
108 | * Trait can ONLY be added to components. |
||
109 | * |
||
110 | * @see Component |
||
111 | * |
||
112 | * @param ContainerInterface|null $container |
||
113 | * |
||
114 | * @return ContainerInterface|null |
||
115 | */ |
||
116 | abstract protected static function staticContainer(ContainerInterface $container = null); |
||
117 | } |