Take the data from the system and serialize it for the database.

@param mixed $mixValues The data to serialize.

@return string An serialized array with binary data or a binary data.
169616
public function serializeData($mixValues)
    {
        $data = ToolboxFile::convertValuesToDatabase($mixValues ?: ['bin' => [], 'value' => [], 'path' => []]);

        // Check single file or multiple file.
        if ($this->get('file_multiple')) {
            return \serialize($data);
        }

        return $data[0];
    }
462635
public function isValid($mixValue){
		if(is_null($mixValue)){
			return true;
		}

		if(is_object($mixValue)){
			if($mixValue instanceof \DateTime){
				return true;
			}else{
				throw new ClassException($mixValue, '\DateTime');
				return false;
			}
		}

		if(is_string($mixValue)){
			try{
				$objTest = new \DateTime($mixValue);
				return true;
			}catch (\Exception $e){
				throw new TypeException($mixValue, get_class($this));
			}
		}

		return false;
	}
1165669
public function valufy($values)
    {
        // we'll only deal with arrays so let's turn it into one if it isn't
        if ( ! is_array($values)) $values = [$values];

        // escape and wrap them with a quote.
        $values = array_map(function ($value)
        {
            // First, we check whether we have a date instance so that
            // we take its string representation instead.
            if ($value instanceof DateTime || $value instanceof Carbon)
            {
                $value = $value->format($this->getDateFormat());
            }

            // We need to keep the data type of values
            // except when they're strings, we need to
            // escape wrap them.
            if (is_string($value))
            {
                $value = "'" . addslashes($value) . "'";
            }
            // In order to support boolean value types and not have PHP convert them to their
            // corresponding string values, we'll have to handle boolean values and add their literal string representation.
            elseif (is_bool($value))
            {
                $value = ($value) ? 'true' : 'false';
            }

            return $value;

        }, $values);

        // stringify them.
        return implode(', ', $values);
    }
697293
public function unserialize($serialized)
    {
        $data = unserialize($serialized);
        if (!is_array($data)) {
            throw new \UnexpectedValueException('Unserialized data is not an array');
        }

        // TODO: check existence
        $this->message      = CustomAmqpMessage::fromProperties($data['message']);
        $this->tag          = (string) $data['tag'];
        $this->exchange     = (string) $data['exchange'];
        $this->queue        = (string) $data['queue'];
        $this->routingKey   = (string) $data['routingKey'];
        $this->redelivered  = (bool) $data['routingKey'];
    }
32123
public static function createUserFromPostValues($postValues)
    {
        if (isset($postValues['username'])) {
            $user = new \stdClass();
            $user->username = $postValues['username'];
            $user->slug = StringUtil::slugify($postValues['username']);
            $user->rights = array();
            if (isset($postValues['rights'])) {
                $user->rights = $postValues['rights'];
            }

            if (isset($postValues['password']) && empty($postValues['password']) === false) {
                $crypt = new Crypt();
                $user->password = $crypt->encrypt($postValues['password'], 16);
                $user->salt = $crypt->getLastSalt();
            } else {
                $user->password = $postValues['passHash'];
                $user->salt = $postValues['salt'];
            }

            return $user;
        } else {
            throw new \Exception('Trying to create user with invalid data.');
        }
    }
27927
protected function buildValues($values)
    {
        $result = [];

        // We will iterate through the entire array of values transforming every
        // item into the data type object linked to this collection. Any null
        // value will be omitted here in order to avoid storing NULL values.
        foreach ($values as $value) {
            if (! is_null($value)) {
                $result[] = $this->buildValue($value);
            }
        }

        return $result;
    }
787426
protected function to_features($calculatedvalues) {

        // Null mean if all calculated values are null.
        $nullmean = true;
        foreach ($calculatedvalues as $value) {
            if (!is_null($value)) {
                // Early break, we don't want to spend a lot of time here.
                $nullmean = false;
                break;
            }
        }

        if ($nullmean) {
            $mean = null;
        } else {
            $mean = round(array_sum($calculatedvalues) / count($calculatedvalues), 2);
        }

        foreach ($calculatedvalues as $sampleid => $calculatedvalue) {

            if (!is_null($calculatedvalue)) {
                $calculatedvalue = round($calculatedvalue, 2);
            }

            if (static::include_averages()) {
                $calculatedvalues[$sampleid] = array($calculatedvalue, $mean);
            } else {
                // Basically just convert the scalar to an array of scalars with a single value.
                $calculatedvalues[$sampleid] = array($calculatedvalue);
            }
        }

        // Returns each sample as an array of values, appending the mean to the calculated value.
        return $calculatedvalues;
    }
850925
public static function serialize(array $values): array
    {
        $serializedData = [];

        foreach ($values as $property => $value) {
            if (is_array($value)) {
                $value = self::serialize($value);
            }

            if ($value instanceof Serializable) {
                $value = $value->serialize();
            }

            $serializedData[$property] = $value;
        }

        return $serializedData;
    }
309437
protected function databaseValue($values)
    {
        if ($values instanceof SetValue) {
            $values = $values->toArray();
        } else {
            if (!is_array($values)) {
                throw ODMException::invalidValueForType('Set', ['array', 'SetValue', 'null'], $values);
            }
        }

        if (count($values) === 0) {
            throw ODMException::setsCannotBeEmpty();
        }

        return $values;
    }
1328514
public function setValue($mixValue){
		if($this->isValid($mixValue)){
			$this->mixValue = array();

			if(is_array($mixValue)){
				//set the array using offsetSet so that checks are carried out on the content of the array
				foreach($mixValue as $strKey => $mixValue){
					$this->offsetSet($strKey, $mixValue);
				}
			}
			return true;
		}

		throw new TypeException($mixValue, get_class($this));
		return false;
	}
1282816
protected function databaseValue($values)
    {
        if (!is_array($values)) {
            throw ODMException::invalidValueForType('List', ['array', 'null'], $values);
        }

        //re-index numerically
        $values = array_values($values); //TODO: Remove me? handle in CollectionPersister?

        return $values;
    }
619155
protected function encodeValues($values)
    {
        if (is_null($this->connection) || $this->type == AttributeConverterInterface::TYPE_SEARCH_FROM) {
            return $values;
        }
        $encoded = is_array($values) ? $values : [$values];

        foreach ($encoded as $index => $value) {
            if (is_string($value)) {
                $encoded[$index] = LdapUtilities::encode($value, $this->connection->getConfig()->getEncoding());
            }
        }

        // This is to pass it back the same way it was received. ldap_modify_batch is picky about values being an array.
        return is_array($values) ? $encoded : reset($encoded);
    }
146582
public function serialize_properties()
    {
        if (!empty($this->serialized_properties)) {
            return $this->serialized_properties;
        }

        $shift = 15;
        $flag_bits = 0;
        $flags = array();
        $raw_bytes = new AMQPWriter();

        foreach ($this->prop_types as $key => $prototype) {
            $val = isset($this->properties[$key]) ? $this->properties[$key] : null;

            // Very important: PHP type eval is weak, use the === to test the
            // value content. Zero or false value should not be removed
            if ($val === null) {
                $shift -= 1;
                continue;
            }

            if ($shift === 0) {
                $flags[] = $flag_bits;
                $flag_bits = 0;
                $shift = 15;
            }

            $flag_bits |= (1 << $shift);
            if ($prototype != 'bit') {
                $raw_bytes->{'write_' . $prototype}($val);
            }

            $shift -= 1;
        }

        $flags[] = $flag_bits;
        $result = new AMQPWriter();
        foreach ($flags as $flag_bits) {
            $result->write_short($flag_bits);
        }

        $result->write($raw_bytes->getvalue());

        $this->serialized_properties = $result->getvalue();

        return $this->serialized_properties;
    }
900172
public function serialize($value) : string
    {
        if (null !== $value && !is_array($value)) {
            throw InvalidValueException::valueDoesNotMatchType($this, $value);
        }

        return json_encode($value);
    }
1311628
public function serialize(FieldValue $fieldValue, array $options = [])
    {
        $serialized = [
            'id' => $fieldValue->getUuid(),
        ];

        if (in_array(Options::SERIALIZE_MINIMAL, $options)) {
            $serialized = array_merge($serialized, [
                'field' => [
                    'id' => $fieldValue->getField()->getUuid(),
                ],
                'fieldFacetValue' => $this->fieldFacetValueSerializer->serialize($fieldValue->getFieldFacetValue(), ['minimal']),
            ]);
        } else {
            $serialized = array_merge($serialized, [
                'field' => $this->fieldSerializer->serialize($fieldValue->getField(), [Options::SERIALIZE_MINIMAL]),
                'fieldFacetValue' => $this->fieldFacetValueSerializer->serialize($fieldValue->getFieldFacetValue(), ['minimal']),
            ]);
        }

        return $serialized;
    }
398813
private function prepareValues($values, callable $valueCallable = null)
    {
        if (is_array($values)) {
            foreach ($values as &$value) {
                if ($valueCallable) {
                    $value = call_user_func_array($valueCallable, [(string) $value]);
                }

                $value = (string) $value;
            }
            unset($value);

            $values = array_values($values);
        } else {
            if ($valueCallable) {
                $values = call_user_func_array($valueCallable, [(string) $values]);
            }

            $values = (string) $values;
        }

        return $values;
    }
1097795
protected function to_features($calculatedvalues) {

        $classes = static::get_classes();

        foreach ($calculatedvalues as $sampleid => $calculatedvalue) {

            // Using intval as it may come as a float from the db.
            $classindex = array_search(intval($calculatedvalue), $classes, true);

            if ($classindex === false && !is_null($calculatedvalue)) {
                throw new \coding_exception(get_class($this) . ' calculated value "' . $calculatedvalue .
                    '" is not one of its defined classes (' . json_encode($classes) . ')');
            }

            // We transform the calculated value into multiple features, one for each of the possible classes.
            $features = array_fill(0, count($classes), 0);

            // 1 to the selected value.
            if (!is_null($calculatedvalue)) {
                $features[$classindex] = 1;
            }

            $calculatedvalues[$sampleid] = $features;
        }

        return $calculatedvalues;
    }