示例#1
0
 private function _test_delimiters()
 {
     $file_options = global_file_options();
     $delimiter = $file_options->path_delimiter;
     $this->_check_equal(false, begins_with_delimiter('path/to/the/folder/'));
     $this->_check_equal(true, begins_with_delimiter($delimiter . 'path/to/the/folder/'));
     $this->_check_equal(true, ends_with_delimiter('path/to/the/folder' . $file_options->path_delimiter));
     $this->_check_equal(false, ends_with_delimiter('path/to/the/folder'));
     $this->_check_equal(true, begins_with_delimiter(ensure_begins_with_delimiter('path/to/the/folder/')));
     $this->_check_equal(true, begins_with_delimiter(ensure_begins_with_delimiter('/path/to/the/folder/')));
     $this->_check_equal(true, ends_with_delimiter(ensure_ends_with_delimiter('path/to/the/folder/')));
     $this->_check_equal(true, ends_with_delimiter(ensure_ends_with_delimiter('path/to/the/folder')));
 }
示例#2
0
 /**
  * Fully resolve the given alias, appending the fragment as a path.
  * Resolve all aliases in 'alias' recursively; the 'fragment' may not contain aliases
  * and is appended directly to the expanded path.
  * @param string $alias
  * @param string $fragment
  * @param boolean $root_override Overrides {@link $resolve_to_root} if True.
  * @see resolve_file_for_alias()
  * @see resolve_file()
  * @see resolve_path()
  * @param string $alias
  * @param string $fragment
  * @return string
  */
 public function resolve_path_for_alias($alias, $fragment, $root_override = null)
 {
     $Result = $this->_resolve_path_for_alias($alias, $fragment, $root_override);
     return ensure_ends_with_delimiter($Result, $this->_url_options);
 }
示例#3
0
/**
 * Convert a file name to a url on this server.
 * Returns empty if the file is not in the server's document root.
 * @param string $f
 * @param URL_OPTIONS $opts
 * @return string
 */
function file_name_to_url($f, $opts = null)
{
    if (!isset($opts)) {
        $opts = global_url_options();
    }
    foreach ($opts->domains as $url_root => $document_root) {
        $pos = strpos($f, $document_root);
        if ($pos === 0) {
            $Result = substr($f, strlen(ensure_ends_with_delimiter($document_root)) - 1);
            $Result = str_replace('\\', $opts->path_delimiter, $Result);
            return join_paths($url_root, $Result, $opts);
        }
    }
    return '';
}
示例#4
0
/**
 * Return the list of files for the given path.
 * @param string $base_path Must be a full path.
 * @param string $path_to_prepend Prepended to each file.
 * @param bool $recurse If true, include all sub-folders.
 * @param FILE_OPTIONS $opts
 * @return string[]
 */
function file_list_for($base_path, $path_to_prepend = '', $recurse = false, $opts = NULL)
{
    if (!isset($opts)) {
        $opts = global_file_options();
    }
    $base_path = ensure_ends_with_delimiter($base_path, $opts);
    $Result = array();
    if ($handle = @opendir($base_path)) {
        while (($name = readdir($handle)) != false) {
            if ($name[0] != '.') {
                if (is_dir(join_paths($base_path, $name))) {
                    if ($recurse) {
                        $Result = array_merge($Result, file_list_for(join_paths($base_path, $name, $opts), join_paths($path_to_prepend, $name, $opts), $recurse, $opts));
                    }
                } else {
                    $Result[] = join_paths($path_to_prepend, $name);
                }
            }
        }
        closedir($handle);
    }
    return $Result;
}