Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 33c8cc9

Browse files
committed
Renamed factory to incorporate verbiage "Abstract"
- per @Ocramius
1 parent 4ba6e25 commit 33c8cc9

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

doc/book/cookbook/automating-controller-factories.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ Writing a factory class for each and every controller that has dependencies
44
can be tedious, particularly in early development as you are still sorting
55
out dependencies.
66

7-
As of version 3.0.1, zend-mvc ships with `Zend\Mvc\Controller\LazyControllerFactory`,
7+
As of version 3.0.1, zend-mvc ships with `Zend\Mvc\Controller\LazyControllerAbstractFactory`,
88
which provides a reflection-based approach to controller instantiation,
99
resolving constructor dependencies to the relevant services. The factory may be
1010
used as either an abstract factory, or mapped to specific controller names as a
1111
factory:
1212

1313
```php
14-
use Zend\Mvc\Controller\LazyControllerFactory;
14+
use Zend\Mvc\Controller\LazyControllerAbstractFactory;
1515

1616
return [
1717
/* ... */
1818
'controllers' => [
1919
'abstract_factories' => [
20-
LazyControllerFactory::class,
20+
LazyControllerAbstractFactory::class,
2121
],
2222
'factories' => [
23-
'MyModule\Controller\FooController' => LazyControllerFactory::class,
23+
'MyModule\Controller\FooController' => LazyControllerAbstractFactory::class,
2424
],
2525
],
2626
/* ... */

src/Controller/LazyControllerFactory.php renamed to src/Controller/LazyControllerAbstractFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* <code>
3737
* 'controllers' => [
3838
* 'abstract_factories' => [
39-
* LazyControllerFactory::class,
39+
* LazyControllerAbstractFactory::class,
4040
* ],
4141
* ],
4242
* </code>
@@ -46,7 +46,7 @@
4646
* <code>
4747
* 'controllers' => [
4848
* 'factories' => [
49-
* MyControllerWithDependencies::class => LazyControllerFactory::class,
49+
* MyControllerWithDependencies::class => LazyControllerAbstractFactory::class,
5050
* ],
5151
* ],
5252
* </code>
@@ -70,7 +70,7 @@
7070
* `$options` passed to the factory are ignored in all cases, as we cannot
7171
* make assumptions about which argument(s) they might replace.
7272
*/
73-
class LazyControllerFactory implements AbstractFactoryInterface
73+
class LazyControllerAbstractFactory implements AbstractFactoryInterface
7474
{
7575
/**
7676
* Maps known classes/interfaces to the service that provides them; only

test/Controller/LazyControllerFactoryTest.php renamed to test/Controller/LazyControllerAbstractFactoryTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
use Interop\Container\ContainerInterface;
1111
use PHPUnit_Framework_TestCase as TestCase;
12-
use Zend\Mvc\Controller\LazyControllerFactory;
12+
use Zend\Mvc\Controller\LazyControllerAbstractFactory;
1313
use Zend\ServiceManager\Exception\ServiceNotFoundException;
1414
use Zend\Validator\ValidatorPluginManager;
1515

16-
class LazyControllerFactoryTest extends TestCase
16+
class LazyControllerAbstractFactoryTest extends TestCase
1717
{
1818
public function setUp()
1919
{
@@ -41,34 +41,34 @@ public function nonClassRequestedNames()
4141
*/
4242
public function testCanCreateReturnsFalseForNonClassRequestedNames($requestedName)
4343
{
44-
$factory = new LazyControllerFactory();
44+
$factory = new LazyControllerAbstractFactory();
4545
$this->assertFalse($factory->canCreate($this->container->reveal(), $requestedName));
4646
}
4747

4848
public function testCanCreateReturnsFalseForClassesThatDoNotImplementDispatchableInterface()
4949
{
50-
$factory = new LazyControllerFactory();
50+
$factory = new LazyControllerAbstractFactory();
5151
$this->assertFalse($factory->canCreate($this->container->reveal(), __CLASS__));
5252
}
5353

5454
public function testFactoryInstantiatesClassDirectlyIfItHasNoConstructor()
5555
{
56-
$factory = new LazyControllerFactory();
56+
$factory = new LazyControllerAbstractFactory();
5757
$controller = $factory($this->container->reveal(), TestAsset\SampleController::class);
5858
$this->assertInstanceOf(TestAsset\SampleController::class, $controller);
5959
}
6060

6161
public function testFactoryInstantiatesClassDirectlyIfConstructorHasNoArguments()
6262
{
63-
$factory = new LazyControllerFactory();
63+
$factory = new LazyControllerAbstractFactory();
6464
$controller = $factory($this->container->reveal(), TestAsset\ControllerWithEmptyConstructor::class);
6565
$this->assertInstanceOf(TestAsset\ControllerWithEmptyConstructor::class, $controller);
6666
}
6767

6868
public function testFactoryRaisesExceptionWhenUnableToResolveATypeHintedService()
6969
{
7070
$this->container->has(TestAsset\SampleInterface::class)->willReturn(false);
71-
$factory = new LazyControllerFactory();
71+
$factory = new LazyControllerAbstractFactory();
7272
$this->setExpectedException(
7373
ServiceNotFoundException::class,
7474
sprintf(
@@ -82,7 +82,7 @@ public function testFactoryRaisesExceptionWhenUnableToResolveATypeHintedService(
8282

8383
public function testFactoryPassesNullForScalarParameters()
8484
{
85-
$factory = new LazyControllerFactory();
85+
$factory = new LazyControllerAbstractFactory();
8686
$controller = $factory($this->container->reveal(), TestAsset\ControllerWithScalarParameters::class);
8787
$this->assertInstanceOf(TestAsset\ControllerWithScalarParameters::class, $controller);
8888
$this->assertNull($controller->foo);
@@ -95,7 +95,7 @@ public function testFactoryInjectsConfigServiceForConfigArgumentsTypeHintedAsArr
9595
$this->container->has('config')->willReturn(true);
9696
$this->container->get('config')->willReturn($config);
9797

98-
$factory = new LazyControllerFactory();
98+
$factory = new LazyControllerAbstractFactory();
9999
$controller = $factory($this->container->reveal(), TestAsset\ControllerAcceptingConfigToConstructor::class);
100100
$this->assertInstanceOf(TestAsset\ControllerAcceptingConfigToConstructor::class, $controller);
101101
$this->assertEquals($config, $controller->config);
@@ -107,7 +107,7 @@ public function testFactoryCanInjectKnownTypeHintedServices()
107107
$this->container->has(TestAsset\SampleInterface::class)->willReturn(true);
108108
$this->container->get(TestAsset\SampleInterface::class)->willReturn($sample);
109109

110-
$factory = new LazyControllerFactory();
110+
$factory = new LazyControllerAbstractFactory();
111111
$controller = $factory($this->container->reveal(), TestAsset\ControllerWithTypeHintedConstructorParameter::class);
112112
$this->assertInstanceOf(TestAsset\ControllerWithTypeHintedConstructorParameter::class, $controller);
113113
$this->assertSame($sample, $controller->sample);
@@ -119,7 +119,7 @@ public function testFactoryResolvesTypeHintsForServicesToWellKnownServiceNames()
119119
$this->container->has('ValidatorManager')->willReturn(true);
120120
$this->container->get('ValidatorManager')->willReturn($validators);
121121

122-
$factory = new LazyControllerFactory();
122+
$factory = new LazyControllerAbstractFactory();
123123
$controller = $factory(
124124
$this->container->reveal(),
125125
TestAsset\ControllerAcceptingWellKnownServicesAsConstructorParameters::class
@@ -145,7 +145,7 @@ public function testFactoryCanSupplyAMixOfParameterTypes()
145145
$this->container->has('config')->willReturn(true);
146146
$this->container->get('config')->willReturn($config);
147147

148-
$factory = new LazyControllerFactory();
148+
$factory = new LazyControllerAbstractFactory();
149149
$controller = $factory($this->container->reveal(), TestAsset\ControllerWithMixedConstructorParameters::class);
150150
$this->assertInstanceOf(TestAsset\ControllerWithMixedConstructorParameters::class, $controller);
151151

0 commit comments

Comments
 (0)