Created
November 8, 2012 12:06
-
-
Save eminetto/4038412 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Admin; | |
// module/Admin/config/module.config.php: | |
return array( | |
'controllers' => array( //add module controllers | |
'invokables' => array( | |
'Admin\Controller\Index' => 'Admin\Controller\IndexController', | |
'Admin\Controller\Auth' => 'Admin\Controller\AuthController', | |
'Admin\Controller\User' => 'Admin\Controller\UserController', | |
), | |
), | |
'router' => array( | |
'routes' => array( | |
'admin' => array( | |
'type' => 'Literal', | |
'options' => array( | |
'route' => '/admin', | |
'defaults' => array( | |
'__NAMESPACE__' => 'Admin\Controller', | |
'controller' => 'Index', | |
'action' => 'index', | |
'module' => 'admin' | |
), | |
), | |
'may_terminate' => true, | |
'child_routes' => array( | |
'default' => array( | |
'type' => 'Segment', | |
'options' => array( | |
'route' => '/[:controller[/:action]]', | |
'constraints' => array( | |
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', | |
'action' => '[a-zA-Z][a-zA-Z0-9_-]*', | |
), | |
'defaults' => array( | |
), | |
), | |
'child_routes' => array( //permite mandar dados pela url | |
'wildcard' => array( | |
'type' => 'Wildcard' | |
), | |
), | |
), | |
), | |
), | |
), | |
), | |
'view_manager' => array( //the module can have a specific layout | |
// 'template_map' => array( | |
// 'layout/layout' => __DIR__ . '/../view/layout/layout.phtml', | |
// ), | |
'template_path_stack' => array( | |
'admin' => __DIR__ . '/../view', | |
), | |
), | |
// 'db' => array( //module can have a specific db configuration | |
// 'driver' => 'PDO_SQLite', | |
// 'dsn' => 'sqlite:' . __DIR__ .'/../data/skel.db', | |
// 'driver_options' => array( | |
// PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION | |
// ) | |
// ) | |
'service_manager' => array( | |
'factories' => array( | |
'Session' => function($sm) { | |
return new \Zend\Session\Container('ZF2napratica'); | |
}, | |
'Admin\Service\Auth' => function($sm) { | |
$dbAdapter = $sm->get('DbAdapter'); | |
return new Service\Auth($dbAdapter); | |
}, | |
'Cache' => function($sm) { | |
$config = $sm->get('Configuration'); | |
$cache = StorageFactory::factory( | |
array( | |
'adapter' => $config['cache']['adapter'], | |
'plugins' => array( | |
'exception_handler' => array('throw_exceptions' => false), | |
'Serializer' | |
), | |
) | |
); | |
return $cache; | |
}, | |
'Doctrine\ORM\EntityManager' => function($sm) { | |
$config = $sm->get('Configuration'); | |
$doctrineConfig = new \Doctrine\ORM\Configuration(); | |
$cache = new $config['doctrine']['driver']['cache']; | |
$doctrineConfig->setQueryCacheImpl($cache); | |
$doctrineConfig->setProxyDir('/tmp'); | |
$doctrineConfig->setProxyNamespace('EntityProxy'); | |
$doctrineConfig->setAutoGenerateProxyClasses(true); | |
$driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver( | |
new \Doctrine\Common\Annotations\AnnotationReader(), | |
array($config['doctrine']['driver']['paths']) | |
); | |
$doctrineConfig->setMetadataDriverImpl($driver); | |
$doctrineConfig->setMetadataCacheImpl($cache); | |
\Doctrine\Common\Annotations\AnnotationRegistry::registerFile( | |
getenv('PROJECT_ROOT'). '/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php' | |
); | |
$em = \Doctrine\ORM\EntityManager::create( | |
$config['doctrine']['connection'], | |
$doctrineConfig | |
); | |
return $em; | |
}, | |
) | |
), | |
'doctrine' => array( | |
'driver' => array( | |
'cache' => 'Doctrine\Common\Cache\ArrayCache', | |
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Model') | |
), | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment