/**
  * @param bool|float|int|null|object|string $value
  * @param bool $strict = true NULL raises an exception
  * @throws \Granam\String\Exceptions\WrongParameterType
  */
 public function __construct($value, $strict = true)
 {
     try {
         parent::__construct(ToString::toString($value, $strict));
     } catch (ToString_WrongParameterType $exception) {
         // wrapping by a local one
         throw new Exceptions\WrongParameterType($exception->getMessage(), $exception->getCode(), $exception);
     }
 }
 /**
  * @test
  */
 public function I_can_use_it_as_scalar_object()
 {
     $stringObject = new StringObject('foo');
     self::assertInstanceOf(Scalar::getClass(), $stringObject);
 }
 /**
  * @param mixed $value
  * @param bool $strict = false Accepts only explicit values, no null or empty string
  * @param bool $paranoid = false Throws exception if some value is lost on cast because of rounding
  * @throws \Granam\Scalar\Tools\Exceptions\WrongParameterType
  */
 public function __construct($value, $strict = true, $paranoid = false)
 {
     $this->strict = (bool) $strict;
     $this->paranoid = (bool) $paranoid;
     parent::__construct(ToNumber::toNumber($value, $this->strict, $this->paranoid));
 }
Example #4
0
 /**
  * @param mixed $value
  * @param bool $strict = true Can suppress raising of an exception on NULL
  */
 public function __construct($value, $strict = true)
 {
     parent::__construct(ToBoolean::toBoolean($value, $strict));
 }
 protected function getExternalRootNamespaces()
 {
     $scalarReflection = new \ReflectionClass(Scalar::getClass());
     return $scalarReflection->getNamespaceName();
 }