r3-v2/utils.php

90 lines
1.8 KiB
PHP

<?php
function to_camel_case_from_upper_underscore($string, $capitalizeFirstCharacter = true)
{
$str = str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($string))));
if (!$capitalizeFirstCharacter) {
$str[0] = strtolower($str[0]);
}
return $str;
}
function from_camel_case($input, $seperator = '_') {
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);
}
return implode($seperator, $ret);
}
function to_upper_underscore($input, $seperator = '_') {
return strtoupper(from_camel_case($input, $seperator));
}
if (isset($argc)) {
for ($i = 0; $i < $argc; $i++) {
// echo "Argument #" . $i . " - " . $argv[$i] . "\n";
}
}
else {
echo "argc and argv disabled\n";
}
$files = [];
function addFiles($folder, &$newFiles)
{
$files = scandir($folder, SCANDIR_SORT_DESCENDING);
for ($i = 0; $i < sizeof($files); $i++) {
if (preg_match('/index\.js$/', $files[$i])) {
continue;
}
if (preg_match('/\.js$/', $files[$i])) {
array_push($newFiles, $folder . $files[$i]);
}
}
}
if ($argv[1] == 'all') {
$files = scandir('src/r3/', SCANDIR_SORT_DESCENDING);
$newFiles = [];
for ($i = 0; $i < sizeof($files); $i++) {
if (preg_match('/index\.js$/', $files[$i])) {
continue;
}
if (preg_match('/\.js$/', $files[$i])) {
array_push($newFiles, 'src/r3/' . $files[$i]);
}
}
$folders = [
'src/r3/r3-component/',
'src/r3/r3-entity/',
'src/r3/r3-object/',
'src/r3/r3-runtime/',
'src/r3/r3-system/'
];
foreach ($folders as $folder) {
addFiles($folder, $newFiles);
}
$files = $newFiles;
} else {
$files = [$argv[1]];
}