-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
87 lines (74 loc) · 3.33 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace TI;use Zend\Mvc\MvcEvent;
use Zend\ServiceManager\ServiceLocatorInterface;
use Doctrine\ORM\Tools\SchemaTool;
use DoctrineORMModule\Service\EntityManagerFactory;
use DoctrineORMModule\Service\DBALConnectionFactory;
use DoctrineORMModule\Service\ConfigurationFactory as ORMConfigurationFactory;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
use Zend\ModuleManager\Feature\ConsoleBannerProviderInterface;
use Zend\ModuleManager\Feature\ConsoleUsageProviderInterface;
use Zend\Console\Adapter\AdapterInterface as Console;
class Module implements ServiceProviderInterface,ConsoleUsageProviderInterface
{
public function onBootstrap(MvcEvent $e) {
$application = $e->getApplication();
$services = $application->getServiceManager();
$this->initDatabase($services);
}
protected function initDatabase(ServiceLocatorInterface $services) {
$em = $services->get('doctrine.entitymanager.orm_default');
$dir = __DIR__ . '/src/' . __NAMESPACE__ . '/Entity/*.php';
$classes = array();
foreach (glob($dir) as $file) {
$filename = end(explode('/', $file));
$lock = 'lock/'.$filename . '.lock';
if (!file_exists($lock)) {
include($file);
$entity = str_replace('.php', '', $file);
$ex = end(explode('/', $entity));
$newentity = __NAMESPACE__ . '\Entity\\' . $ex;
$obj = new $newentity($em);
$classes[] = $em->getClassMetadata($newentity);
file_put_contents($lock, 'lock');
}
}
$tool = new SchemaTool($em);
$tool->createSchema($classes);
}
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__,
),
),
);
}
public function getServiceConfig()
{
return array(
'factories' => array(
'doctrine.entitymanager.orm_alternative' => new EntityManagerFactory('orm_alternative'),
'doctrine.connection.orm_alternative' => new DBALConnectionFactory('orm_alternative'),
'doctrine.configuration.orm_alternative' => new ORMConfigurationFactory('orm_alternative'),
),
);
}
public function getConsoleUsage(Console $console){
return array(
// Describe available commands
'impressao (--importar|-i) [--all|-a] --caminho= [--verbose|-v]' => 'Importa dados de impressao a partir de um arquivo ou diretorio',
// Describe expected parameters
array( '--importar|-i', 'Importar dados da impressao' ),
array( '--all|-a', '(optional) Todos os arquivos do caminho especificado' ),
array( '--caminho', 'Caminho arquivo de dados da impressao' ),
array( '--verbose|-v', '(optional) turn on verbose mode' ),
);
}
}