本文整理汇总了PHP中is_bool函数的典型用法代码示例。如果您正苦于以下问题:PHP is_bool函数的具体用法?PHP is_bool怎么用?PHP is_bool使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_bool函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getExceptionTraceAsString
/**
* @param \Exception $exception
* @return string
* @todo Fix this to get full stack trace
*/
public static function getExceptionTraceAsString(\Exception $exception)
{
$ret = "";
$count = 0;
foreach ($exception->getTrace() as $trace) {
$args = "";
if (isset($trace['args'])) {
$args = array();
foreach ($trace['args'] as $arg) {
if (is_string($arg)) {
$args[] = "'" . $arg . "'";
} elseif (is_array($arg)) {
$args[] = "Array";
} elseif (is_null($arg)) {
$args[] = 'NULL';
} elseif (is_bool($arg)) {
$args[] = $arg ? "true" : "false";
} elseif (is_object($arg)) {
$args[] = get_class($arg);
} elseif (is_resource($arg)) {
$args[] = get_resource_type($arg);
} else {
$args[] = $arg;
}
}
$args = join(", ", $args);
}
$ret .= sprintf("#%s %s(%s): %s(%s)\n", $count, isset($trace['file']) ? $trace['file'] : 'unknown file', isset($trace['line']) ? $trace['line'] : 'unknown line', isset($trace['class']) ? $trace['class'] . $trace['type'] . $trace['function'] : $trace['function'], $args);
$count++;
}
return $ret;
}
示例2: test__call
/**
* __call() test
*
* Call as method call
*
* Expects:
* - method:
* - args:
*
* Returns: mixed
*/
public function test__call()
{
$r = new Zend_Server_Reflection_Parameter($this->_getParameter());
// just test a few call proxies...
$this->assertTrue(is_bool($r->allowsNull()));
$this->assertTrue(is_bool($r->isOptional()));
}
示例3: monopolized
public function monopolized($monopolized = true)
{
if (is_bool($monopolized)) {
return $this->andWhere(['monopolized' => $monopolized == true ? 1 : 0]);
}
return $this;
}
示例4: XMLAppend
/**
* Append any supported $content to $parent
*
* @param DOMNode $parent Node to append to
* @param mixed $content Content to append
* @return self
*/
protected function XMLAppend(\DOMNode &$parent = null, $content = null)
{
if (is_null($parent)) {
$parent = $this->root;
}
if (is_string($content) or is_numeric($content) or is_object($content) and method_exists($content, '__toString')) {
$parent->appendChild($this->createTextNode("{$content}"));
} elseif (is_object($content) and is_subclass_of($content, '\\DOMNode')) {
$parent->appendChild($content);
} elseif (is_array($content) or is_object($content) and $content = get_object_vars($content)) {
array_map(function ($node, $value) use(&$parent) {
if (is_string($node)) {
if (substr($node, 0, 1) === '@') {
$parent->setAttribute(substr($node, 1), $value);
} else {
$node = $parent->appendChild($this->createElement($node));
if (is_string($value)) {
$this->XMLAppend($node, $this->createTextNode($value));
} else {
$this->XMLAppend($node, $value);
}
}
} else {
$this->XMLAppend($parent, $value);
}
}, array_keys($content), array_values($content));
} elseif (is_bool($content)) {
$parent->appendChild($this->createTextNode($content ? 'true' : 'false'));
} else {
throw new \InvalidArgumentException(sprintf('Unable to append unknown content [%s] to %s', get_class($content), get_class($this)));
}
return $this;
}
示例5: checkType
/**
* Returns `true` if value is of the specified type
*
* @param string $type
* @param mixed $value
* @return bool
*/
protected function checkType($type, $value)
{
switch ($type) {
case 'array':
return is_array($value);
case 'bool':
case 'boolean':
return is_bool($value);
case 'callable':
return is_callable($value);
case 'float':
case 'double':
return is_float($value);
case 'int':
case 'integer':
return is_int($value);
case 'null':
return is_null($value);
case 'numeric':
return is_numeric($value);
case 'object':
return is_object($value);
case 'resource':
return is_resource($value);
case 'scalar':
return is_scalar($value);
case 'string':
return is_string($value);
case 'mixed':
return true;
default:
return $value instanceof $type;
}
}
示例6: query
/**
* Query database
*
* @param string $sql SQL Query
* @param array|string $replacement Replacement
* @return mixed
*/
public function query()
{
$args = func_get_args();
$sql = array_shift($args);
// Menerapkan $replacement ke pernyataan $sql
if (!empty($args)) {
$sql = vsprintf($sql, $args);
}
try {
// Return 'false' kalo belum ada koneksi
if (!$this->_db) {
$this->connect();
}
$this->_sql = $sql;
// Eksekusi SQL Query
if ($results = $this->_db->query($sql)) {
if (is_bool($results)) {
return $results;
}
$this->_results = $results;
$this->_num_rows = $this->_results->num_rows;
return $this;
} else {
App::error($this->_db->error . '<br>' . $this->_sql);
}
} catch (Exception $e) {
setAlert('error', $e->getMessage());
return false;
}
}
示例7: useAlias
public function useAlias($bVal = null)
{
if (is_bool($bVal)) {
$this->bAlias = $bVal;
}
return $this->bAlias;
}
示例8: setConfirmed
public function setConfirmed($confirmed)
{
if (!is_bool($confirmed)) {
throw new InvalidArgumentException('Invalid peer link confirmed value "' . $confirmed . '"');
}
$this->confirmed = $confirmed;
}
示例9: varExport
public static function varExport($var)
{
$value = 'n/a';
$preview = '';
if (is_bool($var)) {
$value = $var ? 'true' : 'false';
} elseif (null === $var) {
//return 'null';
} elseif (is_numeric($var)) {
$value = $var;
} elseif (is_array($var)) {
$value = count($var);
$preview = sprintf('[%s]', preg_replace('/\\n\\s*|^array \\(|\\)$/', '', var_export($var, true)));
} elseif (is_string($var)) {
$value = strlen($var);
$preview = sprintf('"%s"', $var);
} elseif (is_object($var)) {
$value = get_class($var);
if (method_exists($var, '__toString')) {
$preview = $var->__toString();
}
}
if ($preview && self::$varExportPreviewMaxLength < strlen($preview)) {
$preview = substr($preview, 0, self::$varExportPreviewMaxLength) . '...';
}
return sprintf('%s(%s)%s', gettype($var), $value, $preview ? ' ' . $preview : '');
}
示例10: Start
public function Start($string, $language, $count, $F)
{
$snippets = array();
$query = urlencode(mb_strtolower($string, 'UTF-8'));
$url = "http://www.mysearch.com/search/GGmain.jhtml?searchfor={$query}&lr=lang_{$language}&ie=utf-8&oe=utf-8";
$html = $F->GetHTML($url, 'www.mysearch.com');
if (!is_bool($html)) {
$i = 0;
foreach ($html->find('div[class="algoLinkBox"]') as $e) {
$t = 'a[class="pseudolink"]';
$d = 'span[class="nDesc"]';
if (isset($e->find($t, 0)->plaintext)) {
$title = $e->find($t, 0)->plaintext;
}
if (isset($e->find($d, 0)->plaintext)) {
$description = $e->find($d, 0)->plaintext;
}
if ($i < $count) {
if (!empty($title) and !empty($description)) {
$snippets[$i]['title'] = trim($title);
$snippets[$i]['description'] = trim($description);
$i++;
}
}
}
$html->clear();
$html = null;
$e = null;
unset($html, $e);
} else {
$F->Error("Can't create outgoing request. Please check MySearch snippets plugin.");
}
return $snippets;
}
示例11: validate
public function validate($value)
{
if ($this->options['type'] == 'boolean' && !is_bool($value)) {
throw new \InvalidArgumentException('Must be a boolean');
}
if ($this->options['type'] == 'choice' && !in_array($value, $this->options['choices'])) {
throw new \InvalidArgumentException('Must be on of ' . json_encode($this->options['choices']));
}
if ($this->options['type'] == 'text') {
if (!is_string($value) || strlen($value) < 1) {
throw new \InvalidArgumentException('Text must be provided');
}
}
if ($this->options['type'] == 'yes-no') {
if ($value === 'yes') {
$value = 'y';
}
if ($value === 'no') {
$value = 'n';
}
if ($value !== 'y' && $value !== 'n') {
throw new \InvalidArgumentException('Value should be [y] or [n]');
}
}
return $value;
}
示例12: getConfigTreeBuilder
/**
* Generates the configuration tree builder.
*
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('framework');
$rootNode->children()->scalarNode('charset')->defaultNull()->beforeNormalization()->ifTrue(function ($v) {
return null !== $v;
})->then(function ($v) {
$message = 'The charset setting is deprecated. Just remove it from your configuration file.';
if ('UTF-8' !== $v) {
$message .= sprintf(' You need to define a getCharset() method in your Application Kernel class that returns "%s".', $v);
}
throw new \RuntimeException($message);
})->end()->end()->scalarNode('trust_proxy_headers')->defaultFalse()->end()->arrayNode('trusted_proxies')->beforeNormalization()->ifTrue(function ($v) {
return !is_array($v) && !is_null($v);
})->then(function ($v) {
return is_bool($v) ? array() : preg_split('/\\s*,\\s*/', $v);
})->end()->prototype('scalar')->validate()->ifTrue(function ($v) {
return !empty($v) && !filter_var($v, FILTER_VALIDATE_IP);
})->thenInvalid('Invalid proxy IP "%s"')->end()->end()->end()->scalarNode('secret')->isRequired()->end()->scalarNode('ide')->defaultNull()->end()->booleanNode('test')->end()->scalarNode('default_locale')->defaultValue('en')->end()->arrayNode('trusted_hosts')->beforeNormalization()->ifTrue(function ($v) {
return is_string($v);
})->then(function ($v) {
return array($v);
})->end()->prototype('scalar')->end()->end()->end();
$this->addFormSection($rootNode);
$this->addEsiSection($rootNode);
$this->addProfilerSection($rootNode);
$this->addRouterSection($rootNode);
$this->addSessionSection($rootNode);
$this->addTemplatingSection($rootNode);
$this->addTranslatorSection($rootNode);
$this->addValidationSection($rootNode);
$this->addAnnotationsSection($rootNode);
return $treeBuilder;
}
示例13: Start
public function Start($string, $language, $count, $F)
{
$snippets = array();
$query = urlencode(mb_strtolower($string, 'UTF-8'));
$url = "http://www.nigma.ru/?s={$query}&lang={$language}&ie=utf-8&oe=utf-8";
$html = $F->GetHTML($url, 'www.nigma.ru');
if (!is_bool($html)) {
$i = 0;
foreach ($html->find('div[id="results"] ol li') as $e) {
$t = 'div[class="snippet_title"] a';
$d = 'div[class="snippet_text"]';
if (isset($e->find($t, 0)->plaintext)) {
$title = $e->find($t, 0)->plaintext;
}
if (isset($e->find($d, 0)->plaintext)) {
$description = $e->find($d, 0)->plaintext;
}
if ($i < $count) {
if (!empty($title) and !empty($description)) {
$snippets[$i]['title'] = trim($title);
$snippets[$i]['description'] = trim($description);
$i++;
}
}
}
$html->clear();
$html = null;
$e = null;
unset($html, $e);
} else {
$F->Error("Can't create outgoing request. Please check Nigma snippets plugin.");
}
return $snippets;
}
示例14: update
/**
* @throws \Exception
*/
public function update()
{
try {
$ts = time();
$this->model->setModificationDate($ts);
$type = get_object_vars($this->model);
foreach ($type as $key => $value) {
if (in_array($key, $this->getValidTableColumns(self::TABLE_NAME_KEYS))) {
if (is_bool($value)) {
$value = (int) $value;
}
if (is_array($value) || is_object($value)) {
if ($this->model->getType() == 'select') {
$value = \Zend_Json::encode($value);
} else {
$value = \Pimcore\Tool\Serialize::serialize($value);
}
}
$data[$key] = $value;
}
}
$this->db->update(self::TABLE_NAME_KEYS, $data, $this->db->quoteInto("id = ?", $this->model->getId()));
return $this->model;
} catch (\Exception $e) {
throw $e;
}
}
示例15: json_encode
function json_encode($data)
{
if (is_array($data)) {
$ret = array();
// OBJECT
if (array_keys($data) !== range(0, count($data) - 1)) {
foreach ($data as $key => $val) {
$ret[] = kcfinder_json_string_encode($key) . ':' . json_encode($val);
}
return "{" . implode(",", $ret) . "}";
// ARRAY
} else {
foreach ($data as $val) {
$ret[] = json_encode($val);
}
return "[" . implode(",", $ret) . "]";
}
// BOOLEAN OR NULL
} elseif (is_bool($data) || $data === null) {
return $data === null ? "null" : ($data ? "true" : "false");
} elseif (is_float($data)) {
return rtrim(rtrim(number_format($data, 14, ".", ""), "0"), ".");
} elseif (is_int($data)) {
return $data;
}
// STRING
return kcfinder_json_string_encode($data);
}