scalar() public static method

Assert that value is a PHP scalar
public static scalar ( mixed $value, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$message string | null
$propertyPath string | null
return boolean
Exemplo n.º 1
0
 public function testValidScalar()
 {
     Assertion::scalar("foo");
     Assertion::scalar(52);
     Assertion::scalar(12.34);
     Assertion::scalar(false);
 }
Exemplo n.º 2
0
 public function addCustomParameter($key, $value)
 {
     Assertion::string($key);
     Assertion::notBlank($key);
     Assertion::scalar($value);
     return $this->handle('newrelic_add_custom_parameter', [$key, $value]);
 }
Exemplo n.º 3
0
 /**
  * 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);
 }
Exemplo n.º 4
0
 /**
  * @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));
 }
Exemplo n.º 5
0
 /**
  * @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));
 }
Exemplo n.º 6
0
 /**
  * @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;
 }
Exemplo n.º 7
0
 /**
  * @param string $tableHeaderText
  */
 public function setTableHeaderText($tableHeaderText)
 {
     Assertion::scalar($tableHeaderText);
     $this->tableHeaderText = $tableHeaderText;
 }
 /**
  * @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;
 }
Exemplo n.º 9
0
 /**
  * @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);
     }
 }