1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AppserverIo\SingleApp\Core\Api\SimpleDeploymentService |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/appserver-io/single-app |
18
|
|
|
* @link http://www.appserver.io |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\SingleApp\Core\Api; |
22
|
|
|
|
23
|
|
|
use AppserverIo\Properties\PropertiesInterface; |
24
|
|
|
use AppserverIo\Appserver\Core\Api\DeploymentService; |
25
|
|
|
use AppserverIo\Appserver\Core\Utilities\SystemPropertyKeys; |
26
|
|
|
use AppserverIo\Appserver\Core\Interfaces\ContainerInterface; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* A service providing functionality for a single app deployment. |
30
|
|
|
* |
31
|
|
|
* @author Tim Wagner <[email protected]> |
32
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
33
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
34
|
|
|
* @link https://github.com/appserver-io/single-app |
35
|
|
|
* @link http://www.appserver.io |
36
|
|
|
*/ |
37
|
|
|
class SimpleDeploymentService extends DeploymentService |
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Prepare's the system properties for the actual mode, which is the runner mode in our case. |
42
|
|
|
* |
43
|
|
|
* @param \AppserverIo\Properties\PropertiesInterface $properties The properties to prepare |
44
|
|
|
* @param string $webappPath The path of the web application to prepare the properties with |
45
|
|
|
* |
46
|
|
|
* @return void |
47
|
|
|
*/ |
48
|
|
|
protected function prepareSystemProperties(PropertiesInterface $properties, $webappPath) |
49
|
|
|
{ |
50
|
|
|
|
51
|
|
|
// let the parent method also prepare the properties |
52
|
|
|
parent::prepareSystemProperties($properties, $webappPath); |
|
|
|
|
53
|
|
|
|
54
|
|
|
// replace the host's application base directory with the parent directory |
55
|
|
|
$properties->add(SystemPropertyKeys::HOST_APP_BASE, dirname($webappPath)); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Loads the containers, defined by the applications, merges them into |
60
|
|
|
* the system configuration and returns the merged system configuration. |
61
|
|
|
* |
62
|
|
|
* @return \AppserverIo\Appserver\Core\Interfaces\SystemConfigurationInterface The merged system configuration |
63
|
|
|
*/ |
64
|
|
|
public function loadContainerInstances() |
65
|
|
|
{ |
66
|
|
|
|
67
|
|
|
// load the system configuration |
68
|
|
|
/** @var AppserverIo\Appserver\Core\Interfaces\SystemConfigurationInterface $systemConfiguration */ |
69
|
|
|
$systemConfiguration = $this->getSystemConfiguration(); |
70
|
|
|
|
71
|
|
|
// if applications are NOT allowed to override the system configuration |
72
|
|
|
if ($systemConfiguration->getAllowApplicationConfiguration() === false) { |
73
|
|
|
return $systemConfiguration; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
// load the service to validate the files |
77
|
|
|
/** @var AppserverIo\Appserver\Core\Api\ConfigurationService $configurationService */ |
78
|
|
|
$configurationService = $this->newService('AppserverIo\Appserver\Core\Api\ConfigurationService'); |
|
|
|
|
79
|
|
|
|
80
|
|
|
/** @var AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface $containerNodeInstance */ |
81
|
|
|
foreach ($systemConfiguration->getContainers() as $containerNode) { |
82
|
|
|
$this->loadContainerInstance($containerNode, $systemConfiguration, getcwd()); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
// returns the merged system configuration |
86
|
|
|
return $systemConfiguration; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Initializes the available application contexts and returns them. |
91
|
|
|
* |
92
|
|
|
* @param \AppserverIo\Appserver\Core\Interfaces\ContainerInterface $container The container we want to add the applications to |
93
|
|
|
* |
94
|
|
|
* @return array The array with the application contexts |
95
|
|
|
*/ |
96
|
|
|
public function loadContextInstancesByWorkingDir(ContainerInterface $container) |
97
|
|
|
{ |
98
|
|
|
|
99
|
|
|
// initialize the array for the context instances |
100
|
|
|
$contextInstances = array(); |
101
|
|
|
|
102
|
|
|
// attach the context to the context instances |
103
|
|
|
$context = $this->loadContextInstance($container, getcwd()); |
|
|
|
|
104
|
|
|
$contextInstances[$context->getName()] = $context; |
105
|
|
|
|
106
|
|
|
// return the array with the context instances |
107
|
|
|
return $contextInstances; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: