/** * Tests getting the target of a stream * * Tests WP_Stream::target() */ public function test_target() { $stream = 'test://example/path1/path2/hello_world.txt'; $expected = 'example/path1/path2/hello_world.txt'; $actual = WP_Stream::target($stream); $this->assertEquals($expected, $actual, "WP_Stream::target returned '{$actual}' instead of the expected '{$expected}'."); }
/** * Implements WP_Stream_Wrapper_Interface::get_web_accessible_url() * * Returns a URL that can be accessed from a browser. For example, * the web URL of the internal URI "local://example.txt" might be * "http://www.example.com/wp-content/example.txt". * * @return string * the web accessible URL for the resource. * * @see WP_Local_Stream_Wrapper_Interface::get_web_accessible_url() * @since 1.0.0 */ public function get_web_accessible_url() { $path = str_replace('\\', '/', WP_Stream::target($this->uri)); return content_url('stream_tests/' . $path); }
/** * 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; }
/** * Implements WP_Stream_Wrapper_Interface::dirname() * * This function is typically invoked through wp_dirname(). * * @param string $uri * the URI or path. * * @return mixed * the new temporary filename, or false on failure. * * @see WP_Stream_Wrapper_Interface::dirname() * @see wp_dirname() * @since 1.0.0 */ public function dirname($uri) { list($scheme, $target) = explode('://', $uri, 2); $target = WP_Stream::target($uri); $dirname = dirname($target); if ($dirname == '.') { $dirname = ''; } return $scheme . '://' . $dirname; }