4 * Class CRM_Core_CodeGen_Util_File
6 class CRM_Core_CodeGen_Util_File
{
11 public static function createDir($dir, $perm = 0755) {
13 mkdir($dir, $perm, TRUE);
20 public static function cleanTempDir($dir) {
21 foreach (glob("$dir/*") as $tempFile) {
25 if (preg_match(':^(.*)\.d$:', $dir, $matches)) {
26 if (file_exists($matches[1])) {
37 public static function createTempDir($prefix) {
38 $newTempDir = tempnam(sys_get_temp_dir(), $prefix) . '.d';
39 if (file_exists($newTempDir)) {
40 self
::removeDir($newTempDir);
42 self
::createDir($newTempDir);
48 * Calculate a cumulative digest based on a collection of files.
51 * List of file names (strings).
52 * @param callable|string $digest a one-way hash function (string => string)
56 public static function digestAll($files, $digest = 'md5') {
58 foreach ($files as $file) {
59 $buffer .= $digest(file_get_contents($file));
61 return $digest($buffer);
65 * Find the path to the main Civi source tree.
68 * @throws RuntimeException
70 public static function findCoreSourceDir() {
71 $path = str_replace(DIRECTORY_SEPARATOR
, '/', __DIR__
);
72 if (!preg_match(':(.*)/CRM/Core/CodeGen/Util:', $path, $matches)) {
73 throw new RuntimeException("Failed to determine path of code-gen");
80 * Find files in several directories using several filename patterns.
83 * Each item is an array(0 => $searchBaseDir, 1 => $filePattern).
87 public static function findManyFiles($pairs) {
89 foreach ($pairs as $pair) {
90 list ($dir, $pattern) = $pair;
91 $files = array_merge($files, CRM_Utils_File
::findFiles($dir, $pattern));