예제 #1
0
 /**
  * Evaluate a glob pattern in the context of a particular extension.
  *
  * @param string $ext
  *   Extension name; use 'civicrm' for core.
  * @param string|array $patterns
  *   Glob pattern; e.g. "*.html".
  * @param null|int $flags
  *   See glob().
  * @return array
  *   List of matching files, relative to the extension base dir.
  * @see glob()
  */
 public function glob($ext, $patterns, $flags = NULL)
 {
     $path = $this->getPath($ext);
     $patterns = (array) $patterns;
     $files = array();
     foreach ($patterns as $pattern) {
         if (CRM_Utils_File::isAbsolute($pattern)) {
             // Absolute path.
             $files = array_merge($files, (array) glob($pattern, $flags));
         } else {
             // Relative path.
             $files = array_merge($files, (array) glob("{$path}/{$pattern}", $flags));
         }
     }
     sort($files);
     // Deterministic order.
     $files = array_unique($files);
     return array_map(function ($file) use($path) {
         return CRM_Utils_File::relativize($file, "{$path}/");
     }, $files);
 }