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 / autoload.php

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

62 lines 2.0 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 — class autoloader.
4 *
5 * Maps the `OpenStation\` namespace onto this directory using the
6 * WordPress file-naming convention, so a class, an interface and a
7 * trait each live where PHPCS expects them:
8 *
9 * OpenStation\App → class-app.php
10 * OpenStation\App\State → app/class-state.php
11 * OpenStation\App\Contracts\Auth → app/contracts/interface-auth.php
12 * OpenStation\App\WordPress\Auth → app/wordpress/class-auth.php
13 *
14 * The framework is deliberately host-agnostic: nothing under this
15 * directory calls a WordPress function except the adapters in
16 * `app/wordpress/` and the procedural glue in `wordpress.php`. A
17 * plain PHP host defines `OPENSTATION_STANDALONE` before requiring
18 * this file and gets the same framework with the standalone
19 * adapters (see `docs/app-framework.md`).
20 *
21 * @package OpenStation
22 */
23
24 // Direct access, unless a standalone host is booting on bare PHP.
25 if ( ! defined( 'ABSPATH' ) ) {
26 defined( 'OPENSTATION_STANDALONE' ) || exit;
27 }
28
29 if ( ! defined( 'OPENSTATION_FRAMEWORK_DIR' ) ) {
30 define( 'OPENSTATION_FRAMEWORK_DIR', __DIR__ );
31 }
32
33 spl_autoload_register(
34 static function ( $class_name ) {
35 $prefix = 'OpenStation\\';
36 if ( 0 !== strpos( $class_name, $prefix ) ) {
37 return;
38 }
39
40 $parts = explode( '\\', substr( $class_name, strlen( $prefix ) ) );
41 $name = array_pop( $parts );
42 $dir = OPENSTATION_FRAMEWORK_DIR;
43 if ( ! empty( $parts ) ) {
44 $dir .= '/' . strtolower( implode( '/', $parts ) );
45 }
46
47 // `LogReader` → `log-reader`, matching `class-log-reader.php`.
48 $file = strtolower( (string) preg_replace( '/(?<!^)[A-Z]/', '-$0', $name ) );
49
50 foreach ( array( 'class-', 'interface-', 'trait-' ) as $kind ) {
51 $path = $dir . '/' . $kind . $file . '.php';
52 if ( is_file( $path ) ) {
53 require_once $path;
54 return;
55 }
56 }
57 }
58 );
59
60 // Template helpers are functions, which no autoloader can find.
61 require_once OPENSTATION_FRAMEWORK_DIR . '/app/html.php';
62