1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/old-town/workflow-zf2 |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace OldTown\Workflow\ZF2\Factory; |
7
|
|
|
|
8
|
|
|
use Zend\Mvc\Application; |
9
|
|
|
use Zend\ServiceManager\FactoryInterface; |
10
|
|
|
use Zend\ServiceManager\MutableCreationOptionsInterface; |
11
|
|
|
use Zend\ServiceManager\MutableCreationOptionsTrait; |
12
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
13
|
|
|
use OldTown\Workflow\Basic\BasicWorkflow; |
14
|
|
|
use OldTown\Workflow\ZF2\Event\CallerEvent; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class PluginMessageAbstractFactory |
18
|
|
|
* |
19
|
|
|
* @package OldTown\EventBus\Message |
20
|
|
|
*/ |
21
|
|
|
class BasicWorkflowFactory implements FactoryInterface, MutableCreationOptionsInterface |
22
|
|
|
{ |
23
|
|
|
use MutableCreationOptionsTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
27
|
|
|
* |
28
|
|
|
* @return BasicWorkflow |
29
|
|
|
* |
30
|
|
|
* @throws Exception\RuntimeException |
31
|
|
|
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
32
|
|
|
* @throws \OldTown\Workflow\Exception\InternalWorkflowException |
33
|
|
|
*/ |
34
|
|
|
public function createService(ServiceLocatorInterface $serviceLocator) |
35
|
|
|
{ |
36
|
|
|
$caller = false; |
37
|
|
|
$appSm = method_exists($serviceLocator, 'getServiceLocator') ? call_user_func([$serviceLocator, 'getServiceLocator']) : null; |
38
|
|
|
if ($appSm && $appSm->has('Application')) { |
39
|
|
|
/** @var Application $app */ |
40
|
|
|
$app = $appSm->get('Application'); |
41
|
|
|
$callerEvent = new CallerEvent(); |
42
|
|
|
$app->getEventManager()->trigger(CallerEvent::EVENT_RESOLVE_CALLER, $callerEvent); |
43
|
|
|
if ($callerEvent->getCaller()) { |
|
|
|
|
44
|
|
|
$caller = $callerEvent->getCaller(); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$w = new BasicWorkflow($caller); |
|
|
|
|
49
|
|
|
|
50
|
|
|
return $w; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: