1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) Enalean, 2013 - 2015. All Rights Reserved. |
4
|
|
|
* |
5
|
|
|
* Tuleap is free software; you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU General Public License as published by |
7
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* |
10
|
|
|
* Tuleap is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU General Public License |
16
|
|
|
* along with Tuleap; if not, write to the Free Software |
17
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
define('IS_SCRIPT', true); |
21
|
|
|
|
22
|
|
|
require_once 'pre.php'; |
23
|
|
|
require_once 'www/project/admin/permissions.php'; |
24
|
|
|
require_once '/usr/share/restler/vendor/restler.php'; |
25
|
|
|
|
26
|
|
|
use Tuleap\REST\GateKeeper; |
27
|
|
|
use Luracast\Restler\Restler; |
28
|
|
|
use Luracast\Restler\Explorer; |
29
|
|
|
use Luracast\Restler\Defaults; |
30
|
|
|
|
31
|
|
|
try { |
32
|
|
|
$gate_keeper = new GateKeeper(); |
33
|
|
|
$gate_keeper->assertAccess(UserManager::instance()->getCurrentUser()); |
34
|
|
|
} catch (Exception $exception) { |
35
|
|
|
header("HTTP/1.0 403 Forbidden"); |
36
|
|
|
$GLOBALS['Response']->sendJSON(array( |
37
|
|
|
'error' => $exception->getMessage() |
38
|
|
|
)); |
39
|
|
|
die(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
preg_match('/^\/api\/v(\d+)\//', $_SERVER['REQUEST_URI'], $matches); |
43
|
|
|
$version = floor(file_get_contents(__DIR__ .'/VERSION')); |
44
|
|
|
if ($matches && isset($matches[1]) && $matches[1] == 2) { |
|
|
|
|
45
|
|
|
$version = 2; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// Do not put .json at the end of the resource |
49
|
|
|
Explorer::$useFormatAsExtension = false; |
50
|
|
|
|
51
|
|
|
//Do not hide the API |
52
|
|
|
Explorer::$hideProtected = false; |
53
|
|
|
// Use /api/v1/projects uri |
54
|
|
|
Defaults::$useUrlBasedVersioning = true; |
55
|
|
|
|
56
|
|
|
if (ForgeConfig::get('DEBUG_MODE')) { |
57
|
|
|
$restler = new Restler(false, true); |
58
|
|
|
$restler->setSupportedFormats('JsonFormat', 'XmlFormat', 'HtmlFormat'); |
59
|
|
|
} else { |
60
|
|
|
$restler_cache = new RestlerCache(); |
61
|
|
|
Defaults::$cacheDirectory = $restler_cache->getAndInitiateCacheDirectory($version); |
62
|
|
|
$restler = new Restler(true, false); |
63
|
|
|
$restler->setSupportedFormats('JsonFormat', 'XmlFormat'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
// Do not let Restler find itself the domain, when behind a reverse proxy, it's |
67
|
|
|
// a mess. |
68
|
|
|
$restler->setBaseUrl($sys_default_domain); |
69
|
|
|
$restler->setAPIVersion($version); |
70
|
|
|
|
71
|
|
|
$core_resources_injector = new Tuleap\REST\ResourcesInjector(); |
72
|
|
|
$core_resources_injector->populate($restler); |
73
|
|
|
|
74
|
|
|
switch ($version) { |
75
|
|
|
case 2: |
76
|
|
|
$event = Event::REST_RESOURCES_V2; |
77
|
|
|
break; |
78
|
|
|
default: |
79
|
|
|
$event = Event::REST_RESOURCES; |
80
|
|
|
break; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
EventManager::instance()->processEvent($event, array('restler' => $restler)); |
84
|
|
|
$restler->addAPIClass('Explorer'); |
85
|
|
|
|
86
|
|
|
$restler->addAuthenticationClass('\\Tuleap\\REST\\TokenAuthentication'); |
87
|
|
|
$restler->addAuthenticationClass('\\Tuleap\\REST\\BasicAuthentication'); |
88
|
|
|
$restler->handle(); |
89
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.