-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload.stdpix.functions.php
More file actions
118 lines (100 loc) · 3.72 KB
/
Copy pathload.stdpix.functions.php
File metadata and controls
118 lines (100 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php declare(strict_types=1);
// @package webkernel/stdpix/load.stdpix.functions.php
use Webkernel\StdPix\BrandingStore;
if (!function_exists('webkernel_branding_store')) {
/**
* Returns the singleton BrandingStore, initializing it on first call.
* @return BrandingStore
*/
function webkernel_branding_store(): BrandingStore
{
static $store = null;
if ($store !== null) {
return $store;
}
$store = new BrandingStore();
try {
$brandsPath = webkernel_package('standard-pix', 'res/brands', relative: false);
foreach (['webkernel', 'numerimondes', 'thebestrecruit'] as $brand) {
$store->loadFromDirectory("{$brandsPath}/{$brand}", $brand);
}
} catch (\Throwable) {
// Brand assets are non-critical — silenced.
}
$store->registerRoutes();
return $store;
}
}
if (!function_exists('webkernel_branding_url')) {
/**
* Return the WebkernelRouter URL for a registered branding asset.
*
* @param string $key Branding asset key.
* @return string Absolute URL served by WebkernelRouter.
*/
function webkernel_branding_url(string $key): string
{
return webkernel_branding_store()->url($key);
}
}
if (!function_exists('webkernel_svg_collection_paths')) {
/**
* Returns the ordered list of directories searched by webkernel_grab_icon().
* Evaluated on first call, not at include time — BASE_PATH must be defined
* before this function is called, not before the file is loaded.
*
* @return list<string>
*/
function webkernel_svg_collection_paths(): array
{
static $paths = null;
if ($paths !== null) {
return $paths;
}
$paths = \Webkernel\StdPix\GetIcons::paths();
return $paths;
}
}
if (!function_exists('webkernel_grab_icon')) {
/**
* Grab an SVG icon from the Webkernel icon collections and inject class and style.
*
* @param string $filename Icon name without extension (e.g. "arrow-right").
* @param string $class Optional CSS classes to inject.
* @param string $style Optional inline styles to inject.
* @return string|null Raw SVG markup, or null if not found.
*/
function webkernel_grab_icon(string $filename, string $class = '', string $style = ''): ?string
{
foreach (webkernel_svg_collection_paths() as $rel) {
$path = project_root($rel);
$full = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $filename . '.svg';
if (is_file($full)) {
$svg = file_get_contents($full);
if ($svg === false) {
return null;
}
// Préparation des attributs à injecter
$inject = '';
if ($class !== '') {
$inject .= ' class="' . htmlspecialchars($class, ENT_QUOTES, 'UTF-8') . '"';
}
if ($style !== '') {
$inject .= ' style="' . htmlspecialchars($style, ENT_QUOTES, 'UTF-8') . '"';
}
// Injection ultra-rapide juste après la balise ouvrante <svg
if ($inject !== '') {
$svg = substr_replace($svg, $inject, 4, 0);
}
return $svg;
}
}
return null;
}
}
// Eagerly initialize branding assets (and register their /__webkernel-app/ routes)
// as soon as this file is loaded via Composer. This ensures routes exist when
// WebkernelRouter dispatch runs after the autoloader (in public/index.php).
if (php_sapi_name() !== 'cli') {
webkernel_branding_store();
}