@param mixed $var
@param array $setting

@return bool|\WP_Error
162934
protected function validate( $var, $setting ) {
		$validate = $this->validate_not_empty( $var );
		if ( $setting['required'] ) {
			if ( $validate instanceof \WP_Error ) {
				return $validate;
			}
		} else {
			if ( $validate instanceof \WP_Error ) {
				return true;
			}
		}
		switch ( $setting['type'] ) {
			case 'int':
				if ( ! empty( $setting['unsigned'] ) ) {
					return $this->validate_positive_int( $var, true );
				}

				return $this->validate_int( $var );
			case 'float':
			case 'number':
				if ( ! empty( $setting['unsigned'] ) ) {
					return $this->validate_positive_float( $var, true );
				}

				return $this->validate_float( $var );
			case 'bool':
				return true;
			case 'string':
				if ( ! empty( $setting['length'] ) ) {
					return $this->validate_string_length( $var, $setting['length'] );
				}
				break;
		}

		return true;
	}
777582
protected function getTimeoutSetting($setting)
    {
        $timeoutSettings = $this->getTimeoutSettings();
        return isset($timeoutSettings[$setting]) ? $timeoutSettings[$setting] : static::DEFAULT_TIMEOUT;
    }
553203
private function _returnError(Settings $settings, Entry $entry)
    {
        if ($this->hasEventHandlers(self::EVENT_AFTER_ERROR)) {
            $this->trigger(self::EVENT_AFTER_ERROR, new SaveEvent([
                'entry' => $entry
            ]));
        }

        if (Craft::$app->getRequest()->getAcceptsJson()) {
            return $this->asJson([
                'success' => false,
                'errors' => $entry->getErrors(),
            ]);
        }

        Craft::$app->getSession()->setError(Craft::t('guest-entries', 'Couldn’t save entry.'));

        // Send the entry back to the template
        Craft::$app->getUrlManager()->setRouteParams([
            'variables' => [$settings->entryVariable => $entry]
        ]);

        return null;
    }
714006
public function youTryToGetSettingWithinSection($setting, $section)
    {
        $this->responseValue = $this->settingService->section($section)->get($setting, 'null');
    }
1242003
public function setContext($var)
    {
        GPBUtil::checkMessage($var, \Google\Cloud\ErrorReporting\V1beta1\ErrorContext::class);
        $this->context = $var;

        return $this;
    }
540374
public static function type_time_decode($var, array $settings)
	{
		if ($settings['data_type'] == 'time_mysql')
		{
			// deal with a 'nulled' date, which according to MySQL is a valid enough to store?
			if ($var == '0000-00-00 00:00:00')
			{
				if (array_key_exists('null', $settings) and $settings['null'] === false)
				{
					throw new InvalidContentType('Value '.$var.' is not a valid date and can not be converted to a Date object.');
				}
				return null;
			}

			return \Date::create_from_string($var, 'mysql');
		}

		return \Date::forge($var);
	}
450603
protected function validate_positive( $var, $include_zero = false ) {
		if ( ! is_numeric( $var ) ) {
			return new \WP_Error( 400, $this->app->translate( 'Invalid format.' ) );
		}
		if ( ( ! $include_zero && $var <= 0 ) || ( $include_zero && $var < 0 ) ) {
			return new \WP_Error( 400, $this->app->translate( 'Outside the range of allowed values.' ) );
		}

		return true;
	}
566004
public function init($setting = array())
    {
        if (!is_array($setting) || count($setting) == 0) return $this;
        foreach ($setting as $key => $value) {
            if (property_exists($this, $key)) {
                $this->$key = (string)$value;
            }
        }

        return $this;
    }
671911
final public static function get_instance( array $setting = [] ) {
		$class_name = get_called_class();
		if ( ! isset( self::$instances[ $class_name ] ) ) {
			self::$instances[ $class_name ] = new $class_name( $setting );
		}

		return self::$instances[ $class_name ];
	}
1226433
public static function type_integer($var, array $settings)
	{
		if (is_array($var) or is_object($var))
		{
			throw new InvalidContentType('Array or object could not be converted to integer.');
		}

		if ((array_key_exists('min', $settings) and $var < intval($settings['min']))
			or (array_key_exists('max', $settings) and $var > intval($settings['max'])))
		{
			throw new InvalidContentType('Integer value outside of range: '.$var);
		}

		return intval($var);
	}
958219
public static function settings($settings=array())
		{
			self::$_readOnce 		= isset($settings['readOnce']) ? (boolean) $settings['readOnce'] : false;
			self::$_defaultReturn 	= (array_key_exists('defaultReturn',$settings)) ? $settings['defaultReturn'] : 'ST__EXCEPTION';
		}
1203454
public function getSetting(string $setting) {
		$settings = $this->getSettings();
		$keys = array_keys($settings);
		
		if (!in_array($setting, $keys)) {
			throw new ControllerException("Unknown setting: $setting.",
				ControllerException::UNKNOWN_SETTING);
		}
		
		return $settings[$setting];
	}
644243
public function initBySetting($model, $setting)
    {
        parent::initBySetting($model, $setting);
        if (is_array($setting)) {
            $setting = new \Stack\Util\ArrayObject($setting);
            $this->options = $setting->getAsArray('options');
            $this->allowNull = $setting->getAsBoolean('allowNull', TRUE);
        }
        if (!$this->allowNull && empty($this->options)) {
            throw new \Exception('No options defined for the selection attribute');
        }
    }
201546
public static function type_json_encode($var, array $settings)
	{
		$var = json_encode($var);

		if (array_key_exists('character_maximum_length', $settings))
		{
			$length  = intval($settings['character_maximum_length']);
			if ($length > 0 and strlen($var) > $length)
			{
				throw new InvalidContentType('Value could not be JSON encoded, exceeds max string length for field.');
			}
		}

		return $var;
	}
130377
public static function set($key,$value,$settings=array())
		{
			self::_cleanPrevious();

			$settings['readOnce'] = isset($settings['readOnce']) ? (boolean) $settings['readOnce'] : self::$_readOnce;

			$_SESSION[self::$_sessionKey.$key] = array(1,$value,$settings);
		}
144545
public function setting($setting, $default = null)
    {
        $value = parent::setting($setting);
        if (null === $value) {
            $value = isset(static::$globalSettings[$setting]) ? static::$globalSettings[$setting] : $default;
        }

        return $value;
    }
901790
public function checkSPSettings($settings)
    {
        assert('is_array($settings)');

        if (!is_array($settings) || empty($settings)) {
            return array('invalid_syntax');
        }

        $errors = array();

        if (!isset($settings['sp']) || empty($settings['sp'])) {
            $errors[] = 'sp_not_found';
        } else {
            $sp = $settings['sp'];
            $security = array();
            if (isset($settings['security'])) {
                $security = $settings['security'];
            }

            if (!isset($sp['entityId']) || empty($sp['entityId'])) {
                $errors[] = 'sp_entityId_not_found';
            }

            if (!isset($sp['assertionConsumerService'])
                || !isset($sp['assertionConsumerService']['url'])
                || empty($sp['assertionConsumerService']['url'])
            ) {
                $errors[] = 'sp_acs_not_found';
            } else if (!filter_var($sp['assertionConsumerService']['url'], FILTER_VALIDATE_URL)) {
                $errors[] = 'sp_acs_url_invalid';
            }

            if (isset($sp['singleLogoutService'])
                && isset($sp['singleLogoutService']['url'])
                && !filter_var($sp['singleLogoutService']['url'], FILTER_VALIDATE_URL)
            ) {
                $errors[] = 'sp_sls_url_invalid';
            }

            if (isset($security['signMetadata']) && is_array($security['signMetadata']) &&
                (!isset($security['signMetadata']['keyFileName']) || !isset($security['signMetadata']['certFileName']))) {
                $errors[] = 'sp_signMetadata_invalid';
            }

            if (((isset($security['authnRequestsSigned']) && $security['authnRequestsSigned'] == true)
                || (isset($security['logoutRequestSigned']) && $security['logoutRequestSigned'] == true)
                || (isset($security['logoutResponseSigned']) && $security['logoutResponseSigned'] == true)
                || (isset($security['wantAssertionsEncrypted']) && $security['wantAssertionsEncrypted'] == true)
                || (isset($security['wantNameIdEncrypted']) && $security['wantNameIdEncrypted'] == true))
                && !$this->checkSPCerts()
            ) {
                $errors[] = 'sp_certs_not_found_and_required';
            }
        }

        if (isset($settings['contactPerson'])) {
            $types = array_keys($settings['contactPerson']);
            $validTypes = array('technical', 'support', 'administrative', 'billing', 'other');
            foreach ($types as $type) {
                if (!in_array($type, $validTypes)) {
                    $errors[] = 'contact_type_invalid';
                    break;
                }
            }

            foreach ($settings['contactPerson'] as $type => $contact) {
                if (!isset($contact['givenName']) || empty($contact['givenName'])
                    || !isset($contact['emailAddress']) || empty($contact['emailAddress'])
                ) {
                    $errors[] = 'contact_not_enought_data';
                    break;
                }
            }
        }

        if (isset($settings['organization'])) {
            foreach ($settings['organization'] as $organization) {
                if (!isset($organization['name']) || empty($organization['name'])
                    || !isset($organization['displayname']) || empty($organization['displayname'])
                    || !isset($organization['url']) || empty($organization['url'])
                ) {
                    $errors[] = 'organization_not_enought_data';
                    break;
                }
            }
        }

        return $errors;
    }