Hydrate a setting object into a SettingEntity

@param \stdClass $setting
@return SettingEntity
191066
public static function hydrate(stdClass $setting)
    {
        $hydrated = new SettingEntity();

        if (isset($setting->key)) {
            $hydrated->setKey($setting->key);
        }

        if (isset($setting->value)) {
            $hydrated->setValue($setting->value);
        }

        if (isset($setting->created_at)) {
            $hydrated->setCreatedAt(new DateTime($setting->created_at));
        }

        return $hydrated;
    }
1219665
public static function hydrate(stdClass $validator)
    {
        $hydrated = new ValidatorEntity();

        if (isset($validator->id)) {
            $hydrated->setId($validator->id);
        }

        if (isset($validator->class)) {
            $hydrated->setClass($validator->class);
        }

        if (isset($validator->method)) {
            $hydrated->setMethod($validator->method);
        }

        if (isset($validator->parameter)) {
            $hydrated->setParameter($validator->parameter);
        }

        if (isset($validator->characters)) {
            $hydrated->setCharacters($validator->characters);
        }

        if (isset($validator->issueType)) {
            $hydrated->setIssueType(TypeHydrator::hydrate($validator->issueType));
        }

        return $hydrated;
    }
229482
public static function hydrate(stdClass $queue)
    {
        $hydrated = new QueueEntity();

        if (isset($queue->id)) {
            $hydrated->setId($queue->id);
        }

        if (isset($queue->started_at)) {
            $hydrated->setStartedAt(new DateTime($queue->started_at));
        }

        if (isset($queue->finished_at)) {
            $hydrated->setFinishedAt(new DateTime($queue->finished_at));
        }

        return $hydrated;
    }
208951
public function updatePrivacy($setting) {
		// Make sure we're logged in and have a valid access token.
		if (!$this->auth_token || !$this->username) {
			return FALSE;
		}

		$timestamp = parent::timestamp();
		$result = parent::post(
			'/settings',
			array(
				'action' => 'updatePrivacy',
				'privacySetting' => $setting,
				'timestamp' => $timestamp,
				'username' => $this->username,
			),
			array(
				$this->auth_token,
				$timestamp,
			)
		);

		return isset($result->param) && $result->param == $setting;
	}
567774
public function importSetting($setting)
    {
        $short_name = basename(str_replace('\\', '/', get_class($setting)));

        $method = 'importSetting' . $short_name;

        if (method_exists($this, $method)) {
            $this->$method($setting);
        }
    }
1168523
public static function hydrate(stdClass $ignore)
    {
        $hydrated = new IgnoredCodeEntity();

        if (isset($ignore->id)) {
            $hydrated->setId($ignore->id);
        }

        if (isset($ignore->class)) {
            $hydrated->setClass($ignore->class);
        }

        if (isset($ignore->method)) {
            $hydrated->setMethod($ignore->method);
        }

        if (isset($ignore->exclude)) {
            $hydrated->setExclude($ignore->exclude);
        }

        return $hydrated;
    }
1262591
public function setSetting($setting_key, $focus, $value, $context = '', $user = null)
    {
        $em = $this->getEntityManager();

        $params = array();
        $params['setting_key'] = $setting_key;
        $params['focus'] = $focus;

        if ($context) {
            $params['context'] = $context;
        }
        if ($user) {
            $params['user'] = $user;
        }

        $setting = $this->findOneBy($params);

        // We create the new setting if it not exists
        if (!$setting) {
            $class_name = $this->container->getParameter('acs_settings.setting_class');
            $setting = new $class_name;
            $setting->setSettingKey($setting_key);
            $setting->setFocus($focus);
            $setting->setContext($context);
        }

        $setting->setValue($value);

        $em->persist($setting);
        $em->flush();

        return $setting;
    }
862623
public final function get_config($setting = null) {
        global $DB;

        if ($setting) {
            if (!$this->assignment->has_instance()) {
                return false;
            }
            $assignment = $this->assignment->get_instance();
            if ($assignment) {
                $dbparams = array('assignment'=>$assignment->id,
                                  'subtype'=>$this->get_subtype(),
                                  'plugin'=>$this->get_type(),
                                  'name'=>$setting);
                $result = $DB->get_record('assign_plugin_config', $dbparams, '*', IGNORE_MISSING);
                if ($result) {
                    return $result->value;
                }
            }
            return false;
        }
        $dbparams = array('assignment'=>$this->assignment->get_instance()->id,
                          'subtype'=>$this->get_subtype(),
                           'plugin'=>$this->get_type());
        $results = $DB->get_records('assign_plugin_config', $dbparams);

        $config = new stdClass();
        if (is_array($results)) {
            foreach ($results as $setting) {
                $name = $setting->name;
                $config->$name = $setting->value;
            }
        }
        return $config;
    }
698156
public function write_setting($data) {
        global $DB, $SITE, $COURSE;
        if (!in_array($data, array_keys($this->choices))) {
            return get_string('errorsetting', 'admin');
        }
        $record = new stdClass();
        $record->id           = SITEID;
        $temp                 = $this->name;
        $record->$temp        = $data;
        $record->timemodified = time();

        course_get_format($SITE)->update_course_format_options($record);
        $DB->update_record('course', $record);

        // Reset caches.
        $SITE = $DB->get_record('course', array('id'=>$SITE->id), '*', MUST_EXIST);
        if ($SITE->id == $COURSE->id) {
            $COURSE = $SITE;
        }
        format_base::reset_course_cache($SITE->id);

        return '';

    }
76817
public function getTransient(string $setting = '')
    {
        $data = $this->get();
        $settings = $data['transient'];

        if ('' !== $setting) {
            if (isset($settings[$setting])) {
                return $settings[$setting];
            }

            if (false !== \strpos($setting, '.')) {
                // convert dot notation to nested arrays
                $keys = \explode('.', $setting);
                foreach ($keys as $key) {
                    if (isset($settings[$key])) {
                        $settings = $settings[$key];
                    } else {
                        return null;
                    }
                }

                return $settings;
            }

            return null;
        }

        return $settings;
    }
1100610
public function bySetting($model, $setting)
    {
        $class = 'Stack\\Attribute';
        if (is_string($setting)) {
            $class .= '\\' . ucfirst($setting);
        } else if (is_array($setting) && isset($setting['attribute'])) {
            $class .= '\\' . ucfirst($setting['attribute']);
        }
        if (strtolower($class) != strtolower(get_class($this))) {
            return (new $class)->bySetting($model, $setting);
        }
        $this->initBySetting($model, $setting);
        return $this;
    }
431858
public static function hydrate(stdClass $comment)
    {
        $hydrated = new CommentEntity();

        if (isset($comment->id)) {
            $hydrated->setId($comment->id);
        }

        if (isset($comment->comment)) {
            $hydrated->setComment($comment->comment);
        }

        if (isset($comment->created_at)) {
            $hydrated->setCreatedAt(new DateTime($comment->created_at));
        }

        if (isset($comment->created_by)) {
            $hydrated->setCreatedBy(UserHydrator::hydrate($comment->created_by));
        }

        if (isset($comment->source)) {
            $hydrated->setSource($comment->source);
        }

        if (isset($comment->issue)) {
            $hydrated->setIssue(IssueHydrator::hydrate($comment->issue));
        }

        return $hydrated;
    }
1163254
public function addSlave(array $setting)
    {
        $database = new Database($setting);
        $database->setMaster($this);
        $this->_slaves[] = $database;
    }
1095743
public static function hydrate(stdClass $customClass)
    {
        $hydrated = new CustomClassEntity();

        if (isset($customClass->id)) {
            $hydrated->setId($customClass->id);
        }

        if (isset($customClass->start_line)) {
            $hydrated->setStartLine($customClass->start_line);
        }

        if (isset($customClass->end_line)) {
            $hydrated->setEndLine($customClass->end_line);
        }

        if (isset($customClass->start_column)) {
            $hydrated->setStartColumn($customClass->start_column);
        }

        if (isset($customClass->end_column)) {
            $hydrated->setEndColumn($customClass->end_column);
        }

        if (isset($customClass->name)) {
            $hydrated->setName($customClass->name);
        }

        if (isset($customClass->file)) {
            $hydrated->setFile(FileHydrator::hydrate($customClass->file));
        }
    
        if (isset($customClass->package)) {
            $hydrated->setPackage($customClass->package);
        }

        return $hydrated;
    }
150384
public static function hydrate(stdClass $log)
    {
        $hydrated = new LogEntity();

        if (isset($log->id)) {
            $hydrated->setId($log->id);
        }

        if (isset($log->text)) {
            $hydrated->setText($log->text);
        }

        if (isset($log->level)) {
            $hydrated->setLevel($log->level);
        }

        if (isset($log->channel)) {
            $hydrated->setChannel($log->channel);
        }

        if (isset($log->request_uri)) {
            $hydrated->setRequestUri($log->request_uri);
        }

        if (isset($log->request_method)) {
            $hydrated->setRequestMethod($log->request_method);
        }

        if (isset($log->ip)) {
            $hydrated->setIp($log->ip);
        }

        if (isset($log->created_by)) {
            $hydrated->setCreatedBy(UserHydrator::hydrate($log->created_by));
        }

        if (isset($log->email)) {
            $hydrated->setEmail($log->email);
        }

        if (isset($log->organization)) {
            $hydrated->setOrganization(OrgHydrator::hydrate($log->organization));
        }

        if (isset($log->organization_name)) {
            $hydrated->setOrganizationName($log->organization_name);
        }

        if (isset($log->context)) {
            $hydrated->setContext($log->context);
        }

        if (isset($log->created_at)) {
            $hydrated->setCreatedAt(new DateTime($log->created_at));
        }

        if (isset($log->user_agent)) {
            $hydrated->setUserAgent($log->user_agent);
        }

        return $hydrated;
    }
1032583
public static function hydrate(stdClass $type)
    {
        $hydrated = new TypeEntity();

        if (isset($type->id)) {
            $hydrated->setId($type->id);
        }

        if (isset($type->tag)) {
            $hydrated->setTag($type->tag);
        }

        if (isset($type->description)) {
            $hydrated->setDescription($type->description);
        }

        if (isset($type->name)) {
            $hydrated->setName($type->name);
        }

        if (isset($type->markup)) {
            $hydrated->setMarkup($type->markup);
        }

        if (isset($type->severity)) {
            $hydrated->setSeverity($type->severity);
        }

        if (isset($type->effort)) {
            $hydrated->setEffort($type->effort);
        }

        if (isset($type->second_order)) {
            $hydrated->setSecondOrder($type->second_order);
        }

        if (isset($type->cwe)) {
            $hydrated->setCwe($type->cwe);
        }

        if (isset($type->owasp2010)) {
            $hydrated->setOwasp2010($type->owasp2010);
        }

        if (isset($type->owasp2013)) {
            $hydrated->setOwasp2013($type->owasp2013);
        }

        if (isset($type->owasp2017)) {
            $hydrated->setOwasp2017($type->owasp2017);
        }

        if (isset($type->sans)) {
            $hydrated->setSans($type->sans);
        }

        if (isset($type->pcidss)) {
            $hydrated->setPcidss($type->pcidss);
        }

        if (isset($type->asvs301)) {
            $hydrated->setAsvs301($type->asvs301);
        }

        if (isset($type->asvs401)) {
            $hydrated->setAsvs401($type->asvs401);
        }

        if (isset($type->enabled)) {
            $hydrated->setEnabled($type->enabled);
        }

        if (isset($type->category)) {
            $hydrated->setCategory($type->category);
        }

        if (isset($type->parent)) {
            $hydrated->setParent(self::hydrate($type->parent));
        }

        if (isset($type->resources)) {
            $hydrated->setResources(ResourceHydrator::hydrateCollection($type->resources));
        }

        if (isset($type->inactive)) {
            $hydrated->setInactive($type->inactive);
        }

        if (isset($type->languages) && is_array($type->languages)) {
            $hydrated->setLanguages(LanguageHydrator::hydrateCollection($type->languages));
        }

        return $hydrated;
    }
1266033
protected function populate(stdClass $response)
    {
        $keys = clone $this;

        $resp = $response->keys;
        $keys->data->basicAuth = $this->getIfSet('basicAuth', $resp);
        $keys->data->encryption = $this->getIfSet('encryption', $resp);

        return $keys;
    }