You are here

class cmfcClassesCore in Calendar Systems 5

all cmf classes inherit from this class

Hierarchy

Expanded class hierarchy of cmfcClassesCore

1 string reference to 'cmfcClassesCore'
calendarV1.class.inc.php in calendar/v1/calendarV1.class.inc.php

File

calendar/lib/classesCore.class.inc.php, line 29

View source
class cmfcClassesCore extends PEAR {

  /**
   * PEAR::Log object used for error logging by ErrorStack
   *
   * @var    Log
   * @access public
   */
  var $_oLog = null;
  var $_version = '$Id$';

  /**
   * @var cmfcStorage instance
   */
  var $_oStorage = null;
  var $_observers = array();
  var $_observeringEnabled = true;
  var $_commandHandlers = array();
  var $_commandingEnabled = true;
  var $_dynamicSystemEnabled = false;
  var $_debugEnabled = false;
  var $_language = CMF_Ln_English;
  var $_options;
  var $_defaultError = CMF_Error;
  var $_messagesValue = array(
    CMF_ClassesCore_Ok => 'no error',
    CMF_ClassesCore_Error => 'unknown error',
  );
  var $_errorsStack = array();

  /**
   * @desc
   */

  //var $_propertiesValues

  /**
   * there is no __construct function in php4 or down , so this function is solution , now it's possible
   * for all chid of this base class to have __construct functions
   *
   */
  function cmfcClassesCore() {

    //$this->PEAR(get_class($this));
    $args = func_get_args();
    if (is_callable(array(
      &$this,
      "__construct",
    ))) {
      call_user_func_array(array(
        &$this,
        "__construct",
      ), $args);
    }
  }
  function getVersion() {
    return $this->_version;
  }
  function setOptions($options, $merge = false) {
    foreach ($options as $name => $value) {
      $r = $this
        ->setOption($name, $value, $merge);
      if (PEAR::isError($r)) {
        return $r;
      }
    }
  }
  function setOption($name, $value, $merge = false) {
    if ($name == 'storage') {
      $r =& $this
        ->setStorage(&$value);
    }
    elseif ($name == 'storage') {
      $r =& $this
        ->setLog(&$value);
    }
    elseif (is_array($value) and $merge == true) {
      $this->{'_' . $name} =& cmfcArray::mergeRecursive($this->{'_' . $name}, $value);
    }
    else {
      $this->{'_' . $name} =& $value;
    }
    $this->_options[$name] =& $value;
    return $r;
  }
  function setStorage(&$value) {
    $this->_oStorage =& $value;
  }

  /**
   * works fine in both php4 & 5. but you should use & when you call the function. $b=&$ins->getOption('property')
   */
  function &getOption($name) {
    return $this->{'_' . $name};
  }
  function setLog(&$value) {

    //if (!empty($this->_oLog))

    //$this->_oLog=&Log::singleton('file', 'out.log', 'CreativeMindFramework');
    $this->_oLog =& $value;
  }
  function getMessageValue($msgCode, $parameters = null) {
    if (isset($this->_messagesValue[$msgCode])) {
      $message = $this->_messagesValue[$msgCode];
    }
    else {
      $message = $this->_messagesValue[$this->_defaultError];
    }
    if (is_array($parameters)) {
      $message = sprintf($message, $parameters);
    }
    return $message;
  }

  /**
   *	fill all of object variables with their default values except $base_properties
   *	$base_properties=array('local_language_name','db','event_system','configurations','table_name_prefix');
   * 	@BENEFITS:increases object creation speed in loop, in fact there is no need to create class anymore, just create it at first time and then call this function for furture uses
   * 	@param $base_properties array
   */
  function resetProperties($baseBroperties = null, $prefix = null) {
    $classVars = get_class_vars(cmfcPhp4::get_class($this));
    foreach ($classVars as $varName => $defaultValue) {
      if (!in_array($varName, $baseBroperties)) {
        if (is_integer($defaultValue) or is_float($defaultValue)) {
          $this->{$prefix . $varName} = $defaultValue;
        }
        else {
          $this->{$prefix . $varName} = $defaultValue;
        }
      }
    }
  }
  function arrayToProperties($propertiesValues, $exceptNulls = false, $prefix = null) {
    if (is_array($propertiesValues)) {
      if ($this->_dynamicSystemEnabled) {
        foreach ($propertiesValues as $propertyName => $propertyValue) {
          $this->{$prefix . $propertyName} = $propertyValue;
        }
      }
      else {

        // only for sample :

        /*
        if ($exceptNulls==false or ($exceptNulls and !is_null($propertiesValues[$this->colnId])))
        	@$this->cvId=$propertiesValues[$this->colnId];
        */
      }
      return true;
    }
    return false;
  }
  function propertiesToArray($exceptNulls = false, $prefix = null) {
    $propertiesValues = array();
    if ($this->_dynamicSystemEnabled) {
      $vars = get_object_vars($this);
      foreach ($vars as $varName => $varValue) {
        if (preg_match('/^' . $prefix . '.*/', $varName) or is_null($prefix)) {
          $propertiesValues[$varName] = $varValue;
        }
      }
    }
    else {

      // only for sample :

      /*
      if ($exceptNulls==false or ($exceptNulls and !is_null($this->cvId)))
      	$propertiesValues[$this->colnId]=$this->cvId;
      */
    }
    return $propertiesValues;
  }
  function clearProperties($prefix = null) {
    if ($this->_dynamicSystemEnabled) {
      $vars = get_object_vars($this);
      foreach ($vars as $varName => $varValue) {
        if (preg_match('/^' . $prefix . '.*/', $varName) or is_null($prefix)) {
          $this->{$varName} = null;
        }
      }
    }
    else {

      // only for sample :

      /*
      $this->_language=null;
      */
    }
  }

  // }}}
  // {{{ raiseError()

  /**
   * conditionally includes PEAR base class and raise an error
   * @example
   * <code>
   * 		return $this->raiseError('', CMF_Language_Error_Unknown_Short_Name,
   *						PEAR_ERROR_RETURN,NULL,
   *						array('shortName'=>$shortName)
   *		);
   * </code>
   * @param string $msg  Error message
   * @param int    $code Error code
   * @access private
   */
  function raiseError($message = null, $code = null, $mode = null, $options = null, $userinfo = null, $error_class = null, $skipmsg = false) {
    if (isset($this->_messagesValue[$code]) && empty($message)) {
      $message = $this->_messagesValue[$code];
    }
    if (is_array($userinfo) && !empty($message)) {
      if (is_array($userinfo)) {
        foreach ($userinfo as $key => $value) {
          $replacements['%' . $key . '%'] = $value;
        }
      }
      $message = cmfcString::replaceVariables($replacements, $message);
    }
    return PEAR::raiseError($message, $code, $mode, $options, $userinfo, $error_class, $skipmsg);
  }
  function isError($obj, $code = null) {
    return PEAR::isError($obj, $code);
  }

  //! An accessor

  /**
   * Calls the update() function using the reference to each
   * registered observer - used by children of Observable
   * @return void
   */
  function notifyObservers($event, $params = null) {
    if ($this->_observeringEnabled == true) {
      if (is_array($this->_observers[$event])) {
        foreach ($this->_observers[$event] as $observer) {
          call_user_func_array($observer, array(
            &$this,
            $params,
          ));
        }
      }
    }
  }

  //! An accessor

  /**
   * Register the reference to an object object
   * @param $observer array|string //like call_user_func first param
   * @return void
   */
  function addObserver($event, $observer, $parameters = null) {
    $this->_observers[$event][] = $observer;
  }
  function prependObserver($event, $observer, $parameters = null) {
    if (empty($this->_observers[$event])) {
      $this->_observers[$event] = array();
    }
    array_unshift($this->_observers[$event], $observer);
  }
  function removeObservers($cmd) {
    $this->_commandHandlers[$cmd] = array();
  }

  /**
   * @example
   * <code>
   * $this->runCommand('sendEmailAfterActivation',$columnsValues);
   * </code>
   */
  function runCommand($cmd, $params = null) {
    if ($this->_commandingEnabled == true) {
      if (is_array($this->_commandHandlers[$cmd])) {
        foreach ($this->_commandHandlers[$cmd] as $commandHandler) {
          $result = call_user_func_array($commandHandler, array(
            &$this,
            $cmd,
            $params,
          ));
          if (!PEAR::isError($result)) {
            return $result;
          }
        }
      }
    }
  }
  function hasCommandHandler($cmd) {
    if (is_array($this->_commandHandlers[$cmd])) {
      if (!empty($this->_commandHandlers[$cmd])) {
        return true;
      }
    }
    return false;
  }

  /**
   * @example
   * <code>
   * $object->addCommandHandler('commandName','functionName')
   * $object->addCommandHandler('commandName',array(&$myObject,'methodName'))
   * </code>
   */
  function addCommandHandler($cmd, $commandHandler, $parameters = null) {
    $this->_commandHandlers[$cmd][] = $commandHandler;
  }
  function removeCommandHandlers($cmd) {
    $this->_commandHandlers[$cmd] = array();
  }
  function prependCommandHandler($cmd, $commandHandler, $parameters = null) {
    if (empty($this->_commandHandlers[$cmd])) {
      $this->_commandHandlers[$cmd] = array();
    }
    array_unshift(&$this->_commandHandlers[$cmd], $commandHandler);
  }

  /**
   * memento design pattern
   * will clone the object for adding undo ability.
   * @todo
   * 	- should become complete
   */
  function saveToMemento() {
    return clone $this;
  }

  /**
   * memento design pattern
   * will load the object previous state
   * @todo
   * 	- should become complete
   */
  function restoreFromMemento($object) {

    //commented duo to incopatiblility with php5

    //$this=$object;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
cmfcClassesCore::$_commandHandlers property
cmfcClassesCore::$_commandingEnabled property
cmfcClassesCore::$_debugEnabled property
cmfcClassesCore::$_defaultError property 1
cmfcClassesCore::$_dynamicSystemEnabled property
cmfcClassesCore::$_errorsStack property
cmfcClassesCore::$_language property 1
cmfcClassesCore::$_messagesValue property 1
cmfcClassesCore::$_observeringEnabled property
cmfcClassesCore::$_observers property
cmfcClassesCore::$_oLog property * PEAR::Log object used for error logging by ErrorStack * * * @access public
cmfcClassesCore::$_options property
cmfcClassesCore::$_oStorage property *
cmfcClassesCore::$_version property
cmfcClassesCore::addCommandHandler function * @example * <code> * $object->addCommandHandler('commandName','functionName') * $object->addCommandHandler('commandName',array(&$myObject,'methodName')) * </code>
cmfcClassesCore::addObserver function Register the reference to an object object
cmfcClassesCore::arrayToProperties function
cmfcClassesCore::clearProperties function
cmfcClassesCore::cmfcClassesCore function * there is no __construct function in php4 or down , so this function is solution , now it's possible * for all chid of this base class to have __construct functions *
cmfcClassesCore::getMessageValue function
cmfcClassesCore::getOption function * works fine in both php4 & 5. but you should use & when you call the function. $b=&$ins->getOption('property')
cmfcClassesCore::getVersion function
cmfcClassesCore::hasCommandHandler function
cmfcClassesCore::isError function Tell whether a value is a PEAR error. Overrides PEAR::isError
cmfcClassesCore::notifyObservers function Calls the update() function using the reference to each registered observer - used by children of Observable
cmfcClassesCore::prependCommandHandler function
cmfcClassesCore::prependObserver function
cmfcClassesCore::propertiesToArray function
cmfcClassesCore::raiseError function conditionally includes PEAR base class and raise an error @example <code> return $this->raiseError('', CMF_Language_Error_Unknown_Short_Name, * PEAR_ERROR_RETURN,NULL, * array('shortName'=>$shortName) … Overrides PEAR::raiseError
cmfcClassesCore::removeCommandHandlers function
cmfcClassesCore::removeObservers function
cmfcClassesCore::resetProperties function * fill all of object variables with their default values except $base_properties * $base_properties=array('local_language_name','db','event_system','configurations','table_name_prefix'); *…
cmfcClassesCore::restoreFromMemento function memento design pattern will load the object previous state @todo - should become complete
cmfcClassesCore::runCommand function * @example * <code> * $this->runCommand('sendEmailAfterActivation',$columnsValues); * </code>
cmfcClassesCore::saveToMemento function memento design pattern will clone the object for adding undo ability. @todo - should become complete
cmfcClassesCore::setLog function
cmfcClassesCore::setOption function 1
cmfcClassesCore::setOptions function
cmfcClassesCore::setStorage function
PEAR::$_debug property Whether to enable internal debug messages.
PEAR::$_default_error_handler property Default error handler (callback) for this object, if error mode is PEAR_ERROR_CALLBACK.
PEAR::$_default_error_mode property Default error mode for this object.
PEAR::$_default_error_options property Default error options used for this object when error mode is PEAR_ERROR_TRIGGER.
PEAR::$_error_class property Which class to use for error objects.
PEAR::$_expected_errors property An array of expected errors.
PEAR::delExpect function This method deletes all occurences of the specified element from the expected error codes stack.
PEAR::expectError function This method is used to tell which errors you expect to get. Expected errors are always returned with error mode PEAR_ERROR_RETURN. Expected error codes are stored in a stack, and this method pushes a new element onto it. The list of expected errors…
PEAR::getStaticProperty function If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them. Eg. in your method(s) do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar'); You MUST…
PEAR::loadExtension function OS independant PHP extension load. Remember to take care on the correct extension name for case sensitive OSes.
PEAR::PEAR function Constructor. Registers this object in $_PEAR_destructor_object_list for destructor emulation if a destructor object exists.
PEAR::popErrorHandling function Pop the last error handler used
PEAR::popExpect function This method pops one element off the expected error codes stack.
PEAR::pushErrorHandling function Push a new error handler on top of the error handler options stack. With this you can easily override the actual error handler for some code and restore it later with popErrorHandling.
PEAR::registerShutdownFunc function Use this function to register a shutdown method for static classes.
PEAR::setErrorHandling function Sets how errors generated by this object should be handled. Can be invoked both in objects and statically. If called statically, setErrorHandling sets the default behaviour for all PEAR objects. If called in an object, setErrorHandling sets the…
PEAR::staticPopErrorHandling function
PEAR::staticPushErrorHandling function
PEAR::throwError function Simpler form of raiseError with fewer options. In most cases message, code and userinfo are enough.
PEAR::_checkDelExpect function This method checks unsets an error code if available
PEAR::_PEAR function Destructor (the emulated type of...). Does nothing right now, but is included for forward compatibility, so subclass destructors should always call it.