/** * Standard error message generation callback * * This method may also be called by a custom error message generator * to fill in template values from the params array, simply * set the third parameter to the error message template string to use * * The special variable %__msg% is reserved: use it only to specify * where a message passed in by the user should be placed in the template, * like so: * * Error message: %msg% - internal error * * If the message passed like so: * * <code> * $stack->push(ERROR_CODE, 'error', array(), 'server error 500'); * </code> * * The returned error message will be "Error message: server error 500 - * internal error" * @param PEAR_ErrorStack * @param array * @param string|false Pre-generated error message template * @static * @return string */ function getErrorMessage(&$stack, $err, $template = false) { if ($template) { $mainmsg = $template; } else { $mainmsg = $stack->getErrorMessageTemplate($err['code']); } $mainmsg = str_replace('%__msg%', $err['message'], $mainmsg); if (is_array($err['params']) && count($err['params'])) { foreach ($err['params'] as $name => $val) { if (is_array($val)) { // @ is needed in case $val is a multi-dimensional array $val = @implode(', ', $val); } if (is_object($val)) { if (method_exists($val, '__toString')) { $val = $val->__toString(); } else { PEAR_ErrorStack::staticPush('PEAR_ErrorStack', PEAR_ERRORSTACK_ERR_OBJTOSTRING, 'warning', array('obj' => get_class($val)), 'object %obj% passed into getErrorMessage, but has no __toString() method'); $val = 'Object'; } } $mainmsg = str_replace('%' . $name . '%', $val, $mainmsg); } } return $mainmsg; }
/** * Encrypts a password for storage in a backend container. * Uses the algorithm defined in the passwordEncryptionMode parameter. * * @param string password to encrypt * @param string the encryption mode * @param string token to use to encrypt data * @return string The encrypted password */ function encryptPW($plainPW, $passwordEncryptionMode, $secret) { if (empty($plainPW) && $plainPW !== 0) { return ''; } $passwordEncryptionMode = strtolower($passwordEncryptionMode); if ($passwordEncryptionMode == 'plain') { return $plainPW; } if ($passwordEncryptionMode == 'md5') { return md5($plainPW); } if (extension_loaded('hash') && in_array($passwordEncryptionMode, hash_algos())) { return hash($passwordEncryptionMode, $plainPW); } if ($passwordEncryptionMode == 'rc4') { return LiveUser::cryptRC4($plainPW, $secret, true); } if (function_exists('sha1') && $passwordEncryptionMode == 'sha1') { return sha1($plainPW); } PEAR_ErrorStack::staticPush('LiveUser', LIVEUSER_ERROR_NOT_SUPPORTED, 'error', array(), 'Could not find the requested encryption function : ' . $passwordEncryptionMode); return false; }
/** * Create a PEAR_PackageFile_v* from an XML string. * @access public * @param string $data contents of package.xml file * @param int $state package state (one of PEAR_VALIDATE_* constants) * @param string $file full path to the package.xml file (and the files * it references) * @param string $archive optional name of the archive that the XML was * extracted from, if any * @return PEAR_PackageFile_v1|PEAR_PackageFile_v2 * @uses parserFactory() to construct a parser to load the package. */ function &fromXmlString($data, $state, $file, $archive = false) { if (preg_match('/<package[^>]+version="([0-9]+\\.[0-9]+)"/', $data, $packageversion)) { if (!in_array($packageversion[1], array('1.0', '2.0', '2.1'))) { return PEAR::raiseError('package.xml version "' . $packageversion[1] . '" is not supported, only 1.0, 2.0, and 2.1 are supported.'); } $object =& $this->parserFactory($packageversion[1]); if ($this->_logger) { $object->setLogger($this->_logger); } $object->setConfig($this->_config); $pf = $object->parse($data, $file, $archive); if (PEAR::isError($pf)) { return $pf; } if ($this->_rawReturn) { return $pf; } if ($pf->validate($state)) { if ($this->_logger) { if ($pf->getValidationWarnings(false)) { foreach ($pf->getValidationWarnings() as $warning) { $this->_logger->log(0, 'WARNING: ' . $warning['message']); } } } if (method_exists($pf, 'flattenFilelist')) { $pf->flattenFilelist(); // for v2 } return $pf; } else { if ($this->_config->get('verbose') > 0) { if ($this->_logger) { if ($pf->getValidationWarnings(false)) { foreach ($pf->getValidationWarnings(false) as $warning) { $this->_logger->log(0, 'ERROR: ' . $warning['message']); } } } } $a = PEAR::raiseError('Parsing of package.xml from file "' . $file . '" failed', 2, null, null, $pf->getValidationWarnings()); return $a; } } elseif (preg_match('/<package[^>]+version="([^"]+)"/', $data, $packageversion)) { $a = PEAR::raiseError('package.xml file "' . $file . '" has unsupported package.xml <package> version "' . $packageversion[1] . '"'); return $a; } else { if (!class_exists('PEAR_ErrorStack')) { require_once 'PEAR/ErrorStack.php'; } PEAR_ErrorStack::staticPush('PEAR_PackageFile', PEAR_PACKAGEFILE_ERROR_NO_PACKAGEVERSION, 'warning', array('xml' => $data), 'package.xml "' . $file . '" has no package.xml <package> version'); $object =& $this->parserFactory('1.0'); $object->setConfig($this->_config); $pf = $object->parse($data, $file, $archive); if (PEAR::isError($pf)) { return $pf; } if ($this->_rawReturn) { return $pf; } if ($pf->validate($state)) { if ($this->_logger) { if ($pf->getValidationWarnings(false)) { foreach ($pf->getValidationWarnings() as $warning) { $this->_logger->log(0, 'WARNING: ' . $warning['message']); } } } if (method_exists($pf, 'flattenFilelist')) { $pf->flattenFilelist(); // for v2 } return $pf; } else { $a = PEAR::raiseError('Parsing of package.xml from file "' . $file . '" failed', 2, null, null, $pf->getValidationWarnings()); return $a; } } }
/** * * Pushes an error onto the PEAR_ErrorStack. * * @return void * */ function error() { // push an error onto the stack PEAR_ErrorStack::staticPush('Savant2', $this->code, null, $this->info, $this->text); }
/** * Scan through the SVN directory looking for subclasses. * * @return mixed array on success, false on failure * @access public */ function fetchCommands() { $commands = array(); $dir = realpath(dirname(__FILE__)) . '/SVN'; $dp = @opendir($dir); if (empty($dp)) { PEAR_ErrorStack::staticPush('VersionControl_SVN', VERSIONCONTROL_SVN_ERROR, 'error', array('errstr' => "fetchCommands: opendir({$dir}) failed")); return false; } while ($entry = readdir($dp)) { if ($entry[0] == '.' || substr($entry, -4) != '.php') { continue; } $commands[] = substr($entry, 0, -4); } closedir($dp); return $commands; }
/** * Adds an error to the stack for the package. This method is a wrapper * for PEAR_ErrorStack::staticPush() method. * * @param integer $code * @param string $message * @param string $level * @param array $params * @param array $repackage * @param array $backtrace * @see PEAR_ErrorStack::staticPush() */ function push($code, $message = false, $level = 'exception', $params = array(), $repackage = false, $backtrace = false) { if (!$backtrace) { $backtrace = debug_backtrace(); } PEAR_ErrorStack::staticPush('Piece_Unity', $code, 'exception', $params, $message, $repackage, $backtrace); }
/** * Donne la représentation UTF-8 d'un caractère Unicode * @param integer $num indice du caractère dans l'Unicode * @todo Vérifier que ce code est vraiment portable. Problèmes possibles : big/little endian, type integer qui n'est pas sur 32 bits. * @return string */ function utf8Chr($num) { if ($num < 127) { return chr($num); } if ($num < 2048) { return chr(192 + ($num >> 6)) . chr(128 + ($num & 63)); } if ($num < 65536) { return chr(224 + ($num >> 12)) . chr(128 + ($num >> 6) & 63) . chr(128 + ($num & 63)); } if ($num < 2097152) { return chr(240 + ($num >> 18)) . chr(128 + ($num >> 12 & 63)) . chr(128 + ($num >> 6 & 63)) . chr(128 + ($num & 63)); } PEAR_ErrorStack::staticPush('OpenWeb::Backend::DocInfos', OW_WRONG_ENTITY, 'warning', array('entity' => '&#' . strval($num) . ';')); return ''; }
/** * Add an error to the stack * Dies if the error is an exception (and would have died anyway) * * @param integer $code Error code. * @param string $level The error level of the message. * Valid are PEAR_LOG_* constants * @param array $params Associative array of error parameters * @param array $trace Error context info (see debug_backtrace() contents) * * @return array PEAR_ErrorStack instance. And with context info (if PHP 4.3+) * @since 0.3.3 * @access public */ function raiseError($code, $level, $params) { if (function_exists('debug_backtrace')) { $trace = debug_backtrace(); // PHP 4.3+ } else { $trace = null; // PHP 4.1.x, 4.2.x (no context info available) } $err = PEAR_ErrorStack::staticPush($this->_package, $code, $level, $params, false, false, $trace); return $err; }
/** * Static method to set defaults into a select params array * * @param array params array * @return array params array * * @access public */ function setSelectDefaultParams($params) { if (!is_array($params)) { PEAR_ErrorStack::staticPush('LiveUser_Admin', LIVEUSER_ADMIN_ERROR, 'exception', array(), 'Parameters must be an array but is of type: ' . gettype($params)); } $params['fields'] = empty($params['fields']) ? array('*') : $params['fields']; $params['with'] = empty($params['with']) ? array() : $params['with']; $params['filters'] = empty($params['filters']) ? array() : $params['filters']; $params['orders'] = empty($params['orders']) ? array() : $params['orders']; $params['rekey'] = empty($params['rekey']) ? false : $params['rekey']; $params['group'] = empty($params['group']) ? false : $params['group']; $params['limit'] = empty($params['limit']) ? null : $params['limit']; $params['offset'] = empty($params['offset']) ? null : $params['offset']; $params['select'] = empty($params['select']) ? 'all' : $params['select']; return $params; }
/** * Creates an instance of the given update class. * * @access public * @param string $driver The type of PPU to create. * @param string $packageName The package to update. * @param string $channel The channel the package resides on. * @return object An instance of type PEAR_PackageUpdate_$driver * @since 0.4.0a1 * @throws PEAR_PACKAGEUPDATE_ERROR_NONEXISTENTDRIVER */ function &factory($driver, $packageName, $channel) { $class = 'PEAR_PackageUpdate_' . $driver; // Attempt to include a custom version of the named class, but don't treat // a failure as fatal. The caller may have already included their own // version of the named class. if (!class_exists($class)) { // Try to include the driver. $file = 'PEAR/PackageUpdate/' . $driver . '.php'; if (!PEAR_PackageUpdate::isIncludable($file)) { PEAR_ErrorStack::staticPush('PEAR_PackageUpdate', PEAR_PACKAGEUPDATE_ERROR_NONEXISTENTDRIVER, null, array('drivername' => $driver), $GLOBALS['_PEAR_PACKAGEUPDATE_ERRORS'][PEAR_PACKAGEUPDATE_ERROR_NONEXISTENTDRIVER]); // Must assign a variable to avoid notice about references. $false = false; return $false; } include_once $file; } // See if the class exists now. if (!class_exists($class)) { // Must assign a variable to avoid notice about references. $false = false; return $false; } // Try to instantiate the class. $instance =& new $class($packageName, $channel); return $instance; }