Orion PHP  0.11.12
The PHP5.3 framework
plugin.php
Go to the documentation of this file.
00001 <?php
00002 
00003 namespace Orion\Core;
00004 
00005 
00006 /**
00007  * \Orion\Core\Plugin
00008  * 
00009  * Orion plugin class.
00010  * 
00011  * Handles plugins load and usage.
00012  *
00013  * @author Thibaut Despoulain
00014  * @license BSD 4-clauses
00015  * @version 0.11.12
00016  * 
00017  * @deprecated With current namespacing autoloading, there should be no need for this class. It's only here to assure backward compatibility.
00018  *
00019  * @static
00020  */
00021 class Plugin
00022 {
00023 
00024     private static $loaded = array( );
00025 
00026     /**
00027      * Loads provided plugin and call its load() function with arguments $args
00028      * @param string $plugin
00029      * @param mixed $args
00030      */
00031     public static function load( $plugin, $args=null )
00032     {
00033         $plist = explode( '.', $plugin );
00034 
00035         if ( is_string( $plist ) )
00036             $plist = array( $plist );
00037 
00038         $parsed = array( );
00039         foreach ( $plist as $p )
00040         {
00041             $file = Context::getPluginPath() . Tools::concatWithTrail( DS, $parsed, true ) . strtolower( $p ) . DS . strtolower( $p ) . '.php';
00042             $class = \Orion::PLUGIN_NS . implode( '\\', $parsed ) . (!empty( $parsed ) ? '\\' : '') . $p;
00043             $pname = Tools::concatWithTrail( '.', $parsed, true ) . $p;
00044 
00045 
00046             if ( file_exists( $file ) )
00047             {
00048                 if ( !in_array( $pname, self::$loaded ) )
00049                 {
00050                     require_once($file);
00051 
00052                     try
00053                     {
00054                         if ( method_exists( $class, 'load' ) )
00055                             $class::load( $args );
00056 
00057                         self::$loaded[ ] = $pname;
00058                     }
00059                     catch ( Exception $e )
00060                     {
00061                         throw $e;
00062                     }
00063                 }
00064 
00065                 $parsed[ ] = $pname;
00066             }
00067             else
00068                 throw new Exception( 'Plugin [' . $p . '] file does not exists : ' . $file, E_USER_WARNING, get_class() );
00069         }
00070     }
00071 
00072 }