- str_replace: documentation ( source)
<?php
namespace HookInvoker\FileSystem {
class PhpFunctionProducer {
const FUNCTION_CODE = <<<PHP
<?php
/**
* This function wau auto created, pleaee do not edit
*/
function :function: () {
return \DrupalContainer\Registry::getContainer()
->get(':class:')
->hook(func_get_args());
}
PHP;
public function getPhpFunctionCode() {
return self::FUNCTION_CODE;
}
public function create($function) {
$code = str_replace(
[':function:', ':class:'],
[$function, 'sds.module.user_install'],
$this->getPhpFunctionCode());
echo $code;
}
}
}
namespace {
$x = new HookInvoker\FileSystem\PhpFunctionProducer();
$x->create('test_init');
}