using Php;

namespace PhpNative {
    public bool file_exists_static (string filename, string php_file, int php_line) throws Error {
        return FileUtils.test (filename, FileTest.EXISTS);
    }

    public zval file_exists_zval (zval filename, string php_file, int php_line) throws Error {
        return zval.boolean (file_exists_static (zval_to_string (filename), php_file, php_line));
    }

    public int filemtime_static (string filename, string php_file, int php_line) throws Error {
        var file = File.new_for_path (filename);
        var info = file.query_info (FileAttribute.TIME_MODIFIED, FileQueryInfoFlags.NONE);
        return (int) info.get_attribute_uint64 (FileAttribute.TIME_MODIFIED);
    }

    public zval filemtime_zval (zval filename, string php_file, int php_line) throws Error {
        try {
            return zval.integer (filemtime_static (zval_to_string (filename), php_file, php_line));
        } catch (Error e) {
            return zval.boolean (false);
        }
    }
}
