4 * Class CRM_Core_CodeGen_Util_File
6 class CRM_Core_CodeGen_Util_File
{
12 public static function createDir($dir, $perm = 0755) {
14 mkdir($dir, $perm, TRUE);
21 public static function cleanTempDir($dir) {
22 foreach (glob("$dir/*") as $tempFile) {
26 if (preg_match(':^(.*)\.d$:', $dir, $matches)) {
27 if (file_exists($matches[1])) {
38 public static function createTempDir($prefix) {
39 $newTempDir = tempnam(sys_get_temp_dir(), $prefix) . '.d';
40 if (file_exists($newTempDir)) {
41 self
::removeDir($newTempDir);
43 self
::createDir($newTempDir);
49 * Calculate a cumulative digest based on a collection of files.
52 * List of file names (strings).
53 * @param callable|string $digest a one-way hash function (string => string)
57 public static function digestAll($files, $digest = 'md5') {
59 foreach ($files as $file) {
60 $buffer .= $digest(file_get_contents($file));
62 return $digest($buffer);
66 * Find the path to the main Civi source tree.
69 * @throws RuntimeException
71 public static function findCoreSourceDir() {
72 $path = str_replace(DIRECTORY_SEPARATOR
, '/', __DIR__
);
73 if (!preg_match(':(.*)/CRM/Core/CodeGen/Util:', $path, $matches)) {
74 throw new RuntimeException("Failed to determine path of code-gen");
81 * Find files in several directories using several filename patterns.
84 * Each item is an array(0 => $searchBaseDir, 1 => $filePattern).
88 public static function findManyFiles($pairs) {
90 foreach ($pairs as $pair) {
91 list ($dir, $pattern) = $pair;
92 $files = array_merge($files, CRM_Utils_File
::findFiles($dir, $pattern));