psr tidy up of util/Factory.php

This commit is contained in:
steve.brazier 2014-03-25 14:18:50 +00:00
parent 7e669ada47
commit 326113ebbc

View file

@ -4,7 +4,8 @@ namespace PHPCI\Plugin\Util;
class Factory { class Factory
{
const TYPE_ARRAY = "array"; const TYPE_ARRAY = "array";
const TYPE_CALLABLE = "callable"; const TYPE_CALLABLE = "callable";
@ -18,18 +19,17 @@ class Factory {
*/ */
private $container; private $container;
function __construct(\Pimple $container = null) public function __construct(\Pimple $container = null)
{ {
if ($container) { if ($container) {
$this->container = $container; $this->container = $container;
} } else {
else {
$this->container = new \Pimple(); $this->container = new \Pimple();
} }
$self = $this; $self = $this;
$this->registerResource( $this->registerResource(
function() use ($self) { function () use ($self) {
return $self->getLastOptions(); return $self->getLastOptions();
}, },
'options', 'options',
@ -89,7 +89,7 @@ class Factory {
if ($constructor) { if ($constructor) {
$argsToUse = array(); $argsToUse = array();
foreach($constructor->getParameters() as $param) { foreach ($constructor->getParameters() as $param) {
$argsToUse = $this->addArgFromParam($argsToUse, $param); $argsToUse = $this->addArgFromParam($argsToUse, $param);
} }
$plugin = $reflectedPlugin->newInstanceArgs($argsToUse); $plugin = $reflectedPlugin->newInstanceArgs($argsToUse);
@ -107,11 +107,11 @@ class Factory {
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @internal param mixed $resource * @internal param mixed $resource
*/ */
public function registerResource($loader, public function registerResource(
$name = null, $loader,
$type = null $name = null,
) $type = null
{ ) {
if ($name === null && $type === null) { if ($name === null && $type === null) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
"Type or Name must be specified" "Type or Name must be specified"
@ -161,9 +161,9 @@ class Factory {
$class = $param->getClass(); $class = $param->getClass();
if ($class) { if ($class) {
return $class->getName(); return $class->getName();
} elseif($param->isArray()) { } elseif ($param->isArray()) {
return self::TYPE_ARRAY; return self::TYPE_ARRAY;
} elseif($param->isCallable()) { } elseif ($param->isCallable()) {
return self::TYPE_CALLABLE; return self::TYPE_CALLABLE;
} else { } else {
return null; return null;
@ -188,4 +188,4 @@ class Factory {
return $existingArgs; return $existingArgs;
} }
} }