-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.php
152 lines (126 loc) · 4.27 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/**
* Metator (http://metator.com/)
* @copyright Copyright (c) 2013 Vehicle Fits, llc
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
namespace VehicleFitsMetator;
use Zend\Console\Adapter\AdapterInterface as Console;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Application\ProductMapper;
use Zend\ModuleManager\Feature\ConsoleBannerProviderInterface;
use Zend\ModuleManager\Feature\ConsoleUsageProviderInterface;
class Module implements
ConsoleBannerProviderInterface,
ConsoleUsageProviderInterface
{
protected $categoryMapper;
function init($moduleManager)
{
}
public function onBootstrap(MvcEvent $e)
{
if(!isset($_SESSION)) {
session_start();
}
define( 'ELITE_CONFIG_DEFAULT', dirname(__FILE__).'/config.default.ini' );
define( 'ELITE_CONFIG', dirname(__FILE__).'/config.ini' );
define( 'ELITE_PATH', '' );
/** @var $zf2DB \Zend\Db\Adapter\Adapter */
$zf2DB = $e->getApplication()->getServiceManager()->get('Zend\Db\Adapter\Adapter');
$pdo = $zf2DB->getDriver()->getConnection()->getResource();
$zf1DB = $this->createDB($pdo);
\VF_Singleton::getInstance()->setReadAdapter($zf1DB);
\VF_Singleton::getInstance()->setRequest(new \Zend_Controller_Request_Http());
\VF_Singleton::getInstance()->setProcessURL('/vf/process?');
$search = new \VF_FlexibleSearch(new \VF_Schema, new \Zend_Controller_Request_Http);
//$search->setConfig(new \Zend_Config(array()));
$search->storeFitInSession();
}
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(
'Product\DataMapper' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
return new DataMapper($dbAdapter);
}
),
);
}
/**
* Define Console Help text
*
* @param Console $console
* @return String
*/
public function getConsoleUsage(Console $console)
{
return array(
);
}
/**
* Generates the Console Banner text
*
* @param Console $console
* @return String
*/
public function getConsoleBanner(Console $console)
{
}
public function getViewHelperConfig()
{
return array(
'invokables'=>array(
'vfsearch'=>'\VehicleFitsMetator\View\Helper\Search',
)
);
}
function createDB($pdo)
{
$this->requireConfig();
// ZF1 throws an exception if params aren't passed to constructor, but we never let it create a PDO
// anyways because we inject our own PDO.
$dbAdapter = new custom(array('dbname'=>'ignored', 'username'=>'ignored', 'password'=>'ignored'));
$dbAdapter->setPDO($pdo);
$dbAdapter->getConnection()->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
$dbAdapter->getConnection()->query('SET character set utf8;');
$dbAdapter->getConnection()->query('SET character_set_client = utf8;');
$dbAdapter->getConnection()->query('SET character_set_results = utf8;');
$dbAdapter->getConnection()->query('SET character_set_connection = utf8;');
$dbAdapter->getConnection()->query('SET character_set_database = utf8;');
$dbAdapter->getConnection()->query('SET character_set_server = utf8;');
return $dbAdapter;
}
/* Figure out where we are reading the database configuration from */
function requireConfig()
{
if(file_exists('config.php')) {
require_once(__DIR__.'/vfconfig.php');
} else {
require_once(__DIR__.'/vfconfig.default.php');
}
}
}
class custom extends \Zend_Db_Adapter_Pdo_Mysql
{
function setPDO($pdo)
{
$this->_connection = $pdo;
}
}