Sources for file plugins/class/storage.php in version 4.0 Beta 1



Click on a comment to hide it. Click here to show all comments.

/**
 * Project:     Xnyo 4: Bubbles
 * File:        plugins/class/storage.php
 *
 * Version:     4.0-dev
 * SVN Id:      $Id: storage.php 5 2007-05-18 03:49:07Z bok $
 * SVN URL:     $HeadURL:
http://svn.syd.wholesalebroadband.com.au/xnyo/trunk/plugins/class/storage.php $
 * Authors:     Robert Amos <bok[at]odynia.org>
 *
 * Copyright (c) 2001-2007 Robert Amos <bok[at]odynia.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/

/**
 * This file contains the various objects that make up the $xnyo->storage objects.
**/
class XnyoStorage
{
    
// Containers
    
public $plugins;
    public 
$session;
    public 
$debug;
    public 
$error;
    public 
$filter;
    public 
$language;
    public 
$smarty;

    
// Constructor
    
public function __construct()
    {
        
$this->plugins = new XnyoStoragePlugins;
    }
}

/**
 * XnyoStoragePlugins
 *
 * This class is a storage area that contains all runtime info about plugins.
 * For example, what is loaded.
**/
class XnyoStoragePlugins
{
    
/**
     * Loaded / Included plugins
     *
     * These keep a list of plugins that have already been loaded, to prevent them from
     * being loaded again.
    **/
    
private $inced_plugins;
    private 
$loaded_plugins;

    
// Constructor
    
public function __construct()
    {
        
/**
         * Fill the loaded arrays with useful subarrays.
        **/
        
$this->inced_plugins = array
        (
            
XNYO_PLUGIN_AJAX => array(),
            
XNYO_PLUGIN_AUTH => array(),
            
XNYO_PLUGIN_CACHE => array(),
            
XNYO_PLUGIN_CLASS => array(),
            
XNYO_PLUGIN_CONFIG => array(),
            
XNYO_PLUGIN_DATABASE => array(),
            
XNYO_PLUGIN_DBSPEC => array(),
            
XNYO_PLUGIN_ERROR => array(),
            
XNYO_PLUGIN_SMARTY => array()
        );
        
$this->loaded_plugins $this->inced_plugins;
    }
    
    
/**
     * is_inced
     *
     * Checks whether a plugin has been included before
    **/
    
public function is_inced ($name$type)
    {
        
$name $this->strip($name$type);
        if (isset(
$this->inced_plugins[$type][strtolower($name)]) &&
$this->inced_plugins[$type][strtolower($name)])
            return 
true;
        return 
false;
    }
    
    
/**
     * is_loaded
     * 
     * Checks whether a plugin has been loaded before
    **/
    
public function is_loaded ($name$type)
    {
        
$name $this->strip($name$type);
        if (!empty(
$this->loaded_plugins[$type][strtolower($name)]))
            return 
true;
        return 
false;
    }
    
    
/**
     * mark_inced
     *
     * Marks a function as having been included before.
    **/
    
public function mark_inced ($name$type)
    {
        
$name $this->strip($name$type);
        
$this->inced_plugins[$type][strtolower($name)] = true;
    }
    
    
/**
     * mark_loaded
     *
     * Marks a plugin as having been loaded before.
    **/
    
public function mark_loaded ($name$type$obj)
    {
        
$name $this->strip($name$type);
        
$this->loaded_plugins[$type][strtolower($name)] = $obj->_plugin_info;
        
$this->loaded_plugins[$type][strtolower($name)]['obj'] = $obj
    }

    
/**
     * get_plugin_reference
     *
     * Gets a reference to the loaded object for a plugin
    **/
    
public function get_plugin_reference ($name$type)
    {
        
$name $this->strip($name$type);
        if (!
$this->is_loaded($name$type))
            throw new 
XnyoError('Unable to return reference to non-loaded plugin <b>%s</b> (<b>%s</b>).',
$name$type);
        return 
$this->loaded_plugins[$type][strtolower($name)]['obj'];
    }
    
    
/**
     * Strip off references to xnyo or the type
    **/
    
private function strip ($name$type)
    {
        
$name strtolower($name);
        
$name substr($name04) == 'xnyo' substr($name4) : $name;
        
$name substr($name0strlen($type)) == strtolower($type) ? substr($namestrlen($type)) :
$name;
        return 
$name;
    }
}

Website is Copyright © Odynia.org 2000-2005 - Xnyo is released under a BSD license.