View source
<?php
if (!class_exists('cmfcExceptionStandAlone')) {
trigger_error('cmfcExceptionStandAlone package does not included , please include it first', E_USER_ERROR);
}
define('CMF_ClassesCore_Ok', true, true);
define('CMF_ClassesCore_Error', 2, true);
define('CMF_Error', 1);
define('CMF_Ln_English', 'en');
class cmfcClassesCoreStandAlone {
var $_oLog = null;
var $_version = '$Id: classesCore.class.inc.php 663 2010-11-16 09:19:55Z salek $';
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();
function cmfcClassesCore() {
$args = func_get_args();
if (is_callable(array(
&$this,
"__construct",
))) {
call_user_func_array(array(
&$this,
"__construct",
), $args);
}
}
function getVersion() {
return $this->_version;
}
function getCalculatedLocations($options, $parameters) {
$server = $_SERVER;
if (!isset($server['DOCUMENT_ROOT'])) {
$server['DOCUMENT_ROOT'] = str_replace('\\', '/', substr($server['SCRIPT_FILENAME'], 0, 0 - strlen($server['PHP_SELF'])));
}
if (isset($server['DOCUMENT_ROOT'])) {
if (strpos('ASD@#$@#$#23423' . dirname(__FILE__), 'ASD@#$@#$#23423' . $server['DOCUMENT_ROOT']) === false) {
$server['DOCUMENT_ROOT'] = '/chroot' . $server['DOCUMENT_ROOT'];
}
}
if (!isset($options['pageFolderPath'])) {
$options['pageFolderPath'] = dirname($server['SCRIPT_FILENAME']);
$options['pageFolderPath'] = str_replace(array(
'/',
'\\',
), DIRECTORY_SEPARATOR, $options['pageFolderPath']);
}
if (!isset($options['pageFolderPathBrowser'])) {
$options['pageFolderPathBrowser'] = dirname($server['SCRIPT_NAME']);
}
if (!isset($options['siteFolderPath'])) {
$options['siteFolderPath'] = $server['DOCUMENT_ROOT'];
if (is_link($options['siteFolderPath'])) {
$options['siteFolderPath'] = readlink($options['siteFolderPath']);
}
}
if (!isset($options['siteFolderPathBrowser'])) {
$options['siteFolderPathBrowser'] = '';
}
if (!isset($options['packageFolderPath'])) {
$options['packageFolderPath'] = dirname($parameters['filePath']);
$options['siteFolderPath'] = str_replace(array(
'/',
'\\',
), DIRECTORY_SEPARATOR, $options['siteFolderPath']);
}
if (!isset($options['packageFolderPathBrowser'])) {
$fileRelativePath = $options['siteFolderPathBrowser'] . '/' . str_replace($options['siteFolderPath'], '', $options['packageFolderPath']);
$options['packageFolderPathBrowser'] = cmfcDirectory::normalizePath($fileRelativePath);
}
if (!isset($options['cmfFolderPath'])) {
$options['cmfFolderPath'] = realpath($options['packageFolderPath'] . '/../../..');
$options['cmfFolderPath'] = str_replace(array(
'/',
'\\',
), DIRECTORY_SEPARATOR, $options['cmfFolderPath']);
}
if (!isset($options['cmfFolderPathBrowser'])) {
$fileRelativePath = $options['siteFolderPathBrowser'] . '/' . str_replace($options['siteFolderPath'], '', $options['cmfFolderPath']);
$options['cmfFolderPathBrowser'] = cmfcDirectory::normalizePath($fileRelativePath);
}
return $options;
}
function setOptions($options, $merge = false) {
foreach ($options as $name => $value) {
$r = $this
->setOption($name, $options[$name], $merge);
if ($this
->isError($r)) {
return $r;
}
}
}
function setOptionsByReference(&$options, $merge = false) {
foreach ($options as $name => $value) {
$r = $this
->setOptionByReference($name, $options[$name], $merge);
if ($this
->isError($r)) {
return $r;
}
}
}
function setOption($name, $value, $merge = false) {
return $this
->setOptionByReference($name, $value, $merge);
}
function setOptionByReference($name, &$value, $merge = false) {
$r = null;
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);
$value =& $this->{'_' . $name};
}
else {
$this->{'_' . $name} =& $value;
}
$this->_options[$name] =& $value;
return $r;
}
function setStorage(&$value) {
$this->_oStorage =& $value;
}
function &getOption($name) {
return $this->{'_' . $name};
}
function setLog(&$value) {
$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;
}
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 {
}
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 {
}
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 {
}
}
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 cmfcExceptionStandAlone::raiseError($message, $code, $mode, $options, $userinfo, $error_class, $skipmsg);
}
public static function isError($obj, $code = null) {
return cmfcExceptionStandAlone::isError($obj, $code);
}
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,
));
}
}
}
}
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();
}
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 (!cmfcExceptionStandAlone::isError($result)) {
return $result;
}
}
}
}
}
function hasCommandHandler($cmd) {
if (is_array($this->_commandHandlers[$cmd])) {
if (!empty($this->_commandHandlers[$cmd])) {
return true;
}
}
return false;
}
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);
}
function saveToMemento() {
return clone $this;
}
function restoreFromMemento($object) {
}
}