/** * 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; }
/** * Tests checking the validity of a scheme * * Tests WP_Stream::scheme_valid() */ public function test_scheme_valid() { $this->assertTrue(WP_Stream::scheme_valid('test')); $this->assertFalse(WP_Stream::scheme_valid('nonexistentwrapper')); }
/** * 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); }