PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.9
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.9
1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 0.8.7 0.8.6 All 33 releases
desktop-mode / includes / framework / app / class-view.php

class-view.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.9, at includes/framework/app/class-view.php

46 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OpenStation App Framework — view capture.
4 *
5 * A view is a callable that paints markup for a state: it may echo
6 * (the natural thing inside `?> … <?php` blocks), return a string, or
7 * both. `View::capture()` turns either into the HTML string the
8 * runtime ships.
9 *
10 * @package OpenStation
11 */
12
13 namespace OpenStation\App;
14
15 // Direct access, unless a standalone host is booting on bare PHP.
16 if ( ! defined( 'ABSPATH' ) ) {
17 defined( 'OPENSTATION_STANDALONE' ) || exit;
18 }
19
20 /**
21 * Turns a view callable into HTML.
22 */
23 final class View {
24
25 /**
26 * Run a view callable and collect everything it painted.
27 *
28 * @param callable $view `function ( State $state, Os $os )`.
29 * @param State $state Current state.
30 * @param Os $os Host handle.
31 * @return string HTML.
32 * @throws \Throwable Whatever the view threw, after the output buffer is discarded.
33 */
34 public static function capture( callable $view, State $state, Os $os ) {
35 ob_start();
36 try {
37 $returned = $view( $state, $os );
38 } catch ( \Throwable $e ) {
39 ob_end_clean();
40 throw $e;
41 }
42 $echoed = (string) ob_get_clean();
43 return $echoed . ( is_string( $returned ) ? $returned : '' );
44 }
45 }
46