本文整理汇总了PHP中get_defined_constants函数的典型用法代码示例。如果您正苦于以下问题:PHP get_defined_constants函数的具体用法?PHP get_defined_constants怎么用?PHP get_defined_constants使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_defined_constants函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendMail
function sendMail($params)
{
// Cargar todas las constantes definidas
$constants = get_defined_constants();
// Obtener la direccion a la cual se va a enviar (TO)
$to = $params['to'];
// Obtener la direccion a la cual se va a enviar (CC)
$cc = $params['cc'];
// Obtener la direccion a la cual se va a enviar (BCC)
$bcc = $params['bcc'];
// Obtener el subject del mail
$subject = $params['subject'];
// Obtener el path del template
$template = $constants[strtoupper($params['TEMPLATE'])];
// Cargar parametros del mail
$mail = new Mail();
$mail->from = MAIL_FROM;
$mail->to = $to;
$mail->cc = $cc;
$mail->bcc = $bcc;
$mail->subject = $subject;
$mail->body = MailHelper::_getBody($template, $params);
// Si el cuerpo excede cierta cantidad de caracteres, se codifica
// en base64
$mail->base64 = strlen($mail->body) > CANT_CARACTERES_EMAIL;
// Enviar mail
return $mail->send();
}
示例2: query
function query($path, $content = array(), $method = 'GET')
{
@ini_set('track_errors', 1);
// @ - may be disabled
$file = @file_get_contents($this->_url . ($this->_db != "" ? "{$this->_db}/" : "") . $path, false, stream_context_create(array('http' => array('method' => $method, 'content' => json_encode($content), 'ignore_errors' => 1))));
if (!$file) {
$this->error = $php_errormsg;
return $file;
}
if (!preg_match('~^HTTP/[0-9.]+ 2~i', $http_response_header[0])) {
$this->error = $file;
return false;
}
$return = json_decode($file, true);
if (!$return) {
$this->errno = json_last_error();
if (function_exists('json_last_error_msg')) {
$this->error = json_last_error_msg();
} else {
$constants = get_defined_constants(true);
foreach ($constants['json'] as $name => $value) {
if ($value == $this->errno && preg_match('~^JSON_ERROR_~', $name)) {
$this->error = $name;
break;
}
}
}
}
return $return;
}
示例3: __construct
public function __construct()
{
parent::__construct("lint-const-literals", "Lint (use of lower- or mixed-case string literals)");
foreach (get_defined_constants() as $const_name => $value) {
$this->system_constants[$const_name] = true;
}
}
示例4: load
static function load($file, $return = false)
{
if (file_exists($file)) {
$before = get_defined_constants();
// 数组返回值方式定义
$lang = (include $file);
if (!is_array($lang)) {
if (isset($_lang)) {
// 采用 $_lang['aaa']= value 方式
$lang =& $_lang;
} else {
// 采用define('aaa',value) 方式
$after = get_defined_constants();
$define = array_diff_assoc($after, $before);
$lang = $define;
}
}
self::$_lang = array_merge(self::$_lang, array_change_key_case($lang));
unset($lang);
if ($return) {
return self::$_lang;
}
} else {
return false;
}
}
示例5: osc_theme_toggle
function osc_theme_toggle($params, $content = null)
{
global $_oscitas_accordion;
extract(shortcode_atts(array('title' => 'title', 'class' => ''), $params));
$con = do_shortcode($content);
$index = count($_oscitas_accordion) - 1;
$id = isset($_oscitas_accordion[$index]['details']) ? 'details-' . $index . '-' . count($_oscitas_accordion[$index]['details']) : 'details-' . $index . '-0';
$const = get_defined_constants();
$_oscitas_accordion[$index]['details'][] = <<<EOS
<div class="panel panel-default{$const['EBS_CONTAINER_CLASS']}">
<div class="panel-heading{$const['EBS_CONTAINER_CLASS']}">
<h4 class="panel-title{$const['EBS_CONTAINER_CLASS']}">
<a class="accordion-toggle{$const['EBS_CONTAINER_CLASS']} collapsed" data-toggle="collapse"
data-parent="#oscitas-accordion-{$index}"
href="#{$id}">
{$title}
</a>
</h4>
</div>
<div id="{$id}" class="panel-collapse collapse {$class}{$const['EBS_CONTAINER_CLASS']}">
<div class="panel-body{$const['EBS_CONTAINER_CLASS']}">{$con}</div>
</div>
</div>
EOS;
}
示例6: saveState
/**
* Save the max id of every table. Thus when we convert again, when can delete id larger then the saved max id.
*
* @access public
* @return void
*/
public function saveState()
{
/* Get user defined tables. */
$constants = get_defined_constants(true);
$userConstants = $constants['user'];
/* These tables needn't save. */
unset($userConstants['TABLE_BURN']);
unset($userConstants['TABLE_GROUPPRIV']);
unset($userConstants['TABLE_PROJECTPRODUCT']);
unset($userConstants['TABLE_PROJECTSTORY']);
unset($userConstants['TABLE_STORYSPEC']);
unset($userConstants['TABLE_TEAM']);
unset($userConstants['TABLE_USERGROUP']);
/* Get max id of every table. */
foreach ($userConstants as $key => $value) {
if (strpos($key, 'TABLE') === false) {
continue;
}
if ($key == 'TABLE_COMPANY') {
continue;
}
$state[$value] = (int) $this->dao->select('MAX(id) AS id')->from($value)->fetch('id');
}
$this->session->set('state', $state);
}
示例7: setUp
/**
* Set up
*
* @return void
*/
public function setUp()
{
//session_start();
// cleaning constants
if (PMA_HAS_RUNKIT) {
$this->oldIISvalue = 'non-defined';
$defined_constants = get_defined_constants(true);
$user_defined_constants = $defined_constants['user'];
if (array_key_exists('PMA_IS_IIS', $user_defined_constants)) {
$this->oldIISvalue = PMA_IS_IIS;
runkit_constant_redefine('PMA_IS_IIS', null);
} else {
runkit_constant_add('PMA_IS_IIS', null);
}
$this->oldSIDvalue = 'non-defined';
if (array_key_exists('SID', $user_defined_constants)) {
$this->oldSIDvalue = SID;
runkit_constant_redefine('SID', null);
} else {
runkit_constant_add('SID', null);
}
}
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
$GLOBALS['server'] = 0;
$GLOBALS['PMA_Config'] = new PMA\libraries\Config();
$GLOBALS['PMA_Config']->enableBc();
}
示例8: getCurlOptionFromResponse
/**
* Returns a cURL option from a Response.
*
* @param Response $response Response to get cURL option from.
* @param integer $option cURL option to get.
*
* @throws \BadMethodCallException
* @return mixed Value of the cURL option.
*/
public static function getCurlOptionFromResponse(Response $response, $option = 0)
{
switch ($option) {
case 0:
// 0 == array of all curl options
$info = array();
foreach (self::$curlInfoList as $option => $key) {
$info[$key] = $response->getInfo($option);
}
break;
case CURLINFO_HTTP_CODE:
$info = $response->getStatusCode();
break;
case CURLINFO_SIZE_DOWNLOAD:
$info = $response->getHeader('Content-Length');
break;
default:
$info = $response->getInfo($option);
break;
}
if (!is_null($info)) {
return $info;
}
$constants = get_defined_constants(true);
$constantNames = array_flip($constants['curl']);
throw new \BadMethodCallException("Not implemented: {$constantNames[$option]} ({$option}) ");
}
示例9: run
public function run(&$params)
{
if (!defined('BUILD_LITE_FILE')) {
return;
}
$litefile = C('RUNTIME_LITE_FILE', null, RUNTIME_PATH . 'lite.php');
if (is_file($litefile)) {
return;
}
$defs = get_defined_constants(true);
$content = 'namespace {$GLOBALS[\'_beginTime\'] = microtime(TRUE);';
if (MEMORY_LIMIT_ON) {
$content .= '$GLOBALS[\'_startUseMems\'] = memory_get_usage();';
}
// 生成数组定义
unset($defs['user']['BUILD_LITE_FILE']);
$content .= $this->buildArrayDefine($defs['user']) . '}';
// 读取编译列表文件
$filelist = is_file(CONF_PATH . 'lite.php') ? include CONF_PATH . 'lite.php' : array(THINK_PATH . 'Common/functions.php', COMMON_PATH . 'Common/function.php', CORE_PATH . 'Think' . EXT, CORE_PATH . 'Hook' . EXT, CORE_PATH . 'App' . EXT, CORE_PATH . 'Dispatcher' . EXT, CORE_PATH . 'Log' . EXT, CORE_PATH . 'Log/Driver/File' . EXT, CORE_PATH . 'Route' . EXT, CORE_PATH . 'Controller' . EXT, CORE_PATH . 'View' . EXT, CORE_PATH . 'Storage' . EXT, CORE_PATH . 'Storage/Driver/File' . EXT, CORE_PATH . 'Exception' . EXT, BEHAVIOR_PATH . 'ParseTemplateBehavior' . EXT, BEHAVIOR_PATH . 'ContentReplaceBehavior' . EXT);
// 编译文件
foreach ($filelist as $file) {
if (is_file($file)) {
$content .= compile($file);
}
}
// 处理Think类的start方法
$content = preg_replace('/\\$runtimefile = RUNTIME_PATH(.+?)(if\\(APP_STATUS)/', '\\2', $content, 1);
$content .= "\nnamespace { Think\\Think::addMap(" . var_export(\Think\Think::getMap(), true) . ");";
$content .= "\nL(" . var_export(L(), true) . ");\nC(" . var_export(C(), true) . ');Think\\Hook::import(' . var_export(\Think\Hook::get(), true) . ');Think\\Think::start();}';
// 生成运行Lite文件
file_put_contents($litefile, strip_whitespace('<?php ' . $content));
}
示例10: help
function help()
{
$const = get_defined_constants(true);
ob_start();
echo '<br />';
echo '------------Constants: --------------------<br />';
foreach ($const['user'] as $key => $name) {
echo "{$key} => {$name}<br />";
}
$method = get_class_methods($this);
echo '<br />';
echo '-------------Methods: ---------------<br />';
print_r($method);
$include = get_included_files();
echo '<br />';
echo '-------------Include Files ---------------<br />';
print_r($include);
$header = getallheaders();
echo '<br />';
echo '-------------Header: ---------------<br />';
print_r($header);
$msg = ob_get_contents();
ob_end_clean();
$this->getError($msg);
}
示例11: mysqli_field_flags
function mysqli_field_flags($result, $field_offset)
{
static $flags;
$flags_num = mysqli_fetch_field_direct($result, $field_offset)->flags;
if (!isset($flags)) {
$flags = array();
$constants = get_defined_constants(true);
foreach ($constants['mysqli'] as $c => $n) {
if (preg_match('/MYSQLI_(.*)_FLAG$/', $c, $m)) {
if (!array_key_exists($n, $flags)) {
$flags[$n] = $m[1];
}
}
}
}
$result = array();
foreach ($flags as $n => $t) {
if ($flags_num & $n) {
$result[] = $t;
}
}
$return = implode(' ', $result);
$return = str_replace('PRI_KEY', 'PRIMARY_KEY', $return);
$return = strtolower($return);
return $return;
}
示例12: info
static function info($type = 1)
{
$type_list = array('basic', 'const', 'variable', 'function', 'class', 'interface', 'file');
if (is_int($type) && $type < 7) {
$type = $type_list[$type];
}
switch ($type) {
case 'const':
$const_arr = get_defined_constants(true);
return $const_arr['user'];
//2因作用域,请在外边直接调用函数
//2因作用域,请在外边直接调用函数
case 'variable':
return 'please use: get_defined_vars()';
case 'function':
$fun_arr = get_defined_functions();
return $fun_arr['user'];
case 'class':
return array_slice(get_declared_classes(), 125);
case 'interface':
return array_slice(get_declared_interfaces(), 10);
case 'file':
return get_included_files();
default:
return array('system' => php_uname(), 'service' => php_sapi_name(), 'php_version' => PHP_VERSION, 'frame_name' => config('frame|name'), 'frame_version' => config('frame|version'), 'magic_quotes' => get_magic_quotes_gpc(), 'time_zone' => date_default_timezone_get());
}
}
示例13: render
/**
* {@inheritdoc}
*/
protected function render()
{
$constants = get_defined_constants(true);
if (!empty($constants["user"])) {
$maxLength = 0;
foreach ($constants["user"] as $name => $value) {
$maxLength = max($maxLength, strlen($name));
}
foreach ($constants["user"] as $name => $value) {
$name = str_pad($name, $maxLength, " ", STR_PAD_RIGHT);
switch (gettype($value)) {
case "string":
$value = str_replace(array("\n", "\r", "\t"), array("\\n", "\\r", "\\t"), $value);
break;
case "bool":
case "boolean":
$value = $value ? "true" : "false";
$value = "<<2>>{$value}";
break;
case "null":
case "NULL":
$value = "<<2>>null";
break;
}
$this->printText("<<3>>{$name} : <<0>>{$value}\n");
}
} else {
// no user constants
$this->printText("No user constants");
}
}
示例14: get_mapi_error_name
/**
* Function to get a human readable string from a MAPI error code
*
*@param int $errcode the MAPI error code, if not given, we use mapi_last_hresult
*@return string The defined name for the MAPI error code
*/
function get_mapi_error_name($errcode = null)
{
if ($errcode === null) {
$errcode = mapi_last_hresult();
}
if ($errcode !== 0) {
// get_defined_constants(true) is preferred, but crashes PHP
// https://bugs.php.net/bug.php?id=61156
$allConstants = get_defined_constants();
foreach ($allConstants as $key => $value) {
/**
* If PHP encounters a number beyond the bounds of the integer type,
* it will be interpreted as a float instead, so when comparing these error codes
* we have to manually typecast value to integer, so float will be converted in integer,
* but still its out of bound for integer limit so it will be auto adjusted to minus value
*/
if ($errcode == (int) $value) {
// Check that we have an actual MAPI error or warning definition
$prefix = substr($key, 0, 7);
if ($prefix == "MAPI_E_" || $prefix == "MAPI_W_") {
return $key;
}
}
}
} else {
return "NOERROR";
}
// error code not found, return hex value (this is a fix for 64-bit systems, we can't use the dechex() function for this)
$result = unpack("H*", pack("N", $errcode));
return "0x" . $result[1];
}
示例15: quickCacheConstants
/**
* Back compat. with `QUICK_CACHE_` constants.
*
* @since 150422 Rewrite.
*/
public static function quickCacheConstants()
{
if (!($constants = get_defined_constants(true)) || empty($constants['user'])) {
return;
// Nothing to do; i.e. no user-defined constants.
}
foreach ($constants['user'] as $_constant => $_value) {
if (stripos($_constant, 'QUICK_CACHE_') !== 0) {
continue;
// Nothing to do here.
}
if (!($_constant_sub_name = substr($_constant, 12))) {
continue;
// Nothing to do here.
}
if (!defined(GLOBAL_NS . '_' . $_constant_sub_name)) {
define(GLOBAL_NS . '_' . $_constant_sub_name, $_value);
}
}
unset($_constant, $_value);
// Housekeeping.
if (isset($_SERVER['QUICK_CACHE_ALLOWED']) && !isset($_SERVER[GLOBAL_NS . '_ALLOWED'])) {
$_SERVER[GLOBAL_NS . '_ALLOWED'] = $_SERVER['QUICK_CACHE_ALLOWED'];
}
}