Skip to content

Commit

Permalink
Merge pull request #13 from Saeven/feature/laminas-update
Browse files Browse the repository at this point in the history
Feature/laminas update
  • Loading branch information
Saeven authored Jun 18, 2021
2 parents 34ec8ee + 0913be2 commit f50ab04
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Spec\CirclicalAutoWire\Form\DummyForm;
use Spec\CirclicalAutoWire\Model\DummyObject;
use Laminas\EventManager\EventManager;
use Laminas\Form\FormElementManager\FormElementManagerV3Polyfill;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\Form\FormElementManager;

/**
* Class ControllerWithParameters
Expand All @@ -18,16 +18,20 @@ class ControllerWithParameters extends AbstractActionController
* ControllerWithParameters constructor.
*
* @param DummyObject $dummyObject
* @param FormElementManagerV3Polyfill $formManager
* @param FormElementManager $formManager
* @param DummyForm $form This should invoke the FormElementManager
* @param array $config This is a magic name that conjures the ZF config
* @param $formElementManager Magic parameter that injects the FormElementManager
* @param $serviceLocator Should inject the container (bad, but here by popular demand)
* @param EventManager $eventManager Should inject an application event manager, lazy shorthand
*/
public function __construct(DummyObject $dummyObject, FormElementManagerV3Polyfill $formManager, DummyForm $form, array $config, $formElementManager, $serviceLocator, EventManager $eventManager)
{

public function __construct(
DummyObject $dummyObject,
FormElementManager $formManager,
DummyForm $form,
array $config,
FormElementManager $formElementManager,
EventManager $eventManager
) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use Spec\CirclicalAutoWire\Form\DummyForm;
use Spec\CirclicalAutoWire\Model\DummyObject;
use Laminas\EventManager\EventManager;
use Laminas\Form\FormElementManager\FormElementManagerV3Polyfill;
use Laminas\Mvc\Application;
use Laminas\Form\FormElementManager;

class ReflectionFactorySpec extends ObjectBehavior
{
Expand All @@ -30,8 +30,14 @@ function it_only_creates_controllers(ContainerInterface $interface)
$this->canCreate($interface, 'SuperFactory')->shouldBe(false);
}

function it_can_create_controllers_through_reflection(ContainerInterface $interface, DummyObject $dummyObject, FormElementManagerV3Polyfill $formManager, DummyForm $form, EventManager $eventManager, Application $application)
{
function it_can_create_controllers_through_reflection(
ContainerInterface $interface,
DummyObject $dummyObject,
FormElementManager $formManager,
DummyForm $form,
EventManager $eventManager,
Application $application
) {
$formManager->get(DummyForm::class)->willReturn($form);
$interface->get(DummyObject::class)->willReturn($dummyObject);
$interface->get('FormElementManager')->willReturn($formManager);
Expand Down
15 changes: 4 additions & 11 deletions src/CirclicalAutoWire/Factory/Controller/ReflectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace CirclicalAutoWire\Factory\Controller;

use CirclicalAutoWire\Model\ApplicationEventManager;
use Interop\Container\ContainerInterface;
use Laminas\EventManager\EventManager;
use Laminas\Form\FormElementManager\FormElementManagerV3Polyfill;
use Laminas\Form\FormElementManager;
use Laminas\ServiceManager\Factory\AbstractFactoryInterface;
use Laminas\Validator\ValidatorPluginManager;

Expand All @@ -16,10 +15,10 @@ final class ReflectionFactory implements AbstractFactoryInterface
* These aliases work to substitute class names with SM types that are buried in ZF.
* @var array
*/
private static $aliases = [
private static array $aliases = [

ValidatorPluginManager::class => 'ValidatorManager',
FormElementManagerV3Polyfill::class => 'FormElementManager',
FormElementManager::class => 'FormElementManager',

/* using strings since they're not required by package composer */
'ZfcTwig\View\TwigRenderer' => 'TemplateRenderer',
Expand All @@ -28,7 +27,7 @@ final class ReflectionFactory implements AbstractFactoryInterface

public function canCreate(ContainerInterface $container, $requestedName)
{
return substr($requestedName, -10) == 'Controller';
return substr($requestedName, -10) === 'Controller';
}

/**
Expand Down Expand Up @@ -74,12 +73,6 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
echo $exception->getMessage();
die(__CLASS__ . " couldn't create an instance of <b>$className</b> to satisfy the constructor for <b>$requestedName</b> at param $parameter.");
}
} else {
if ($parameter->getName() === 'formElementManager') {
$parameterInstances[] = $parentLocator->get('FormElementManager');
} elseif ($parameter->getName() === 'serviceLocator') {
$parameterInstances[] = $container;
}
}
}

Expand Down

0 comments on commit f50ab04

Please sign in to comment.