Skip to content

Commit d6dd6e6

Browse files
author
Sebastian Buckpesch
committed
Change order of loading the primary entity. The more specific the definition is, the more likely it is to be used:
1) App 2) Template 3) Version
1 parent 7a57228 commit d6dd6e6

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/AppArena/AppManager.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,15 @@ public function __construct( array $options = [] ) {
124124
* @return AbstractEntity Entity object to get information for
125125
* @throws EntityUnknownException Throws an exception, when now Entity ID is available
126126
*/
127-
private function getPrimaryEntity() {
127+
private function getPrimaryEntity(): AbstractEntity {
128128

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 );
135133
}
136134

137-
return $this->version;
135+
return $this->app;
138136
}
139137

140138
// If a templateId GET or POST param is set, then the primary Entity is the Template object
@@ -148,6 +146,17 @@ private function getPrimaryEntity() {
148146
return $this->template;
149147
}
150148

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+
151160
// Else the app is the primary object
152161
if ( ! $this->app ) {
153162
$this->app = new App( $this->appId, $this->versionId );

0 commit comments

Comments
 (0)