$v) { if (!is_scalar($v)) { continue; } $map['$'.$k] = $v; $map['${'.$k.'}'] = $v; } return strtr($path, $map); } public static function getatime($path) { try { $rc = fileatime($path); return $rc; } catch (Exception $e) { throw new OSError($e->getMessage, $e->getCode()); } } public static function getmtime($path) { try { $rc = filemtime($path); return $rc; } catch (Exception $e) { throw new OSError($e->getMessage, $e->getCode()); } } public static function getctime($path) { try { $rc = filectime($path); return $rc; } catch (Exception $e) { throw new OSError($e->getMessage, $e->getCode()); } } public static function getsize($path) { try { $rc = filesize($path); return $rc; } catch (Exception $e) { throw new OSError($e->getMessage, $e->getCode()); } } public static function isabs($path) { // fixme: implement check for windows. return $path[0] == '/'; } public static function isfile($path) { return is_file($path); } public static function isdir($path) { return is_dir($path); } public static function islink($path) { return is_link($path); } public static function ismount($path) { self::_unimplemented(); } public static function split($path) { $parts = explode(DIRECTORY_SEPARATOR, $path); $first = implode(DIRECTORY_SEPARATOR, array_slice($parts, 0, count($parts) - 1)); $last = $parts[count($parts) - 1]; return [$first, $last]; } public static function join($path, ...$paths) { $buf = rtrim($path, '/'); foreach ($paths as $p) { $i = 0; $p = trim($p, '/'); $buf .= DIRECTORY_SEPARATOR.$p; } return $buf; } public static function normcase($path) { // fixme: different behavior on windows. return $path; } public static function normpath($path) { return realpath($path); } public static function realpath($path) { return realpath($path); } public static function relpath($path, $start) { self::_unimplemented(); } public static function samefile($path1, $path2) { return fileinode($path1) == fileinode($path2); } public static function sameopenfile($fd1, $fd2) { $s1 = fstat($fd1); $s2 = fstat($fd2); return $s1['ino'] == $s2['ino']; } public static function samestat($stat1, $stat2) { return $stat1 == $stat2; } public static function splitdrive($path) { //fixme: implement windows case. return ['', $path]; } public static function splitext($path) { $first = $path; $second = ''; $pos = strrpos($path, '.'); if ($pos !== false) { $first = substr($path, 0, $pos); $second = substr($path, $pos); } return [$first, $second]; } public static function splitunc($path) { self::_unimplemented(); } public static function walk($path, $visit, $arg) { // Note: deprecated in python 3 in favor of os.walk() self::_unimplemented(); } private static function _unimplemented() { throw new Exception('Unimplemented. Please consider submitting a patch to py2php project on github.'); } }