Example #1
0
 /**
  * Class constructor
  * 
  * The class constructor is private to avoid multiple instances of the
  * class (singleton).
  * 
  * @return  void
  */
 private function __construct()
 {
     // Gets the instance of the configuration object
     $this->_conf = Woops_Core_Config_Getter::getInstance();
     // Stores the name of the default database engine
     $this->_defaultEngine = $this->_conf->getVar('database', 'engine');
 }
Example #2
0
 /**
  * Sets the needed static variables
  * 
  * @return  void
  */
 private static function _setStaticVars()
 {
     // Gets the instance of the number utilities
     self::$_debug = (bool) Woops_Core_Config_Getter::getInstance()->getVar('error', 'verbose');
     // Static variables are set
     self::$_hasStatic = true;
 }
Example #3
0
 /**
  * Class constructor
  * 
  * @return  void
  */
 private function __construct()
 {
     $this->_conf = Woops_Core_Config_Getter::getInstance();
     $this->_env = Woops_Core_Env_Getter::getInstance();
     $this->_request = Woops_Core_Request_Getter::getInstance();
     $this->_db = Woops_Database_Layer::getInstance()->getEngine();
     $this->_str = Woops_String_Utils::getInstance();
     $this->_pageId = $this->_getPageId();
     $this->_langName = $this->_getLanguage();
     $this->_page = $this->_getPage($this->_pageId, $this->_langName);
     $this->_template = $this->_getTemplate($this->_page->id_templates);
 }
Example #4
0
 /**
  * Sets the needed static variables
  * 
  * @return  void
  */
 private static function _setStaticVars()
 {
     // Gets the instance of the WOOPS page getter
     self::$_pageGetter = Woops_Page_Getter::getInstance();
     // Gets the instance of the environment object
     self::$_env = Woops_Core_Env_Getter::getInstance();
     // Gets the instance of the configuration object
     self::$_conf = Woops_Core_Config_Getter::getInstance();
     // Gets the instance of the string utilities
     self::$_str = Woops_String_Utils::getInstance();
     // Static variables are set
     self::$_hasStatic = true;
 }
Example #5
0
 /**
  * Class constructor
  * 
  * @return  void
  */
 private function __construct()
 {
     $this->_conf = Woops_Core_Config_Getter::getInstance();
     $this->_env = Woops_Core_Env_Getter::getInstance();
     $this->_registerModuleDirectory($this->_env->getSourcePath('modules/'), $this->_env->getSourceWebPath('modules/'));
     $this->_registerModuleDirectory($this->_env->getPath('modules/'), $this->_env->getWebPath('modules/'));
     $loadedModules = $this->_conf->getVar('modules', 'loaded');
     if (is_array($loadedModules)) {
         foreach ($loadedModules as $moduleName) {
             if (!isset($this->_modules[$moduleName])) {
                 throw new Woops_Core_Module_Manager_Exception('The module \'' . $moduleName . '\' does not exist', Woops_Core_Module_Manager_Exception::EXCEPTION_NO_MODULE);
             }
             $this->_loadedModules[$moduleName] = false;
         }
         foreach ($this->_loadedModules as $moduleName => $void) {
             $this->_loadModuleInfos($moduleName);
         }
     }
 }
Example #6
0
# All rights reserved                                                          #
################################################################################
# $Id$
// Sets the error reporting level to the highest possible value
error_reporting(E_ALL | E_STRICT);
// Checks the PHP version
if ((double) PHP_VERSION < 5.2) {
    // We are not running PHP 5.2 or greater
    trigger_error('PHP version 5.2 is required to use this script (actual version is ' . PHP_VERSION . ')', E_USER_ERROR);
}
// Checks for the SPL
if (!function_exists('spl_autoload_register')) {
    // The SPL is unavailable
    throw new Exception('The SPL (Standard PHP Library) is required to use this script');
}
// Checks for the SimpleXMLElement class
if (!class_exists('SimpleXMLElement')) {
    // SimpleXMLElement is unavailable
    throw new Exception('The SimpleXMLElement class is required to use this script');
}
// Includes the Woops class manager
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'Woops' . DIRECTORY_SEPARATOR . 'Core' . DIRECTORY_SEPARATOR . 'Class' . DIRECTORY_SEPARATOR . 'Manager.class.php';
// Registers an SPL autoload method to use to load the classes form the Woops project
spl_autoload_register(array('Woops_Core_Class_Manager', 'autoLoad'));
// Sets the error and exception handlers - From now every mistake will produce a fatal error
set_exception_handler(array('Woops_Core_Exception_Handler', 'handleException'));
set_error_handler(array('Woops_Core_Error_Handler', 'handleError'));
// Sets the default timezone
date_default_timezone_set(Woops_Core_Config_Getter::getInstance()->getVar('time', 'timezone'));
// Loads the active modules
Woops_Core_Module_Manager::getInstance()->initModules();
Example #7
0
 // We don't want any error here
 try {
     // Checks if AOP is enabled, and if the class is not an interface
     if (Woops_Core_Config_Getter::getInstance()->getVar('aop', 'enable') && substr($CLASSNAME, -9) !== 'Interface') {
         // Creates an AOP version of the class
         $AOP = new Woops_Core_Aop_Class_Builder($CLASSNAME);
         // Gets the code of the AOP version
         $CLASSCODE = (string) $AOP;
     } else {
         // Creates a reflection object for the class
         $REF = Woops_Core_Reflection_Class::getInstance($CLASSNAME);
         // Gets the PHP source code
         $CLASSCODE = file_get_contents($REF->getFileName());
     }
     // Checks if the source code must be optimized
     if (Woops_Core_Config_Getter::getInstance()->getVar('classCache', 'optimize')) {
         // Creates a source optimizer
         $OPT = new Woops_Php_Source_Optimizer($CLASSCODE);
         // Gets the optimized source code
         $CLASSCODE = (string) $OPT;
     }
     // Writes the class in the cache
     file_put_contents($CACHEDIR . $CLASSNAME . '.class.php', $CLASSCODE);
     // The cached version of the class was built
     header('X-WOOPS-CLASS-CACHE-BUILD-STATUS: OK');
     // Aborts the script
     exit;
 } catch (Exception $e) {
     // DEBUG ONLY!!!
     #throw( $e );
 }
Example #8
0
 /**
  * Adds an AOP advice on a target
  * 
  * This method registers a callback as an AOP advice, for a target. The
  * target can be a class name or an instance of class. In the first case,
  * the advice callback will be executed on all instances of the class. In
  * the second case, it will only be executed for the given instance.
  * 
  * Two categories of advice types are available:
  * 
  * - The first one allows you to execute code when a PHP magic method is
  * called on the target. The advices types are, in such a case:
  * 
  *      -# Woops_Core_Aop_Advisor::ADVICE_TYPE_CONSTRUCT
  *         Called when the constructor of the target class is called
  *      -# Woops_Core_Aop_Advisor::ADVICE_TYPE_DESTRUCT
  *         Called when the destructor of the target class is called
  *      -# Woops_Core_Aop_Advisor::ADVICE_TYPE_CLONE
  *         Called when an object of the target class is cloned
  *      -# Woops_Core_Aop_Advisor::ADVICE_TYPE_SLEEP
  *         Called when an object of the target class is serialized
  *      -# Woops_Core_Aop_Advisor::ADVICE_TYPE_WAKEUP
  *         Called when an object of the target class is unserialized
  *      -# Woops_Core_Aop_Advisor::ADVICE_TYPE_TO_STRING
  *         Called when an object of the target class is converted to a string
  * 
  * - The second one allows you to execute specific code on specific join
  * points, registered in the target class. In that case, you must specify
  * the name of the join point on which to place the advice as the fourth
  * parameter. Available advices types in such a case are:
  * 
  *      -# Woops_Core_Aop_Advisor::ADVICE_TYPE_VALID_CALL
  *         Called before the join point is executed, and may prevents the join
  *         point to be executed
  *      -# Woops_Core_Aop_Advisor::ADVICE_TYPE_BEFORE_CALL
  *         Called before the join point is executed
  *      -# Woops_Core_Aop_Advisor::ADVICE_TYPE_BEFORE_RETURN
  *         Called before the return value of the join point is return, and may
  *         change the return value
  *      -# Woops_Core_Aop_Advisor::ADVICE_TYPE_AFTER_CALL
  *         Called after the join point is executed
  *      -# Woops_Core_Aop_Advisor::ADVICE_TYPE_AFTER_THROWING
  *         Called after an exception is thrown from the join point. The
  *         original exception won't be thrown if the callback method
  *         returns true
  * 
  * @param   int                                 The type of the advice (one of the Woops_Core_Aop_Advisor::ADVICE_TYPE_XXX constant)
  * @param   callback                            The callback to invoke (must be a valid PHP callback)
  * @param   mixed                               The target on which to place the advice (either a class name or an object)
  * @param   string                              The join point on which to place the advice
  * @return  boolean
  * @throws  Woops_Core_Aop_Advisor_Exception   If the passed callback is not a valid PHP callback
  * @throws  Woops_Core_Aop_Advisor_Exception   If the target class does not exist
  * @throws  Woops_Core_Aop_Advisor_Exception   If the no join point is specified, when trying to register a user advice type
  * @throws  Woops_Core_Aop_Advisor_Exception   If the join point has not been registered in the target
  * @throws  Woops_Core_Aop_Advisor_Exception   If the advice type is not allowed for the join point
  * @throws  Woops_Core_Aop_Advisor_Exception   If the advice type does not exist
  */
 public static final function addAdvice($type, $callback, $target, $joinPoint = '')
 {
     // Checks if the configuration object exists
     if (!is_object(self::$_conf)) {
         // Gets the instance of the configuration object
         self::$_conf = Woops_Core_Config_Getter::getInstance();
         // Gets the AOP mode from the configuration to know if it's turned on or not
         self::$_enableAop = self::$_conf->getVar('aop', 'enable');
     }
     // If we are not using class caching, the AOP features must be turned off
     if (defined('WOOPS_CLASS_CACHE_MODE_OFF') || !self::$_enableAop) {
         // Nothing to do, as AOP is disabled
         return true;
     }
     // Checks if the callback must be executed for a specific object or for all instances
     if (is_object($target)) {
         // Gets the class name and object hash, so the callback will be added for the specific object only
         $className = $target->_className;
         $objectHash = $target->_objectHash;
     } else {
         // Callback will be executed for all instances
         $className = $target;
         $objectHash = false;
         // Checks if the class exists
         if (!class_exists($className)) {
             // Error - Unexisting class
             throw new Woops_Core_Aop_Advisor_Exception('Cannot add an advice on unexisting class ' . $className, Woops_Core_Aop_Advisor_Exception::EXCEPTION_NO_CLASS);
         }
     }
     // Checks if the advice type is for a specific join point or not
     if ($type & self::ADVICE_TYPE_GLOBAL) {
         // Process the global advice types
         foreach (self::$_globalAdvices as $adviceType) {
             // Checks if the requested type matches a global advice type
             if ($type & $adviceType) {
                 // Checks if the storage array for the advice exists
                 if (!isset(self::$_advices[$adviceType][$className])) {
                     // Creates the storage array for the advice
                     self::$_advices[$adviceType][$className] = array();
                 }
                 // Adds the advice callback for the join point
                 self::$_advices[$adviceType][$className][] = array(new Woops_Core_Callback($callback), $objectHash);
             }
         }
         // The advice(s) was(were) added
         return true;
     } elseif ($type & self::ADVICE_TYPE_USER_DEFINED) {
         // Checks if a join point is specified
         if (!$joinPoint) {
             // Error - A join point must be specified
             throw new Woops_Core_Aop_Advisor_Exception('A join point must be specified for that type of advice', Woops_Core_Aop_Advisor_Exception::EXCEPTION_NO_JOINPOINT);
         }
         // Checks if the join point exists
         if (!isset(self::$_joinPointsByName[$className][$joinPoint])) {
             // Creates a reflection object for the class
             // If no instance exist at the moment the advice is added, the automatic join points won't be declared, so we'll have to check it manually
             $reflection = Woops_Core_Reflection_Class::getInstance($className);
             // Name of the method
             $methodName = $joinPoint . self::JOINPOINT_METHOD_SUFFIX;
             // Checks if we are processing an automatic join point
             if (!$reflection->hasMethod($methodName) || !$reflection->getMethod($methodName)->isPublic()) {
                 // Error - No such join point in the target class
                 throw new Woops_Core_Aop_Advisor_Exception('The join point ' . $joinPoint . ' does not exist in class ' . $className, Woops_Core_Aop_Advisor_Exception::EXCEPTION_NO_JOINPOINT);
             }
             // Process the user advice types
             foreach (self::$_userAdvices as $adviceType) {
                 // Checks if the requested type matches a user advice type
                 if ($type & $adviceType) {
                     // Checks if the storage array for the requested join point exists
                     if (!isset(self::$_advices[$adviceType][$className][$joinPoint])) {
                         // Creates the storage array
                         self::$_advices[$adviceType][$className][$joinPoint] = array();
                     }
                     // Adds the advice
                     self::$_advices[$adviceType][$className][$joinPoint][] = array(new Woops_Core_Callback($callback), $objectHash);
                 }
             }
             // The advice(s) was(were) added
             return true;
         }
         // Storage for the allowed advice types
         $allowedAdviceTypes = 0;
         // Process the join points for each instance of the target class
         foreach (self::$_joinPoints[$className] as $joinPoints) {
             // Adds the allowed types of advices for the joint point
             $allowedAdviceTypes |= $joinPoints[$joinPoint][1];
         }
         // Process the user advice types
         foreach (self::$_userAdvices as $adviceType) {
             // Checks if the requested type matches a user advice type
             if ($type & $adviceType) {
                 // Checks if the advice type is allowed
                 if ($adviceType & $allowedAdviceTypes) {
                     // Adds the advice callback for the join point
                     self::$_advices[$adviceType][$className][$joinPoint][] = array(new Woops_Core_Callback($callback), $objectHash);
                     return true;
                 } else {
                     // Error - The advice type is not allowed for the join point
                     throw new Woops_Core_Aop_Advisor_Exception('Advice of type ' . $adviceType . ' is not permitted for join point ' . $joinPoint, Woops_Core_Aop_Advisor_Exception::EXCEPTION_ADVICE_TYPE_NOT_PERMITTED);
                 }
             }
         }
     }
     // Error - Advice type is invalid
     throw new Woops_Core_Aop_Advisor_Exception('Invalid advice type (' . $type . ')', Woops_Core_Aop_Advisor_Exception::EXCEPTION_INVALID_ADVICE_TYPE);
 }
Example #9
0
 /**
  * Sets the needed static variables
  * 
  * @return  void
  */
 private static function _setStaticVars()
 {
     // Gets the instance of the string utilities
     self::$_str = Woops_String_Utils::getInstance();
     // Gets the instance of the configuration object
     self::$_conf = Woops_Core_Config_Getter::getInstance();
     // Sets the XML formatting option
     self::$_formattedOutput = (bool) self::$_conf->getVar('xml', 'format');
     // Static variables are set
     self::$_hasStatic = true;
 }
Example #10
0
 /**
  * Gets the unique class instance
  * 
  * This method is used to get the unique instance of the class
  * (singleton). If no instance is available, it will create it.
  * 
  * @return  Woops_Core_Env_Getter   The unique instance of the class
  * @see     __construct
  */
 public static function getInstance()
 {
     // Checks if the unique instance already exists
     if (!is_object(self::$_instance)) {
         // Creates the unique instance
         self::$_instance = new self();
     }
     // Returns the unique instance
     return self::$_instance;
 }
Example #11
0
 /**
  * Gets the unique class instance
  * 
  * This method is used to get the unique instance of the class
  * (singleton). If no instance is available, it will create it.
  * 
  * @return  Woops_Core_ClassManager The unique instance of the class
  * @see     __construct
  */
 public static function getInstance()
 {
     // Checks if the unique instance already exists
     if (!is_object(self::$_instance)) {
         // Creates the unique instance
         self::$_instance = new self();
         // Gets the instance of the WOOPS environment
         self::$_instance->_env = Woops_Core_Env_Getter::getInstance();
         // Gets the instance of the WOOPS module manager
         self::$_instance->_modManager = Woops_Core_Module_Manager::getInstance();
         // Checks if we must use AOP classes
         self::$_instance->_enableAop = Woops_Core_Config_Getter::getInstance()->getVar('aop', 'enable');
         // If AOP is enabled, the class cache must also be enabled
         if (self::$_instance->_enableAop) {
             // Enables the class cache
             self::$_instance->_classCache = true;
         } else {
             // Checks if we must use a class cache
             self::$_instance->_classCache = Woops_Core_Config_Getter::getInstance()->getVar('classCache', 'enable');
         }
         // Checks if we must use cached classes
         if (self::$_instance->_classCache) {
             // Gets the class cache directory
             self::$_instance->_cacheDirectory = self::$_instance->_env->getPath('cache/classes/');
             // Checks if the cache directory exist, and is writeable
             if (!self::$_instance->_cacheDirectory || !is_dir(self::$_instance->_cacheDirectory) || !is_writeable(self::$_instance->_cacheDirectory)) {
                 // Disables the AOP and the class cache
                 // Maybe this should generate a fatal error, but in that
                 // case, and if we are installing WOOPS, this could
                 // generate a bad first impression...
                 self::$_instance->_classCache = false;
                 self::$_instance->_enableAop = false;
                 define('WOOPS_CLASS_CACHE_MODE_OFF', true);
             }
         }
         // Adds the WOOPS version to the HTTP headers
         header('X-WOOPS-VERSION: ' . Woops_Core_Informations::WOOPS_VERSION . '-' . Woops_Core_Informations::WOOPS_VERSION_SUFFIX);
     }
     // Returns the unique instance
     return self::$_instance;
 }
Example #12
0
/**
 * Creates the cached version of a class
 * 
 * @param   string  The name of the class for which to build a cached version
 * @return  void
 */
function createClassCache($className)
{
    // The environment object
    static $env;
    // The configuration object
    static $conf;
    // The path to the cache directory for the PHP classes
    static $cacheDir;
    // Whether AOP is enabled
    static $aop;
    // Whether the PHP code must be optimized
    static $optimize;
    // Checks if we already have the environment object
    if (!is_object($env)) {
        // Gets the environment object
        $env = Woops_Core_Env_Getter::getInstance();
        // Gets the configuration object
        $conf = Woops_Core_Config_Getter::getInstance();
        // Sets the path to the cache directory
        $cacheDir = $env->getPath('cache/classes/');
        // Gets the AOP state
        $aop = $conf->getVar('aop', 'enable');
        // Gets the optimize state
        $optimize = $conf->getVar('classCache', 'optimize');
    }
    // Checks if the cached version already exists
    if (file_exists($cacheDir . $className . '.class.php')) {
        // Nothing to do, the cached version already exists
        return;
    }
    // Checks if AOP is enabled, and if the class is not an interface
    if ($aop && substr($className, -9) !== 'Interface') {
        // Creates an AOP version of the class
        $aopBuilder = new Woops_Core_Aop_Class_Builder($className);
        // Gets the code of the AOP version
        $classCode = (string) $aopBuilder;
    } else {
        // Creates a reflection object
        $reflection = Woops_Core_Reflection_Class::getInstance($className);
        // Gets the PHP source code
        $classCode = file_get_contents($reflection->getFileName());
    }
    // Checks if the source code must be optimized
    if ($optimize) {
        // Creates a source optimizer
        $optimizer = new Woops_Php_Source_Optimizer($classCode);
        // Gets the optimized source code
        $classCode = (string) $optimizer;
    }
    // Writes the class in the cache
    file_put_contents($cacheDir . $className . '.class.php', $classCode);
}
Example #13
0
 /**
  * 
  */
 private function _handleException(Exception $e)
 {
     if (!is_subclass_of($e, 'Woops_Core_Exception_Base')) {
         $e = new Woops_Core_Php_Exception('Exception of type ' . get_class($e) . ': ' . $e->getMessage(), $e->getCode(), $e->getTrace());
     }
     $report = Woops_Core_Config_Getter::getInstance()->getVar('error', 'report');
     if ($report === 'development') {
         print $e->getInfos();
         exit;
     } elseif ($report === 'production') {
         print $e;
         exit;
     } else {
         exit;
     }
 }
Example #14
0
 /**
  * Sets the needed static variables
  * 
  * @return  void
  */
 private static function _setStaticVars()
 {
     self::$_conf = Woops_Core_Config_Getter::getInstance();
     self::$_modManager = Woops_Core_Module_Manager::getInstance();
     self::$_request = Woops_Core_Request_Getter::getInstance();
     self::$_env = Woops_Core_Env_Getter::getInstance();
     self::$_str = Woops_String_Utils::getInstance();
     self::$_moduleVariables = self::$_request->getWoopsVar('mod');
     // Static variables are set
     self::$_hasStatic = true;
 }