-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.php
58 lines (46 loc) · 1.28 KB
/
init.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
<?php
declare(strict_types=1);
// Get the second inout val (the first one is the filename)
function getProblem($argc, $argv)
{
if ($argc > 1) {
$arg = $argv[1];
$matches = [];
$problem = preg_match('/[0-9]+/', $arg, $matches);
if ($matches !== false && count($matches) > 0) {
return $matches[0];
}
}
return false;
}
function copyBoilerplate($name)
{
$src = './boilerplate';
$dst = './src/'.$name;
if (file_exists($dst)) {
echo 'Directory '.$dst.' already exists, aborting!' . PHP_EOL;
exit;
}
echo 'Copying '.$src.' to '.$dst. PHP_EOL;
$dir = opendir($src);
mkdir($dst);
while (false !== ($file = readdir($dir))) {
if (($file != '.' ) && ( $file != '..' )) {
copy($src . '/' . $file, $dst . '/' . $file);
$str = file_get_contents($dst . '/' . $file);
$str = str_replace('PROBLEM_ID', $name, $str);
file_put_contents($dst . '/' . $file, $str);
}
}
closedir($dir);
exec('composer dump-autoload');
}
// Get the input
$problem = getProblem($argc, $argv);
// Copy the boilerplate
if ($problem) {
copyBoilerplate('P'.$problem);
} else {
echo 'No proper problem format, use "PXXX"' . PHP_EOL;
exit;
}