1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Plugin Definitions |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Fr3nch13\Jira; |
9
|
|
|
|
10
|
|
|
use Cake\Core\BasePlugin; |
11
|
|
|
use Cake\Core\Configure; |
12
|
|
|
use Cake\Core\PluginApplicationInterface; |
13
|
|
|
use Cake\Routing\Route\DashedRoute; |
14
|
|
|
use Cake\Routing\RouteBuilder; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Plugin Definitions |
18
|
|
|
*/ |
19
|
|
|
class Plugin extends BasePlugin |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Bootstraping for this specific plugin. |
23
|
|
|
* |
24
|
|
|
* @param \Cake\Core\PluginApplicationInterface $app The app object. |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
68 |
|
public function bootstrap(PluginApplicationInterface $app): void |
28
|
|
|
{ |
29
|
|
|
// Add constants, load configuration defaults, |
30
|
|
|
// and initiate any required cakephp plugins. |
31
|
|
|
|
32
|
|
|
// detect which major version of php we're running, |
33
|
|
|
// and only filter if the version is greater than 7. |
34
|
68 |
|
$jiraHost = env('JIRA_HOST', false); |
35
|
68 |
|
if ($jiraHost) { |
36
|
68 |
|
$version = explode('.', PHP_VERSION); |
37
|
68 |
|
if ((int)$version[0] >= 7) { |
38
|
68 |
|
$jiraHost = filter_var($jiraHost, FILTER_VALIDATE_DOMAIN); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
68 |
|
if (!Configure::read('Jira')) { |
43
|
68 |
|
if (!defined('LOGS')) { |
44
|
|
|
define('LOGS', '/tmp/'); |
45
|
|
|
} |
46
|
68 |
|
Configure::write('Jira', [ |
47
|
68 |
|
'schema' => env('JIRA_SCHEMA', 'https'), |
48
|
68 |
|
'host' => $jiraHost, |
49
|
68 |
|
'username' => env('JIRA_USERNAME', null), |
50
|
68 |
|
'apiKey' => env('JIRA_API_KEY', null), |
51
|
68 |
|
'projectKey' => env('JIRA_PROJECT_KEY', null), |
52
|
68 |
|
'useV3RestApi' => env('JIRA_REST_API_V3', true), |
53
|
68 |
|
'jiraLogFile' => LOGS . 'jira-client.log', |
54
|
68 |
|
]); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// By default will load `config/bootstrap.php` in the plugin. |
58
|
68 |
|
parent::bootstrap($app); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Add plugin specific routes here. |
63
|
|
|
* |
64
|
|
|
* @param \Cake\Routing\RouteBuilder $routes The passed routes object. |
65
|
|
|
* @return void |
66
|
|
|
*/ |
67
|
17 |
|
public function routes(RouteBuilder $routes): void |
68
|
|
|
{ |
69
|
|
|
// Add routes. |
70
|
17 |
|
$routes->plugin( |
71
|
17 |
|
'Fr3nch13/Jira', |
72
|
17 |
|
['path' => '/jira'], |
73
|
17 |
|
function (RouteBuilder $routes) { |
74
|
17 |
|
$routes->fallbacks(DashedRoute::class); |
75
|
17 |
|
} |
76
|
17 |
|
); |
77
|
|
|
|
78
|
|
|
// By default will load `config/routes.php` in the plugin. |
79
|
17 |
|
parent::routes($routes); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|