' .
sprintf(
__('You can use wildcards %s') ,
'%year%, %module_id%, %module_name%, %module_author%, %module_type%, %user_cn%, %user_name%, %user_email%, %user_url%'
) . ' ' . __('Do not put structural elements to the begining of lines.') . '
' .
'
' . __('Exemple') .'
' . self::$exemple . '
';
}
public function openModule(string $module_type, array $module_info): ?bool
{
$this->type = $module_type;
$this->module = $module_info;
$this->replaceInfo();
return null;
}
public function openDirectory(string $path): ?bool
{
$this->stop_scan = false;
if (!empty($this->getPreference('exclude_locales')) && preg_match('/\/(locales|libs)(\/.*?|)$/', $path)) {
$this->stop_scan = true;
}
return null;
}
public function readFile($path, $extension, &$content): ?bool
{
if ($this->stop_scan || $extension !='php' || self::hasNotice()) {
return null;
}
if (!empty($this->getPreference('remove_old'))) {
$content = $this->deleteOldBloc($content);
}
if (empty($this->getPreference('bloc_action'))) {
return null;
}
$clean = $this->deleteDocBloc($content);
if ($this->getPreference('bloc_action') == 'remove') {
$content = $clean;
return null;
}
if ($content != $clean && $this->getPreference('bloc_action') == 'create') {
return null;
}
if ($content == $clean && $this->getPreference('bloc_action') == 'replace') {
return null;
}
$content = $this->writeDocBloc($clean);
return true;
}
private function replaceInfo()
{
$bloc = trim($this->getPreference('bloc_content'));
if (empty($bloc)) {
self::notice(__('bloc is empty'), false);
return null;
}
$bloc = trim(str_replace("\r\n", "\n", $bloc));
try {
$this->bloc = preg_replace_callback(
// use \u in bloc content for first_upper_case
'/(\\\u([a-z]{1}))/',
function($str) { return ucfirst($str[2]); },
str_replace(
$this->bloc_wildcards,
[
date('Y'),
$this->module['id'],
$this->module['name'],
$this->module['author'],
$this->module['type'],
$this->core->auth->getInfo('user_cn'),
$this->core->auth->getinfo('user_name'),
$this->core->auth->getInfo('user_email'),
$this->core->auth->getInfo('user_url')
],
$bloc
)
);
} catch (Exception $e) {
self::notice(__('failed to parse bloc'));
return null;
}
}
private function writeDocBloc($content)
{
return preg_replace(
'/^(\<\?php[\n|\r\n]+)/',
'bloc)) . "\n */\n\n",
$content,
1
);
}
private function deleteDocBloc($content)
{
return preg_replace(
'/^(\<\?php\s*[\n|\r\n]{0,1}\s*\/\*\*.*?\s*\*\/\s*[\n|\r\n]+)/msi',
"