/** * Tests getting directory name component of path * * Tests wp_dirname() */ public function test_wp_dirname() { /** * Test using URI */ $this->assertEquals('test://', wp_dirname('test://dir1')); $this->assertEquals('test://dir1', wp_dirname('test://dir1/dir2')); /** * Test using path */ $this->assertEquals(dirname('/dir1/dir2'), wp_dirname('/dir1/dir2')); }
/** * 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); }