Checks if value can be cast to a string

@param mixed $value The value

@return bool
549433
public static function isStringCastable($value): bool
    {
        $result = false;
        $type = strtolower(gettype($value));
        switch ($type) {
            case 'string':
            case 'null':
            case 'boolean':
            case 'integer':
            case 'double':
                $result = true;
                break;
            case 'object':
                if (method_exists($value, '__toString')) {
                    $result = true;
                }
                break;
            default:
                break;
        }

        return $result;
    }
1362174
public function checkValue(&$value)
    {
        if (is_string($value)) {
            $value = Placeholder::replaceStringsAndComments($value);
            $value = Placeholder::removeCommentPlaceholders($value, true);
            $value = Placeholder::replaceStringPlaceholders($value, true);
            $value = trim($value);

            if ($value !== '') {
                return true;
            } else {
                $this->setIsValid(false);
            }
        } else {
            throw new \InvalidArgumentException(
                "Invalid type '" . gettype($value). "' for argument 'value' given."
            );
        }
    }
976626
private function isCountable($value): bool
    {
        return is_string($value) || is_array($value) || $value instanceof \Countable || $value instanceof \Traversable;
    }
502696
public function _isValueIndexable($value)
    {
        return (
            is_string($value)
            || is_null($value)
            || is_bool($value)
            || is_integer($value)
        );
    }
466898
public function isValid($value)
    {
        if (!is_string($value)) {
            $this->_error(self::INVALID);
            return false;
        }

        $this->_setValue($value);
        if ($this->_encoding !== null) {
            $length = iconv_strlen($value, $this->_encoding);
        } else {
            $length = iconv_strlen($value);
        }

        if ($length < $this->_min) {
            $this->_error(self::TOO_SHORT);
        }

        if (null !== $this->_max && $this->_max < $length) {
            $this->_error(self::TOO_LONG);
        }

        if (count($this->_messages)) {
            return false;
        } else {
            return true;
        }
    }
660512
public static function parseArgValueOut(&$value)
	{
		if(isset($value[0]) && '#' === $value[0])
		{
			$value = substr($value,1);
			return true;
		}
		else
		{
			$value = '\'' . addcslashes($value,'\'') . '\'';
			return false;
		}
	}
64259
private function castValue($value)
    {
        foreach ([
            // Integers
            '/^-?\d+$/' => function ($value) {
                return (int) $value;
            },
            // Floats
            '/^-?\d+\.\d+$/' => function ($value) {
                return (float) $value;
            },
            // Booleans
            '/^(?:true|false)$/' => function ($value) {
                return filter_var($value, \FILTER_VALIDATE_BOOLEAN);
            },
        ] as $format => $castFunction) {
            if (preg_match($format, $value)) {
                return $castFunction($value);
            }
        }

        return $value;
    }
92562
protected function castValueForUpdate($value)
    {
        switch ($this->type) {
            case 'string':
                $value = [(string)$value];
                break;
            case 'list':
            case 'set':
                $value = (array)$value;
                break;
            case 'zset':
                $casted = [];
                foreach ($value as $k => $v) {
                    $casted[] = $v;
                    $casted[] = $k;
                }
                $value = $casted;
                break;
            case 'hash':
                $casted = [];
                foreach ($value as $k => $v) {
                    $casted[] = $k;
                    $casted[] = $v;
                }
                $value = $casted;
                break;
            default:
                break;
        }

        return $value;
    }
676055
protected function castToString($value, bool $nullable = true)
    {
        if (null === $value && $nullable) {
            return null;
        }

        return (string) $value;
    }
676851
public function cast($value)
    {
        if (isset($this->traversable) && !is_a($this->traversable, Traversable::class, true)) {
            return $this->dontCast($value, "{$this->traversable} is not Traversable");
        }

        $fn = 'cast' . ucfirst(gettype($value));
        $result = method_exists($this, $fn) ? $this->$fn($value) : (array)$value;

        if (!is_iterable($result)) {
            return $result;
        }

        //Commented out as there's no HandlerRepositoryInterface
        // if (isset($this->subtype)) {
        //     $result = $this->typecast instanceof HandlerRepositoryInterface
        //         ? $this->castEachWithHandler($result, $this->typecast)
        //         : $this->castEach($result);
        // }

        if (isset($this->subtype)) {
            $result = $this->castEach($result);
        }

        if (is_array($result) && isset($this->traversable)) {
            $class = $this->traversable;
            $result = new $class($result);
        }

        return $result;
    }
87985
public function isAssignableFromValue($value)
    {
        if (!is_object($value))
            return false;

        if (get_class($value) === $this->getName())
            return true;

        return is_subclass_of($value, $this->className);
    }
133331
public function castValue($value)
    {
        if ($value === 'Off' || $value === '' || $value === 0 || $value === '0' || $value === false) {
            $casted = 0;
        } elseif ($value === 'On' || $value === '1' || $value === 1) {
            $casted = 1;
        } else {
            $casted = $value;
        }

        $casted = $this->castPowers($casted);

        return $casted;
    }
1035037
protected function getStringValue($value)
    {
        if ($value === true) {
            return 'true';
        } elseif ($value === false) {
            return 'false';
        } elseif ($value === null) {
            return 'null';
        } elseif (is_string($value)) {
            return "\"$value\"";
        }

        return rtrim(print_r($value, true));
    }
632821
private function ensureString($value)
    {
        if (is_string($value)) {
            return $value;
        }

        if (is_array($value) || $value instanceOf \Traversable) {
            $string = array();
            foreach ($value as $val) {
                if (is_object($val) && method_exists($val, '__toString')) {
                    $string[] = $val->__toString();
                }
                else {
                    $string[] = (string) $val;
                }
            }
            return implode(',', $string);
        }

        if (is_object($value) && method_exists($value, '__toString')) {
            return $value->__toString();
        }
    }
252954
public static function url(string $value): bool
    {
        $result = filter_var($value, FILTER_VALIDATE_URL);
        return is_string($result) && $value === $result;
    }
562448
public function transform($value)
    {
        if ($value instanceof JsonSerializable || $value instanceof StdClass) {
            return json_encode($value);
        }

        // If a toJson() method exists, the object can cast itself automatically.
        if (method_exists($value, 'toJson')) {
            return $value;
        }

        // Otherwise, if the object doesn't even have a __toString() method, we can't proceed.
        if (! method_exists($value, '__toString')) {
            throw new \Exception('Cannot transform this object to JavaScript.');
        }

        return "'{$value}'";
    }
480177
protected function castToObject($value)
    {
        if (is_scalar($value) || is_resource($value)) {
            $value = $this->dontCast($value);
        }

        return (object)$value;
    }