1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* @link http://github.com/zendframework/zend-form for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Form;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\Config;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class FormElementManagerFactory implements FactoryInterface
{
/**
* zend-servicemanager v2 support for invocation options.
*
* @param array
*/
protected $creationOptions;
/**
* {@inheritDoc}
*
* @return AbstractPluginManager
*/
public function __invoke(ContainerInterface $container, $name, array $options = null)
{
$pluginManager = $this->isV3Container()
? new FormElementManager\FormElementManagerV3Polyfill($container, $options ?: [])
: new FormElementManager\FormElementManagerV2Polyfill($container, $options ?: []);
// If this is in a zend-mvc application, the ServiceListener will inject
// merged configuration during bootstrap.
if ($container->has('ServiceListener')) {
return $pluginManager;
}
// If we do not have a config service, nothing more to do
if (! $container->has('config')) {
return $pluginManager;
}
$config = $container->get('config');
// If we do not have form_elements configuration, nothing more to do
if (! isset($config['form_elements']) || ! is_array($config['form_elements'])) {
return $pluginManager;
}
// Wire service configuration for forms and elements
(new Config($config['form_elements']))->configureServiceManager($pluginManager);
return $pluginManager;
}
/**
* {@inheritDoc}
*
* @return AbstractPluginManager
*/
public function createService(ServiceLocatorInterface $container, $name = null, $requestedName = null)
{
return $this(
$container,
$requestedName ?: __NAMESPACE__ . '\FormElementManager',
$this->creationOptions
);
}
/**
* zend-servicemanager v2 support for invocation options.
*
* @param array $options
* @return void
*/
public function setCreationOptions(array $options)
{
$this->creationOptions = $options;
}
/**
* Are we running under zend-servicemanager v3?
*
* @return bool
*/
private function isV3Container()
{
return method_exists(AbstractPluginManager::class, 'configure');
}
}