|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* \AppserverIo\Appserver\PersistenceContainer\ServiceLocator |
|
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/appserver |
|
18
|
|
|
* @link http://www.appserver.io |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace AppserverIo\Appserver\PersistenceContainer; |
|
22
|
|
|
|
|
23
|
|
|
use AppserverIo\Psr\EnterpriseBeans\EnterpriseBeansException; |
|
24
|
|
|
use AppserverIo\Psr\EnterpriseBeans\ServiceContextInterface; |
|
25
|
|
|
use AppserverIo\Psr\EnterpriseBeans\ServiceResourceLocatorInterface; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The service locator implementation. |
|
29
|
|
|
* |
|
30
|
|
|
* @author Tim Wagner <[email protected]> |
|
31
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
|
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
33
|
|
|
* @link https://github.com/appserver-io/appserver |
|
34
|
|
|
* @link http://www.appserver.io |
|
35
|
|
|
*/ |
|
36
|
|
|
class ServiceLocator implements ServiceResourceLocatorInterface |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Tries to lookup the service with the passed identifier. |
|
41
|
|
|
* |
|
42
|
|
|
* @param \AppserverIo\Psr\EnterpriseBeans\ServiceContextInterface $serviceContext The service context instance |
|
43
|
|
|
* @param string $serviceIdentifier The identifier of the service to be looked up |
|
44
|
|
|
* @param array $args The arguments passed to the service providers constructor |
|
45
|
|
|
* |
|
46
|
|
|
* @return \AppserverIo\Psr\EnterpriseBeans\ServiceProviderInterface The requested service provider instance |
|
47
|
|
|
* @throws \AppserverIo\Psr\EnterpriseBeans\EnterpriseBeansException Is thrown if the requested server can't be lookup up |
|
48
|
|
|
* @see \AppserverIo\Psr\EnterpriseBeans\ServiceResourceLocatorInterface::lookup() |
|
49
|
|
|
*/ |
|
50
|
|
|
public function lookup(ServiceContextInterface $serviceContext, $serviceIdentifier, array $args = array()) |
|
51
|
|
|
{ |
|
52
|
|
|
|
|
53
|
|
|
// first check if the service is available |
|
54
|
|
|
if ($serviceContext->getServices()->has($serviceIdentifier) === false) { |
|
55
|
|
|
throw new EnterpriseBeansException( |
|
56
|
|
|
sprintf( |
|
57
|
|
|
'Requested service %s to handle %s is not available', |
|
58
|
|
|
$serviceContext->getIdentifier(), |
|
|
|
|
|
|
59
|
|
|
$serviceIdentifier |
|
60
|
|
|
) |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
// return the initialized service instance |
|
65
|
|
|
return $serviceContext->getServices()->get($serviceIdentifier); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|