phpDocumentor GloryLands
Extensions
[ class tree: GloryLands ] [ index: GloryLands ] [ all elements ]

Source for file glmodule.php

Documentation is available at glmodule.php

  1. <?php
  2. /**
  3.   * GloryLands Extendions System
  4.   * Module information system
  5.   *
  6.   * <pre>
  7.   * GloryLands, a Web-Based, Massive Multiplayer Online RPG/Strategy Game
  8.   * Copyright (C) 2008-09  John Haralampidis <jïhnys2[at]gmail.cïm>
  9.   *
  10.   * This program is free software: you can redistribute it and/or modify
  11.   * it under the terms of the GNU General Public License as published by
  12.   * the Free Software Foundation, either version 3 of the License, or
  13.   * (at your option) any later version.
  14.   *
  15.   * This program is distributed in the hope that it will be useful,
  16.   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.   * GNU General Public License for more details.
  19.   *
  20.   * You should have received a copy of the GNU General Public License
  21.   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  22.   *
  23.   * For any help/suggestions or troubleshooting you can see the
  24.   * project community website at <http://www.glorylands.gr>
  25.   * </pre>
  26.   *
  27.   * @license GNU/GPLv3 GNU General Public License version 3
  28.   * @package GloryLands
  29.   * @subpackage Extensions
  30.   * @author John Haralampidis <jïhnys2[at]gmail.cïm>
  31.   * @copyright Copyright (C) 2007-2009, John Haralampidis
  32.   * @version 1.0
  33.   */
  34.  
  35. /**
  36.   * GloryLands Extension Module
  37.   *
  38.   * This class provides access to the module information
  39.   * and structures.
  40.   *
  41.   * @subpackage Extensions
  42.   * @version 1.0
  43.   */
  44. class GLModule {
  45.     
  46.     public $name;
  47.     
  48.     public $root;
  49.     public $url;
  50.     
  51.     public $config;
  52.     public $unitconfig;
  53.  
  54.     public function __construct($name{
  55.         
  56.         // Initialize variables
  57.         $this->name = $name;
  58.         $this->unitconfig = array();
  59.         $this->root = GLConfig::$root.'/modules/'.$this->name;
  60.         $this->url = 'modules/'.$name;
  61.         
  62.         // Initialize config
  63.         if (!is_dir($this->root)) return false;
  64.         $config GLOptimizer::optimize_file($this->root.'/config.xml''xmlconfig')/* This will convert XML to PHP array */
  65.         if (!$config{
  66.             // Cannot load optimizer?
  67.             GLError::log('extensions''Cannot load an XMLConfig optimizer! Un-onptimized config parsing will be used. This will might decrease performance'GLError::WARNING);
  68.             $this->config = GLTools::serialize_xml(simplexml_load_file($this->root.'/config.xml'));
  69.         else {
  70.             $this->config = include($config);
  71.         }
  72.         
  73.         // Prepare the array that will hold the names of 
  74.         // all of our PHP classes (used by GLModule::of() 
  75.         // in order to find out the parent GLModule)
  76.         $classes array();
  77.         
  78.         // Include all the external files
  79.         if (isset($this->config['provide'])) {
  80.         
  81.             // Make sure provide units is an array, even if it's only one
  82.             if (!isset($this->config['provide'][0]['unit'][0])) $this->config['provide'][0]['unit']=array($this->config['provide'][0]['unit']);            
  83.             foreach ($this->config['provide'][0]['unit'as $unit{                
  84.                 $id $unit['name'];
  85.                 
  86.                 // Check for server file to include
  87.                 if (isset($unit['server'])) {
  88.                     include_once($this->root.'/'.$unit['server'][0]['file']);
  89.                 
  90.                     // Store the class name
  91.                     $classes[$unit['server'][0]['class'];
  92.                 }
  93.                 
  94.                 // Check for client file to include
  95.                 if (isset($unit['client'])) {
  96.                     GL::$stream->headers['js'][$this->url.'/'.$unit['client'][0]['file'];
  97.                 }
  98.                 
  99.                 // Store the configuration of this unit (For quick fetching from $this->get_config_for()
  100.                 $this->unitconfig[$id$unit;
  101.                 
  102.             }
  103.         }
  104.         
  105.         // Register this instance on the static store
  106.         if (!GLModules::$cacheGLModules::$cache=array();
  107.         GLModules::$cache[$this->namearray(
  108.             'object' => &$this,
  109.             'classes' => $classes
  110.         );    
  111.     }
  112.  
  113.     public function get_config_for($object{
  114.         $name get_class($object);
  115.         if (!isset($this->unitconfig[$name])) return false;
  116.         return $this->unitconfig[$name];
  117.     }
  118.     
  119.     public function call($call$vars{
  120.         
  121.     }
  122.  
  123. }
  124.  
  125. ?>

Documentation generated on Tue, 13 Oct 2009 23:49:04 +0300 by phpDocumentor 1.4.1