@@ -124,17 +124,15 @@ public function __construct( array $options = [] ) {
124
124
* @return AbstractEntity Entity object to get information for
125
125
* @throws EntityUnknownException Throws an exception, when now Entity ID is available
126
126
*/
127
- private function getPrimaryEntity () {
127
+ private function getPrimaryEntity (): AbstractEntity {
128
128
129
- // If a versionId GET or POST param is set, then the primary Entity is the Version object
130
- if ( isset ( $ _GET ['versionId ' ] ) || isset ( $ _POST ['versionId ' ] ) ) {
131
- if ( ! $ this ->version ) {
132
- $ versionId = isset ( $ _GET ['versionId ' ] ) ? $ _GET ['versionId ' ] : false ;
133
- $ versionId = $ versionId ? $ versionId : $ _POST ['versionId ' ];
134
- $ this ->version = new Version ( $ versionId );
129
+ // If an appId is already available, then return the app as primary entity.
130
+ if ( $ this ->appId ) {
131
+ if (!$ this ->app ) {
132
+ $ this ->app = new App ( $ this ->appId , $ this ->versionId );
135
133
}
136
134
137
- return $ this ->version ;
135
+ return $ this ->app ;
138
136
}
139
137
140
138
// If a templateId GET or POST param is set, then the primary Entity is the Template object
@@ -148,6 +146,17 @@ private function getPrimaryEntity() {
148
146
return $ this ->template ;
149
147
}
150
148
149
+ // If a versionId GET or POST param is set, then the primary Entity is the Version object
150
+ if ( isset ( $ _GET ['versionId ' ] ) || isset ( $ _POST ['versionId ' ] ) ) {
151
+ if ( ! $ this ->version ) {
152
+ $ versionId = isset ( $ _GET ['versionId ' ] ) ? $ _GET ['versionId ' ] : false ;
153
+ $ versionId = $ versionId ? $ versionId : $ _POST ['versionId ' ];
154
+ $ this ->version = new Version ( $ versionId );
155
+ }
156
+
157
+ return $ this ->version ;
158
+ }
159
+
151
160
// Else the app is the primary object
152
161
if ( ! $ this ->app ) {
153
162
$ this ->app = new App ( $ this ->appId , $ this ->versionId );
0 commit comments