$v ) { if( !is_scalar( $v )) { continue; } $map['$' . $k] = $v; $map['${' . $k . '}'] = $v; } return strtr($path, $map); } static function getatime($path) { try { $rc = fileatime($path); return $rc; } catch( Exception $e ) { throw new OSError($e->getMessage, $e->getCode()); } } static function getmtime($path) { try { $rc = filemtime($path); return $rc; } catch( Exception $e ) { throw new OSError($e->getMessage, $e->getCode()); } } static function getctime($path) { try { $rc = filectime($path); return $rc; } catch( Exception $e ) { throw new OSError($e->getMessage, $e->getCode()); } } static function getsize($path) { try { $rc = filesize($path); return $rc; } catch( Exception $e ) { throw new OSError($e->getMessage, $e->getCode()); } } static function isabs($path) { // fixme: implement check for windows. return $path[0] == '/'; } static function isfile($path) { return is_file($path); } static function isdir($path) { return is_dir($path); } static function islink($path) { return is_link($path); } static function ismount($path) { self::_unimplemented(); } 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 array($first, $last); } static function join($path, ...$paths) { $buf = rtrim($path, '/'); foreach( $paths as $p ) { $i = 0; $p = trim( $p, '/'); $buf .= DIRECTORY_SEPARATOR . $p; } return $buf; } static function normcase($path) { // fixme: different behavior on windows. return $path; } static function normpath($path) { return realpath($path); } static function realpath($path) { return realpath($path); } static function relpath($path, $start) { self::_unimplemented(); } static function samefile($path1, $path2) { return fileinode($path1) == fileinode($path2); } static function sameopenfile($fd1, $fd2) { $s1 = fstat( $fd1 ); $s2 = fstat( $fd2 ); return $s1['ino'] == $s2['ino']; } static function samestat($stat1, $stat2) { return $stat1 == $stat2; } static function splitdrive($path) { //fixme: implement windows case. return array('', $path); } static function splitext($path) { $first = $path; $second = ''; $pos = strrpos( $path, '.'); if( $pos !== false ) { $first = substr($path, 0, $pos); $second = substr($path, $pos); } return array($first, $second); } static function splitunc($path) { self::_unimplemented(); } 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."); } }