Browse files

Created service factories

- Table factory grabs service for adapter, and initial table name, to seed a
  PeepTable instance
- Service factory grabs the phly-peep-table service, and uses that and the
  page_size, if configured, to seed a PeepService instance
- Controller factory grabs the phly-peep-service and zfcuser_auth_service
  services, and uses them to seed a PeepController instance
  • Loading branch information...
1 parent 1a7ecde commit fca61a5ded9819d8ac4700139bb058828d1bd5c5 @weierophinney committed Jun 1, 2012
View
11 config/module.config.php
@@ -5,6 +5,7 @@
'adapter' => 'Zend\Db\Adapter\Adapter',
'table' => 'peep',
),
+ 'page_size' => 20,
),
'router' => array(
'routes' => array(
@@ -59,8 +60,14 @@
),
),
'controller' => array(
- 'classes' => array(
- 'phly-peep' => 'PhlyPeep\Controller\PeepController',
+ 'factories' => array(
+ 'phly-peep' => 'PhlyPeep\Service\PeepControllerFactory',
+ ),
+ ),
+ 'service_manager' => array(
+ 'factories' => array(
+ 'phly-peep-table' => 'PhlyPeep\Service\PeepTableFactory',
+ 'phly-peep-service' => 'PhlyPeep\Service\PeepServiceFactory',
),
),
);
View
20 src/PhlyPeep/Service/PeepControllerFactory.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace PhlyPeep\Service;
+
+use PhlyPeep\Controller\PeepController;
+use Zend\ServiceManager\FactoryInterface;
+use Zend\ServiceManager\ServiceLocatorInterface;
+
+class PeepControllerFactory implements FactoryInterface
+{
+ public function createService(ServiceLocatorInterface $services)
+ {
+ $authService = $services->get('zfcuser_auth_service');
+ $peepService = $services->get('phly-peep-service');
+ $controller = new PeepController();
+ $controller->setAuthService($authService);
+ $controller->setPeepService($peepService);
+ return $controller;
+ }
+}
View
23 src/PhlyPeep/Service/PeepServiceFactory.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace PhlyPeep\Service;
+
+use PhlyPeep\Model\PeepService;
+use Zend\ServiceManager\FactoryInterface;
+use Zend\ServiceManager\ServiceLocatorInterface;
+
+class PeepServiceFactory implements FactoryInterface
+{
+ public function createService(ServiceLocatorInterface $services)
+ {
+ $config = $services->get('config');
+ $peepTable = $services->get('phly-peep-table');
+ $service = new PeepService($peepTable);
+
+ if (isset($config['phly_peep']) && isset($config['phly_peep']['page_size'])) {
+ $service->setPageSize($config['phly_peep']['page_size']);
+ }
+
+ return $service;
+ }
+}
View
23 src/PhlyPeep/Service/PeepTableFactory.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace PhlyPeep\Service;
+
+use PhlyPeep\Model\PeepTable;
+use Zend\ServiceManager\FactoryInterface;
+use Zend\ServiceManager\ServiceLocatorInterface;
+
+class PeepTableFactory implements FactoryInterface
+{
+ public function createService(ServiceLocatorInterface $services)
+ {
+ $config = $services->get('config');
+ $config = $config['phly_peep']['db'];
+
+ $adapter = $services->get($config['adapter']);
+ $tableName = $config['table'];
+
+ $table = new PeepTable($adapter, $tableName);
+
+ return $table;
+ }
+}

0 comments on commit fca61a5

Please sign in to comment.