class cmfcClassesCore in Calendar Systems 5
all cmf classes inherit from this class
Hierarchy
- class \PEAR
- class \cmfcClassesCore
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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
cmfcClassesCore:: |
property | |||
cmfcClassesCore:: |
property | |||
cmfcClassesCore:: |
property | |||
cmfcClassesCore:: |
property | 1 | ||
cmfcClassesCore:: |
property | |||
cmfcClassesCore:: |
property | |||
cmfcClassesCore:: |
property | 1 | ||
cmfcClassesCore:: |
property | 1 | ||
cmfcClassesCore:: |
property | |||
cmfcClassesCore:: |
property | |||
cmfcClassesCore:: |
property | * PEAR::Log object used for error logging by ErrorStack * * * @access public | ||
cmfcClassesCore:: |
property | |||
cmfcClassesCore:: |
property | * | ||
cmfcClassesCore:: |
property | |||
cmfcClassesCore:: |
function | * @example * <code> * $object->addCommandHandler('commandName','functionName') * $object->addCommandHandler('commandName',array(&$myObject,'methodName')) * </code> | ||
cmfcClassesCore:: |
function | Register the reference to an object object | ||
cmfcClassesCore:: |
function | |||
cmfcClassesCore:: |
function | |||
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:: |
function | |||
cmfcClassesCore:: |
function | * works fine in both php4 & 5. but you should use & when you call the function. $b=&$ins->getOption('property') | ||
cmfcClassesCore:: |
function | |||
cmfcClassesCore:: |
function | |||
cmfcClassesCore:: |
function |
Tell whether a value is a PEAR error. Overrides PEAR:: |
||
cmfcClassesCore:: |
function | Calls the update() function using the reference to each registered observer - used by children of Observable | ||
cmfcClassesCore:: |
function | |||
cmfcClassesCore:: |
function | |||
cmfcClassesCore:: |
function | |||
cmfcClassesCore:: |
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:: |
||
cmfcClassesCore:: |
function | |||
cmfcClassesCore:: |
function | |||
cmfcClassesCore:: |
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:: |
function | memento design pattern will load the object previous state @todo - should become complete | ||
cmfcClassesCore:: |
function | * @example * <code> * $this->runCommand('sendEmailAfterActivation',$columnsValues); * </code> | ||
cmfcClassesCore:: |
function | memento design pattern will clone the object for adding undo ability. @todo - should become complete | ||
cmfcClassesCore:: |
function | |||
cmfcClassesCore:: |
function | 1 | ||
cmfcClassesCore:: |
function | |||
cmfcClassesCore:: |
function | |||
PEAR:: |
property | Whether to enable internal debug messages. | ||
PEAR:: |
property | Default error handler (callback) for this object, if error mode is PEAR_ERROR_CALLBACK. | ||
PEAR:: |
property | Default error mode for this object. | ||
PEAR:: |
property | Default error options used for this object when error mode is PEAR_ERROR_TRIGGER. | ||
PEAR:: |
property | Which class to use for error objects. | ||
PEAR:: |
property | An array of expected errors. | ||
PEAR:: |
function | This method deletes all occurences of the specified element from the expected error codes stack. | ||
PEAR:: |
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:: |
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:: |
function | OS independant PHP extension load. Remember to take care on the correct extension name for case sensitive OSes. | ||
PEAR:: |
function | Constructor. Registers this object in $_PEAR_destructor_object_list for destructor emulation if a destructor object exists. | ||
PEAR:: |
function | Pop the last error handler used | ||
PEAR:: |
function | This method pops one element off the expected error codes stack. | ||
PEAR:: |
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:: |
function | Use this function to register a shutdown method for static classes. | ||
PEAR:: |
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:: |
function | |||
PEAR:: |
function | |||
PEAR:: |
function | Simpler form of raiseError with fewer options. In most cases message, code and userinfo are enough. | ||
PEAR:: |
function | This method checks unsets an error code if available | ||
PEAR:: |
function | Destructor (the emulated type of...). Does nothing right now, but is included for forward compatibility, so subclass destructors should always call it. |