Check property is valid against type

@param string $property
@param string $type
@return bool
491816
protected function validatePropertyType(string $property, string $type) : bool
    {
        list($type, $arg) = $this->parseType($type);

        switch ($type) {
            case 'any':
            case 'notnull':
            case 'isset':
            case 'set':
                return true;
            case 'string':
                return is_string($this->{$property});
            case 'email':
                return filter_var($this->{$property}, FILTER_VALIDATE_EMAIL) !== false;
            case 'url':
                return filter_var($this->{$property}, FILTER_VALIDATE_URL) !== false;
            case 'int':
                return is_int($this->{$property});
            case 'bool':
            case 'boolean':
                return is_bool($this->{$property});
            case 'array':
                return is_array($this->{$property});
            case 'null':
                return $this->{$property} === null;
            case 'is_a':
                return is_a($this->{$property}, $arg, true);
            case 'is':
                return is_a($this->{$property}, $arg);
            case 'instanceof':
                return $this->{$property} instanceof $arg;
            default:
                throw new \InvalidArgumentException("{$type} is not a recognised type");
        }
    }
139430
public function __isset($property)
    {
        if (method_exists($this, $getter = 'get' . $property)) {
            return $this->$getter() !== null;
        } else {
            $names = $this->attributeNames();
            return in_array($property, $names);
        }
    }
1344529
public function propertyExists($property, $item)
    {
        if (gettype($item) == 'array') {
            return array_key_exists($property, $item);
        } elseif (gettype($item) == 'object') {
            return property_exists($item , $property);
        }
        return false;
    }
481322
protected function validateProperty(string $property, bool $needed = false)
    {
        if (!property_exists($this, $property)) {
            throw new InvalidArgumentException("Property {$property} does not exist");
        }

        if ($needed && !isset($this->{$property})) {
            throw new LogicException("Property {$property} could not be calculated");
        }

        return $this;
    }
1022532
protected function validateValue($property, $value)
    {
        $type = $this->getType($property);
        if (!$type) {
            $this->stdErr->writeln("Property not writable: <error>$property</error>");

            return false;
        }
        $valid = true;
        $message = '';
        // @todo find out exactly how these should best be validated
        $selectedEnvironment = $this->getSelectedEnvironment();
        switch ($property) {
            case 'parent':
                if ($selectedEnvironment->id === 'master') {
                    $message = "The master environment cannot have a parent";
                    $valid = false;
                } elseif ($value === $selectedEnvironment->id) {
                    $message = "An environment cannot be the parent of itself";
                    $valid = false;
                } elseif (!$parentEnvironment = $this->api()->getEnvironment($value, $this->getSelectedProject())) {
                    $message = "Environment not found: <error>$value</error>";
                    $valid = false;
                } elseif ($parentEnvironment->parent === $selectedEnvironment->id) {
                    $valid = false;
                }
                break;
        }
        switch ($type) {
            case 'boolean':
                $valid = in_array($value, ['1', '0', 'false', 'true']);
                break;
        }
        if (!$valid) {
            if ($message) {
                $this->stdErr->writeln($message);
            } else {
                $this->stdErr->writeln("Invalid value for <error>$property</error>: $value");
            }

            return false;
        }

        return true;
    }
244460
protected function _propertyTypeAllowed($property, $type)
    {
        $definedType = $this->_getPropertyType($property);
        if (!$definedType) {
            return true;
        }
        if (is_object($type) && class_exists($definedType, false)) {
            return ($type instanceof $definedType);
        }
        return gettype($type) == $definedType;
    }
834218
public function validateProperty(string $property, $allowed): bool
    {
        if (is_string($allowed)) {
            $allowed = explode('|', $allowed);
        }

        if (!is_array($allowed)) {
            throw new InvalidTypeException('$allowed must be a string or array');
        }

        $valid = false;
        $optional = in_array('optional', $allowed);

        if ($optional && (!isset($this->{$property}) || $this->{$property} === null)) {
            return true;
        }

        foreach ($allowed as $index => $type) {
            if ($type === 'optional') {
                continue;
            }

            if ($valid = $this->validatePropertyType($property, $type)) {
                break;
            }
        }

        if (!$valid) {
            $this->throwInvalidTypeException($property, $allowed, $optional);
        }

        return true;
    }
1130671
public function __isset($property)
    {
        if ($property = $this->getEntityDescription()->getProperty($property)) {
            $name = $property->getName();

            if ($this->_data->offsetExists($name)) {
                //if a property is one to one or many to one make sure the value
                //actually exists in the database
                $value = $this->_data->offsetGet($name);

                if ($value instanceof AnDomainEntityProxy) {
                    if ($property->isRelationship() && $property->isOneToOne()) {
                        if (!$value->getObject()) {
                            $this->getRepository()->getCommandChain()->disable();
                            $this->set($name, null);
                            $this->getRepository()->getCommandChain()->enable();

                            return false;
                        }
                    }
                }

                return true;
            }
        }

        return false;
    }
1352222
public function enum(string $property): EnumPropertyColumnDefiner
    {
        $this->verifyProperty(__METHOD__, $property);
        $type       = $this->class->getPropertyType($property);
        $isNullable = $type->isNullable();
        $enumType   = $type->nonNullable();

        if (!($enumType instanceof ObjectType)) {
            throw InvalidArgumentException::format(
                'Invalid enum property \'%s\': must map to an object type, %s given',
                $property, $type->asTypeString()
            );
        }

        $class = $enumType->getClass();

        return $this->relation($property)->asEmbedded()->enum($class, $isNullable);
    }
379250
public function isValueValid($value) {
		return $value instanceof Type\PropertyValue || $value instanceof DataType\TextType || $value instanceof DataType\URLType;
	}
370192
private static boolean isValidPropertyClass(final PropertyDescriptor _property) {
        final Class type = _property.getPropertyType();
        return Number.class.isAssignableFrom(type) || type == String.class || Date.class.isAssignableFrom(type) || type == Boolean.class;
    }
1163926
protected function isValid($type, $data)
    {
        $valid = Validation::i();

        switch ($type) {
            case 'location':
                return $valid->isLocation($data);
            case 'utc':
                return $valid->isUtc($data);
            case 'abbr':
                return $valid->isAbbr($data);
            default:
                break;
        }

        return parent::isValid($type, $data);
    }
674677
public static function isValidFieldType(string $type) : bool
    {
        try {
            $config = ConfigFactory::getByType($type, 'dummy_field');
        } catch (InvalidArgumentException $e) {
            return false;
        }

        return true;
    }
328958
private function checkType($type)
    {
        $isInType = true;

        foreach ($this->getKeys() as $key) {
            if (gettype($key) !== $type) {
                $isInType = false;
                break;
            }
        }

        return $isInType;
    }
292601
public function __isset($property)
    {
        if (method_exists($this, $getter = 'get' . $property)) {
            return $this->$getter() !== null;
        } else {
            return false;
        }
    }
450164
public function isValid($property = null) {
		$validators = $this->getValidators();
		
		if ($validators === null) {
			return true;
		}
		
		if ($property === null) {
			$data = &$this->_data;
		} else if (is_array($property)) {
			$data = array_intersect_key($this->_data, array_flip($property));

			if (empty($data)) {
				throw new Exception('Specified properties are absent');
			}
		} else {
			if (! isset($this->_data[$property])) {
				throw new Exception('Specified property is absent');
			}
			
			$data = [$property => $this->_data[$property]];
		}
		
		$valid    = true;
		$messages = [];
		
		foreach ($data as $name => $value) {
			if (! isset($validators[$name])) {
				continue;
			}
			
			foreach ($validators[$name] as $validator) {
				if ($validator->isValid($value)) {
					continue;
				}
				
				if (isset($messages[$name])) {
					$messages[$name] = array_merge($messages[$name], $validator->getMessages());
				} else {
					$messages[$name] = $validator->getMessages();
				}

				$valid = false;
				
			}
			
		}
		
		$this->_validatorsMessages = $messages;
		
		return $valid;
	}
650098
static function validate ($type, $v)
  {
    if (is_null ($v) || $v === '')
      return true;

    switch ($type) {

      case type::binding:
        return is_string ($v);

      case type::any:
      case type::bool: // Any value can be typecast to boolean.
        return true;

      case type::data:
        return is_array ($v) || is_object ($v)
               || $v instanceof \Traversable
               || (is_string ($v) && strpos ($v, '{') !== false);

      case type::id:
        return !!preg_match ('#^[\w\-]+$#', $v);

      case type::content:
        return $v instanceof Metadata || is_string ($v); // Note: content props can be specified in attribute syntax.

      case type::metadata:
        return $v instanceof Metadata;

      case type::collection:
        return is_array ($v);

      case type::number:
        return is_numeric ($v);

      case type::string:
        return is_scalar ($v) || (is_object ($v) && method_exists ($v, '__toString'));
    }
    return false;
  }