public static function scan($dirs) { foreach ($dirs as $dir) { $fullDir = app_dir . '/' . $dir; // get the timestamp on reg.php $regStat = stat(app_dir . '/' . $dir . '/reg.php'); // echo_r($regStat); // check the timestamp on the dir // ------- you should also be checking any sub directories $dirStat = stat(app_dir . '/' . $dir); // the directory was changed after reg.php then recreate reg.php if ($dirStat['mtime'] > $regStat['mtime'] && is_writable("{$fullDir}/reg.php")) { $classes = array(); dir_r($fullDir, function ($it, $cur) use(&$classes, $dir) { $info = pathinfo($cur->getPathName()); if ($info['extension'] == 'php' && $info['basename'] != 'reg.php') { $subPath = $it->getSubPath() ? "/" . $it->getSubPath() : ''; $classes[$info['filename']] = "{$dir}{$subPath}"; } }); // echo_r($classes); ksort($classes); $regString = '<?php' . "\n"; $regString .= 'Zinc::registerClasses(array(' . "\n"; foreach ($classes as $name => $dir) { $regString .= "\t'{$name}' => '{$dir}',\n"; } $regString .= '));' . "\n"; file_put_contents("{$fullDir}/reg.php", $regString); } include "{$fullDir}/reg.php"; } }
public static function gen_r($name, $statName, $params) { Zinc::loadMod('app'); Zinc::loadMod('gui'); $statPath = dirname(zinc_dir) . "/stationary/{$statName}"; // get a list of all the files that need to be processed as templates $raw = file_get_contents($statPath . '/stationary'); // replace any separators that may have been used with just single spaces $stripped = preg_replace('/[\\s,;:]+/', ' ', $raw); $templateFiles = explode(' ', $stripped); if (!file_exists($name)) { mkdir($name); } // go through each file, if it is a template process it, otherwise just copy it dir_r($statPath, function ($it, $info) use($templateFiles, $statPath, $name, $params) { $filename = $it->getSubPathName(); if ($filename == 'stationary' && $it->isFile() || $it->isDot()) { return; } $path = "{$name}/" . $it->getSubPath(); if ($path && !file_exists($path)) { mkdir($path, 0775, true); } if (in_array($filename, $templateFiles)) { echo "processing template {$filename}\n"; CommandStationary::gen("{$statPath}/{$filename}", "{$name}/{$filename}", $params); } else { echo "copying file {$filename}\n"; copy("{$statPath}/{$filename}", "{$name}/{$filename}"); } }); }