1 | <?php |
||
23 | trait SourceTrait |
||
24 | { |
||
25 | /** |
||
26 | * Find multiple documents based on provided query. |
||
27 | * |
||
28 | * Example: |
||
29 | * User::find(['status' => 'active']; |
||
30 | * |
||
31 | * @param array $query Selection WHERE statement. |
||
32 | * |
||
33 | * @return DocumentSelector |
||
34 | * |
||
35 | * @throws ScopeException |
||
36 | */ |
||
37 | public static function find(array $query = []): DocumentSelector |
||
41 | |||
42 | /** |
||
43 | * Fetch one record based on provided query or return null. Make sure to specify sort by in |
||
44 | * order to stabilize selection |
||
45 | * |
||
46 | * Example: |
||
47 | * User::findOne(['name' => 'Wolfy-J'], ['id' => -1]); |
||
48 | * |
||
49 | * @param array $where Selection WHERE statement. |
||
50 | * @param array $sortBy Sort by. |
||
51 | * |
||
52 | * @return CompositableInterface|Document|null |
||
53 | * |
||
54 | * @throws ScopeException |
||
55 | */ |
||
56 | public static function findOne($where = [], array $sortBy = []) |
||
60 | |||
61 | /** |
||
62 | * Find record using it's primary key. |
||
63 | * |
||
64 | * Example: |
||
65 | * User::findByOK(1); |
||
66 | * |
||
67 | * @param mixed $primaryKey Primary key. |
||
68 | * |
||
69 | * @return CompositableInterface|Document|null |
||
70 | * |
||
71 | * @throws ScopeException |
||
72 | */ |
||
73 | public static function findByPK($primaryKey) |
||
77 | |||
78 | /** |
||
79 | * Instance of ODM Selector associated with specific document. |
||
80 | * |
||
81 | * @see Component::staticContainer() |
||
82 | ** |
||
83 | * @return DocumentSource |
||
84 | * |
||
85 | * @throws ScopeException |
||
86 | */ |
||
87 | public static function source(): DocumentSource |
||
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 | } |