Validate an array of properties

@param array $properties
@return bool
@throws \Laranix\Support\Exception\InvalidTypeException
327383
public function validateProperties(array $properties): bool
    {
        foreach ($properties as $property => $allowed) {
            $this->validateProperty($property, $allowed);
        }

        return true;
    }
903228
public function sets(array $properties)
  {
    foreach($properties as $k => $v){
      $this->set($k, $v);
    }
    return $this;
  }
1279139
protected function processProperty(array &$properties, $property)
    {
        try {
            if ($this->validatePropertyStructure($property)) {
                $property->values = $this->getPropertyValues($property->values);
                if (count($property->values)) {
                    $properties[] = $property;
                }
            }
        } catch (InvalidArgumentException $exception) {
            // Skip this property
        }
    }
491759
public function isValidProperty(string $property)
    {
        if (!empty($this->validProperties) && !array_key_exists($property, $this->validProperties)) {
            return false;
        }

        return true;
    }
184144
protected function ensureFormatProperties(array $properties)
	{
		// defaults keys for transforming
		$properties += [
			'bit_rate'    => 0,
			'duration'    => 0.0,
			'format_name' => '',
			'tags'        => [],
			'codecs'      => []
		];
		
		if ( ! empty($this->options[ServiceFactoryInterface::OPTION_TEST_CODECS]))
		{
			$properties['codecs'] = $this->getAvailableCodecs();
		}
		
		$properties['metadata'] = (array) $properties['tags'];
		$properties['format'] = $properties['format_name'];
		$properties['bitrate'] = $properties['bit_rate'];
		
		unset($properties['tags'], $properties['bit_rate']);
		
		return $properties;
	}
776839
public function validate($params)
    {
        $params = $this->boolParams($params);

        if (!empty($params['html']) && (!empty($params['url']) || !empty($params['file'])))
            throw new InvalidParameterException("Only one of [html, url, file] parameters can be set!");

        if (!empty($params['url']) && !empty($params['file']))
            throw new InvalidParameterException("Only one of [html, url, file] parameters can be set!");

        if ((!empty($params['page_width']) && empty($params['page_height']))
            ||(empty($params['page_width']) && !empty($params['page_height'])))
        {
            throw new InvalidParameterException('Page width and page height must both be set or unset!');
        }
        if (!empty($params['filename']) && !is_string($params['filename']))
            throw new InvalidParameterException('Filename must be a string.');

        if (!empty($params['footer']) && !is_string($params['footer']))
            throw new InvalidParameterException('Footer must be a string.');

        if (!empty($params['header']) && !is_string($params['header']))
            throw new InvalidParameterException('Header must be a string.');

        if (!empty($params['header_spacing']) && !is_int($params['header_spacing']))
            throw new InvalidParameterException('Header spacing parameter must be an integer.');

        if (!empty($params['footer_spacing']) && !is_int($params['footer_spacing']))
            throw new InvalidParameterException('Footer spacing parameter must be an integer.');

        if (!empty($params['page_size']) && !is_string($params['page_size']))
            throw new InvalidParameterException('Page size must be a string of some standard page size.');

        if (!empty($params['dpi']) && (!is_int($params['dpi']) || $params['dpi']<75))
            throw new InvalidParameterException('DPI must be an integer larger than 75.');

        if (!empty($params['image_dpi']) && !is_int($params['image_dpi']))
            throw new InvalidParameterException('Image DPI must be an integer.');

        if (!empty($params['lowquality']) && (!is_int($params['lowquality']) || !in_array($params['lowquality'], array(
                    0, 1 ) )))
            throw new InvalidParameterException(
                'Lowquality must be either 0 or 1 (alternative: use bool values');

        if (!empty($params['orientation']) && (!is_string($params['orientation']) || !in_array($params['orientation'],
                array("landscape", "portrait"))))
            throw new InvalidParameterException('Orientation must be set to either "landscape" or "portrait"');

        if (!empty($params['margin_top']) && !is_int($params['margin_top']))
            throw new InvalidParameterException('Margin top must be an integer.');

        if (!empty($params['margin_bottom']) && !is_int($params['margin_bottom']))
            throw new InvalidParameterException('Margin top must be an integer.');

        if (!empty($params['margin_left']) && !is_int($params['margin_left']))
            throw new InvalidParameterException('Margin top must be an integer.');

        if (!empty($params['margin_right']) && !is_int($params['margin_right']))
            throw new InvalidParameterException('Margin top must be an integer.');

        if (!empty($params['background']) && (!is_int($params['background']) || !in_array($params['background'], array(
                    0, 1 ) )))
            throw new InvalidParameterException(
                'Background must be either 0 or 1 (alternative: use bool values');

        if (!empty($params['images']) && (!is_int($params['images']) || !in_array($params['images'], array(
                    0, 1 ) )))
            throw new InvalidParameterException(
                'Images must be either 0 or 1 (alternative: use bool values');

        if (!empty($params['page_width']) && !is_int($params['page_width']))
            throw new InvalidParameterException('Page width must be an integer.');

        if (!empty($params['page_height']) && !is_int($params['page_height']))
            throw new InvalidParameterException('Page height must be an integer.');

        if (!empty($params['disposition']) && (!is_string($params['disposition']) || !in_array($params['disposition'],
                    array("attachment", "inline"))))
            throw new InvalidParameterException('Disposition can only be "attachment or "inline"');

        if (!empty($params['group']) && !is_string($params['group']))
            throw new InvalidParameterException('Group must be a string.');

        if (!empty($params['engine_version']) && (!is_int($params['engine_version']) || !in_array($params['engine_version'],
        array( 11, 12 ) )))
            throw new InvalidParameterException(
                'Engine version can be integer 11 or 12');

        if (!empty($params['title']) && !is_string($params['title']))
            throw new InvalidParameterException('Title must be a string.');

        if (!empty($params['outline']) && (!is_int($params['outline']) || !in_array($params['outline'], array(
                    0, 1 ) )))
            throw new InvalidParameterException(
                'Outline must be either 0 or 1 (alternative: use bool values');

        if (!empty($params['outline_depth']) && !is_int($params['outline_depth']))
            throw new InvalidParameterException('Outline depth must be an integer.');

        if (!empty($params['encoding']) && !is_string($params['encoding']))
            throw new InvalidParameterException('Encoding must be a string.');

        if (!empty($params['javascript']) && (!is_int($params['javascript']) || !in_array($params['javascript'], array(
                    0, 1 ) )))
            throw new InvalidParameterException(
                'Javascript must be either 0 or 1 (alternative: use bool values');

        if (!empty($params['javascript_delay']) &&
            (!is_int($params['javascript_delay']) || $params['javascript_delay']<1 || $params['javascript_delay']>800))
            throw new InvalidParameterException('Javascript delay must be an integer larger than 1, but smaller than 800.');

        if (!empty($params['internal_links']) &&
            (!is_int($params['internal_links']) || !in_array($params['internal_links'], array( 0, 1 ) )))
            throw new InvalidParameterException(
                'Internal links must be either 0 or 1 (alternative: use bool values');

        if (!empty($params['external_links']) &&
            (!is_int($params['external_links']) || !in_array($params['external_links'], array( 0, 1 ) )))
            throw new InvalidParameterException(
                'External links must be either 0 or 1 (alternative: use bool values');

        if (!empty($params['page_offset']) && !is_int($params['page_offset']))
            throw new InvalidParameterException('Page offset must be an integer.');

        if (!empty($params['username']) && !is_string($params['username']))
            throw new InvalidParameterException('Username must be a string.');

        if (!empty($params['password']) && !is_string($params['password']))
            throw new InvalidParameterException('Password must be a string.');

        if (!empty($params['use_print_media']) &&
            (!is_int($params['use_print_media']) || !in_array($params['use_print_media'], array(
                    0, 1 ) )))
            throw new InvalidParameterException(
                'Use print media must be either 0 or 1 (alternative: use bool values');

        if (!empty($params['zoom']) && !is_numeric($params['zoom']))
            throw new InvalidParameterException('Zoom must be an integer.');

        if (!empty($params['viewport_size']) &&
            (!is_string($params['viewport_size'] || preg_match("^\\d+x\\d+$", $params['viewport_size']))))
            throw new InvalidParameterException('Viewport must be a string of a following format: [width]x[height].');

        if (!empty($params['id']) && !is_string($params['id']))
            throw new InvalidParameterException('ID must be a string.');

        /*if (!empty($params['file']))
            $this->validateFile($params['file']);*/

        return $params;
    }
693172
private function valid($types, $value) {
        $types = (array) $types;

        foreach($types as $type) {
            switch($type) {
            case self::T_NULL:
                if(is_null($value)) {
                    return true;
                }
                break;
            case self::T_INT:
                if(is_int($value)) {
                    return true;
                }
                break;
            case self::T_STR:
                if(is_string($value)) {
                    return true;
                }
                break;
            case self::T_ARR:
                if(is_array($value)) {
                    return true;
                }
                break;
            }
        }

        return false;
    }
352154
public function validate(array $rules = array(), array $customMessages = array()) {
        if ($this->fireModelEvent('validating') === false) {
            if ($this->throwOnValidation) {
                throw new InvalidModelException($this);
            } else {
                return false;
            }
        }

        // check for overrides, then remove any empty rules
        $rules = (empty($rules))? static::$rules : $rules;
        foreach ($rules as $field => $rls) {
            if ($rls == '') {
                unset($rules[$field]);
            }
        }

        if (empty($rules)) {
            $success = true;
        } else {
			$customMessages = (empty($customMessages))? static::$customMessages : $customMessages;

			if ($this->forceEntityHydrationFromInput || (empty($this->attributes) && $this->autoHydrateEntityFromInput)) {
				$this->fill(Input::all());
			}

			$data = $this->getAttributes(); // the data under validation

			// perform validation
			$validator = static::makeValidator($data, $rules, $customMessages);
			$success   = $validator->passes();

			if ($success) {
				// if the model is valid, unset old errors
				if ($this->validationErrors->count() > 0) {
					$this->validationErrors = new MessageBag;
				}
			} else {
				// otherwise set the new ones
				$this->validationErrors = $validator->messages();

				// stash the input to the current session
				if (!self::$externalValidator && Input::hasSession()) {
					Input::flash();
				}
			}
		}

        $this->fireModelEvent('validated', false);

	    if (!$success && $this->throwOnValidation) {
		    throw new InvalidModelException($this);
	    }

        return $success;
    }
1121634
private function validate()
    {
        if (!array_key_exists('type', $this->properties)) {
            throw new StatusException(sprintf('Key %s in %s missing', 'type', __CLASS__), 100, null);
        }

        $type = $this->properties['type'];

        // the type specified must be valid
        if (!in_array($this->properties['type'], $this->types)) {
            throw new StatusException('The type specified is invalid', 100, null);
        }

        switch ($type) {
            case StatusInterface::TYPE_INITIAL:
            case StatusInterface::TYPE_EXCEPTION:
                $mandatoryKeys = ['name'];
                break;

            default:
                $mandatoryKeys = ['name', 'transitions_from', 'transitions_to'];
                break;
        }

        foreach ($mandatoryKeys as $key) {
            if (!array_key_exists($key, $this->properties)) {
                throw new StatusException(sprintf('Key %s in %s missing', $key, __CLASS__), 100, null);
            }
        }

        if (StatusInterface::TYPE_INITIAL != $type && StatusInterface::TYPE_EXCEPTION != $type) {
            $keysMustBeArray = ['transitions_from', 'transitions_to'];
            foreach ($keysMustBeArray as $key) {
                if (!is_array($this->properties[$key])) {
                    throw new StatusException(sprintf('Key %s is not an array', $key), 100, null);
                }
            }
        }
    }
317848
protected function has($property, ...$properties)
    {
        if (is_array($property)) {
            $properties = $property;
        } else {
            $properties[] = $property;
        }

        foreach ($properties as $property) {
            $property = $this->translateProperty($property);
            if (!isset($this->{$property})) {
                return false;
            }
        }

        return true;
    }
440979
protected function parseProperties(array $properties)
    {
        $parsed = [];

        foreach ($properties as $propertyString) {
            if (!mb_strpos($propertyString, ':')) {
                list($key, $value) = $this->parseBooleanShortcut($propertyString);
                $parsed[Type::camelCase($key)] = $value;
                continue;
            }


            list($key, $value) = explode(':', $propertyString, 2);


            if (!$this->isNestedShortCut($value)) {
                $parsed[Type::camelCase($key)] = $value;
                continue;
            }

            $type = $this->stringToType(trim($value, '[]'));

            $parsed[Type::camelCase($key)] = $type;
        }

        return $parsed;
    }
1093742
public function setRange(array $properties)
    {
        if (self::isValidSelectRangeType($properties)) {
            $this->range = explode(':', substr($properties['html-type'], 12));
        }

        if (Helpers::isKeyExists($properties, 'range') && is_array($properties['range'])) {
            $this->range = $properties['range'];
        }

        return $this;
    }
1040710
public function setProperties(array $properties)
    {
        if (isset($properties[ 'presets' ])) {
            $this->setPresets($properties[ 'presets' ]);

            unset($properties[ 'presets' ]);
        }

        $this->properties = $properties;

        return $this;
    }
333314
private function setType(array &$properties)
    {
        $type = array_pull($properties, 'type', null);

        $this->type = is_null($type)
            ? $this->guessType($properties)
            : $type;

        return $this;
    }
433219
protected function map(array $properties)
    {
        $map = array();

        foreach ($properties as $name => $default) {
            $map[$name] = (true === empty($this->$name)) ? $default : $this->$name;
        }

        return $map;
    }
407665
final public static function format_properties($properties) {
        foreach ($properties as $property => $definition) {
            // Ensures that null is set to its default.
            if (!isset($definition['null'])) {
                $properties[$property]['null'] = NULL_NOT_ALLOWED;
            }
            if (!isset($definition['description'])) {
                $properties[$property]['description'] = $property;
            }

            // If an array is provided, it may be a nested array that is unformatted so rinse and repeat.
            if (is_array($definition['type'])) {
                $properties[$property]['type'] = static::format_properties($definition['type']);
            }
        }
        return $properties;
    }
460983
public static function get(array $properties)
    {
        if (!array_key_exists('columns', $properties)) {
            throw new Exception('An index requires at least one column.');
        }

        $index = new Index();

        foreach ((array) $properties['columns'] as $column) {
            $index->addColumn($column);
        }

        if (array_key_exists('name', $properties) && !empty($properties['name'])) {
            $index->setName($properties['name']);
        }

        if (array_key_exists('type', $properties) && !empty($properties['type'])) {
            $index->setType($properties['type']);
        }

        return $index;
    }