File: src/Factory/Zf2ControllerFactory.php

Recommend this page to a friend!
  Classes of Thierry Feuzeu  >  Jaxon for Zend Framework  >  src/Factory/Zf2ControllerFactory.php  >  Download  
File: src/Factory/Zf2ControllerFactory.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Jaxon for Zend Framework
Zend plugin to call PHP classes from with AJAX
Author: By
Last change: The view objects are saved in the DI container.
Date: 3 years ago
Size: 1,267 bytes
 

Contents

Class file image Download
<?php

namespace Jaxon\Zend\Factory;

use
Zend\ServiceManager\ServiceLocatorInterface;
use
Zend\ServiceManager\FactoryInterface;

class
Zf2ControllerFactory implements FactoryInterface
{
   
/**
     * Create a Jaxon Controller
     *
     * @param ServiceLocatorInterface $serviceLocator
     *
     * @return mixed
     */
   
public function createService(ServiceLocatorInterface $serviceLocator)
    {
       
// Service Manager
       
$sm = $serviceLocator->getServiceLocator();
       
// Controller name
       
$routeMatch = $sm->get('Application')->getMvcEvent()->getRouteMatch();
       
$controllerName = $routeMatch->getParam('controller');
       
// Controller class
       
$controllerClass = $controllerName;
        if(
substr($controllerName, 0, 1) != '\\')
        {
           
$controllerClass = '\\' . $controllerName;
        }
        if(
substr($controllerName, -10) != 'Controller')
        {
           
$controllerClass .= 'Controller';
        }
       
// Get and configure the Jaxon plugin
       
$jaxonPlugin = $sm->get('JaxonPlugin');
       
$jaxonPlugin->setZendViewRenderer($sm->get('ViewRenderer'));
       
// Create the Controller, passing the JaxonPlugin as parameter
       
return new $controllerClass($jaxonPlugin);
    }
}


For more information send a message to info at phpclasses dot org.