Differences From Artifact [9567b63903]:

To Artifact [e3dead6a86]:


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73





74
75
76
77
78
79
80
		'monnaie'               => 'string',
		'pays'                  => 'string',

		'champs_membres'        => Champs::class,

		'categorie_membres'     => 'int',

		'admin_homepage'        => '?Garradin\Entities\Files\File',

		'frequence_sauvegardes' => '?int',
		'nombre_sauvegardes'    => '?int',

		'champ_identifiant'     => 'string',
		'champ_identite'        => 'string',

		'last_chart_change'     => '?int',
		'last_version_check'    => '?string',

		'couleur1'              => '?string',
		'couleur2'              => '?string',
		'admin_background'      => '?Garradin\Entities\Files\File',

		'desactiver_site'       => 'bool',
	];






	protected $_deleted_files = [];

	static protected $_instance = null;

	static public function getInstance()
	{







|












|



>
>
>
>
>







50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
		'monnaie'               => 'string',
		'pays'                  => 'string',

		'champs_membres'        => Champs::class,

		'categorie_membres'     => 'int',

		'admin_homepage'        => '?string',

		'frequence_sauvegardes' => '?int',
		'nombre_sauvegardes'    => '?int',

		'champ_identifiant'     => 'string',
		'champ_identite'        => 'string',

		'last_chart_change'     => '?int',
		'last_version_check'    => '?string',

		'couleur1'              => '?string',
		'couleur2'              => '?string',
		'admin_background'      => '?string',

		'desactiver_site'       => 'bool',
	];

	protected $_special_types = [
		'admin_homepage'        => 'Garradin\Entities\Files\File',
		'admin_background'      => 'Garradin\Entities\Files\File',
	];

	protected $_deleted_files = [];

	static protected $_instance = null;

	static public function getInstance()
	{
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126











127
128
129


130
131
132
133
134
135
136
137
138
139
140
141

		foreach ($this->_types as $key => $type) {
			$value = $config[$key];

			if ($type[0] == '?' && $value === null) {
				continue;
			}

			if ($type == File::class || substr($type, 1) == File::class) {
				$config[$key] = Files::get($value);
			}
		}

		$this->load($config);

		$this->champs_membres = new Membres\Champs((string)$this->champs_membres);
	}












	public function set(string $key, $value, bool $loose = false, bool $check_for_changes = true)
	{


		// Append to deleted files queue if it's set to null
		if (isset($this->_types[$key])
			&& substr($this->_types[$key], -strlen(File::class)) == File::class
			&& $value === null
			&& $this->$key !== null) {
			$this->_deleted_files[] = $this->$key;
		}

		parent::set($key, $value, $loose, $check_for_changes);
	}

	public function save(): bool







<
<
<
<






>
>
>
>
>
>
>
>
>
>
>



>
>

<
|
<
<







115
116
117
118
119
120
121




122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

145


146
147
148
149
150
151
152

		foreach ($this->_types as $key => $type) {
			$value = $config[$key];

			if ($type[0] == '?' && $value === null) {
				continue;
			}




		}

		$this->load($config);

		$this->champs_membres = new Membres\Champs((string)$this->champs_membres);
	}

	public function get(string $key)
	{
		$type = $this->_special_types[$key] ?? null;

		if ($type == File::class && is_string($this->$key)) {
			return Files::get($this->$key);
		}

		return parent::get($key);
	}

	public function set(string $key, $value, bool $loose = false, bool $check_for_changes = true)
	{
		$type = $this->_special_types[$key] ?? null;

		// Append to deleted files queue if it's set to null

		if ($type == File::class && null === $value && null !== $this->$key) {


			$this->_deleted_files[] = $this->$key;
		}

		parent::set($key, $value, $loose, $check_for_changes);
	}

	public function save(): bool
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
		$values = [];
		$db = DB::getInstance();

		foreach ($this->_modified as $key => $modified) {
			$value = $this->$key;
			$type = ltrim($this->_types[$key], '?');

			if ($type == File::class && null !== $value) {
				$value = $value->path();
			}
			else if ($type == Champs::class) {
				$value = $value->toString();
			}
			elseif (is_object($value)) {
				throw new \UnexpectedValueException('Unexpected object as value: ' . get_class($value));
			}

			$values[$key] = $value;







<
<
<
|







160
161
162
163
164
165
166



167
168
169
170
171
172
173
174
		$values = [];
		$db = DB::getInstance();

		foreach ($this->_modified as $key => $modified) {
			$value = $this->$key;
			$type = ltrim($this->_types[$key], '?');




			if ($type == Champs::class) {
				$value = $value->toString();
			}
			elseif (is_object($value)) {
				throw new \UnexpectedValueException('Unexpected object as value: ' . get_class($value));
			}

			$values[$key] = $value;
221
222
223
224
225
226
227
228

229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
		}
		elseif (isset($source['admin_background']) && strlen($source['admin_background'])) {
			if ($this->admin_background) {
				$this->admin_background->storeFromBase64($source['admin_background']);
				$this->admin_background->save();
			}
			else {
				$this->set('admin_background', File::createFromBase64(File::CONTEXT_CONFIG, 'admin_background.png', $source['admin_background']));

			}

			unset($source['admin_background']);
		}

		parent::importForm($source);
	}

	protected function _filterType(string $key, $value)
	{
		switch ($this->_types[$key]) {
			case 'int':
				return (int) $value;
			case 'bool':
				return (bool) $value;
			case 'string':
				return (string) $value;
			case File::class:
			case Champs::class:
				if (!is_object($value) || !($value instanceof $this->_types[$key])) {
					throw new \InvalidArgumentException(sprintf('"%s" is not of type "%s"', $key, $this->_types[$key]));
				}
				return $value;
			default:
				throw new \InvalidArgumentException(sprintf('"%s" has unknown type "%s"', $key, $this->_types[$key]));







|
>

















<







229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254

255
256
257
258
259
260
261
		}
		elseif (isset($source['admin_background']) && strlen($source['admin_background'])) {
			if ($this->admin_background) {
				$this->admin_background->storeFromBase64($source['admin_background']);
				$this->admin_background->save();
			}
			else {
				$file = File::createFromBase64(File::CONTEXT_CONFIG, 'admin_background.png', $source['admin_background']);
				$this->set('admin_background', $file->pathname());
			}

			unset($source['admin_background']);
		}

		parent::importForm($source);
	}

	protected function _filterType(string $key, $value)
	{
		switch ($this->_types[$key]) {
			case 'int':
				return (int) $value;
			case 'bool':
				return (bool) $value;
			case 'string':
				return (string) $value;

			case Champs::class:
				if (!is_object($value) || !($value instanceof $this->_types[$key])) {
					throw new \InvalidArgumentException(sprintf('"%s" is not of type "%s"', $key, $this->_types[$key]));
				}
				return $value;
			default:
				throw new \InvalidArgumentException(sprintf('"%s" has unknown type "%s"', $key, $this->_types[$key]));