PersistenceFacade.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
11 namespace wcmf\lib\persistence;
12 
16 
17 /**
18  * PersistenceFacade defines the interface for PersistenceFacade
19  * implementations.
20  *
21  * @author ingo herwig <ingo@wemove.com>
22  */
23 interface PersistenceFacade {
24 
25  /**
26  * Get a list of types defined in the application.
27  * @return The list of fully qualified type names
28  */
29  public function getKnownTypes();
30 
31  /**
32  * Check if a type is defined in the application.
33  * @param $type The type to check (either fully qualified or simple, if not ambiguous)
34  * @return Boolean whether the type is defined or not
35  */
36  public function isKnownType($type);
37 
38  /**
39  * Get the fully qualified type name for a given simple type name.
40  * @param $type Type name without namespace
41  * @return Fully qualified type name (with namespace)
42  */
43  public function getFullyQualifiedType($type);
44 
45  /**
46  * Get the simple type name for a given fully qualified type name.
47  * @param $type Type name with namespace
48  * @return Simple type name (without namespace)
49  */
50  public function getSimpleType($type);
51 
52  /**
53  * Load an object from the storage. The object will be attached to the transaction,
54  * if the transaction is active.
55  * @note The parameter buildDepth is used to improve fetching from the storage, but objects
56  * returned by this method are not guaranteed to only contain the parameter values.
57  * This is especially true, if the same object was loaded before with a wider fetch definition
58  * (e.g. greater buildDeph value)
59  * @param $oid The object id of the object to construct
60  * @param $buildDepth One of the BUILDDEPTH constants or a number describing the number of generations to build
61  * (except BuildDepth::REQUIRED, BuildDepth::PROXIES_ONLY) (default: _BuildDepth::SINGLE_)
62  * @return PersistentObject, null if oid does not exist or a given condition prevents loading.
63  */
64  public function load(ObjectId $oid, $buildDepth=BuildDepth::SINGLE);
65 
66  /**
67  * Construct the template of an object of a given type. The object will be
68  * attached to the transaction, if the transaction is active.
69  * @note If an object required to be transient, the IPersistentMapper::create() method or the class
70  * constructor must be used.
71  * @param $type The type of object to build (either fully qualified or simple, if not ambiguous)
72  * @param $buildDepth One of the BUILDDEPTH constants or a number describing the number of generations to build
73  * (except BuildDepth::INFINITE, BuildDepth::PROXIES_ONLY) (default: _BuildDepth::SINGLE_)
74  * @return PersistentObject
75  */
76  public function create($type, $buildDepth=BuildDepth::SINGLE);
77 
78  /**
79  * Get the object id of the last created object of a given type.
80  * @param $type The type of the object (either fully qualified or simple, if not ambiguous)
81  * @return ObjectId or null
82  */
83  public function getLastCreatedOID($type);
84 
85  /**
86  * Get the object ids of objects matching a given criteria. If a PagingInfo instance is passed it will be used and updated.
87  * @param $type The type of the object (either fully qualified or simple, if not ambiguous)
88  * @param $criteria An array of Criteria instances that define conditions on the type's attributes (optional, default: _null_)
89  * @param $orderby An array holding names of attributes to order by, maybe appended with 'ASC', 'DESC' (optional, default: _null_)
90  * @param $pagingInfo A reference PagingInfo instance. (default: _null_)
91  * @return Array containing the ObjectId instances
92  */
93  public function getOIDs($type, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null);
94 
95  /**
96  * Get the first object id of objects matching a given condition. If a PagingInfo instance is passed it will be used and updated.
97  * @param $type The type of the object (either fully qualified or simple, if not ambiguous)
98  * @param $criteria An array of Criteria instances that define conditions on the type's attributes (optional, default: _null_)
99  * @param $orderby An array holding names of attributes to order by, maybe appended with 'ASC', 'DESC' (optional, default: _null_)
100  * @param $pagingInfo A reference PagingInfo instance. (default: _null_)
101  * @return ObjectId or null
102  */
103  public function getFirstOID($type, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null);
104 
105  /**
106  * Load the objects matching a given condition. If a PagingInfo instance is passed it will be used and updated.
107  * @param $typeOrTypes The type or types array of objects (either fully qualified or simple, if not ambiguous)
108  * @param $buildDepth One of the BUILDDEPTH constants or a number describing the number of generations to build
109  * (except BuildDepth::REQUIRED, BuildDepth::PROXIES_ONLY) (default: BuildDepth::SINGLE)
110  * @param $criteria An array of Criteria instances that define conditions on the object's attributes (optional, default: _null_)
111  * @param $orderby An array holding names of attributes to order by, maybe appended with 'ASC', 'DESC' (optional, default: _null_)
112  * @param $pagingInfo A reference PagingInfo instance (optional, default: _null_)
113  * @return Array containing the PersistentObject instances
114  */
115  public function loadObjects($typeOrTypes, $buildDepth=BuildDepth::SINGLE, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null);
116 
117  /**
118  * Load the first object matching a given condition. If a PagingInfo instance is passed it will be used and updated.
119  * @param $typeOrTypes The type or types array of objects (either fully qualified or simple, if not ambiguous)
120  * @param $buildDepth One of the BUILDDEPTH constants or a number describing the number of generations to build
121  * (except BuildDepth::REQUIRED, BuildDepth::PROXIES_ONLY) (default: BuildDepth::SINGLE)
122  * @param $criteria An array of Criteria instances that define conditions on the type's attributes (optional, default: _null_)
123  * @param $orderby An array holding names of attributes to order by, maybe appended with 'ASC', 'DESC' (optional, default: _null_)
124  * @param $pagingInfo A reference PagingInfo instance (default: _null_)
125  * @return PersistentObject or null
126  */
127  public function loadFirstObject($typeOrTypes, $buildDepth=BuildDepth::SINGLE, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null);
128 
129  /**
130  * Get the current business transaction.
131  * @note There is only one transaction instance at the same time.
132  * @return Transaction
133  */
134  public function getTransaction();
135 
136  /**
137  * Get the PersistenceMapper for a given type. If no mapper for this type is defined the mapper for type '*' will be returned
138  * @param $type The type of the object to get the PersistenceMapper for (either fully qualified or simple, if not ambiguous)
139  * @return PersistenceMapper or null on error
140  */
141  public function getMapper($type);
142 
143  /**
144  * Explicitly set a PersistentMapper for a type
145  * @param $type The type to set the mapper for (fully qualified)
146  * @param $mapper PersistenceMapper instance
147  */
148  public function setMapper($type, PersistenceMapper $mapper);
149 }
150 ?>
isKnownType($type)
Check if a type is defined in the application.
getKnownTypes()
Get a list of types defined in the application.
getFullyQualifiedType($type)
Get the fully qualified type name for a given simple type name.
Persistence layer related interfaces and classes.
Definition: namespaces.php:42
PersistenceMapper defines the interface for all mapper classes.
create($type, $buildDepth=BuildDepth::SINGLE)
Construct the template of an object of a given type.
ObjectId is the unique identifier of an object.
Definition: ObjectId.php:28
loadObjects($typeOrTypes, $buildDepth=BuildDepth::SINGLE, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
Load the objects matching a given condition.
getTransaction()
Get the current business transaction.
PersistenceFacade defines the interface for PersistenceFacade implementations.
setMapper($type, PersistenceMapper $mapper)
Explicitly set a PersistentMapper for a type.
load(ObjectId $oid, $buildDepth=BuildDepth::SINGLE)
Load an object from the storage.
getMapper($type)
Get the PersistenceMapper for a given type.
getFirstOID($type, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
Get the first object id of objects matching a given condition.
getOIDs($type, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
Get the object ids of objects matching a given criteria.
PagingInfo contains information about a paged list.
Definition: PagingInfo.php:18
getLastCreatedOID($type)
Get the object id of the last created object of a given type.
loadFirstObject($typeOrTypes, $buildDepth=BuildDepth::SINGLE, $criteria=null, $orderby=null, PagingInfo $pagingInfo=null)
Load the first object matching a given condition.
getSimpleType($type)
Get the simple type name for a given fully qualified type name.