Filter data by using blueprints.

@param  array $data                  Incoming data, for example from a form.
@param  bool  $missingValuesAsNull   Include missing values as nulls.
@param bool   $keepEmptyValues       Include empty values.
@return array
438266
public function filter(array $data, $missingValuesAsNull = false, $keepEmptyValues = false)
    {
        return $this->filterArray($data, $this->nested, $missingValuesAsNull, $keepEmptyValues);
    }
154545
public function deserialize(StringLiteral $data)
    {
        $data = parent::deserialize($data);

        if (empty($data->label)) {
            throw new MissingValueException('Missing value "label".');
        }
        if (empty($data->offers)) {
            throw new MissingValueException('Missing value "offers".');
        }

        $label = new Label($data->label);
        $offers = new OfferIdentifierCollection();

        foreach ($data->offers as $offer) {
            $offers = $offers->with(
                $this->offerIdentifierDeserializer->deserialize(
                    new StringLiteral(
                        json_encode($offer)
                    )
                )
            );
        }

        return new AddLabelToMultiple($offers, $label);
    }
1005160
protected static function removeEmptyAttributes($data)
    {
        $records = $data;
        $unwrapped = false;
        if (isset($data[ResourcesWrapper::getWrapper()])) {
            $records = $data[ResourcesWrapper::getWrapper()];
            $unwrapped = true;
        }

        foreach ($records as $i => $record) {
            if (is_numeric($i) && [$record]) {
                foreach ($record as $key => $value) {
                    if (empty($value)) {
                        unset($records[$i][$key]);
                    } elseif (is_string($value)) {
                        if (strtolower($value) === "true") {
                            $records[$i][$key] = true;
                        } elseif (strtolower($value) === "false") {
                            $records[$i][$key] = false;
                        } elseif (strtolower($value) === "null") {
                            $records[$i][$key] = null;
                        }
                    }
                }
            }
        }

        $data = $records;
        if ($unwrapped) {
            $data = ResourcesWrapper::wrapResources($data);
        }

        return $data;
    }
530590
public static function getDataArrayFrom($instance, $properties = [], $ignoreNull = true)
    {
        $clsName = get_class($instance);
        $ref = self::getReflectionCls($clsName);
        $data = [];
        if (empty($properties)) {
            $properties = self::getAllProperties($ref);
        }
        foreach ($properties as $vo) {
            if ($vo instanceof \ReflectionProperty) {
                $propName = self::uncamelize($vo->getName());
            } else {
                $propName = self::uncamelize($vo);
            }

            $key = self::convertUnderline($propName);
            $methodName = 'get' . ucfirst($key);

            if ($ref->hasMethod($methodName)) {
                $method = $ref->getMethod($methodName);
                if ($method->isPublic()) {
                    $propValue = $instance->$methodName();
                    if ($ignoreNull && is_null($propValue)) {
                        continue;
                    }

                    if ($propValue instanceof ObjectToArrayInterface) {
                        $data[$propName] = $propValue->toArray();
                    } else {
                        $data[$propName] = $propValue;
                    }
                }
            }
        }
        return $data;
    }
992804
public function filterInsertValues($data, $fields)
	{
		$insertValues = array();
		$field_keys = array_flip($fields);
		foreach ($data as $key => $values) {
			$filteredValues = array_intersect_key($values, $field_keys);
			$emptyFields = array_fill_keys($fields, null);
			$filledValues = array_values(array_merge($emptyFields, $filteredValues));
			$insertValues = array_merge($insertValues, $filledValues);
		}
		return $insertValues;
	}
955902
public static function values($withEmpty = false)
    {
        $values = parent::values($withEmpty);
        $values[static::WORK] = \Yii::t('app', $values[static::WORK]);
        $values[static::PERSONAL] = \Yii::t('app', $values[static::PERSONAL]);
        $values[static::GOOGLEPLUS] = 'GooglePlus';
        $values[static::LINKEDIN] = 'LinkedIn';

        return $values;
    }
1237657
protected function buildQuery($data = null)
    {
        $params = array();

        if ($data instanceof Criteria) {
            $params = array_merge($params, $data->getParams());
            $params['orderBy'] = $data->getOrderBy();
        }

        if ($token = $this->getOption('token', false)) {
            $params['auth'] = $token;
        }

        return $params;
    }
447241
protected function mapArray(array $arrayValues = null)
    {
        if ($arrayValues === null) {
            return [];
        }

        $array = [];
        foreach ($arrayValues as $arrayValue) {
            if ($arrayValue['value'] === null) {
                $array[$arrayValue['index']] = null;
            } else {
                switch ($arrayValue['type']) {
                    case 'integer':
                        $array[$arrayValue['index']] = (int) $arrayValue['value'];
                    break;
                    case 'float':
                        $array[$arrayValue['index']] = (float) $arrayValue['value'];
                    break;
                    case 'boolean':
                        $array[$arrayValue['index']] = (boolean) $arrayValue['value'];
                    break;
                    case 'string':
                        $array[$arrayValue['index']] = (string) $arrayValue['value'];
                    break;
                    case 'DateTime':
                        $array[$arrayValue['index']] = $this->mapDateTime($arrayValue['value']);
                    break;
                    case 'array':
                        $array[$arrayValue['index']] = $this->mapArray($arrayValue['value']);
                    break;
                    case 'SplObjectStorage':
                        $array[$arrayValue['index']] = $this->mapSplObjectStorage($arrayValue['value']);
                    break;
                    default:
                        $array[$arrayValue['index']] = $this->mapToObject($arrayValue['value']);
                    break;
                }
            }
        }

        return $array;
    }
180420
protected function getWildcardValues($data, array $keys) {
        $values = [];

        if ( ! is_array($data) && ! $data instanceof Traversable) {
            if ($data instanceof IArrayable) {
                $data = $data->toArray();
            }

            if ( ! is_array($data)) {
                $data = [];
            }
        }

        if (count($keys) === 0) {
            foreach ($data as $itemKey => $itemValue) {
                $values[$itemKey] = $itemValue;
            }
        }

        if (count($keys) > 0) {
            foreach ($data as $itemKey => $itemValue) {
                // since there are still selector keys left and the next
                // item is not an array, it is safe to skip it
                if ( ! is_array($itemValue)) {
                    continue;
                }

                $nestedValues = $this->getValues($itemValue, $keys);

                foreach ($nestedValues as $nestedKey => $nestedValue) {
                    $values[$this->buildKey($itemKey, $nestedKey)] = $nestedValue;
                }
            }
        }

        return $values;
    }
263996
public function insert_many($data, $skip_validation = FALSE)
    {
        $ids = array();

        foreach ($data as $key => $row)
        {
            $ids[] = $this->insert($row, $skip_validation, ($key == count($data) - 1));
        }

        return $ids;
    }
430704
protected function prepare_submitted_data( $fields, array $data, $clear_missing ) {
		$submitted = [];

		foreach ( $fields as $field ) {
			if ( $this->maybe_skip_field( $field ) ) {
				continue;
			}

			$value = array_key_exists( $field->get_id(), $data )
				? $data[ $field->get_id() ]
				: null;

			// Treat false as NULL to support binding false to checkboxes.
			// Don't convert NULL to a string here in order to determine later
			// whether an empty value has been submitted or whether no value has
			// been submitted at all. This is important for processing checkboxes
			// and radio buttons with empty values.
			if ( false === $value ) {
				$value = null;
			} elseif ( is_scalar( $value ) ) {
				$value = (string) $value;
			}

			// Perform the sanitization to get sanitized value.
			$sanitized = $field->get_sanitization_value( $value );

			if ( $field->is_group() ) {
				$submitted[ $field->get_id() ] = $this->get_group_values( $field, $sanitized );
			} else {
				$submitted[ $field->get_id() ] = $sanitized;
			}
		}

		// Clear "null" input data.
		if ( $clear_missing ) {
			$submitted = array_filter( $submitted, function ( $value ) {
				return ! is_null( $value );
			} );
		}

		return $submitted;
	}
263323
private String[] nullToEmpty(String... labelValues) {
        return Arrays.stream(labelValues)
                .map(labelValue -> null == labelValue ? "" : labelValue)
                .toArray(String[]::new);
    }
1370691
public function toArray($notEmptyValues = false)
    {
        $props = $this->getReflection()->getProperties();
        if ($this->getReflection()->getParentClass()) {
            $temp = $this->getReflection()->getParentClass()->getProperties();
            $props = array_merge($props, $temp);
        }

        if (strpos($this->getReflection()->getName(), '__CG__') !== FALSE) {
            $props = $this->getReflection()->getParentClass()->getProperties();
        }

        $array = array();
        foreach ($props as $prop) {
            $getter = 'get'.ucfirst($prop->getName());

            if (method_exists($this, $getter)) {
                $empty = $this->$getter();
                $empty = is_null($empty) || empty($empty);

                if (!is_object($this->$getter())) {
                    if (($notEmptyValues && !$empty) || !$empty) {
                        $array[$prop->getName()] = $this->$getter();
                    }
                } elseif (is_object($this->$getter())) {
                    if (method_exists($this->$getter(), 'getId')) {
                        $array[$prop->getName()] = $this->$getter()->getId();
                    } elseif ($this->$getter() instanceof \DateTime) {
                        $array[$prop->getName()] = $this->$getter()->format('d.m.Y');
                    } elseif ($this->$getter() instanceof \Doctrine\Common\Collections\Collection) {
                        $tmp = array();
                        foreach ($this->$getter() as $item) {
                            $tmp[] = $item->getId();
                        }

                        $array[$prop->getName()] = $tmp;
                    }
                }
            }
        }

        return $array;
    }
231255
public function setData($data, $allowEmpty = true, $allowUnset = false)
    {
        if ($data != null) {
            if (is_array($data)) {
                $fileds = $this->getFields();
                foreach ($fileds as $field) {
                    if (isset($data[$field]) && ($allowEmpty || $data[$field] !== '')) {
                        if (strpos($this->getFieldType($field), 'varchar') !== false || $this->getFieldType($field) === 'text') {
                            $encoding = mb_detect_encoding($data[$field]);
                            if ($encoding !== 'utf8') {
                                $this->{$field} = mb_convert_encoding($data[$field], 'utf8', $encoding);
                            } else {
                                $this->{$field} = $data[$field];
                            }
                        } else {
                            $this->{$field} = $data[$field];
                        }
                    } elseif ($allowUnset) {
                        $this->{$field} = false;
                    }
                }
            } else {
                $result = $this->get($data);
                $this->setData($result->model);
                if (empty($result->model)) {
                    $this->asDefault();
                }
            }
        }
        if (empty($data)) {
            $this->asDefault();
        }
        return $this;
    }
1086991
public function format($data = null) {
        $validType = $this->checkType($data);
        $validRange = $this->checkRange($data);
        $validValue = $this->checkValueSet($data);

        if ($validType && $validRange && $validValue) {
            return $data;
        } else if ($validType && (!$validRange || !$validValue)) {

            if ($this->getNull()) {
                return null;
            } else if (!$validValue) {
                $valueSet = $this->getValueSet();
                return $valueSet[0];
            } else {
                throw new \Exception("Unable to format " . $this->getType() . " to range" . $this->getRange());
            }

        } else if (!$validType) {
            if (!settype($data, $this->getType())) {
                if ($this->getType() === "integer" && (float)$data !== (int)$data) {
                    $data = (float)$data;
                } else {
                    $data = (int)$data;
                }
            }
            $validRange = $this->checkRange($data);
            $validValue = $this->checkValueSet($data);

            if ($validRange && $validValue) {
                return $data;
            } else if ($this->getNull()) {
                return null;
            } else if (!$validValue) {
                $valueSet = $this->getValueSet();
                return $valueSet[0];
            } else {
                throw new \Exception("Unable to format " . $this->getType() . " to range" . $this->getRange());
            }
        }
    }
357630
public function getAsQuestion()
    {
        $question = new Question($this->getQuestionText(), $this->default);
        $question->setMaxAttempts($this->maxAttempts);
        $question->setValidator(function ($value) {
            if ($this->isEmpty($value) && $this->isRequired()) {
                throw new MissingValueException("'{$this->name}' is required");
            }
            $this->validate($value);

            return $value;
        });
        $question->setAutocompleterValues($this->autoCompleterValues);

        return $question;
    }
737538
public final function validate(array $data = null, array $rules = null) {
		if ($data === null && isset($this->_formData)) {
			$data = $this->_formData;
		}
		if (empty($data)) {
			throw new ValidateException(['error' => 'data is empty']);
		}
		if ($rules) {
			$this->rules    = [];
			$this->rulesIdx = [];
			$this->ruleKeys = [];
			foreach ($rules as $field => $rule) {
				$this->addRule($field, $rule);
			}
		}

		return $this->validateNewData($data);
	}