1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Stitcher\Exception; |
4
|
|
|
|
5
|
|
|
use Pageon\Config; |
6
|
|
|
use Stitcher\File; |
7
|
|
|
use Symfony\Component\Yaml\Yaml; |
8
|
|
|
|
9
|
|
|
class InvalidConfiguration extends StitcherException |
10
|
|
|
{ |
11
|
|
|
public static function siteConfigurationFileNotFound(): InvalidConfiguration |
12
|
|
|
{ |
13
|
|
|
return new self( |
14
|
|
|
'No site configuration file was found.', |
15
|
|
|
<<<MD |
16
|
|
|
All static pages should be configured in a site configuration file. |
17
|
|
|
The path to this file can be configured in `./config/config.php` |
18
|
|
|
|
19
|
|
|
```php |
20
|
|
|
return [ |
21
|
|
|
// ... |
22
|
|
|
|
23
|
|
|
'configurationFile' => File::path('src/site.yaml'), |
24
|
|
|
]; |
25
|
|
|
``` |
26
|
|
|
|
27
|
|
|
This `site.yaml` file contains a list of routes and their configuration. |
28
|
|
|
|
29
|
|
|
```yaml |
30
|
|
|
/: |
31
|
|
|
template: home.twig |
32
|
|
|
# ... |
33
|
|
|
|
34
|
|
|
/blog/page-{page}: |
35
|
|
|
template: blog/overview.twig |
36
|
|
|
# ... |
37
|
|
|
|
38
|
|
|
/blog/{id}: |
39
|
|
|
template: blog/detail.twig |
40
|
|
|
# ... |
41
|
|
|
``` |
42
|
|
|
MD |
43
|
|
|
|
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
1 |
|
public static function pageTemplateMissing(string $pageId): InvalidConfiguration |
48
|
|
|
{ |
49
|
1 |
|
$templateDirectory = File::relativePath(Config::get('templateDirectory')); |
50
|
|
|
|
51
|
1 |
|
return new self( |
52
|
1 |
|
'A page requires a `template` value.', |
53
|
|
|
<<<MD |
54
|
1 |
|
A template file should be saved in the `$templateDirectory` folder. |
55
|
|
|
Its path is relative to this template direcotry path. |
56
|
|
|
|
57
|
|
|
```yaml |
58
|
1 |
|
$pageId: |
59
|
|
|
template: template.twig |
60
|
|
|
``` |
61
|
|
|
|
62
|
|
|
The `templateDirectory` path can be overridden in a `php` config file which lives in the `./config` directory. |
63
|
|
|
|
64
|
|
|
```php |
65
|
|
|
return [ |
66
|
|
|
// ... |
67
|
|
|
|
68
|
|
|
'templateDirectory' => File::path('resources/view'), |
69
|
|
|
]; |
70
|
|
|
``` |
71
|
|
|
MD |
72
|
|
|
|
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
1 |
|
public static function pageIdMissing($pageConfiguration): InvalidConfiguration |
77
|
|
|
{ |
78
|
1 |
|
$yaml = Yaml::dump($pageConfiguration); |
79
|
|
|
|
80
|
1 |
|
return new self('A page requires an `id` value.', <<<MD |
81
|
|
|
Instead got this: |
82
|
|
|
|
83
|
|
|
```yaml |
84
|
1 |
|
$yaml |
85
|
|
|
``` |
86
|
|
|
MD |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public static function fileNotFound(string $path): InvalidConfiguration |
91
|
|
|
{ |
92
|
|
|
return new self("File with path `{$path}` could not be found."); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public static function templateNotFound(string $path): InvalidConfiguration |
96
|
|
|
{ |
97
|
|
|
return new self("Template with path `{$path}` could not be found."); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public static function invalidAdapterConfiguration(string $adapter, string $fields): InvalidConfiguration |
101
|
|
|
{ |
102
|
|
|
return new self("The `{$adapter}` adapter requires following configuration: {$fields}"); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public static function adapterNotFound(string $adapter): InvalidConfiguration |
106
|
|
|
{ |
107
|
|
|
return new self("The adapter `{$adapter}` does not exist."); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public static function dotEnvNotFound(string $directory): InvalidConfiguration |
111
|
|
|
{ |
112
|
|
|
return new self("Could not find `.env` file. Looked in {$directory}"); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public static function missingParameter(string $parameter): InvalidConfiguration |
116
|
|
|
{ |
117
|
|
|
return new self("Missing parameter `{$parameter}`, did you add it in your config file?"); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|