/
WebFontCollectionFactory.php
37 lines (31 loc) · 1.13 KB
/
WebFontCollectionFactory.php
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
<?php
namespace Concrete\Core\StyleCustomizer\WebFont;
use Concrete\Core\Entity\Page\Theme\CustomSkin;
use Concrete\Core\StyleCustomizer\Preset\PresetInterface;
class WebFontCollectionFactory
{
/**
* @param PresetInterface $preset
* @return WebFontCollection
*/
public function createFromPreset(PresetInterface $preset): WebFontCollection
{
$presetIdentifier = $preset->getIdentifier();
$collection = new WebFontCollection();
$file = $preset->getTheme()->getThemeCustomizer()->getConfigurationFile();
if ($file) {
$xml = simplexml_load_file($file);
if ($xml->webfonts) {
foreach ($xml->webfonts->preset as $presetNode) {
if ((string) $presetNode['identifier'] == $presetIdentifier) {
foreach ($presetNode->font as $fontNode) {
$font = new WebFont((string) $fontNode['name'], (string) $fontNode['type']);
$collection->add($font);
}
}
}
}
}
return $collection;
}
}