<?php
/*
 * $RCSfile: GalleryPhpVm.class,v $
 *
 * Gallery - a web based photo album viewer and editor
 * Copyright (C) 2000-2005 Bharat Mediratta
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
 */
/**
 * @version $Revision: 1.9.4.1 $ $Date: 2005/11/24 18:15:55 $
 * @package GalleryCore
 * @author Bharat Mediratta <bharat@menalto.com>
 */

/**
 * An abstraction layer over PHP.  For now, this serves as a way to allow our test classes to
 * interpose themselves between the code and the PHP VM so that we can simulate different VMs.
 * For example, this lets us return arbitrary values for calls like function_exists().  Every call
 * here is a straight pass-through.  New functions can be added at any time.
 *
 * @package GalleryCore
 * @abstract
 * @access public
 */
class GalleryPhpVm {
    /**
     * Return true if the given function has been defined.
     *
     * @param string function name
     * @return bool
     */
    function function_exists($functionName) {
	return function_exists($functionName);
    }

    /**
     * iconv -- Convert string to requested character encoding
     *
     * @param string source character set
     * @param string target character set
     * @param string data
     * @return string result
     */
    function iconv($inCharset, $outCharset, $string) {
	return iconv($inCharset, $outCharset, $string);
    }

    /**
     * mb_convert_encoding -- Convert character encoding
     *
     * @param string data
     * @param string target character set
     * @param string source character set
     * @return string result
     */
    function mb_convert_encoding($string, $outCharset, $inCharset) {
	return mb_convert_encoding($string, $outCharset, $inCharset);
    }

    /**
     * recode_string -- Recode a string according to a recode request
     *
     * @param string source..target character set
     * @param string data
     * @return string result
     */
    function recode_string($request, $string) {
	return recode_string($request, $string);
    }

    /**
     * Return the 32-byte md5 hash of the given string
     *
     * @param string string to be hashed
     * @return string hashed string value
     */
    function md5($string) {
	return md5($string);
    }

    /**
     * Query language and locale information
     *
     * @param int item
     */
    function nl_langinfo($item) {
	return nl_langinfo($item);
    }

    /**
     * Set locale information.  Passing multiple locales isn't avialable until
     * PHP 4.3.0 so it's not supported here (yet).
     *
     * @param mixed category
     * @param string locale
     */
    function setlocale($category, $locale) {
	return setlocale($category, $locale);
    }

    /**
     * Send a raw HTTP header
     *
     * PHP 4.1 compatible header() function. The second optional parameter http_response_code
     * was introduced in PHP 4.3.0 and is therefore not supported in G2
     *
     * @param string string
     * @param [optional boolean replace]
     */
    function header($string, $replace=null) {
	return header($string, $replace);
    }

    /**
     * Checks if or where headers have been sent
     *
     * PHP 4.1 compatible headers_sent() function. The optional parameters
     * were introduced in PHP 4.3.0 and are therefore not supported in G2
     *
     * @return boolean whether headers are already sent
     */
    function headers_sent() {
	return headers_sent();
    }

    /**
     * Gets the current configuration setting of magic quotes gpc
     *
     * @return integer 0 for off, 1 for on
     */
    function get_magic_quotes_gpc() {
	return get_magic_quotes_gpc();
    }

    /**
     * Get configuration parameter
     *
     * @param string varname
     * @return string
     */
    function ini_get($varname) {
	return ini_get($varname);
    }

    /**
     * Set configuration parameter
     *
     * @param string varname
     * @param string newvalue
     * @return string
     */
    function ini_set($varname, $newvalue) {
	return ini_set($varname, $newvalue);
    }
}
?>
