forked from albsierra/codetest
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinitTsugi.php
More file actions
86 lines (68 loc) · 2.75 KB
/
Copy pathinitTsugi.php
File metadata and controls
86 lines (68 loc) · 2.75 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
<?php
require_once('config.php');
require 'vendor/autoload.php';
require_once $CFG_CT->codetestBasePath. '/util/RestClient.php';
require_once $CFG_CT->codetestBasePath. '/util/JSONManager.php';
include_once('util/ValidatorService.php');
use Tsugi\Core\LTIX;
use Tsugi\Core\Launch;
use Symfony\Bridge\Twig\Extension\TranslationExtension;
use Symfony\Component\Translation\Loader\PhpFileLoader;
use Symfony\Component\Translation\Translator;
// Load launch data with Tsugi
$LAUNCH = LTIX::requireData();
// Initialize function that will get the help template for each page
$help = function() {
$phpFile = basename($_SERVER['PHP_SELF']);
if (file_exists("views/help/$phpFile.twig")) {
$filename = "$phpFile.twig";
} else {
$filename = 'no-help.php.twig';
}
return $filename;
};
// Add views path to loader
$loader = new \Twig\Loader\FilesystemLoader($CFG_CT->twig['viewsPath']);
$twig = new \Twig\Environment($loader, [
'debug' => false, // $CFG_CT->twig['debug'],
'cache' => $CFG_CT->twig['cachePath'],
]);
$jsonData = JSONManager::getJsonData(getenv("CODETEST_REST_FILE_PATH") ? sys_get_temp_dir().getenv("CODETEST_REST_FILE_PATH") : $CFG_CT->codetestBasePath. '/rest-data.json');
if(!empty($jsonData['spring-repo']['token'])){
$restClientRepo = new RestClient($CFG_CT->apiConfigs['spring-repo']['baseUrl'], $jsonData['spring-repo']['token']['accessToken']);
}else{
$restClientRepo = new RestClient($CFG_CT->apiConfigs['spring-repo']['baseUrl'], null);
$restClientRepo->loginRepo(
$CFG_CT->apiConfigs['spring-repo']['user'],
$CFG_CT->apiConfigs['spring-repo']['pass']
);
}
$restClientRepo->checkRepoIsOnline();
$GLOBALS['REST_CLIENT_REPO'] = $restClientRepo;
// Get locale from TSUGI extracted from the launch-data
$lang = substr($TSUGI_LOCALE, 0, 2);
// Initialize translations
$translator = new Translator($lang);
$translator->setFallbackLocales(["en"]);
$translator->addLoader('php', new PhpFileLoader());
// look for all the files recursively inside the locale folder
$filesIterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
realpath(__DIR__.'/locale')
)
);
// Add the files to the translation
foreach ($filesIterator as $file) {
if ($file->isDir() || !str_ends_with($file->getFileName(), 'php')){
continue;
}
$localeValueInPath = basename(dirname($file->getPathname(), 1));
$translator->addResource('php', $file->getPathname(), $localeValueInPath);
}
$twig->addExtension(new TranslationExtension( $translator));
function logg($message){
$timeFormat = new DateTime('now', new DateTimeZone("Europe/Madrid"));
$timeFormat = $timeFormat->format('d/m/Y H:i:s');
error_log("CT -> [$timeFormat] $message");
}
$validatorService = new ValidatorService;