1: <?php
2:
3: namespace Xu\Foundation;
4:
5: use Exception;
6: use Frozzare\Tank\Container;
7: use InvalidArgumentException;
8:
9: class Foundation extends Container {
10:
11: 12: 13: 14: 15:
16: protected static $instance;
17:
18: 19: 20:
21: public function __construct() {
22: $this->require_files();
23: $this->boot();
24: }
25:
26: 27: 28:
29: public function boot() {
30: xu_register_large_option_post_type();
31: }
32:
33: 34: 35: 36: 37: 38: 39: 40: 41: 42:
43: public function fn( $method, $args ) {
44: $method = $this->get_fn_name( $method );
45:
46: if ( ! is_array( $args ) ) {
47: $args = [$args];
48: }
49:
50: if ( ! function_exists( $method ) ) {
51: throw new Exception( sprintf( '`%s` function does not exists', $method ) );
52: }
53:
54: return call_user_func_array( $method, $args );
55: }
56:
57: 58: 59: 60: 61: 62: 63:
64: protected function get_fn_name( $fn ) {
65: return 'xu_' . preg_replace( '/^xu\_/', '', $fn );
66: }
67:
68: 69: 70: 71: 72:
73: public static function get_instance() {
74: if ( ! isset( self::$instance ) ) {
75: return self::$instance = new self;
76: }
77:
78: return self::$instance;
79: }
80:
81: 82: 83:
84: protected function require_files() {
85: $files = [
86: 'helpers.php',
87: 'lib/cache.php',
88: 'lib/clean.php',
89: 'lib/conditional.php',
90: 'lib/http.php',
91: 'lib/media.php',
92: 'lib/menu.php',
93: 'lib/option.php',
94: 'lib/post.php',
95: 'lib/rewrite.php',
96: 'lib/string.php',
97: 'lib/transient.php',
98: 'lib/utils.php',
99: 'model/helpers.php'
100: ];
101:
102: foreach ( $files as $file ) {
103: if ( strpos( $file, '/' ) !== false ) {
104: $file = '../' . $file;
105: }
106:
107: if ( file_exists( __DIR__ . '/' . $file ) ) {
108: require_once __DIR__ . '/' . $file;
109: }
110: }
111:
112: unset( $file );
113: }
114: }
115: