Performs the cast operation on the supplied value.

@param string $castTypeOperator
@param mixed  $value

@return mixed
@throws PinqException
348357
public static function doCast($castTypeOperator, $value)
    {
        if (!isset(self::$castTypeMap[$castTypeOperator])) {
            throw new PinqException('Cast operator \'%s\' is not supported', $castTypeOperator);
        }

        settype($value, self::$castTypeMap[$castTypeOperator]);

        return $value;
    }
1167737
protected function castValue($cast, $value)
    {
        switch ($cast) {
            case 'integer';
                $value = (integer) $value;
                break;
            case 'boolean';
                $value = in_array($value, array('true', 't', 'yes', 'y'));
                break;
            case 'string':
            default:
                $value = (string) $value;
        }

        return $value;
    }
976433
public function cast($value): array
    {
        $result = [];
        foreach ((array)$value as $key => $itemValue) {
            $result[$key] = $this->type->cast($itemValue);
        }
        return $result;
    }
1292072
public static function castString($value): string
    {
        if ($value !== null && !is_scalar($value)) {
            throw new InvalidArgumentException('Value could not be parsed to string');
        }

        return (string)$value;
    }
209038
public static function cast( $value, $phpType ) {
		if( $phpType === null or $value === null ) return $value;
		
		switch( $phpType ) {
		case 'string': return (string)$value;
		case 'float': return (float)$value;
		case 'int': return (int)$value;
		case 'bool':
			if( is_bool($value) ) return $value;
			if( is_numeric($value) ) {
				if( $value == 1 ) return true;
				if( $value == 0 ) return false;
			}
			if( is_string($value) ) {
				if( in_array($value, array('yes','true','on')) ) return true;
				if( in_array($value, array('no','false','off','')) ) return false;
			}
			throw new Exception("Invalid boolean representation: ".var_export($value,true));
		default:
			throw new Exception("Don't know how to cast to PHP type '$phpType'.");
		}
	}
779208
public static function castToString($type, $value)
    {
        if ($value === '') {
            return '';
        }

        switch ($type) {
            case self::PROPERTY_TYPE_BOOLEAN:
                return $value ? 'true' : 'false';

            case self::PROPERTY_TYPE_DATE:
                /**
                 * @var \DateTimeInterface
                 */
                return $value->format('Y-m-d');

            case self::PROPERTY_TYPE_TIMESTAMP:
                /**
                 * @var \DateTimeInterface
                 */
                return $value->format('c');

            case self::PROPERTY_TYPE_OBJECT:
                if ($value instanceof self) {
                    return $value->toStringArray();
                }

                return '';
            default:
                if (is_scalar($value)) {
                    return (string) $value;
                }

                return '';
        }
    }
1275520
protected function castArrayValue($value)
    {
        if (!is_object($value)) {
            return $this->key($value);
        }

        try {
            if ($key = $this->objectCategorizer->key($value)) {
                return $this->hashIfToLong($key);
            }
        } catch (Exception $e) {
        }

        return $this->hashIfToLong($this->objectToKey($value));
    }
1344185
private function castToType(string $value, string $type)
    {
        $casts = [
            'integer' => 'intval',
            'number' => 'floatval',
            'float' => 'floatval',
            'boolean' => 'boolval',
        ];

        // First, we handle booleans. We can't use a regular cast,
        //because PHP considers string 'false' as true.
        if ($value == 'false' && $type == 'boolean') {
            return false;
        }

        if (isset($casts[$type])) {
            return $casts[$type]($value);
        }

        return $value;
    }
609888
protected function castValue($value)
    {
        if (is_null($value)) {
            return $value;
        }

        if ($this->isElementOfDate() && $this->isDateCastable()) {
            return $this->fromDateTime($value);
        }

        switch ($this->getCast()) {
            case 'int':
            case 'integer':
                return (int) $value;
            case 'real':
            case 'float':
            case 'double':
                return (float) $value;
            case 'string':
                return (string) $value;
            case 'bool':
            case 'boolean':
                return (bool) $value;
            case 'object':
                return $this->fromJson($value, true);
            case 'array':
            case 'json':
                return $this->fromJson($value);
            case 'collection':
                return new Collection($this->fromJson($value));
            case 'comma':
                return $this->fromCommaSeparated($value);
            default:
                return $value;
        }
    }
1016298
private function castValue(string $value)
    {
        $value = $this->normalize($value);
        if (\preg_match('/^[0-9]+$/', $value)) {
            $value = (int)$value;
        } elseif (\preg_match('/^[0-9\.]+$/', $value)) {
            $value = (float)$value;
        } elseif (\preg_match('/^true|false$/', $value)) {
            $value = $value === 'true' ? true : false;
        }
        return $value;
    }
1153308
protected function castParameter($value, $type = null) {
		//check null value
		if (is_null($value))
			return 'NULL';
		elseif (is_null($type)) {
			//obtain default type handler
			$typeHandler = $this->getDefaultTypeHandler($value);
			if (is_null($typeHandler))
				return 'NULL';
			if (is_array($value))
				return $this->castArray($value, $typeHandler, '_');
		}
		else {
			//cast value to the specified type
			$typeHandler = $this->typeManager->getTypeHandler($type);
				
			if ($typeHandler === false)
				throw new \RuntimeException("No type handler found for type '$type'");
				
			if (is_array($value))
				return $this->castArray($value, $typeHandler, '_');
			
			//check if returned value is null
			$value = $typeHandler->castParameter($value);
			if (is_null($value))
				return 'NULL';
		}
	
		//get parameter expression
		$value = $typeHandler->setParameter($value);
	
		//check null value
		if (is_null($value))
			return 'NULL';
		//cast to string
		if (!is_string($value))
			$value = strval($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;
    }
353810
public function juggle($value, $type)
    {
        // Cast non-null values
        if ( ! is_null($value)) {
            // Ensure that the type is a valid type to cast.
            // We do this check here because it might not have been done
            // as is the case when the model is first initialized.
            if ($this->checkJuggleType($type)) {
                // Get the method that the type maps to
                $method = $this->buildJuggleMethod($type);

                // Cast the value to the type using the method
                $value = $this->{$method}($value);
            }
        }

        return $value;
    }
552033
protected function typecast($value)
    {
        if ($value === '' && $this->type !== Schema::TYPE_STRING) {
            return null;
        }
        if ($value === null || gettype($value) === $this->phpType || $value instanceof Expression) {
            return $value;
        }
        switch ($this->phpType) {
            case 'resource':
            case 'string':
                return is_resource($value) ? $value : (string) $value;
            case 'int':
            case 'integer':
                return (int) $value;
            case 'bool':
            case 'boolean':
                return (bool) $value;
            case 'double':
                return (double) $value;
        }

        return $value;
    }
259422
public static function cast($value) {
		$matches = array();
		if(strtolower($value) === 'true') {
			$value = (bool) true;
		} else if(strtolower($value) === 'false') {
			$value = (bool) false;
		} else if(is_numeric($value)) {
			$value = (int) $value;
		} else if(preg_match('/^"(.*)"$/', $value, $matches)) {
			$value = $matches[1];
		}
		return $value;
	}
113438
public function cast($value)
    {
        if ($value === null) {
            return null;
        }

        $fn = 'cast' . ucfirst(gettype($value));

        switch (strtolower($this->class)) {
            case '':
                return $this->castToObject($value);
            case 'stdclass':
                return $this->castToStdClass($value);
            default:
                return $this->castToClass($value);
        }
    }
743521
protected function castToDb($value, $column)
    {
        if ($this->hasCast($column) && !$this->isIgnoreCast($value)) {
            $value = $this->toDbType($value, $this->casts[$column]);
        }

        return $value;
    }