Overview
Comment:Add keep parameter to include to be able to send variables to parent skeleton
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA3-256: 45e169e77f8b0e3e7910688ae72caf7db04910db078b6c73e8b8cfd6661a220e
User & Date: bohwaz on 2022-11-20 02:04:24
Other Links: branch diff | manifest | tags
Context
2022-11-20
02:04
Implement math and json_encode modifiers check-in: 73e45ba011 user: bohwaz tags: dev
02:04
Add keep parameter to include to be able to send variables to parent skeleton check-in: 45e169e77f user: bohwaz tags: dev
01:47
Change some exceptions types check-in: 33bc233c99 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/UserTemplate/Functions.php from [38c7d1eadb] to [ae984cc587].

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use const Garradin\{ROOT, WWW_URL};

class Functions
{
	const FUNCTIONS_LIST = [
		'include',
		'http',
		'dump',
		'error',
		'read',
		'save',
		'admin_header',
		'admin_footer',
		'signature',
		'mail',







|







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use const Garradin\{ROOT, WWW_URL};

class Functions
{
	const FUNCTIONS_LIST = [
		'include',
		'http',
		'debug',
		'error',
		'read',
		'save',
		'admin_header',
		'admin_footer',
		'signature',
		'mail',
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

		// Merge before update
		if ($exists) {
			$params = array_merge($exists, $params);
		}

		if ($validate) {
			$schema = self::read(['file' => $validate_schema], $tpl, $line);

			try {
				$s = JSONSchema::fromString($schema);
				$s->validate($params);
			}
			catch (\RuntimeException $e) {
				throw new Brindille_Exception(sprintf("line %d: error in validating data:\n%s\n\n%s",
					$line, $e->getMessage(), json_encode($params, JSON_PRETTY_PRINT)));
			}
		}

		$value = json_encode($params);

		if ($key == 'config') {







|






|







137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

		// Merge before update
		if ($exists) {
			$params = array_merge($exists, $params);
		}

		if ($validate) {
			$schema = self::read(['file' => $validate], $tpl, $line);

			try {
				$s = JSONSchema::fromString($schema);
				$s->validate($params);
			}
			catch (\RuntimeException $e) {
				throw new Brindille_Exception(sprintf("ligne %d: impossible de valider le schéma:\n%s\n\n%s",
					$line, $e->getMessage(), json_encode($params, JSON_PRETTY_PRINT)));
			}
		}

		$value = json_encode($params);

		if ($key == 'config') {
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
		if (empty($params['body'])) {
			throw new Brindille_Exception(sprintf('Ligne %d: argument "body" manquant pour la fonction "mail"', $line));
		}

		Emails::queue(Emails::CONTEXT_PRIVATE, [$params['to']], null, $params['subject'], $params['body']);
	}

	static public function dump(array $params, Brindille $tpl)
	{
		if (!count($params)) {
			$params = $tpl->getAllVariables();
		}

		$dump = htmlspecialchars(ErrorManager::dump($params));








|







181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
		if (empty($params['body'])) {
			throw new Brindille_Exception(sprintf('Ligne %d: argument "body" manquant pour la fonction "mail"', $line));
		}

		Emails::queue(Emails::CONTEXT_PRIVATE, [$params['to']], null, $params['subject'], $params['body']);
	}

	static public function debug(array $params, Brindille $tpl)
	{
		if (!count($params)) {
			$params = $tpl->getAllVariables();
		}

		$dump = htmlspecialchars(ErrorManager::dump($params));

273
274
275
276
277
278
279










280
281
282
283
284
285
286
			throw new Brindille_Exception(sprintf('Ligne %d : fonction "include" : le fichier à inclure "%s" n\'existe pas', $line, $path));
		}

		$params['included_from'] = array_merge($from, [$path]);

		$include->assignArray(array_merge($ut->getAllVariables(), $params));
		$include->display();










	}

	static public function http(array $params, UserTemplate $tpl): void
	{
		if (headers_sent()) {
			return;
		}







>
>
>
>
>
>
>
>
>
>







273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
			throw new Brindille_Exception(sprintf('Ligne %d : fonction "include" : le fichier à inclure "%s" n\'existe pas', $line, $path));
		}

		$params['included_from'] = array_merge($from, [$path]);

		$include->assignArray(array_merge($ut->getAllVariables(), $params));
		$include->display();

		if (isset($params['keep'])) {
			$keep = explode(',', $params['keep']);
			$keep = array_map('trim', $keep);

			foreach ($keep as $name) {
				// Transmit variables
				$ut::__assign(['var' => $name, 'value' => $include->get($name)], $ut);
			}
		}
	}

	static public function http(array $params, UserTemplate $tpl): void
	{
		if (headers_sent()) {
			return;
		}