-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtoggl2redmine.php
executable file
·111 lines (89 loc) · 3.33 KB
/
toggl2redmine.php
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
use Psr\Container\ContainerInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use undpaul\Kernel;
if (version_compare('8.3.0', PHP_VERSION, '>')) {
fwrite(
STDERR,
sprintf(
'This version of Toggl2Redmine requires PHP >= 8.2.' . PHP_EOL .
'You are using PHP %s (%s).' . PHP_EOL,
PHP_VERSION,
PHP_BINARY
)
);
die(1);
}
if (isset($GLOBALS['_composer_autoload_path'])) {
define('TOGGL2REDMINE_COMPOSER_AUTOLOAD', $GLOBALS['_composer_autoload_path']);
unset($GLOBALS['_composer_autoload_path']);
}
else {
$autoload_candidates = [
__DIR__ . '/../../autoload.php',
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/vendor/autoload.php',
];
foreach ($autoload_candidates as $file) {
if (file_exists($file)) {
define('TOGGL2REDMINE_COMPOSER_AUTOLOAD', $file);
break;
}
}
unset($file);
}
if (!defined('TOGGL2REDMINE_COMPOSER_AUTOLOAD')) {
fwrite(
STDERR,
'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL .
' composer install' . PHP_EOL . PHP_EOL .
'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL
);
die(1);
}
require TOGGL2REDMINE_COMPOSER_AUTOLOAD;
// Initialize the kernel
$kernel = new Kernel($_ENV['APP_ENV'] ?? 'dev', (bool) ($_ENV['APP_DEBUG'] ?? false));
$kernel->boot();
$application = new Application(
name: 'Toggl2Redmine',
version: '2.1.1',
);
// Create a new ContainerBuilder instance
$container_builder = new ContainerBuilder();
// Manually set parameters that are usually set by the Symfony kernel
$container_builder->setParameter('kernel.project_dir', $kernel->getProjectDir());
$container_builder->setParameter('kernel.environment', $kernel->getEnvironment());
$container_builder->setParameter('kernel.debug', $kernel->isDebug());
$container_builder->setParameter('kernel.cache_dir', $kernel->getCacheDir());
$container_builder->setParameter('kernel.logs_dir', $kernel->getLogDir());
$container_builder->setParameter('kernel.container_class', get_class($container_builder));
// Load additional service configurations
$loader = new YamlFileLoader($container_builder, new FileLocator($kernel->getProjectDir() . '/config'));
$loader->load('services.yaml');
// Setup the RequestStack manually
$request_stack = new RequestStack();
$request = Request::createFromGlobals();
$request_stack->push($request);
// Register the RequestStack in the container
$container_builder->set('request_stack', $request_stack);
// Alias the Psr\Container\ContainerInterface to the Symfony service container
$container_builder->setAlias(ContainerInterface::class, 'service_container');
// Compile container
$container_builder->compile();
// Register commands from the container
foreach ($container_builder->findTaggedServiceIds('console.command') as $id => $tags) {
$application->add($container_builder->get($id));
}
// Set input and output
$input = new ArgvInput();
$output = new ConsoleOutput();
// Run the application
exit($application->run($input, $output));