AdminPageFramework_Bootstrap::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 17
rs 10
c 1
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
/**
3
 * Admin Page Framework
4
 *
5
 * Facilitates WordPress plugin and theme development.
6
 *
7
 * @author      Michael Uno <[email protected]>
8
 * @copyright   2013-2022 (c) Michael Uno
9
 * @license     MIT <http://opensource.org/licenses/MIT>
10
 * @package     AdminPageFramework
11
 */
12
13
if ( ! class_exists( 'AdminPageFramework_Registry', false ) ) :
14
/**
15
 * Facilitates WordPress plugin and theme development.
16
 *
17
 * One of the most time-consuming part of developing WordPress plugins and themes is building setting pages.
18
 * Admin Page Framework provides means of building pages and forms that the users save settings in the administration area of WordPess.
19
 * By extending the abstract classes the framework provides, you can build your own functionality.
20
 *
21
 * @image               http://admin-page-framework.michaeluno.jp/image/icon-256x256.png
22
 * @heading             Admin Page Framework
23
 * @author              Michael Uno
24
 * @copyright           2013-2022 (c) Michael Uno
25
 * @license             https://opensource.org/licenses/MIT  MIT
26
 * @since               3.1.3
27
 * @repository          https://github.com/michaeluno/admin-page-framework
28
 * @link                https://wordpress.org/plugins/admin-page-framework/
29
 * @link                https://en.michaeluno.jp/admin-page-framework
30
 * @package             AdminPageFramework
31
 * @requirement         >= WordPress 3.4
32
 * @requirement         >= PHP 5.2.4
33
 * @remark              To use the framework, 1. Extend the class 2. Override the setUp() method. 3. Use the hook functions.
34
 * @remark              The documentation employs the <a href="http://en.wikipedia.org/wiki/PHPDoc">PHPDOc(DocBlock)</a> syntax.
35
 * @download_latest     https://github.com/michaeluno/admin-page-framework/archive/master.zip
36
 * @download_stable     https://downloads.wordpress.org/plugin/admin-page-framework.latest-stable.zip
37
 * @catchcopy           The framework for all WordPress developers.
38
 * @version             3.9.1
39
 */
40
abstract class AdminPageFramework_Registry_Base {
41
42
    const VERSION       = '3.9.1'; // <--- DON'T FORGET TO CHANGE THIS AS WELL!!
43
    const NAME          = 'Admin Page Framework';
44
    const DESCRIPTION   = 'Facilitates WordPress plugin and theme development.';
45
    const URI           = 'https://en.michaeluno.jp/admin-page-framework';
46
    const AUTHOR        = 'Michael Uno';
47
    const AUTHOR_URI    = 'https://en.michaeluno.jp/';
48
    const COPYRIGHT     = 'Copyright (c) 2013-2022, Michael Uno';
49
    const LICENSE       = 'MIT <https://opensource.org/licenses/MIT>';
50
    const CONTRIBUTORS  = '';
51
52
}
53
54
/**
55
 * Defines the framework common information.
56
 *
57
 * @since    3.1.3
58
 * @package  AdminPageFramework
59
 * @internal
60
 */
61
final class AdminPageFramework_Registry extends AdminPageFramework_Registry_Base {
62
63
    const TEXT_DOMAIN        = 'admin-page-framework';
64
    const TEXT_DOMAIN_PATH   = '/language';  // not used at the moment
65
66
    /**
67
     * Indicates whether the framework is loaded from the minified version or not.
68
     *
69
     * @remark The value will be reassigned by the bootstrap script.
70
     * @remark The minified version will be deprecated in the near future.
71
     * @var    boolean
72
     */
73
    static public $bIsMinifiedVersion = true;
74
75
    /**
76
     * Indicates whether the framework is the development version or not.
77
     *
78
     * @since 3.5.4
79
     * @var   boolean
80
     */
81
    static public $bIsDevelopmentVersion = true;
82
83
    /**
84
     * Stores the autoloader class file path.
85
     * @var string
86
     */
87
    static public $sAutoLoaderPath;
88
89
    /**
90
     * Stores the file path of the inclusion class map.
91
     * @since 3.5.4
92
     * @since 3.9.0  Renamed from `$sIncludeClassListPath`.
93
     * @var   string
94
     */
95
    static public $sClassMapPath;
96
97
    /**
98
     * Stores paths of class files.
99
     * @since 3.5.4
100
     * @var   array
101
     */
102
    static public $aClassFiles = array();
103
104
    // These properties will be defined in the setUp() method.
105
    static public $sFilePath   = '';
106
    static public $sDirPath    = '';
107
108
    /**
109
     * Sets up static properties.
110
     */
111
    static public function setUp( $sFilePath=__FILE__ ) {
112
        self::$sFilePath             = $sFilePath;
113
        self::$sDirPath              = dirname( self::$sFilePath );
114
        self::$sClassMapPath         = self::$sDirPath . '/admin-page-framework-class-map.php';
115
        self::$aClassFiles           = include( self::$sClassMapPath );
116
        self::$sAutoLoaderPath       = isset( self::$aClassFiles[ 'AdminPageFramework_RegisterClasses' ] )
117
            ? self::$aClassFiles[ 'AdminPageFramework_RegisterClasses' ]
118
            : '';
119
        self::$bIsMinifiedVersion    = class_exists( 'AdminPageFramework_MinifiedVersionHeader', false );
120
        self::$bIsDevelopmentVersion = isset( self::$aClassFiles[ 'AdminPageFramework_ClassMapHeader' ] );
121
    }
122
123
    /**
124
     * Returns the framework version.
125
     *
126
     * @since  3.3.1
127
     * @return string
128
     */
129
    static public function getVersion() {
130
131
        if ( ! isset( self::$sAutoLoaderPath ) ) {
132
            trigger_error( self::NAME . ': ' . ' : ' . sprintf( 'The method, <code>%1$s</code>, is called too early. Perform <code>%2$s</code> earlier.', __METHOD__, 'setUp()' ), E_USER_WARNING );
133
            return self::VERSION;
134
        }
135
        $_aMinifiedVersionSuffix    = array(
136
            0 => '',
137
            1 => '.min',
138
        );
139
        $_aDevelopmentVersionSuffix = array(
140
            0 => '',
141
            1 => '.dev',
142
        );
143
        return self::VERSION
144
            . $_aMinifiedVersionSuffix[ ( integer ) self::$bIsMinifiedVersion ]
145
            . $_aDevelopmentVersionSuffix[ ( integer ) self::$bIsDevelopmentVersion ];
146
147
    }
148
149
    /**
150
     * Returns an information array of this class.
151
     *
152
     * @since  3.4.6
153
     * @return array
154
     */
155
    static public function getInfo() {
156
        $_oReflection = new ReflectionClass( __CLASS__ );
157
        return $_oReflection->getConstants()
158
            + $_oReflection->getStaticProperties();
159
    }
160
161
}
162
endif;
163
164
if ( ! class_exists( 'AdminPageFramework_Bootstrap', false ) ) :
165
/**
166
 * Loads the Admin Page Framework library.
167
 *
168
 * @since    3.0.0
169
 * @package  AdminPageFramework/Utility
170
 * @internal
171
 */
172
final class AdminPageFramework_Bootstrap {
173
174
    /**
175
     * Indicates whether the bootstrap has run or not.
176
     */
177
    static private $___bLoaded = false;
178
179
    /**
180
     * Loads the framework.
181
     */
182
    public function __construct( $sLibraryPath ) {
183
184
        // Singleton
185
        if ( ! $this->___isLoadable() ) {
186
            return;
187
        }
188
189
        // Sets up registry properties.
190
        AdminPageFramework_Registry::setUp( $sLibraryPath );
191
192
        // Bail if it is the minified version.
193
        if ( AdminPageFramework_Registry::$bIsMinifiedVersion ) {
194
            return;
195
        }
196
197
        // Load the classes only for the non-minified version.
198
        $this->___include();
199
200
    }
201
        /**
202
         * Checks whether the framework can be loaded or not.
203
         *
204
         * @since  3.5.4
205
         * @return boolean
206
         */
207
        private function ___isLoadable() {
208
209
            // Prevent it from being loaded multiple times.
210
            if ( self::$___bLoaded ) {
211
                return false;
212
            }
213
            self::$___bLoaded = true;
214
215
            // The minifier script will include this file (but it does not include WordPress) to use the reflection class to extract the doc-block.
216
            return defined( 'ABSPATH' );
217
218
        }
219
220
        /**
221
         * Includes required files and registers auto-load classes.
222
         *
223
         * @since 3.7.3
224
         */
225
        private function ___include() {
226
227
            include( AdminPageFramework_Registry::$sAutoLoaderPath );
228
            new AdminPageFramework_RegisterClasses(
229
                '', // the scanning directory - do not scan anything
230
                array(
231
                    'exclude_class_names'   => array(
232
                        'AdminPageFramework_MinifiedVersionHeader',
233
                        'AdminPageFramework_BeautifiedVersionHeader',
234
                    ),
235
                ),
236
                // a class list array
237
                AdminPageFramework_Registry::$aClassFiles
238
            );
239
240
            /**
241
             * Reduce the nesting level of recursive function calls produced by the `spl_autoload_call()` PHP function.
242
             *
243
             * Instantiating a class with many class inheritances (extending a class) triggers `spl_autoload_call()`
244
             * and it keeps getting called until all the parent classes are loaded, which causes a fatal error,
245
             * `Maximum function nesting level of 'x' reached,..` if the Xdebug extension is enabled with a low value of the `xdebug.max_nesting_level` option.
246
             *
247
             * This instantiation of a class below won't do anything in particular but just tells the spl autoloader to include those files
248
             * so that the next time the program utilizing the framework tries to instantiate its class has a less nesting level of nested function calls,
249
             * which reduces the chance of getting the fatal error.
250
             */
251
            self::$___bXDebug = isset( self::$___bXDebug ) ? self::$___bXDebug : extension_loaded( 'xdebug' );
252
            if ( self::$___bXDebug ) {
253
                new AdminPageFramework_Utility;
254
                new AdminPageFramework_WPUtility;
255
            }
256
257
        }
258
            /**
259
             * @since 3.7.10
260
             * @var   boolean
261
             */
262
            static private $___bXDebug;
263
264
}
265
new AdminPageFramework_Bootstrap( __FILE__ );
266
endif;