Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****************************************
- *Type: Config
- *Name: module.config.php
- *erstellt am: 15.10.2012
- *****************************************/
- <?php
- return array(
- 'di' => array(
- 'allowed_controllers' => array(
- 'helloworld-index-controller'
- ),
- 'definition' => array(
- 'class' => array(
- 'Helloworld\Service\GreetingService' => array(
- 'setLoggingService' => array(
- 'required' => true
- )
- ),
- 'Helloworld\Controller\IndexController' => array(
- 'setGreetingService' => array(
- 'required' => true
- )
- )
- )
- ),
- 'instance' => array(
- 'preferences' => array(
- 'Helloworld\Service\LoggingServiceInterface' => 'Helloworld\Service\LoggingService'
- ),
- 'Helloworld\Service\LoggingService' => array(
- 'parameters' => array(
- 'logfile' => __DIR__ . '/../../../data/log.txt'
- )
- ),
- 'alias' => array(
- 'helloworld-index-controller' => 'Helloworld\Controller\IndexController',
- ),
- )
- ),
- 'view_manager' => array(
- 'template_path_stack' => array(
- __DIR__ . '/../view'
- ),
- ),
- 'router' => array(
- 'routes' => array(
- 'sayhello' => array(
- 'type' => 'Zend\Mvc\Router\Http\Literal',
- 'options' => array(
- 'route' => '/sayhello',
- 'defaults' => array(
- 'controller' => 'Helloworld\Controller\Index',
- 'action' => 'index',
- )
- )
- ),
- 'testForm' => array(
- 'type' => 'Zend\Mvc\Router\Http\Literal',
- 'options' => array(
- 'route' => '/testForm',
- 'defaults' => array(
- 'controller' => 'Helloworld\Controller\TestForm',
- 'action' => 'test',
- )
- )
- ),
- 'testFormSignUp' => array(
- 'type' => 'Zend\Mvc\Router\Http\Literal',
- 'options' => array(
- 'route' => '/testForm2/signup',
- 'defaults' => array(
- 'controller' => 'Helloworld\Controller\TestForm',
- 'action' => 'signup',
- )
- )
- ),
- )
- ),
- 'controllers' => array(
- 'invokables' => array(
- 'Helloworld\Controller\TestForm' => 'Helloworld\Controller\TestFormController'
- ),
- 'factories' => array(
- 'Helloworld\Controller\Index' => 'Helloworld\Controller\IndexControllerFactory'
- )
- ),
- 'view_helpers' => array(
- 'invokables' => array(
- 'displayCurrentDate' => 'Helloworld\View\Helper\DisplayCurrentDate'
- )
- )
- );
- ?>
- /****************************************
- *Type: ControllerFactory
- *Name: IndexControllerFactory.php
- *erstellt am: 15.10.2012
- *****************************************/
- <?PHP
- namespace Helloworld\Controller;
- use Zend\ServiceManager\FactoryInterface;
- use Zend\ServiceManager\ServiceLocatorInterface;
- class IndexControllerFactory implements FactoryInterface
- {
- public function createService(ServiceLocatorInterface $serviceLocator)
- {
- $ctr = new IndexController();
- $serviceLocator = $serviceLocator->getServiceLocator();
- $greetingSrv = $serviceLocator->get('Helloworld\Service\GreetingService');
- $ctr->setGreetingService($greetingSrv);
- return $ctr;
- }
- }
- ?>
- /****************************************
- *Type: Controller
- *Name: IndexController.php
- *erstellt am: 15.10.2012
- *****************************************/
- <?php
- namespace Helloworld\Controller;
- use Zend\Mvc\Controller\AbstractActionController;
- use Zend\View\Model\ViewModel;
- class IndexController extends AbstractActionController
- {
- private $greetingService;
- public function indexAction()
- {
- $greetingLine = $this->greetingService->getGreeting();
- return new ViewModel(
- array('greetingLine' => $greetingLine)
- );
- }
- public function setGreetingService($greetingService)
- {
- $this->greetingService = $greetingService;
- }
- public function getGreetingService()
- {
- return $this->greetingService;
- }
- }
- ?>
- /****************************************
- *Type: ServiceFactory
- *Name: GreetingServiceFactory.php
- *erstellt am: 15.10.2012
- *****************************************/
- <?PHP
- namespace Helloworld\Service;
- use Zend\ServiceManager\FactoryInterface;
- use Zend\ServiceManager\ServiceLocatorInterface;
- class GreetingServiceFactory implements FactoryInterface
- {
- public function createService(ServiceLocatorInterface $serviceLocator)
- {
- $greetingService = new \Helloworld\Service\GreetingService();
- $hourProvider = new \Helloworld\Service\GreetingService\HourProviderDateFunction();
- $greetingService->setHourProvider($hourProvider);
- return $greetingService;
- }
- }
- ?>
- /****************************************
- *Type: Service
- *Name: GreetingService.php
- *erstellt am: 15.10.2012
- *****************************************/
- <?php
- namespace Helloworld\Service;
- use Zend\EventManager\EventManagerInterface;
- use Helloworld\Service\GreetingService\HourProviderInterface;
- class GreetingService
- {
- private $eventManager;
- private $loggingService;
- private $hourProvider;
- public function getGreeting()
- {
- if (!$this->hourProvider)
- throw new \BadFunctionCallException('HourProvider not yet set.');
- $hour = $this->hourProvider->getHour();
- if($hour <= 11)
- return "Good morning, world!";
- else if($hour > 11 && $hour < 17)
- return "Hello, world!";
- else
- return "Good evending, world!";
- }
- public function setHourProvider(HourProviderInterface $hourProvider)
- {
- $this->hourProvider = $hourProvider;
- }
- public function getHourProvider()
- {
- return $this->hourProvider;
- }
- public function getEventManager()
- {
- return $this->eventManager;
- }
- public function setEventManager(EventManagerInterface $em)
- {
- $this->eventManager = $em;
- }
- public function setLoggingService(LoggingServiceInterface $loggingService)
- {
- return $this->loggingService = $loggingService;
- }
- public function getLoggingService()
- {
- return $this->loggingService;
- }
- }
- ?>
- /****************************************
- *Type: Interface
- *Name: HourProviderInterface.php
- *erstellt am: 15.10.2012
- *****************************************/
- <?php
- namespace Helloworld\Service\GreetingService;
- interface HourProviderInterface
- {
- public function getHour();
- }
- /****************************************
- *Type: Function
- *Name: HourProviderDateFunction.php
- *erstellt am: 15.10.2012
- *****************************************/
- <?php
- namespace Helloworld\Service\GreetingService;
- use Helloworld\Service\GreetingService\HourProviderInterface;
- class HourProviderDateFunction implements HourProviderInterface
- {
- public function getHour()
- {
- return date("H");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement