1: <?php
2: /**
3: * LICENSE (BSD)
4: *
5: * Copyright (c) 2012, Gerd Christian Kunze
6: * All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions are
10: * met:
11: *
12: * * Redistributions of source code must retain the above copyright
13: * notice, this list of conditions and the following disclaimer.
14: *
15: * * Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: *
19: * * Neither the name of Gerd Christian Kunze nor the names of the
20: * contributors may be used to endorse or promote products derived from
21: * this software without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24: * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34: *
35: * MOC
36: * 29.08.2012 15:21
37: */
38: namespace MOC;
39: /**
40: *
41: */
42: class Api {
43: /**
44: * Setup / Startup-Procedure for MOC-System
45: *
46: * @static
47: * @return void
48: */
49: public static function Setup() {
50: // Register Auto-Loader
51: spl_autoload_register( array(__CLASS__,'AutoLoader') );
52:
53: // Register Error-Handler
54: Core\Error::InterfaceInstance()->Register()->Error()->SetHandler();
55: // Register Exception-Handler
56: Core\Error::InterfaceInstance()->Register()->Exception()->SetHandler();
57: // Register Shutdown-Handler
58: Core\Error::InterfaceInstance()->Register()->Shutdown()->SetHandler();
59: // Set Reporting-Level
60: Core\Error::InterfaceInstance()->Reporting()->Level( E_ALL )->Display( true )->Debug( true )->Apply();
61: }
62:
63: /**
64: * Auto-Loader for MOC-System
65: *
66: * @static
67: *
68: * @param string $Class
69: *
70: * @return bool
71: * @noinspection PhpUnusedPrivateMethodInspection
72: */
73: private static function AutoLoader( $Class ) {
74: // Cut Root-Namespace
75: $Class = preg_replace( '!^'.__NAMESPACE__.'!', '', $Class );
76: // Correct & Trim DIRECTORY_SEPARATOR
77: $Class = preg_replace( '![\\\/]+!', DIRECTORY_SEPARATOR, __DIR__.DIRECTORY_SEPARATOR.$Class.'.php' );
78: if( false === ( $Class = realpath( $Class ) ) ) {
79: // File not found
80: return false;
81: } else {
82: /** @noinspection PhpIncludeInspection */
83: require_once( $Class );
84: return true;
85: }
86: }
87:
88: /**
89: * @return Adapter\Core
90: */
91: public static function Core() {
92: return Adapter\Core::InterfaceInstance();
93: }
94: /**
95: * @return Adapter\Extension
96: */
97: public static function Extension() {
98: return Adapter\Extension::InterfaceInstance();
99: }
100: /**
101: * @return Adapter\Module
102: */
103: public static function Module() {
104: return Adapter\Module::InterfaceInstance();
105: }
106:
107: /**
108: * @return Adapter\Plugin
109: */
110: public static function Plugin() {
111: return Adapter\Plugin::InterfaceInstance();
112: }
113: }
114:
115: /**
116: * Startup MOC-API
117: */
118: Api::Setup();
119: