-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
102 lines (79 loc) · 3.54 KB
/
bootstrap.php
File metadata and controls
102 lines (79 loc) · 3.54 KB
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
<?php
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Setup;
use Symfony\Component\Yaml\Parser;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
require_once "vendor/autoload.php";
class Bootstrap {
private static $entityManager;
private static $config;
private static $logger = [];
private static $runmode;
public static function go() {
$parser = new Parser();
$config = $parser->parse(file_get_contents(__DIR__ . '/config.yml'));
self::$config = $config;
$logger['pf3'] = new Logger('pf3');
$logger['pf3']->pushHandler(new StreamHandler($config['pf3server_log_directory'] . '/pinfinder.log', Logger::INFO));
$logger['pf3']->pushHandler(new StreamHandler($config['pf3server_log_directory'] . '/pinfinder_error.log', Logger::ERROR));
$logger['pf3_scrape'] = new Logger('pf3_scrape');
//$logger['pf3_scrape']->pushHandler(new StreamHandler($config['pf3server_log_directory'] . '/scrape.log', Logger::INFO));
$logger['pf3_scrape']->pushHandler(new StreamHandler($config['pf3server_log_directory'] . '/scrape_error.log', Logger::ERROR));
self::$logger = $logger;
self::$runmode = $config['pf3server_runmode'];
$credentials = $parser->parse(file_get_contents(__DIR__ . '/credentials.yml'));
$conn = array(
'driver' => 'pdo_mysql',
'dbname' => $credentials['pf3server_db_name'],
'user' => $credentials['pf3server_db_user'],
'password' => $credentials['pf3server_db_password'],
'host' => $credentials['pf3server_db_host'],
'driverOptions' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => "SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))"
)
);
$proxy_dir = __DIR__ . '/cache';
if (self::$runmode === 'production' && extension_loaded('memcached')) {
$memcached = new Memcached();
$memcached->addServer('localhost', 11211);
$cache_impl = new \Doctrine\Common\Cache\MemcachedCache();
$cache_impl->setMemcached($memcached);
}
if (empty($cache_impl)) {
$cache_impl = new \Doctrine\Common\Cache\FilesystemCache(__DIR__ . '/cache');
}
$config = Setup::createYAMLMetadataConfiguration(array(__DIR__ . '/src/PF/Doctrine/yml'), self::$runmode !== 'production', $proxy_dir, $cache_impl);
$config->addCustomNumericFunction('SIN', '\DoctrineExtensions\Query\Mysql\Sin');
$config->addCustomNumericFunction('COS', '\DoctrineExtensions\Query\Mysql\Cos');
$config->addCustomNumericFunction('ACOS', '\DoctrineExtensions\Query\Mysql\Acos');
$config->addCustomNumericFunction('RADIANS', '\DoctrineExtensions\Query\Mysql\Radians');
$config->addCustomNumericFunction('YEAR', '\DoctrineExtensions\Query\Mysql\Year');
$config->addCustomNumericFunction('MONTH', '\DoctrineExtensions\Query\Mysql\Month');
$config->addCustomNumericFunction('DATEDIFF', '\DoctrineExtensions\Query\Mysql\DateDiff');
$config->addCustomStringFunction('DATE_FORMAT', '\DoctrineExtensions\Query\Mysql\DateFormat');
$config->addCustomDatetimeFunction('LAST_DAY', '\DoctrineExtensions\Query\Mysql\LastDay');
self::$entityManager = EntityManager::create($conn, $config);
}
/**
* @var $identifier string
*
* @return Logger
*/
public static function getLogger($identifier = 'pf3') {
return static::$logger[$identifier];
}
/**
* @return EntityManager
*/
public static function getEntityManager() {
return static::$entityManager;
}
public static function getConfig() {
return static::$config;
}
public static function getRunmode() {
return static::$runmode;
}
}
Bootstrap::go();