Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 7e334d1

Browse files
committed
Container factory can be null
1 parent bf8ca17 commit 7e334d1

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

‎src/Module/AbstractBaseModule.php‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ abstract class AbstractBaseModule implements
105105
*
106106
* @since [*next-version*]
107107
*
108-
* @var ContainerFactoryInterface
108+
* @var ContainerFactoryInterface|null
109109
*/
110110
protected $containerFactory;
111111

@@ -114,12 +114,12 @@ abstract class AbstractBaseModule implements
114114
*
115115
* @since [*next-version*]
116116
*
117-
* @param ContainerFactoryInterface $containerFactory The container factory.
117+
* @param ContainerFactoryInterface|null $containerFactory The container factory, or null.
118118
* @param string|Stringable $key The module key.
119119
* @param string[]|Stringable[] $dependencies The module dependencies.
120120
* @param array|ArrayAccess|stdClass|ContainerInterface $config The module config.
121121
*/
122-
protected function _initModule(ContainerFactoryInterface $containerFactory, $key, $dependencies = array(), $config = array())
122+
protected function _initModule($containerFactory, $key, $dependencies = array(), $config = array())
123123
{
124124
$this->_setKey($key);
125125
$this->_setDependencies($dependencies);
@@ -132,7 +132,7 @@ protected function _initModule(ContainerFactoryInterface $containerFactory, $key
132132
*
133133
* @since [*next-version*]
134134
*
135-
* @return ContainerFactoryInterface The container factory instance.
135+
* @return ContainerFactoryInterface|null The container factory instance, if any.
136136
*/
137137
protected function _getContainerFactory()
138138
{
@@ -144,10 +144,19 @@ protected function _getContainerFactory()
144144
*
145145
* @since [*next-version*]
146146
*
147-
* @param ContainerFactoryInterface $containerFactory The container factory instance.
147+
* @param ContainerFactoryInterface|null $containerFactory The container factory instance or null.
148148
*/
149-
protected function _setContainerFactory(ContainerFactoryInterface $containerFactory)
149+
protected function _setContainerFactory($containerFactory)
150150
{
151+
if ($containerFactory !== null && !($containerFactory instanceof ContainerFactoryInterface)) {
152+
throw $this->_createInvalidArgumentException(
153+
$this->__('Argument is not a container factory'),
154+
null,
155+
null,
156+
$containerFactory
157+
);
158+
}
159+
151160
$this->containerFactory = $containerFactory;
152161
}
153162

@@ -163,10 +172,21 @@ protected function _setContainerFactory(ContainerFactoryInterface $containerFact
163172
*
164173
* @throws CouldNotMakeExceptionInterface If the factory failed to create the exception.
165174
* @throws FactoryExceptionInterface If the factory encountered an error.
175+
* @throws RuntimeException If the container factory associated with this instance is null.
166176
*/
167177
protected function _createContainer($definitions = array(), ContainerInterface $parent = null)
168178
{
169-
return $this->_getContainerFactory()->make(['definitions' => $definitions, 'parent' => $parent]);
179+
$containerFactory = $this->_getContainerFactory();
180+
181+
if (!($containerFactory instanceof ContainerFactoryInterface)) {
182+
throw $this->_createRuntimeException(
183+
$this->__('Not a valid container factory instance'),
184+
null,
185+
null
186+
);
187+
}
188+
189+
return $containerFactory->make(['definitions' => $definitions, 'parent' => $parent]);
170190
}
171191

172192
/**

0 commit comments

Comments
 (0)