/**
  * Tests getting the scheme of a stream
  *
  * Tests WP_Stream::scheme()
  */
 public function test_scheme()
 {
     $stream = 'test://example/path1/path2/hello_world.txt';
     $expected = 'test';
     $actual = WP_Stream::scheme($stream);
     $this->assertEquals($expected, $actual, "WP_Stream::scheme returned '{$actual}' instead of the expected '{$expected}'.");
 }
 /**
  * Tests setting and getting URI
  *
  * Tests the $uri attribute of
  */
 public function test_uri_attribute()
 {
     $uri = 'test://testfile.txt';
     $scheme = WP_Stream::scheme($uri);
     $class_name = WP_Stream::wrapper_class_name($scheme);
     $instance = WP_Stream::new_wrapper_instance($uri);
     $this->assertEquals($uri, $instance->get_uri());
     $new_uri = 'test://testfile2.txt';
     $instance->set_uri($new_uri);
     $this->assertEquals($new_uri, $instance->get_uri());
 }
 /**
  * Normalizes a stream URI by making it syntactically correct
  *
  * The following actions are performed on the stream URI that is
  * returned.
  *
  * - Removing leading slashes from target.
  * - Removing duplicate path separators from target.
  *
  * @param string $uri
  *   the stream URI to normalize.
  * @return string
  *   the normalized stream URI after the modifications listed in the
  *   function description have been performed.
  *
  * @access  public
  * @static
  * @since   1.0.0
  */
 public static function normalize($uri)
 {
     $scheme = WP_Stream::scheme($uri);
     if ($scheme && WP_Stream::scheme_valid($scheme)) {
         $target = WP_Stream::target($uri);
         if ($target !== false) {
             $target = self::_clean_path_components($target);
             $uri = $scheme . '://' . $target;
         }
     }
     return $uri;
 }
/**
 * Sets access and modification time of file
 *
 * PHP's touch() does not work well with stream wrappers. This helper function
 * adds this missing support.
 *
 * This function is fully compatible with PHP's touch() function and may be
 * called in the same way. For example, both a URI and a normal filepath
 * can be provided for the $uri parameter.
 *
 * @param string $uri
 *   the URI or path to file being touched.
 * @param   int $time
 *   The touch time. If $time is not provided, the current system time is
 *   used.
 * @param int $atime
 *   If present, the access time of the given filename is set to the value
 *   of $atime. Otherwise, it is set to $time.
 *
 * @return bool
 *   true on success or false on failure.
 *
 * @link    http://php.net/manual/en/function.touch.php
 * @see     touch()
 * @since   1.0.0
 */
function wp_touch($uri, $time = null, $atime = null)
{
    if (is_null($time)) {
        $time = time();
    }
    $scheme = WP_Stream::scheme($uri);
    if ($scheme && WP_Stream::scheme_valid($scheme)) {
        $dirname = wp_dirname($uri);
        $filename = basename($uri);
        $path = wp_realpath($dirname);
        if ($path !== false) {
            $uri = $path . '/' . $filename;
        } else {
            // The directory path does not exist
            return false;
        }
    }
    return touch($uri, $time, $atime);
}