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