Parses PostgreSQL composite type encoded in string

@param string $value
@param int $i parse starting position
@return array
420473
private function parseComposite($value, &$i = 0)
    {
        $result = [];
        $length = strlen($value);
        for(++$i; $i < $length; ++$i) {
            switch ($value[$i]) {
                case ')':
                    break 2;
                case ',':
                    if (empty($result)) {
                        $result[] = null;
                    }
                    if (in_array($value[$i + 1], [',', ')'], true)) {
                        $result[] = null;
                    }
                    break;
                default:
                    $result[] = $this->parseString($value, $i);
            }
        }

        return $result;
    }
179619
public static function parse($value, $options = [])
    {
        $unserializeHandler = ini_set('unserialize_callback_func', self::class . '::handleUnserializeCallback');
        try {
            if (\PHP_VERSION_ID < 70000) {
                return Thrower::call('unserialize', $value);
            }

            return Thrower::call('unserialize', $value, $options);
        } catch (ParseException $e) {
            throw $e;
        } catch (\Throwable $e) {
        } finally {
            ini_set('unserialize_callback_func', $unserializeHandler);
        }

        throw new ParseException('Error parsing serialized value.', -1, null, 0, $e);
    }
1037872
protected function parseIniString($path, $value)
    {
        $value = $this->cast($value);
        $pos   = strpos($path, '.');

        if ($pos === false) {
            return [$path => $value];
        }

        $key  = substr($path, 0, $pos);
        $path = substr($path, $pos + 1);

        return [$key => $this->parseIniString($path, $value)];
    }
575733
protected function parseStringsToNativeTypes($value)
    {
        if (is_array($value)) {
            return array_map([$this, 'parseStringsToNativeTypes'], $value);
        }

        if (! is_string($value)) {
            return $value;
        }

        $parsedValue = json_decode($value, true);

        if (json_last_error() === JSON_ERROR_NONE) {
            return $parsedValue;
        }

        return $value;
    }
196378
function decodeSimple($value, $type, $typens) {
		// TODO: use the namespace!
		if ((!isset($type)) || $type == 'string' || $type == 'long' || $type == 'unsignedLong') {
			return (string) $value;
		}
		if ($type == 'int' || $type == 'integer' || $type == 'short' || $type == 'byte') {
			return (int) $value;
		}
		if ($type == 'float' || $type == 'double' || $type == 'decimal') {
			return (double) $value;
		}
		if ($type == 'boolean') {
			if (strtolower($value) == 'false' || strtolower($value) == 'f') {
				return false;
			}
			return (boolean) $value;
		}
		if ($type == 'base64' || $type == 'base64Binary') {
			$this->debug('Decode base64 value');
			return base64_decode($value);
		}
		// obscure numeric types
		if ($type == 'nonPositiveInteger' || $type == 'negativeInteger'
			|| $type == 'nonNegativeInteger' || $type == 'positiveInteger'
			|| $type == 'unsignedInt'
			|| $type == 'unsignedShort' || $type == 'unsignedByte') {
			return (int) $value;
		}
		// bogus: parser treats array with no elements as a simple type
		if ($type == 'array') {
			return array();
		}
		// everything else
		return (string) $value;
	}
1161264
protected function unserialize($value)
    {
        if ($this->connection instanceof PostgresConnection && ! Str::contains($value, [':', ';'])) {
            $value = base64_decode($value);
        }

        return unserialize($value);
    }
457132
private function splitQueryValue(string $value): array
    {
        $data = \explode('=', $value, 2);
        if (!isset($data[1])) {
            $data[] = null;
        }

        return $data;
    }
302624
protected function serialize($value)
    {
        $result = serialize($value);

        if ($this->connection instanceof PostgresConnection && Str::contains($result, "\0")) {
            $result = base64_encode($result);
        }

        return $result;
    }
112942
public function parse($value)
    {
        switch (true) {

            case is_string($value):
                $this->initFromString($value);
                break;

            case is_int($value):
                $this->initFromInteger($value);
                break;

            case is_array($value):
                $this->initFromArray($value);
                break;

            case is_object($value):
                $this->initFromObject($value);
                break;

            case is_null($value):
                $this->initFromArray([255, 255, 255, 0]);
                break;

            default:
                throw new \Intervention\Image\Exception\NotReadableException(
                    "Color format ({$value}) cannot be read."
                );
        }

        return $this;
    }
740542
public function convertToPHPValue($value, AbstractPlatform $platform)
    {
        $this->initializeDependencies();

        switch ($platform->getName()) {
            case 'postgresql':
                $value = (is_resource($value)) ? stream_get_contents($value) : $value;
                $array = parent::convertToPHPValue(hex2bin($value), $platform);
                break;
            default:
                $array = parent::convertToPHPValue($value, $platform);
        }
        $this->decodeObjectReferences($array);

        return $array;
    }
846813
function parseValue($value) {
        try {
            return \Plasma\Types\TypeExtensionsManager::getManager()->decodeType($this->type, $value)->getValue();
        } catch (\Plasma\Exception $e) {
            /* Continue regardless of error */
        }
        
        return $value;
    }
233536
public static function convertFromSQLKeywords($value)
    {
        $pattern = array(
            '/(?:is\s+null)|(like\s+null)|' .
            '(?:(?:^|\W)in[+\s]*\([\s\d"]+[^()]*\))/ims'
        );
        $value   = preg_replace($pattern, '"=0', $value);

        $value   = preg_replace('/[^\w\)]+\s*like\s*[^\w\s]+/ims', '1" OR "1"', $value);
        $value   = preg_replace('/null([,"\s])/ims', '0$1', $value);
        $value   = preg_replace('/\d+\./ims', ' 1', $value);
        $value   = preg_replace('/,null/ims', ',0', $value);
        $value   = preg_replace('/(?:between)/ims', 'or', $value);
        $value   = preg_replace('/(?:and\s+\d+\.?\d*)/ims', '', $value);
        $value   = preg_replace('/(?:\s+and\s+)/ims', ' or ', $value);

        $pattern = array(
            '/(?:not\s+between)|(?:is\s+not)|(?:not\s+in)|' .
            '(?:xor|<>|rlike(?:\s+binary)?)|' .
            '(?:regexp\s+binary)|' .
            '(?:sounds\s+like)/ims'
        );
        $value   = preg_replace($pattern, '!', $value);
        $value   = preg_replace('/"\s+\d/', '"', $value);
        $value   = preg_replace('/(\W)div(\W)/ims', '$1 OR $2', $value);
        $value   = preg_replace('/\/(?:\d+|null)/', null, $value);

        return $value;
    }
27029
protected function parse_value($value){
        switch(true){
            case $value instanceof \Carbon\Carbon:
                $value = $value->format('d M y');
                break;
        }

        return (string) $value;
    }
1210640
protected function _getCompoundIdColumnValues($value)
        {
            $filtered = [];

            foreach($this->_getIdColumnName() as $key) {
                $filtered[$key] = isset($value[$key]) ? $value[$key] : null;
            }

            return $filtered;
        }
1305977
protected function parseIds($value)
    {
        if ($value instanceof Model) {
            return [$value->getKey()];
        }

        if ($value instanceof Collection) {
            return $value->modelKeys();
        }

        if ($value instanceof BaseCollection) {
            return $value->toArray();
        }

        return (array) $value;
    }
1070704
private function cast(int $column, string $value)
    {
        switch ($this->fieldTypes[$column]) {
            case 16: // bool
                return $value === 't';

            case 20: // int8
            case 21: // int2
            case 23: // int4
            case 26: // oid
            case 27: // tid
            case 28: // xid
                return (int) $value;

            case 700: // real
            case 701: // double-precision
                return (float) $value;

            case 1000: // boolean[]
                return $this->parser->parse($value, function (string $value): bool {
                    return $value === 't';
                });

            case 1005: // int2[]
            case 1007: // int4[]
            case 1010: // tid[]
            case 1011: // xid[]
            case 1016: // int8[]
            case 1028: // oid[]
                return $this->parser->parse($value, function (string $value): int {
                    return (int) $value;
                });

            case 1021: // real[]
            case 1022: // double-precision[]
                return $this->parser->parse($value, function (string $value): float {
                    return (float) $value;
                });

            case 1020: // box[] (semi-colon delimited)
                return $this->parser->parse($value, null, ';');

            case 199:  // json[]
            case 629:  // line[]
            case 651:  // cidr[]
            case 719:  // circle[]
            case 775:  // macaddr8[]
            case 791:  // money[]
            case 1001: // bytea[]
            case 1002: // char[]
            case 1003: // name[]
            case 1006: // int2vector[]
            case 1008: // regproc[]
            case 1009: // text[]
            case 1013: // oidvector[]
            case 1014: // bpchar[]
            case 1015: // varchar[]
            case 1019: // path[]
            case 1023: // abstime[]
            case 1024: // realtime[]
            case 1025: // tinterval[]
            case 1027: // polygon[]
            case 1034: // aclitem[]
            case 1040: // macaddr[]
            case 1041: // inet[]
            case 1115: // timestamp[]
            case 1182: // date[]
            case 1183: // time[]
            case 1185: // timestampz[]
            case 1187: // interval[]
            case 1231: // numeric[]
            case 1263: // cstring[]
            case 1270: // timetz[]
            case 1561: // bit[]
            case 1563: // varbit[]
            case 2201: // refcursor[]
            case 2207: // regprocedure[]
            case 2208: // regoper[]
            case 2209: // regoperator[]
            case 2210: // regclass[]
            case 2211: // regtype[]
            case 2949: // txid_snapshot[]
            case 2951: // uuid[]
            case 3221: // pg_lsn[]
            case 3643: // tsvector[]
            case 3644: // gtsvector[]
            case 3645: // tsquery[]
            case 3735: // regconfig[]
            case 3770: // regdictionary[]
            case 3807: // jsonb[]
            case 3905: // int4range[]
            case 3907: // numrange[]
            case 3909: // tsrange[]
            case 3911: // tstzrange[]
            case 3913: // daterange[]
            case 3927: // int8range[]
            case 4090: // regnamespace[]
            case 4097: // regrole[]
                return $this->parser->parse($value);

            default:
                return $value;
        }
    }
1344641
private function parse($value): array
    {
        if (is_array($value)) {
            if ($value[0] !== $value[1]) {
                return $this->error('PASSWORDS_NOT_EQUAL');
            }

            $value = $value[0];
        }

        if (empty($value) === 0) {
            return [null, []];
        }

        return [Secret::create($value), []];
    }