/** * return stacktrace-like information about the given variable * * @return string */ function getValueInfo($val) { if (is_null($val)) { return 'null'; } if (is_array($val)) { return 'array[' . count($val) . ']'; } if (is_bool($val)) { return $val ? 'true' : 'false'; } if (is_float($val) || is_int($val) || is_long($val) || is_real($val)) { return 'num:' . $val; } if (is_string($val)) { return 'string[' . strlen($val) . ']=' . substr($val, 0, 16); } if (is_resource($val)) { return 'resource' . get_resource_type($val); } if (is_object($val)) { return 'object'; } return '?'; }
/** * The constructor for the exception that sets up the exception and the Error class. * * @access public * @param string $message The error message or the key matching a registered error * @param mixed $params The error params or the error code */ public function __construct($message, $params = 0) { $code = null; if (!is_array($params) && $params != 0) { $params = array('code' => $params); } // call hook Hook::call('Exeception.construct', array(&$message, &$params)); if ($error = Config::getError($message)) { if (isset($error['messageArgs']) && isset($params['messageArgs'])) { $params['messageArgs'] = array_merge($error['messageArgs'], $params['messageArgs']); } $params = array_merge($error, (array) $params); $message = $params['message']; if (isset($params['code'])) { $code = $params['code']; } } if (isset($params['messageArgs']) && is_array($params['messageArgs'])) { $message = $this->dsprintf($message, $params['messageArgs']); } $this->params = (array) $params; parent::__construct($message, is_long($code) ? $code : null); Error::setupError($this); }
public function getChecksum($ccnum) { $len = strlen($ccnum); if (!is_long($len / 2)) { $weight = 2; $digit = $ccnum[0]; } elseif (is_long($len / 2)) { $weight = 1; $digit = $ccnum[0] * 2; } if ($digit > 9) { $digit = $digit - 9; } $i = 1; $checksum = $digit; while ($i < $len) { if ($ccnum[$i] != ' ') { $digit = $ccnum[$i] * $weight; $weight = $weight == 1 ? 2 : 1; if ($digit > 9) { $digit = $digit - 9; } $checksum += $digit; } $i++; } return $checksum; }
public function __construct($key) { if (!is_long($key)) { E("传入了非法的信号量key"); } $this->ipc_signal = sem_get($key); }
private function _runPHP() { $this->_source = "return " . $this->_source . ";"; if (function_exists("token_get_all")) { //tokenizer extension may be disabled $php = "<?php\n" . $this->_source . "\n?>"; $tokens = token_get_all($php); foreach ($tokens as $token) { $type = $token[0]; if (is_long($type)) { if (in_array($type, array(T_OPEN_TAG, T_RETURN, T_WHITESPACE, T_ARRAY, T_LNUMBER, T_DNUMBER, T_CONSTANT_ENCAPSED_STRING, T_DOUBLE_ARROW, T_CLOSE_TAG, T_NEW))) { continue; } if ($type == T_STRING) { $func = strtolower($token[1]); if (in_array($func, array("mongoid", "mongocode", "mongodate", "mongoregex", "mongobindata", "mongoint32", "mongoint64", "mongodbref", "mongominkey", "mongomaxkey", "mongotimestamp", "true", "false", "null"))) { continue; } } exit("For your security, we stoped data parsing at '(" . token_name($type) . ") " . $token[1] . "'."); } } } return eval($this->_source); }
/** * CrsDate::__construct() * * @param mixed $date * @return */ function __construct($date) { if (is_integer($date) || is_long($date)) { $this->p_date = $date; $this->DecomposeDate(); } elseif (is_object($date)) { $this->Copy($date); } else { $time = ""; $pos = strpos($date, " "); if ($pos) { $time = substr($date, $pos + 1, strlen($date) - $pos - 1); } if (strpos($date, "-")) { $this->p_year = substr($date, 0, 4) + 0; $this->p_month = substr($date, 5, 2) + 0; $this->p_day = substr($date, 8, 2) + 0; } else { $this->p_year = substr($date, 6, 4) + 0; $this->p_month = substr($date, 0, 2) + 0; $this->p_day = substr($date, 3, 2) + 0; } if ($time) { $this->p_hour = substr($time, 0, 2) + 0; $this->p_minute = substr($time, 3, 2) + 0; $this->p_second = substr($time, 6, 2) + 0; } else { $this->p_hour = 0; $this->p_minute = 0; $this->p_second = 0; } $this->p_date = mktime($this->p_hour, $this->p_minute, $this->p_second, $this->p_month, $this->p_day, $this->p_year); } }
public function setISBN($isbn) { if (!is_long($isbn)) { throw new InvalidArgumentException('"' . $isbn . '" is not a valid long.'); } $this->isbn = $isbn; }
function _translate($tokens) { $this->tokens = $tokens; $this->idx_current_token = 0; $this->in_quoted_string = false; $this->curnode->addChild('attrs'); $this->begin_statement_list(); for ($this->idx_current_token = 0; $this->idx_current_token < count($this->tokens); $this->idx_current_token++) { $token = $this->tokens[$this->idx_current_token]; if (is_array($token)) { $token_name = token_name($token[0]); $token_value = $token[1]; } else { if (is_long($token)) { $token_name = token_name($token); } else { $token_name = $token; $token_value = $token; } } $method_name = strtolower($token_name); if (strlen($method_name) == 1) { $this->handle_char($method_name); } else { if (method_exists($this, $method_name)) { $token[2] = token_name($token[0]); $this->{$method_name}($token); } else { $this->jsbuf .= $token_value; } } } }
/** * Extract data from a PDF document and add this to the Lucene index. * * @param string $pdfPath The path to the PDF document. * @param Zend_Search_Lucene_Proxy $luceneIndex The Lucene index object. * @return Zend_Search_Lucene_Proxy */ public static function index($pdfPath, $luceneIndex) { // Load the PDF document. $pdf = Zend_Pdf::load($pdfPath); $key = md5($pdfPath); /** * Set up array to contain the document index data. * The Filename will be used to retrive the document if it is found in * the search resutls. * The Key will be used to uniquely identify the document so we can * delete it from the search index. */ $indexValues = array('Filename' => $pdfPath, 'Key' => $key, 'Title' => '', 'Author' => '', 'Subject' => '', 'Keywords' => '', 'Creator' => '', 'Producer' => '', 'CreationDate' => '', 'ModDate' => '', 'Contents' => ''); // Go through each meta data item and add to index array. foreach ($pdf->properties as $meta => $metaValue) { switch ($meta) { case 'Title': $indexValues['Title'] = $pdf->properties['Title']; break; case 'Subject': $indexValues['Subject'] = $pdf->properties['Subject']; break; case 'Author': $indexValues['Author'] = $pdf->properties['Author']; break; case 'Keywords': $indexValues['Keywords'] = $pdf->properties['Keywords']; break; case 'CreationDate': $dateCreated = $pdf->properties['CreationDate']; $distance = substr($dateCreated, 16, 2); if (!is_long($distance)) { $distance = null; } // Convert date from the PDF format of D:20090731160351+01'00' $dateCreated = mktime(substr($dateCreated, 10, 2), substr($dateCreated, 12, 2), substr($dateCreated, 14, 2), substr($dateCreated, 6, 2), substr($dateCreated, 8, 2), substr($dateCreated, 2, 4), $distance); //distance $indexValues['CreationDate'] = date('Ymd', $dateCreated); break; case 'Date': $indexValues['Date'] = $pdf->properties['Date']; break; } } /** * Parse the contents of the PDF document and pass the text to the * contents item in the $indexValues array. */ $pdfParse = new App_Search_Helper_PdfParser(); $indexValues['Contents'] = $pdfParse->pdf2txt($pdf->render()); // Create the document using the values $doc = new App_Search_Lucene_Document($indexValues); if ($doc !== false) { // If the document creation was sucessful then add it to our index. $luceneIndex->addDocument($doc); } // Return the Lucene index object. return $luceneIndex; }
/** * @param Claim\Expiration $expirationClaim * @throws \InvalidArgumentException * @return \DateTime */ private function getDateTimeFromClaim(Claim\Expiration $expirationClaim) { if (!is_long($expirationClaim->getValue())) { throw new \InvalidArgumentException(sprintf('Invalid expiration timestamp "%s"', $expirationClaim->getValue())); } $expiration = new \DateTime(); $expiration->setTimestamp($expirationClaim->getValue()); return $expiration; }
function comprobar_nif($nif) { $letras = explode(',', 'T,R,W,A,G,M,Y,F,P,D,X,B,N,J,Z,S,Q,V,H,L,C,K,E'); if (strlen($nif) != 9 || !is_long($entero = intval(substr($nif, 0, 8))) || !in_array($letra = strtoupper(substr($nif, 8, 1)), $letras) || $letra != $letras[$entero % 23]) { return false; } else { return true; } }
/** * Sets an IP * * @param string $ip */ public function set($ip) { if (is_long($ip)) { $ip = long2ip($ip); } Assertion::ip($ip); $this->callMethod('setip', compact('ip')); return true; }
/** * @param $key * @param $size * @throws InvalidArgumentException * @return array */ protected function attach($key, $size) { if (!array_key_exists($key, $this->values)) { if (!is_long($key)) { throw new InvalidArgumentException(sprintf('Expected type long for "key" but "%s" given.', gettype($key))); } $this->values[$key] = array('shm' => shm_attach($key, $size), 'mutex' => sem_get($key, 1)); } return $this->values[$key]; }
/** * Creates a money instance using a complete * integer value for both the whole part * and the fractional part * * @param $amount * @param Currency|null $currency * * @return Money * @throws InvalidAmountException */ public static function withSecure($amount, Currency $currency = null) { if (!is_long($amount)) { throw new InvalidAmountException(); } $money = self::withRaw(0, $currency); $money->setFraction($amount / 100); $money->setWhole($amount / 100); return $money; }
/** * Setter for curl pre-request settings. * @param array/int $option * @param mixed $value */ public function setOption($option, $value = null) { if (!is_array($option)) { $option = is_long($option) ? $option : constant($option); curl_setopt($this->res, $option, $value); } else { foreach ($option as $key => $opt) { $this->setOption($key, $opt); } } }
private function checkErrors() { if ($this->code) { $errors = array_merge($this->_generalErrors, $this->errors); if (array_key_exists($this->code, $errors)) { $message = $this->error ? $this->error : $errors[$this->code]; throw new \Exception($message, is_long($this->code) ? $this->code : 0); } } return $this; }
/** * @param int $timeout_min * @return bool */ public function isExpired($timeout_min) { if (!is_long($this->startTime) || !$this->isState(SurveyExecutionState::InProgress())) { return true; } $diff = time() - $this->startTime; if ($diff > $timeout_min) { return true; } return false; }
function __construct($message = null, $code = 0, $file = null, $line = -1, $context = array(), Exception $previous = null) { if (is_array($message)) { $message = array_shift($message); } if (!is_long($code)) { $code = PHP_INT_MAX; } parent::__construct((string) $message, (int) $code, $previous); $this->file = $file; $this->line = $line; }
function connect($host, $port = 21) { // Setup server parameters if (!is_long($port)) { return false; } else { $ip = @gethostbyname($host); $dns = @gethostbyaddr($host); if (!$ip) { $ip = $host; } if (!$dns) { $dns = $host; } if (ip2long($ip) === -1) { return false; } $this->_host = $ip; $this->_fullhost = $dns; $this->_port = $port; $this->_dataport = $port - 1; } // Already connected if ($this->_ready) { return true; } // Attempt to connect if (!($this->_ftp_control_sock = $this->_connect($this->_host, $this->_port))) { return false; } // Wait for a welcome message do { if (!$this->_readmsg() || !$this->_checkCode()) { return false; } $this->_lastaction = time(); } while ($this->_code < 200); // Get remote system type $syst = $this->getSystemType(); if ($syst) { if (preg_match("/win|dos|novell/i", $syst[0])) { $this->OS_remote = "w"; } elseif (preg_match("/os/i", $syst[0])) { $this->OS_remote = "m"; } elseif (preg_match("/(li|u)nix/i", $syst[0])) { $this->OS_remote = "u"; } else { $this->OS_remote = "m"; } } $this->_ready = true; return true; }
function test_validation($val, $msg) { $f = filter_var($val, FILTER_VALIDATE_INT); echo "{$msg} filtered: "; var_dump($f); // filtered value (or false) echo "{$msg} is_long: "; var_dump(is_long($f)); // test validation echo "{$msg} equal: "; var_dump($val == $f); // test equality of result }
/** * create a entity for sending to fluentd server * * @param $tag * @param $data * @param int $time unixtime */ public function __construct($tag, $data, $time = null) { if (is_long($time)) { $this->time = $time; } else { if (!is_null($time)) { error_log("Entity::__construct(): unexpected time format `{$time}` specified."); } $this->time = time(); } $this->tag = $tag; $this->data = $data; }
/** * Return true if $ip is currently banned. * * @param int|string $ip * * @return bool */ public function isBanned($ip) { if (!is_long($ip)) { $ip = ip2long($ip); } $query = $this->getEntityManager()->createQuery('SELECT count(b.id) as ipCount FROM JdrAppBundle:IpBanned b WHERE ( b.expiration > :now OR b.expiration is NULL ) AND :ip BETWEEN b.start AND b.end')->setParameter('now', new \DateTime())->setParameter('ip', $ip); $isBannedIp = $query->getOneOrNullResult(); $query->free(); return $isBannedIp['ipCount'] > 0; }
/** * Register syntax variables * */ function syntax_register($file_id, $var_name) { if (is_array($var_name)) { $this->syn_array($file_id, $var_name); } elseif ($var_name != '') { if (is_long(strpos($var_name, ',')) == TRUE) { $var_name = explode(',', $var_name); for (reset($var_name); $current = current($var_name); next($var_name)) { $this->syn_var_names[$file_id][] = trim($current); } } else { $this->syn_var_names[$file_id][] = $var_name; } } }
function foo() { echo "set: " . isset($a) . "\n"; echo "nul: " . is_null($a) . "\n"; echo "str: " . is_string($a) . "\n"; echo "obj: " . is_object($a) . "\n"; echo "arr: " . is_array($a) . "\n"; echo "int: " . is_int($a) . "\n"; echo "integer: " . is_integer($a) . "\n"; echo "long: " . is_long($a) . "\n"; echo "real: " . is_real($a) . "\n"; echo "double: " . is_double($a) . "\n"; echo "float: " . is_float($a) . "\n"; echo "bool: " . is_bool($a) . "\n"; }
function options($sendno = null, $time_to_live = null, $override_msg_id = null, $apns_production = null, $big_push_duration = null) { if (is_null($sendno) && is_null($time_to_live) && is_null($override_msg_id) && is_null($apns_production) && is_null($big_push_duration)) { throw new InvalidArgumentException("Not all options args is null"); } $payload = array(); if (!is_null($sendno)) { if (is_int($sendno)) { $payload['sendno'] = $sendno; } else { throw new InvalidArgumentException("options.sendno must be a int"); } } else { $payload['sendno'] = generateSendno(); } if (!is_null($time_to_live)) { if (is_int($time_to_live) && $time_to_live >= 0 && $time_to_live <= 864000) { $payload['time_to_live'] = $time_to_live; } else { throw new InvalidArgumentException("options.time_to_live must be a int and in [0, 864000]"); } } if (!is_null($override_msg_id)) { if (is_long($override_msg_id)) { $payload['override_msg_id'] = $override_msg_id; } else { throw new InvalidArgumentException("options.override_msg_id must be a long"); } } if (!is_null($apns_production)) { if (is_bool($apns_production)) { $payload['apns_production'] = $apns_production; } else { throw new InvalidArgumentException("options.apns_production must be a bool"); } } else { $payload['apns_production'] = false; } if (!is_null($big_push_duration)) { if (is_int($big_push_duration) && $big_push_duration >= 0 && $big_push_duration <= 1440) { $payload['big_push_duration'] = $big_push_duration; } else { throw new InvalidArgumentException("options.big_push_duration must be a int and between 0 and 1440"); } } return $payload; }
/** * [getCmlbInfo 获取CMLB信息] * @return [type] [description] */ public function getCmlbInfo($cmlbNum) { $cmlb = new Cmlb(); try { //spkey server cmlb num $cmlb->init($cmlbNum); } catch (Exception $e) { echo "get cmlb error and cmlb num is {$cmlbNum} \r\n"; return false; } $conf = $cmlb->getOneIntf(); if (is_long($conf)) { echo "cmlb error \r\n"; return false; } return $conf; }
public function verify(Token $token) { /** @var Claim\NotBefore $notBeforeClaim */ $notBeforeClaim = $token->getPayload()->findClaimByName(Claim\NotBefore::NAME); if (null === $notBeforeClaim) { return null; } $now = new \DateTime('now', new \DateTimeZone('UTC')); if (!is_long($notBeforeClaim->getValue())) { throw new \InvalidArgumentException(sprintf('Invalid not before timestamp "%s"', $notBeforeClaim->getValue())); } if ($now->getTimestamp() < $notBeforeClaim->getValue()) { $notBefore = new \DateTime(); $notBefore->setTimestamp($notBeforeClaim->getValue()); throw new VerificationException(sprintf('Token must not be processed before "%s"', $notBefore->format('r'))); } }
public function testOptionConstantsExist() { $this->assertTrue(is_long(SMBCLIENT_OPT_OPEN_SHAREMODE)); $this->assertTrue(is_long(SMBCLIENT_OPT_ENCRYPT_LEVEL)); $this->assertTrue(is_long(SMBCLIENT_OPT_CASE_SENSITIVE)); $this->assertTrue(is_long(SMBCLIENT_OPT_BROWSE_MAX_LMB_COUNT)); $this->assertTrue(is_long(SMBCLIENT_OPT_URLENCODE_READDIR_ENTRIES)); $this->assertTrue(is_long(SMBCLIENT_OPT_USE_KERBEROS)); $this->assertTrue(is_long(SMBCLIENT_OPT_FALLBACK_AFTER_KERBEROS)); $this->assertTrue(is_long(SMBCLIENT_OPT_AUTO_ANONYMOUS_LOGIN)); $this->assertTrue(is_long(SMBCLIENT_OPT_USE_CCACHE)); $this->assertTrue(is_long(SMBCLIENT_OPT_USE_NT_HASH)); $this->assertTrue(is_long(SMBCLIENT_OPT_NETBIOS_NAME)); $this->assertTrue(is_long(SMBCLIENT_OPT_WORKGROUP)); $this->assertTrue(is_long(SMBCLIENT_OPT_USER)); $this->assertTrue(is_long(SMBCLIENT_OPT_PORT)); $this->assertTrue(is_long(SMBCLIENT_OPT_TIMEOUT)); }
public function toPrimitiveType($value) { if (is_null($value)) { return null; } if (is_string($value)) { $value = trim($value); if (empty($value)) { return null; } else { return $this->toNumeric($value); } } if (is_integer($value) || is_long($value) || is_double($value) || is_float($value) || is_real($value) || is_numeric($value)) { return $this->toNumeric($value); } throw new Exception("Invalid {$this->typeprefix}."); }
function _translate($tokens) { $this->tokens = $tokens; $this->idx_current_token = 0; $this->in_quoted_string = false; for ($this->idx_current_token = 0; $this->idx_current_token < count($this->tokens); $this->idx_current_token++) { $token = $this->tokens[$this->idx_current_token]; if (is_array($token)) { $token_name = token_name($token[0]); $token_value = $token[1]; } else { if (is_long($token)) { $token_name = token_name($token); } else { $token_name = $token; $token_value = $token; } } $method_name = strtolower($token_name); if ($this->array_brace_count) { if ($this->get_token_name($tokens[$this->idx_current_token + 2]) == 'T_DOUBLE_ARROW') { $this->jsbuf .= '['; if (!isset($this->array_assoc_count[$this->array_brace_count])) { $this->array_assoc_count[$this->array_brace_count] = 0; } $this->array_assoc_count[$this->array_brace_count]++; } } if (strlen($method_name) == 1) { $this->handle_char($method_name); } else { if (method_exists($this, $method_name)) { $token[2] = token_name($token[0]); $skip_ahead = $this->{$method_name}($token); } else { $this->jsbuf .= $token_value; } } if ($skip_ahead) { $this->idx_current_token += $skip_ahead; } // $this->idx_current_token ++; } }