本文整理汇总了PHP中Assert\Assertion::scalar方法的典型用法代码示例。如果您正苦于以下问题:PHP Assertion::scalar方法的具体用法?PHP Assertion::scalar怎么用?PHP Assertion::scalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Assert\Assertion
的用法示例。
在下文中一共展示了Assertion::scalar方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testValidScalar
public function testValidScalar()
{
Assertion::scalar("foo");
Assertion::scalar(52);
Assertion::scalar(12.34);
Assertion::scalar(false);
}
示例2: addCustomParameter
public function addCustomParameter($key, $value)
{
Assertion::string($key);
Assertion::notBlank($key);
Assertion::scalar($value);
return $this->handle('newrelic_add_custom_parameter', [$key, $value]);
}
示例3: replace
/**
* replace any tokens found in string with tokens
* @param string $string
* @return string
*/
public function replace($string)
{
Assertion::scalar($string);
// token delimiter not found, just return the string
if (strpos($string, '{') === false) {
return $string;
}
$tokens = $this->getTokens();
return str_replace(array_keys($tokens), array_values($tokens), $string);
}
示例4: getValue
/**
* @return string
*/
public function getValue()
{
$value = $this->fetchRawValueFromDataSource();
Assertion::isArray($this->trueValues);
Assertion::isArray($this->falseValues);
Assertion::scalar($value);
// check and see if value is one of these:
// 1, true, yes
$labelHtml = '<span class="label %s">%s</span>';
$labelCss = 'label-default';
if (in_array(strtolower((string) $value), $this->trueValues, true)) {
$value = $this->trueLabel;
$labelCss = 'label-success';
}
if (in_array(strtolower((string) $value), $this->falseValues, true) || empty($value)) {
$value = $this->falseLabel;
$labelCss = 'label-danger';
}
if (!$this->asHtmlLabel) {
return $value;
}
return sprintf($labelHtml, $labelCss, e($value));
}
示例5: buildSection
/**
* @param $dataSource
* @param $cellTag
* @param Column[] $columns
* @param array $buttons
* @return string
*/
public function buildSection($dataSource, $cellTag, array $columns, array $buttons = [])
{
Assertion::scalar($cellTag);
Assertion::inArray($cellTag, ['th', 'td', 'tf']);
$cols = [];
foreach ($columns as $column) {
$cellCss = $cellTag == 'td' ? $this->getTdCss() . ' ' . $column->getCss() : $this->getThCss();
$columnValue = $cellTag == 'th' ? $column->getHeader() : $column->render();
$columnValue = $cellTag == 'tf' ? $column->getFooter() : $columnValue;
$cellTag = $cellTag == 'tf' ? 'td' : $cellTag;
$cols[] = sprintf('<%s class="%s">%s</%1$s>', $cellTag, trim($cellCss), $columnValue);
}
if (count($buttons)) {
$cols[] = sprintf('<td>%s</td>', implode(PHP_EOL, $buttons));
}
if ($cellTag == 'th' && count($this->buttons) > 0) {
$cols[] = '<th>Actions</th>';
}
$rowCss = $cellTag == 'td' ? $this->getRowCss($dataSource) : null;
return sprintf('<tr class="%s">%s</tr>', $rowCss, implode(PHP_EOL, $cols));
}
示例6: getUrl
/**
* @return string
*/
public function getUrl()
{
$url = $this->url;
if ($url instanceof \Closure) {
$url = $url($this->dataSource);
}
Assertion::scalar($url);
if (strpos($url, '{') !== false) {
$this->createTokens($this->dataSource);
return $this->replace($url);
}
return $url;
}
示例7: setTableHeaderText
/**
* @param string $tableHeaderText
*/
public function setTableHeaderText($tableHeaderText)
{
Assertion::scalar($tableHeaderText);
$this->tableHeaderText = $tableHeaderText;
}
示例8: withSetting
/**
* @param string $name
* @param mixed $value
*
* @throws UnknownSettingException
* @throws InvalidArgumentException
*
* @return $this
*/
public function withSetting($name, $value)
{
Assertion::string($name);
Assertion::scalar($value);
if (!array_key_exists($name, $this->settings)) {
throw UnknownSettingException::fromSetting($name, array_keys($this->settings));
}
$this->settings[$name] = $value;
return $this;
}
示例9: assertMetadata
/**
* @param array $metadata
*/
public static function assertMetadata($metadata)
{
Assertion::isArray($metadata, 'metadata must be an array');
foreach ($metadata as $key => $value) {
Assertion::minLength($key, 1, 'A metadata key must be non empty string');
Assertion::scalar($value, 'A metadata value must have a scalar type. Got ' . gettype($value) . ' for ' . $key);
}
}