2015-11-16 11:40:01 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$animeclient_file_patterns = [
|
|
|
|
'app/config/*.php',
|
2016-08-30 10:57:41 -04:00
|
|
|
'app/bootstrap.php',
|
2015-11-16 11:40:01 -05:00
|
|
|
'src/functions.php',
|
2016-08-30 10:57:41 -04:00
|
|
|
'src/*.php'
|
2015-11-16 11:40:01 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
if ( ! function_exists('glob_recursive'))
|
|
|
|
{
|
2015-12-09 14:54:11 -05:00
|
|
|
// Does not support flag GLOB_BRACE
|
2015-11-16 11:40:01 -05:00
|
|
|
|
2015-12-09 14:54:11 -05:00
|
|
|
function glob_recursive($pattern, $flags = 0)
|
|
|
|
{
|
|
|
|
$files = glob($pattern, $flags);
|
2015-11-16 11:40:01 -05:00
|
|
|
|
2015-12-09 14:59:54 -05:00
|
|
|
foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir)
|
2015-12-09 14:54:11 -05:00
|
|
|
{
|
2015-12-09 14:59:54 -05:00
|
|
|
$files = array_merge($files, glob_recursive($dir . '/' . basename($pattern), $flags));
|
2015-12-09 14:54:11 -05:00
|
|
|
}
|
2015-11-16 11:40:01 -05:00
|
|
|
|
2015-12-09 14:54:11 -05:00
|
|
|
return $files;
|
|
|
|
}
|
2015-11-16 11:40:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_text_to_replace($tokens)
|
|
|
|
{
|
|
|
|
if ($tokens[0][0] !== T_OPEN_TAG)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is already a docblock, as the second token after the
|
|
|
|
// open tag, get the contents of that token to replace
|
|
|
|
if ($tokens[1][0] === T_DOC_COMMENT)
|
|
|
|
{
|
|
|
|
return "<?php\n" . $tokens[1][1];
|
|
|
|
}
|
2015-12-09 14:59:54 -05:00
|
|
|
else if ($tokens[1][0] !== T_DOC_COMMENT)
|
2015-11-16 11:40:01 -05:00
|
|
|
{
|
|
|
|
return "<?php";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_tokens($source)
|
|
|
|
{
|
|
|
|
return token_get_all($source);
|
|
|
|
}
|
|
|
|
|
|
|
|
function replace_files(array $files, $template)
|
|
|
|
{
|
2015-12-09 14:59:54 -05:00
|
|
|
foreach ($files as $file)
|
2015-11-16 11:40:01 -05:00
|
|
|
{
|
|
|
|
$source = file_get_contents($file);
|
|
|
|
$tokens = get_tokens($source);
|
|
|
|
$text_to_replace = get_text_to_replace($tokens);
|
|
|
|
|
|
|
|
$header = file_get_contents(__DIR__ . $template);
|
|
|
|
$new_text = "<?php\n{$header}";
|
|
|
|
|
|
|
|
$new_source = str_replace($text_to_replace, $new_text, $source);
|
|
|
|
file_put_contents($file, $new_source);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-09 14:59:54 -05:00
|
|
|
foreach ($animeclient_file_patterns as $glob)
|
2015-11-16 11:40:01 -05:00
|
|
|
{
|
|
|
|
$files = glob_recursive($glob);
|
|
|
|
replace_files($files, '/animeclient_header_comment.txt');
|
|
|
|
}
|
|
|
|
$loose_files = [
|
|
|
|
__DIR__ . '/../index.php',
|
|
|
|
__DIR__ . '/../public/css.php',
|
|
|
|
__DIR__ . '/../public/js.php'
|
|
|
|
];
|
|
|
|
replace_files($loose_files, '/animeclient_header_comment.txt');
|
|
|
|
|
|
|
|
echo "Successfully updated headers \n";
|