-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
preflight.php
71 lines (57 loc) · 3.59 KB
/
preflight.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
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
<?php
declare(strict_types=1);
use Symfony\Component\Yaml\Yaml as SymfonyYaml;
$flextypeManifestFilePath = ROOT_DIR . '/src/flextype/flextype.yaml';
$defaultFlextypeSettingsFilePath = ROOT_DIR . '/src/flextype/settings.yaml';
$customFlextypeSettingsFilePath = PATH['project'] . '/config/flextype/settings.yaml';
$preflightFlextypePath = PATH['tmp'] . '/preflight/flextype/';
$customFlextypeSettingsPath = PATH['project'] . '/config/flextype/';
! filesystem()->directory($preflightFlextypePath)->exists() and filesystem()->directory($preflightFlextypePath)->create(0755, true);
! filesystem()->directory($customFlextypeSettingsPath)->exists() and filesystem()->directory($customFlextypeSettingsPath)->create(0755, true);
$f1 = file_exists($flextypeManifestFilePath) ? filemtime($flextypeManifestFilePath) : '';
$f2 = file_exists($defaultFlextypeSettingsFilePath) ? filemtime($defaultFlextypeSettingsFilePath) : '';
$f3 = file_exists($customFlextypeSettingsFilePath) ? filemtime($customFlextypeSettingsFilePath) : '';
// Create Unique Cache ID
$cacheID = md5($flextypeManifestFilePath . $defaultFlextypeSettingsFilePath . $customFlextypeSettingsFilePath . $f1 . $f2 . $f3);
if (filesystem()->file($preflightFlextypePath . '/' . $cacheID . '.txt')->exists()) {
$flextypeData = unserialize(filesystem()->file($preflightFlextypePath . '/' . $cacheID . '.txt')->get());
} else {
// Set settings if Flextype Default settings config files exist
if (! filesystem()->file($defaultFlextypeSettingsFilePath)->exists()) {
throw new RuntimeException('Flextype Default settings config file does not exist.');
}
if (($defaultFlextypeSettingsContent = filesystem()->file($defaultFlextypeSettingsFilePath)->get()) === false) {
throw new RuntimeException('Load file: ' . $defaultFlextypeSettingsFilePath . ' - failed!');
} else {
if (trim($defaultFlextypeSettingsContent) === '') {
$defaultFlextypeSettings['settings'] = [];
} else {
$defaultFlextypeSettings['settings'] = SymfonyYaml::parse($defaultFlextypeSettingsContent);
}
}
// Create flextype custom settings file
! filesystem()->file($customFlextypeSettingsFilePath)->exists() and filesystem()->file($customFlextypeSettingsFilePath)->put($defaultFlextypeSettingsContent);
if (($customFlextypeSettingsContent = filesystem()->file($customFlextypeSettingsFilePath)->get()) === false) {
throw new RuntimeException('Load file: ' . $customFlextypeSettingsFilePath . ' - failed!');
} else {
if (trim($customFlextypeSettingsContent) === '') {
$customFlextypeSettings['settings'] = [];
} else {
$customFlextypeSettings['settings'] = SymfonyYaml::parse($customFlextypeSettingsContent);
}
}
if (($flextypeManifestContent = filesystem()->file($flextypeManifestFilePath)->get()) === false) {
throw new RuntimeException('Load file: ' . $flextypeManifestFilePath . ' - failed!');
} else {
if (trim($flextypeManifestContent) === '') {
$flextypeManifest['manifest'] = [];
} else {
$flextypeManifest['manifest'] = SymfonyYaml::parse($flextypeManifestContent);
}
}
// Merge flextype default settings with custom project settings.
$flextypeData = array_replace_recursive($defaultFlextypeSettings, $customFlextypeSettings, $flextypeManifest);
filesystem()->file($preflightFlextypePath . $cacheID . '.txt')->put(serialize($flextypeData));
}
// Store flextype merged data in the flextype registry.
flextype()->container()->get('registry')->set('flextype', $flextypeData);