1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Contract\Container; |
4: | |
5: | use Salient\Contract\Console\ConsoleInterface as Console; |
6: | use Salient\Contract\Curler\CurlerInterface; |
7: | use Salient\Contract\Sync\SyncNamespaceHelperInterface; |
8: | use Salient\Contract\Sync\SyncStoreInterface; |
9: | use Closure; |
10: | use LogicException; |
11: | |
12: | /** |
13: | * @api |
14: | */ |
15: | interface ApplicationInterface extends ContainerInterface |
16: | { |
17: | /** |
18: | * Get the name of the application |
19: | */ |
20: | public function getName(): string; |
21: | |
22: | /** |
23: | * Get the version of the application, optionally including its commit |
24: | * reference |
25: | */ |
26: | public function getVersion(bool $withRef = true): string; |
27: | |
28: | /** |
29: | * Get the application's name, version and commit reference, followed by the |
30: | * PHP version |
31: | */ |
32: | public function getVersionString(): string; |
33: | |
34: | /** |
35: | * Get the application's base path |
36: | */ |
37: | public function getBasePath(): string; |
38: | |
39: | /** |
40: | * Get a cache directory for the application |
41: | */ |
42: | public function getCachePath(): string; |
43: | |
44: | /** |
45: | * Get a directory for configuration files created by the application |
46: | */ |
47: | public function getConfigPath(): string; |
48: | |
49: | /** |
50: | * Get a data directory for the application |
51: | */ |
52: | public function getDataPath(): string; |
53: | |
54: | /** |
55: | * Get a directory for the application's log files |
56: | */ |
57: | public function getLogPath(): string; |
58: | |
59: | /** |
60: | * Get a directory for the application's temporary files |
61: | */ |
62: | public function getTempPath(): string; |
63: | |
64: | /** |
65: | * Check if the application is running in a production environment |
66: | */ |
67: | public function isRunningInProduction(): bool; |
68: | |
69: | /** |
70: | * Check if console output is being logged to the application's log |
71: | * directory |
72: | */ |
73: | public function hasOutputLog(): bool; |
74: | |
75: | /** |
76: | * Log console output to the application's log directory |
77: | * |
78: | * Messages with levels between `LEVEL_EMERGENCY` and `LEVEL_INFO` are |
79: | * written to `<name>.log`. |
80: | * |
81: | * If `$debug` is `true`, or `$debug` is `null` and debug mode is enabled in |
82: | * the environment, messages with levels between `LEVEL_EMERGENCY` and |
83: | * `LEVEL_DEBUG` are also written to `<name>.debug.log`. |
84: | * |
85: | * @param string|null $name If `null`, the name of the application is used. |
86: | * @return $this |
87: | * @throws LogicException if console output is already being logged. |
88: | */ |
89: | public function logOutput(?string $name = null, ?bool $debug = null); |
90: | |
91: | /** |
92: | * Check if the application's HTTP requests are being recorded |
93: | * |
94: | * Returns `true` if {@see recordHar()} has been called, even if no |
95: | * subsequent HTTP requests have been made. |
96: | */ |
97: | public function hasHarRecorder(): bool; |
98: | |
99: | /** |
100: | * Record the application's HTTP requests to an HTTP Archive (HAR) file in |
101: | * its log directory |
102: | * |
103: | * If any HTTP requests are made via {@see CurlerInterface} implementations, |
104: | * they are recorded in `<name>-<timestamp>-<uuid>.har`. |
105: | * |
106: | * @param string|null $name If `null`, the name of the application is used. |
107: | * @param (Closure(): string)|string|null $uuid |
108: | * @return $this |
109: | * @throws LogicException if HTTP requests are already being recorded. |
110: | */ |
111: | public function recordHar( |
112: | ?string $name = null, |
113: | ?string $creatorName = null, |
114: | ?string $creatorVersion = null, |
115: | $uuid = null |
116: | ); |
117: | |
118: | /** |
119: | * Get the name of the application's HTTP Archive (HAR) file if it exists |
120: | * |
121: | * Returns `null` if {@see recordHar()} has been called but no HTTP requests |
122: | * have been made. |
123: | * |
124: | * @throws LogicException if HTTP requests are not being recorded. |
125: | */ |
126: | public function getHarFilename(): ?string; |
127: | |
128: | /** |
129: | * Check if a cache has been started for the application |
130: | */ |
131: | public function hasCache(): bool; |
132: | |
133: | /** |
134: | * Start a cache for the application and make it the global cache |
135: | * |
136: | * If the cache is filesystem-backed, it is started in the application's |
137: | * cache directory. |
138: | * |
139: | * @return $this |
140: | * @throws LogicException if a cache has already been started for the |
141: | * application. |
142: | */ |
143: | public function startCache(); |
144: | |
145: | /** |
146: | * Stop the application's cache if started |
147: | * |
148: | * @return $this |
149: | */ |
150: | public function stopCache(); |
151: | |
152: | /** |
153: | * Check if a sync entity store has been started for the application |
154: | */ |
155: | public function hasSync(): bool; |
156: | |
157: | /** |
158: | * Start a sync entity store for the application and make it the global sync |
159: | * entity store |
160: | * |
161: | * If the entity store is filesystem-backed, it is started in the |
162: | * application's data directory. |
163: | * |
164: | * @return $this |
165: | * @throws LogicException if a sync entity store has already been started |
166: | * for the application. |
167: | */ |
168: | public function startSync(); |
169: | |
170: | /** |
171: | * Stop the application's sync entity store if started |
172: | * |
173: | * @return $this |
174: | */ |
175: | public function stopSync(); |
176: | |
177: | /** |
178: | * Register a namespace for sync entities and their provider interfaces with |
179: | * the application's sync entity store, starting it if necessary |
180: | * |
181: | * @see SyncStoreInterface::registerNamespace() |
182: | * |
183: | * @return $this |
184: | */ |
185: | public function sync( |
186: | string $prefix, |
187: | string $uri, |
188: | string $namespace, |
189: | ?SyncNamespaceHelperInterface $helper = null |
190: | ); |
191: | |
192: | /** |
193: | * Get the directory in which the application was started |
194: | */ |
195: | public function getInitialWorkingDirectory(): string; |
196: | |
197: | /** |
198: | * Set the directory in which the application was started |
199: | * |
200: | * @return $this |
201: | */ |
202: | public function setInitialWorkingDirectory(string $directory); |
203: | |
204: | /** |
205: | * Change to the directory in which the application was started |
206: | * |
207: | * @return $this |
208: | */ |
209: | public function restoreWorkingDirectory(); |
210: | |
211: | /** |
212: | * Write the application's name, version and commit reference, followed by |
213: | * the PHP version, to the console |
214: | * |
215: | * @param Console::LEVEL_* $level |
216: | * @return $this |
217: | */ |
218: | public function reportVersion(int $level = Console::LEVEL_INFO); |
219: | |
220: | /** |
221: | * Write a summary of the application's system resource usage to the console |
222: | * |
223: | * @param Console::LEVEL_* $level |
224: | * @return $this |
225: | */ |
226: | public function reportResourceUsage(int $level = Console::LEVEL_INFO); |
227: | |
228: | /** |
229: | * Write a summary of the application's runtime performance metrics to the |
230: | * console |
231: | * |
232: | * @param Console::LEVEL_* $level |
233: | * @param string[]|string|null $groups If `null` or `["*"]`, all metrics are |
234: | * reported, otherwise only metrics in the given groups are reported. |
235: | * @return $this |
236: | */ |
237: | public function reportMetrics( |
238: | int $level = Console::LEVEL_INFO, |
239: | bool $includeRunningTimers = true, |
240: | $groups = null, |
241: | ?int $limit = 10 |
242: | ); |
243: | |
244: | /** |
245: | * Write a summary of the application's runtime performance metrics and |
246: | * system resource usage to the console when it terminates |
247: | * |
248: | * @param Console::LEVEL_* $level |
249: | * @param string[]|string|null $groups If `null` or `["*"]`, all metrics are |
250: | * reported, otherwise only metrics in the given groups are reported. |
251: | * @return $this |
252: | */ |
253: | public function registerShutdownReport( |
254: | int $level = Console::LEVEL_INFO, |
255: | bool $includeResourceUsage = true, |
256: | bool $includeRunningTimers = true, |
257: | $groups = null, |
258: | ?int $limit = 10 |
259: | ); |
260: | } |
261: |