Ejemplo n.º 1
0
 /**
  * As found on php.net posted by: BigueNique at yahoo dot ca 20-Apr-2010 07:15
  * A safe empowered glob().
  *
  * Supported flags: GLOB_MARK, GLOB_NOSORT, GLOB_ONLYDIR
  * Additional flags: GlobFlags::GLOB_NODIR, GlobFlags::GLOB_PATH, GlobFlags::GLOB_NODOTS, GlobFlags::GLOB_RECURSE (not original glob() flags, defined here)
  *
  * @author BigueNique AT yahoo DOT ca
  *
  * @param string $pattern
  * @param int    $flags
  *
  * @return array|bool
  */
 public static function glob($pattern, $flags = 0)
 {
     $_split = explode('/', str_replace('\\', '/', $pattern));
     $_mask = array_pop($_split);
     $_path = implode('/', $_split);
     $_glob = false;
     if (false !== ($_directory = opendir($_path))) {
         $_glob = array();
         while (false !== ($_file = readdir($_directory))) {
             //	Recurse directories
             if ($flags & GlobFlags::GLOB_RECURSE && is_dir($_file) && !in_array($_file, array('.', '..'))) {
                 $_glob = array_merge($_glob, Scalar::array_prepend(self::glob($_path . '/' . $_file . '/' . $_mask, $flags), $flags & GlobFlags::GLOB_PATH ? '' : $_file . '/'));
             }
             // Match file mask
             if (fnmatch($_mask, $_file)) {
                 if ((!($flags & GLOB_ONLYDIR) || is_dir("{$_path}/{$_file}")) && (!($flags & GlobFlags::GLOB_NODIR) || !is_dir($_path . '/' . $_file)) && (!($flags & GlobFlags::GLOB_NODOTS) || !in_array($_file, array('.', '..')))) {
                     $_glob[] = ($flags & GlobFlags::GLOB_PATH ? $_path . '/' : '') . $_file . ($flags & GLOB_MARK ? '/' : '');
                 }
             }
         }
         closedir($_directory);
         if (!($flags & GLOB_NOSORT)) {
             sort($_glob);
         }
     }
     return $_glob;
 }