Data/DataContainer.php
private function checkTypes(string $property, $value)
    {
        $integrityConstraints = $this->getIntegritySpecification($property);

        $actualValueType = gettype($value);

        if ($actualValueType == 'double') {
            $actualValueType = is_int($value) ? 'integer' : 'number';
        } else {
            if ($actualValueType == 'NULL') {
                $actualValueType = 'null';
            }
        }

        if (count($integrityConstraints)) {
            // object check
            if ($actualValueType == 'object') {
                if (!in_array(get_class($value), $integrityConstraints)) {
                    throw new PropertyValueNotValidException("Type error: Property [$property] accepts only [".implode(',', $integrityConstraints).'], but given value is instance of : [' . get_class($value).']');
                }
            } else {
                // primitive type value
                $isValidType = false;
                foreach ($integrityConstraints as $type) {
                    if ($type === 'object' && is_object($value)) {
                        $isValidType = true;
                        break;
                    } elseif ($type == 'array' && is_array($value)) {
                        $isValidType = true;
                        break;
                    } elseif ($type == 'string' && is_string($value)) {
                        $isValidType = true;
                        break;
                    } elseif ($type == 'number' && is_numeric($value)) {
                        $isValidType = true;
                        break;
                    } elseif (($type == 'integer' || $type == 'int') && is_int($value)) {
                        $isValidType = true;
                        break;
                    } elseif (($type == 'boolean' || $type == 'bool') && is_bool($value)) {
                        $isValidType = true;
                        break;
                    } elseif ($type == 'null' && $value === null) {
                        $isValidType = true;
                        break;
                    }
                }
                if (!$isValidType) {
                    throw new PropertyValueNotValidException("Type error: Property [$property] accepts only [".implode(',', $integrityConstraints)."], but given value is: [$actualValueType]");
                }
            }
        }

        return true;
    }
private function checkTypes(string $property, $value)
    {
        $integrityConstraints = $this->getIntegritySpecification($property);

        $actualValueType = gettype($value);

        if ($actualValueType == 'double') {
            $actualValueType = is_int($value) ? 'integer' : 'number';
        } else {
            if ($actualValueType == 'NULL') {
                $actualValueType = 'null';
            }
        }

        if (count($integrityConstraints)) {
            // object check
            if ($actualValueType == 'object') {
                if (!in_array(get_class($value), $integrityConstraints)) {
                    throw new PropertyValueNotValidException("Type error: Property [$property] accepts only [".implode(',', $integrityConstraints).'], but given value is instance of : [' . get_class($value).']');
                }
            } else {
                // primitive type value
                $isValidType = false;
                foreach ($integrityConstraints as $type) {
                    if ($type === 'object' && is_object($value)) {
                        $isValidType = true;
                        break;
                    } elseif ($type == 'array' && is_array($value)) {
                        $isValidType = true;
                        break;
                    } elseif ($type == 'string' && is_string($value)) {
                        $isValidType = true;
                        break;
                    } elseif ($type == 'number' && is_numeric($value)) {
                        $isValidType = true;
                        break;
                    } elseif (($type == 'integer' || $type == 'int') && is_int($value)) {
                        $isValidType = true;
                        break;
                    } elseif (($type == 'boolean' || $type == 'bool') && is_bool($value)) {
                        $isValidType = true;
                        break;
                    } elseif ($type == 'null' && $value === null) {
                        $isValidType = true;
                        break;
                    }
                }
                if (!$isValidType) {
                    throw new PropertyValueNotValidException("Type error: Property [$property] accepts only [".implode(',', $integrityConstraints)."], but given value is: [$actualValueType]");
                }
            }
        }

        return true;
    }
private function checkTypes ( string $ property , $ value ) { $ integrityConstraints = $ this -> getIntegritySpecification ( $ property ) ; $ actualValueType = gettype ( $ value ) ; if ( $ actualValueType == 'double' ) { $ actualValueType = is_int ( $ value ) ? 'integer' : 'number' ; } else { if ( $ actualValueType == 'NULL' ) { $ actualValueType = 'null' ; } } if ( count ( $ integrityConstraints ) ) { // object check if ( $ actualValueType == 'object' ) { if ( ! in_array ( get_class ( $ value ) , $ integrityConstraints ) ) { throw new PropertyValueNotValidException ( "Type error: Property [$property] accepts only [" . implode ( ',' , $ integrityConstraints ) . '], but given value is instance of : [' . get_class ( $ value ) . ']' ) ; } } else { // primitive type value $ isValidType = false ; foreach ( $ integrityConstraints as $ type ) { if ( $ type === 'object' && is_object ( $ value ) ) { $ isValidType = true ; break ; } elseif ( $ type == 'array' && is_array ( $ value ) ) { $ isValidType = true ; break ; } elseif ( $ type == 'string' && is_string ( $ value ) ) { $ isValidType = true ; break ; } elseif ( $ type == 'number' && is_numeric ( $ value ) ) { $ isValidType = true ; break ; } elseif ( ( $ type == 'integer' || $ type == 'int' ) && is_int ( $ value ) ) { $ isValidType = true ; break ; } elseif ( ( $ type == 'boolean' || $ type == 'bool' ) && is_bool ( $ value ) ) { $ isValidType = true ; break ; } elseif ( $ type == 'null' && $ value === null ) { $ isValidType = true ; break ; } } if ( ! $ isValidType ) { throw new PropertyValueNotValidException ( "Type error: Property [$property] accepts only [" . implode ( ',' , $ integrityConstraints ) . "], but given value is: [$actualValueType]" ) ; } } } return true ; }
Check property value type
@param string $property
@param mixed $value
@return bool
@throws PropertyValueNotValidException
Check property value type