|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Contains Yapeal class. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5.5 |
|
6
|
|
|
* |
|
7
|
|
|
* LICENSE: |
|
8
|
|
|
* This file is part of Yet Another Php Eve Api Library also know as Yapeal |
|
9
|
|
|
* which can be used to access the Eve Online API data and place it into a |
|
10
|
|
|
* database. |
|
11
|
|
|
* Copyright (C) 2014-2016 Michael Cummings |
|
12
|
|
|
* |
|
13
|
|
|
* This program is free software: you can redistribute it and/or modify it |
|
14
|
|
|
* under the terms of the GNU Lesser General Public License as published by the |
|
15
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
|
16
|
|
|
* option) any later version. |
|
17
|
|
|
* |
|
18
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
19
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
20
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
|
21
|
|
|
* for more details. |
|
22
|
|
|
* |
|
23
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
24
|
|
|
* along with this program. If not, see |
|
25
|
|
|
* <http://www.gnu.org/licenses/>. |
|
26
|
|
|
* |
|
27
|
|
|
* You should be able to find a copy of this license in the LICENSE.md file. A |
|
28
|
|
|
* copy of the GNU GPL should also be available in the GNU-GPL.md file. |
|
29
|
|
|
* |
|
30
|
|
|
* @copyright 2014-2016 Michael Cummings |
|
31
|
|
|
* @license http://www.gnu.org/copyleft/lesser.html GNU LGPL |
|
32
|
|
|
* @author Michael Cummings <[email protected]> |
|
33
|
|
|
*/ |
|
34
|
|
|
namespace Yapeal; |
|
35
|
|
|
|
|
36
|
|
|
use PDO; |
|
37
|
|
|
use PDOException; |
|
38
|
|
|
use Yapeal\Container\ContainerInterface; |
|
39
|
|
|
use Yapeal\Event\EveApiEventEmitterTrait; |
|
40
|
|
|
use Yapeal\Exception\YapealDatabaseException; |
|
41
|
|
|
use Yapeal\Exception\YapealException; |
|
42
|
|
|
use Yapeal\Log\Logger; |
|
43
|
|
|
use Yapeal\Sql\CommonSqlQueries; |
|
44
|
|
|
use Yapeal\Xml\EveApiReadWriteInterface; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Class Yapeal |
|
48
|
|
|
*/ |
|
49
|
|
|
class Yapeal |
|
50
|
|
|
{ |
|
51
|
|
|
use CommonToolsTrait, EveApiEventEmitterTrait; |
|
52
|
|
|
/** |
|
53
|
|
|
* @param ContainerInterface $dic |
|
54
|
|
|
* |
|
55
|
|
|
* @throws \DomainException |
|
56
|
|
|
* @throws \InvalidArgumentException |
|
57
|
|
|
* @throws YapealException |
|
58
|
|
|
* @throws YapealDatabaseException |
|
59
|
|
|
* @throws \LogicException |
|
60
|
|
|
*/ |
|
61
|
|
|
public function __construct(ContainerInterface $dic) |
|
62
|
|
|
{ |
|
63
|
|
|
$this->setDic($dic); |
|
64
|
|
|
} |
|
65
|
|
|
/** |
|
66
|
|
|
* Starts Eve API processing |
|
67
|
|
|
* |
|
68
|
|
|
* @return int Returns 0 if everything was fine else something >= 1 for any |
|
69
|
|
|
* errors. |
|
70
|
|
|
* @throws \LogicException |
|
71
|
|
|
* @throws \DomainException |
|
72
|
|
|
* @throws \InvalidArgumentException |
|
73
|
|
|
*/ |
|
74
|
|
|
public function autoMagic() |
|
75
|
|
|
{ |
|
76
|
|
|
$dic = $this->getDic(); |
|
77
|
|
|
$this->setYem($dic['Yapeal.Event.Mediator']); |
|
78
|
|
|
$mess = 'Let the magic begin!'; |
|
79
|
|
|
$this->getYem() |
|
80
|
|
|
->triggerLogEvent('Yapeal.Log.log', Logger::INFO, $mess); |
|
81
|
|
|
/** |
|
82
|
|
|
* @var CommonSqlQueries $csq |
|
83
|
|
|
*/ |
|
84
|
|
|
$csq = $dic['Yapeal.Sql.CommonQueries']; |
|
85
|
|
|
$sql = $csq->getActiveApis(); |
|
86
|
|
|
$this->getYem() |
|
87
|
|
|
->triggerLogEvent('Yapeal.Log.log', Logger::INFO, $sql); |
|
88
|
|
|
try { |
|
89
|
|
|
/** |
|
90
|
|
|
* @var PDO $pdo |
|
91
|
|
|
*/ |
|
92
|
|
|
$pdo = $dic['Yapeal.Sql.Connection']; |
|
93
|
|
|
$records = $pdo->query($sql) |
|
94
|
|
|
->fetchAll(PDO::FETCH_ASSOC); |
|
95
|
|
|
} catch (PDOException $exc) { |
|
96
|
|
|
$mess = 'Could not access utilEveApi table'; |
|
97
|
|
|
$this->getYem() |
|
98
|
|
|
->triggerLogEvent('Yapeal.Log.log', Logger::INFO, $mess, ['exception' => $exc]); |
|
99
|
|
|
return 1; |
|
100
|
|
|
} |
|
101
|
|
|
// Always check APIKeyInfo. |
|
102
|
|
|
array_unshift($records, ['apiName' => 'APIKeyInfo', 'interval' => '300', 'sectionName' => 'account']); |
|
103
|
|
|
foreach ($records as $record) { |
|
104
|
|
|
/** |
|
105
|
|
|
* Get new Data instance from factory. |
|
106
|
|
|
* |
|
107
|
|
|
* @var EveApiReadWriteInterface $data |
|
108
|
|
|
*/ |
|
109
|
|
|
$data = $dic['Yapeal.Xml.Data']; |
|
110
|
|
|
$data->setEveApiName($record['apiName']) |
|
111
|
|
|
->setEveApiSectionName($record['sectionName']) |
|
112
|
|
|
->setCacheInterval($record['interval']); |
|
113
|
|
|
$this->emitEvents($data, 'start'); |
|
114
|
|
|
} |
|
115
|
|
|
return 0; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|