Skip to content
This repository was archived by the owner on May 1, 2019. It is now read-only.

Commit 0d31b7d

Browse files
author
Gianluca Arbezzano
committed
Split indexController into userController
1 parent f75e966 commit 0d31b7d

File tree

5 files changed

+74
-17
lines changed

5 files changed

+74
-17
lines changed

module/ZfModule/config/module.config.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'controllers' => [
1212
'factories' => [
1313
Controller\IndexController::class => Controller\IndexControllerFactory::class,
14+
Controller\UserController::class => Controller\UserControllerFactory::class,
1415
],
1516
],
1617
'router' => [
@@ -33,7 +34,7 @@
3334
'owner' => '[a-zA-Z][a-zA-Z0-9_-]*',
3435
],
3536
'defaults' => [
36-
'controller' => Controller\IndexController::class,
37+
'controller' => Controller\UserController::class,
3738
'action' => 'modulesForUser',
3839
],
3940
],

module/ZfModule/src/ZfModule/Controller/IndexController.php

-16
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,6 @@ public function viewAction()
7777
]);
7878
}
7979

80-
public function modulesForUserAction()
81-
{
82-
$query = $this->params()->fromQuery('query', null);
83-
$page = (int) $this->params()->fromQuery('page', 1);
84-
$owner = $this->params()->fromRoute('owner');
85-
86-
$modules = $this->moduleMapper->pagination($page, 10, $owner, 'created_at', "DESC");
87-
88-
$viewModel = new ViewModel([
89-
'modules' => $modules,
90-
'query' => $query,
91-
]);
92-
93-
return $viewModel;
94-
}
95-
9680
public function indexAction()
9781
{
9882
if (!$this->zfcUserAuthentication()->hasIdentity()) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
namespace ZfModule\Controller;
3+
4+
use Zend\Mvc\Controller\AbstractActionController;
5+
use Zend\View\Model\ViewModel;
6+
use ZfModule\Mapper;
7+
8+
class UserController extends AbstractActionController
9+
{
10+
/**
11+
* @var Mapper\Module
12+
*/
13+
private $moduleMapper;
14+
15+
/**
16+
* @param Mapper\Module $moduleMapper
17+
*/
18+
public function __construct(
19+
Mapper\Module $moduleMapper
20+
) {
21+
$this->moduleMapper = $moduleMapper;
22+
}
23+
24+
public function modulesForUserAction()
25+
{
26+
$query = $this->params()->fromQuery('query', null);
27+
$page = (int) $this->params()->fromQuery('page', 1);
28+
$owner = $this->params()->fromRoute('owner');
29+
30+
$modules = $this->moduleMapper->pagination($page, 10, $owner, 'created_at', "DESC");
31+
32+
$viewModel = new ViewModel([
33+
'modules' => $modules,
34+
'query' => $query,
35+
]);
36+
37+
return $viewModel;
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace ZfModule\Controller;
4+
5+
use Zend\Mvc\Controller\ControllerManager;
6+
use Zend\ServiceManager\FactoryInterface;
7+
use Zend\ServiceManager\ServiceLocatorInterface;
8+
use ZfModule\Mapper;
9+
use ZfModule\Service;
10+
11+
class UserControllerFactory implements FactoryInterface
12+
{
13+
/**
14+
* @param ServiceLocatorInterface $controllerManager
15+
* @return IndexController
16+
*/
17+
public function createService(ServiceLocatorInterface $controllerManager)
18+
{
19+
/* @var ControllerManager $controllerManager */
20+
$serviceManager = $controllerManager->getServiceLocator();
21+
22+
/* @var Mapper\Module $moduleMapper */
23+
$moduleMapper = $serviceManager->get(Mapper\Module::class);
24+
25+
/* @var Service\Module $moduleService */
26+
$moduleService = $serviceManager->get(Service\Module::class);
27+
28+
return new UserController(
29+
$moduleMapper,
30+
$moduleService
31+
);
32+
}
33+
}

0 commit comments

Comments
 (0)