r3-v2/utils.php

90 lines
1.8 KiB
PHP
Raw Normal View History

2021-06-21 11:43:10 +02:00
<?php
2021-09-06 06:38:32 +02:00
function to_camel_case_from_upper_underscore($string, $capitalizeFirstCharacter = true)
2021-08-04 10:50:28 +02:00
{
$str = str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($string))));
if (!$capitalizeFirstCharacter) {
$str[0] = strtolower($str[0]);
}
return $str;
}
2021-10-01 06:08:34 +02:00
function from_camel_case($input, $seperator = '_') {
2021-08-04 10:50:28 +02:00
preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches);
$ret = $matches[0];
foreach ($ret as &$match) {
$match = $match == strtoupper($match) ? strtolower($match) : lcfirst($match);
}
2021-10-01 06:08:34 +02:00
return implode($seperator, $ret);
2021-08-04 10:50:28 +02:00
}
2021-10-01 12:40:04 +02:00
function to_upper_underscore($input, $seperator = '_') {
return strtoupper(from_camel_case($input, $seperator));
}
2021-06-21 11:43:10 +02:00
if (isset($argc)) {
2021-07-01 16:39:25 +02:00
for ($i = 0; $i < $argc; $i++) {
2021-09-13 09:39:38 +02:00
// echo "Argument #" . $i . " - " . $argv[$i] . "\n";
2021-07-01 16:39:25 +02:00
}
2021-06-21 11:43:10 +02:00
}
else {
2021-07-01 16:39:25 +02:00
echo "argc and argv disabled\n";
2021-06-21 11:43:10 +02:00
}
$files = [];
2021-09-10 07:18:08 +02:00
function addFiles($folder, &$newFiles)
{
2021-07-01 16:39:25 +02:00
2021-09-10 07:18:08 +02:00
$files = scandir($folder, SCANDIR_SORT_DESCENDING);
2021-07-01 16:39:25 +02:00
for ($i = 0; $i < sizeof($files); $i++) {
if (preg_match('/index\.js$/', $files[$i])) {
continue;
}
if (preg_match('/\.js$/', $files[$i])) {
2021-09-10 07:18:08 +02:00
array_push($newFiles, $folder . $files[$i]);
2021-07-01 16:39:25 +02:00
}
}
2021-06-21 11:43:10 +02:00
2021-09-10 07:18:08 +02:00
}
2021-06-21 11:43:10 +02:00
2021-09-10 07:18:08 +02:00
if ($argv[1] == 'all') {
2021-06-21 11:43:10 +02:00
2021-09-10 07:18:08 +02:00
$files = scandir('src/r3/', SCANDIR_SORT_DESCENDING);
$newFiles = [];
2021-06-21 11:43:10 +02:00
2021-09-10 07:18:08 +02:00
for ($i = 0; $i < sizeof($files); $i++) {
2021-07-03 10:40:05 +02:00
2021-09-10 07:18:08 +02:00
if (preg_match('/index\.js$/', $files[$i])) {
2021-07-03 10:40:05 +02:00
continue;
}
2021-09-10 07:18:08 +02:00
if (preg_match('/\.js$/', $files[$i])) {
array_push($newFiles, 'src/r3/' . $files[$i]);
2021-07-03 10:40:05 +02:00
}
}
2021-09-10 07:18:08 +02:00
$folders = [
'src/r3/r3-component/',
2021-10-01 06:08:34 +02:00
'src/r3/r3-entity/',
'src/r3/r3-object/',
2021-09-10 07:18:08 +02:00
'src/r3/r3-runtime/',
2021-10-01 06:08:34 +02:00
'src/r3/r3-system/'
2021-09-10 07:18:08 +02:00
];
2021-09-07 09:08:37 +02:00
2021-09-10 07:18:08 +02:00
foreach ($folders as $folder) {
addFiles($folder, $newFiles);
2021-09-07 09:08:37 +02:00
}
2021-07-01 16:39:25 +02:00
$files = $newFiles;
2021-06-21 11:43:10 +02:00
} else {
2021-07-01 16:39:25 +02:00
$files = [$argv[1]];
2021-06-21 11:43:10 +02:00
}