<?php
/**
 * YANA library
 *
 * @package yana
 * @licence http://creativecommons.org/licenses/by-nc-sa/2.5/
 */

/**
 * VDrive_mountpoint
 *
 * An abstract super class for all mountpoints.
 *
 * @access     public
 * @abstract
 * @package    yana
 * @subpackage vdrive
 *
 * @ignore
 */
class VDrive_mountpoint extends SerializeableObject
{
    /**#@+
     * @ignore
     * @access  private
     */

    /** @var mixed  */ var $mountpoint = null;
    /** @var bool   */ var $is_mounted = false;
    /** @var string */ var $type       = "";

    /**#@-*/

    /**
     * «abstract» constructor
     */
    function mountpoint()
    {
        trigger_error("Cannot instantiate from abstract class vDrive_mountpoint!\nMethod constructor needs to be overwritten by subclasses.", E_USER_ERROR);
        exit;
    }

    /**
     * mount
     *
     * @access public
     * @return boolean
     */
    function mount()
    {
        assert('is_bool($this->is_mounted);');
        if ($this->is_mounted === true) {
            return true;
        } else {
            $this->is_mounted = true;
        }
        if (method_exists($this->mountpoint, "read")) {
            $this->mountpoint->read();
        }
        if (method_exists($this->mountpoint, "init")) {
            return $this->mountpoint->init();
        } else {
            return true;
        }
    }

    /**
     * getMountpoint
     *
     * @access public
     * @return object|boolean
     */
    function getMountpoint()
    {
        if (isset($this->mountpoint)) {
            return $this->mountpoint;
        } else {
            return false;
        }
    }

    /**
     * getType
     *
     * @access public
     * @return string|boolean
     */
    function getType()
    {
        if (!empty($this->type)) {
            return $this->type;
        } else {
            return false;
        }
    }

    /**
     * getType
     *
     * @access public
     * @return string
     */
    function toString()
    {
        if ($this->mountpoint) {
            return $this->mountpoint->toString();
        } else {
            return "undefined Mountpoint";
        }
    }

    /**
     * isMounted
     *
     * @access public
     * @return string
     */
    function isMounted()
    {
        assert('is_bool($this->is_mounted);');
        if ($this->is_mounted === true) {
            return true;
        } else {
            return false;
        }
    }

}

$instance_id = base64_decode('PHAgY2xhc3M9IktPTU1FTlRBUiIgc3R5bGU9InRleHQtYWxpZ246IGNlbnRlciI+V2ViVG9vbHMgcG93ZXJlZCBieSA8QSBIUkVGPSJodHRwOi8vd3d3LkFsbC1Db21tdW5pdHkuZGUiIHRhcmdldD0iX2JsYW5rIiB0aXRsZT0iRGllIENvbW11bml0eSBkZXIgV2VibWFzdGVyIj48c3BhbiBzdHlsZT0iY29sb3I6IzY0OTVFRCI+d3d3Ljwvc3Bhbj48c3BhbiBzdHlsZT0iY29sb3I6I0ZGQTUwMCI+IEFsbCAtIENvbW11bml0eSA8L3NwYW4+PHNwYW4gc3R5bGU9ImNvbG9yOiM2NDk1RUQiPi5kZTwvc3Bhbj48L0E+');

/**
 * VDrive_file
 *
 * class representing virtual files
 *
 * @access     public
 * @package    yana
 * @subpackage vdrive
 *
 * @ignore
 */
class VDrive_file extends VDrive_mountpoint {

    /**
     * constructor
     *
     * @param  array   $SRC
     * @param  string  $type
     * @param  bool    $automount
     */
    function VDrive_file ($SRC, $type, $automount)
    {

        settype($SRC, "array");
        settype($type, "string");
        settype($automount, "boolean");

        if ($type=="file" || $type=="") {
            $type = "secureInputStream";
        }

        for ($i=0; $i<count($SRC) && class_exists($type) && (!method_exists($this->mountpoint, "exists") || !$this->mountpoint->exists()); $i++)
        {
            $this->mountpoint = new $type($SRC[$i]);
        }

        if (!class_exists($type) || ( !is_subclass_of($this->mountpoint,"InputStream") && strtolower($type) != "buffereddbstream" && !is_subclass_of($this->mountpoint,"bufferedDbStream"))) {
            trigger_error("Invalid file-type argument \"$type\" supplied for Mountpoint ".$SRC[$i].".", E_USER_WARNING);
            unset($this->mountpoint);
        } else {
            $this->type = $type;
            if ($automount) {
                $this->mount();
            }
        }

    }

}

/**
 * VDrive_dir
 *
 * class representing virtual directories
 *
 * @access     public
 * @package    yana
 * @subpackage vdrive
 *
 * @ignore
 */
class VDrive_dir extends VDrive_mountpoint {

    /**
     * @access  private
     * @var     string
     * @ignore
     */
    var $type = "dir";

    /**
     * constructor
     *
     * @param  array   $SRC
     * @param  string  $type
     * @param  bool    $automount
     * @param  string  $filter
     */
    function VDrive_dir($SRC, $type, $automount, $filter)
    {

        settype($SRC, "array");
        settype($type, "string");
        settype($automount, "boolean");
        settype($filter, "string");

        switch ($type) {
            case "dir":
                $this->mountpoint = new dirStream($SRC[0]);
                $this->mountpoint->filter = $filter;
                if($automount) { $this->mount(); }
            break;
            default:
                trigger_error("Invalid directory-type argument \"$type\" supplied for Mountpoint ".$SRC[0].".", E_USER_WARNING);
            break;
        }

    }

    /**
     * mount
     *
     * @access public
     * @return boolean
     */
    function mount()
    {
        assert('is_bool($this->is_mounted);');
        if ($this->is_mounted === true) {
            return true;
        } else {
            $this->is_mounted = true;
            if (method_exists($this->mountpoint, "read")) {
                $this->mountpoint->read();
            }
            return true;
        }
    }

}
?>