Skip to content
This repository has been archived by the owner on Feb 6, 2020. It is now read-only.

Commit

Permalink
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/AbstractPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,42 @@ protected function createFromInvokable($canonicalName, $requestedName)

return $instance;
}

/**
* Attempt to create an instance via a factory class
*
* Overrides parent implementation by passing $creationOptions to the
* constructor, if non-null.
*
* @param string $canonicalName
* @param string $requestedName
* @return mixed
* @throws Exception\ServiceNotCreatedException If factory is not callable
*/
protected function createFromFactory($canonicalName, $requestedName)
{
$factory = $this->factories[$canonicalName];
if (is_string($factory) && class_exists($factory, true)) {
if (null === $this->creationOptions || (is_array($this->creationOptions) && empty($this->creationOptions))) {
$factory = new $factory();
} else {
$factory = new $factory($this->creationOptions);
}

$this->factories[$canonicalName] = $factory;
}

if ($factory instanceof FactoryInterface) {
$instance = $this->createServiceViaCallback(array($factory, 'createService'), $canonicalName, $requestedName);
} elseif (is_callable($factory)) {
$instance = $this->createServiceViaCallback($factory, $canonicalName, $requestedName);
} else {
throw new Exception\ServiceNotCreatedException(sprintf(
'While attempting to create %s%s an invalid factory was registered for this instance type.', $canonicalName, ($requestedName ? '(alias: ' . $requestedName . ')' : '')
));
}

return $instance;
}

}

0 comments on commit 3fab1eb

Please sign in to comment.