ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
SkinnedMailAssets.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27final class SkinnedMailAssets implements MailAssets
28{
29 private const string STYLE_SHEET = 'mail.css';
30 private const string LOGO_DIRECTORY = 'images/logo';
31 private const string IMAGE_PATTERN = '/\.(jpg|jpeg|gif|svg|png)$/i';
32
34 private readonly array $locations;
35
36 public function __construct(
37 private readonly MailAssets $fallback,
38 private readonly string $skin_directory,
39 private readonly LogoByFileName $logo,
40 string $skin,
41 string $style
42 ) {
43 $this->locations = $skin === 'default' ? [] : [$skin, $skin . '/' . $style];
44 }
45
46 public function styleSheet(): AssetFile
47 {
48 foreach (array_reverse($this->locations) as $location) {
49 $path = $this->skin_directory . '/' . $location . '/' . self::STYLE_SHEET;
50
51 if (is_file($path) && is_readable($path)) {
52 return new AssetFile($path);
53 }
54 }
55
56 return $this->fallback->styleSheet();
57 }
58
59 public function inlineImages(): InlineImages
60 {
61 $images = InlineImages::none();
62
63 foreach ($this->locations as $location) {
64 $directory = $this->skin_directory . '/' . $location . '/' . self::LOGO_DIRECTORY;
65
66 if (is_dir($directory) && is_readable($directory)) {
67 $images = $images->with(...$this->imagesIn($directory));
68 }
69 }
70
71 if ($images->isEmpty()) {
72 return $this->fallback->inlineImages();
73 }
74
75 return $this->logo->markIn($images);
76 }
77
81 private function imagesIn(string $directory): array
82 {
83 $paths = [];
84 $files = new \RegexIterator(
85 new \FilesystemIterator(
86 $directory,
87 \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::SKIP_DOTS
88 ),
89 self::IMAGE_PATTERN
90 );
91
92 foreach ($files as $path) {
93 if (is_file($path) && is_readable($path)) {
94 $paths[] = $path;
95 }
96 }
97
98 sort($paths);
99
100 return array_map(static fn(string $path): InlineImage => InlineImage::at($path), $paths);
101 }
102}
$location
Definition: buildRTE.php:22
A readable file an HTML mail is built from.
Definition: AssetFile.php:33
Designates one of a set of images as the mail's logo by file name convention, falling back to the fir...
Prefers the mail assets of a Customizing skin and falls back to the assets it decorates.
__construct(private readonly MailAssets $fallback, private readonly string $skin_directory, private readonly LogoByFileName $logo, string $skin, string $style)