-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.php
66 lines (55 loc) · 2.42 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace Zf2FileUploader;
use Zf2FileUploader\Options\ModuleOptions;
use Zend\Mvc\MvcEvent;
class Module
{
/**
* @param MvcEvent $e
*/
public function onBootstrap(MvcEvent $e)
{
/* @var $sm \Zend\ServiceManager\ServiceManager */
$sm = $e->getApplication()->getServiceManager();
/* @var $di \Zend\Di\Di */
$di = $sm->get('di');
$config = $sm->get('config');
$options = new ModuleOptions(isset($config['zf2fileuploader']) ?
$config['zf2fileuploader'] :
array());
// Add the default entity driver only if specified in configuration
if ($options->getEnableDefaultEntities()) {
/* @var $chain \Doctrine\ORM\Mapping\Driver\DriverChain */
$chain = $sm->get('doctrine.driver.orm_default');
$annotationReader = $di->get('Doctrine\Common\Annotations\AnnotationReader');
$chain->addDriver($di->get('Doctrine\ORM\Mapping\Driver\AnnotationDriver',
array('reader'=>$annotationReader,
'paths' => array(__DIR__ . '/src/Zf2FileUploader/Entity'))),
'Zf2FileUploader\Entity');
}
$entityManager = $sm->get('Doctrine\ORM\EntityManager');
$di->instanceManager()->addSharedInstance($options, 'Zf2FileUploader\Options\ModuleOptions');
$di->instanceManager()->addSharedInstance($entityManager, 'Doctrine\ORM\EntityManager');
$di->instanceManager()->setTypePreference('Zf2FileUploader\Entity\ImageInterface',
array($options->getImageEntityClass()));
$translator = $options->getTranslator();
if (!is_null($translator) && class_exists($translator)) {
$di->instanceManager()->setParameters('Zf2FileUploader\I18n\Translator\Translator',
array('translator' => $translator));
}
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
)
)
);
}
}