17if ( ! defined(
'XCUBE_CORE_PATH' ) ) {
18 define(
'XCUBE_CORE_PATH', __DIR__ );
21require_once XCUBE_CORE_PATH .
'/XCube_HttpContext.class.php';
23if ( PHP_VERSION_ID >= 50000 ) {
24 function XC_CLASS_EXISTS( $className ) {
25 return $className && class_exists( $className,
false );
28 function XC_CLASS_EXISTS( $className ) {
29 return class_exists( $className );
44 public $mLanguageManager;
50 public $mDelegateManager;
56 public $mServiceManager;
64 public $_mRenderSystems = [];
70 public $mSiteConfig = [];
77 public $mPermissionManager;
118 public function __construct() {
126 public static function &getSingleton() {
129 if ( ! isset( $instance ) ) {
130 $instance =
new XCube_Root();
150 public function loadSiteConfig() {
151 $n = func_num_args();
153 die(
'FETAL: open error: site setting config.' );
156 $files = func_get_args();
157 $file = array_shift( $files );
159 if ( ! file_exists( $file ) ) {
160 die(
'FETAL: open error: site setting config.' );
163 $this->setSiteConfig( parse_ini_file( $file,
true ) );
169 foreach ( $files as $overrideFile ) {
170 if ( file_exists( $overrideFile ) ) {
171 $this->overrideSiteConfig( parse_ini_file( $overrideFile,
true ) );
187 public function setSiteConfig( $config ) {
188 $this->mSiteConfig = $config;
203 public function overrideSiteConfig( $config ) {
204 foreach ( $config as $_overKey => $_overVal ) {
205 if ( array_key_exists( $_overKey, $this->mSiteConfig ) ) {
206 $this->mSiteConfig[ $_overKey ] = array_merge( $this->mSiteConfig[ $_overKey ], $_overVal );
208 $this->mSiteConfig[ $_overKey ] = $_overVal;
230 public function getSiteConfig() {
234 $m = &$this->mSiteConfig;
235 $n = func_num_args();
240 $a = func_get_arg( 0 );
241 if ( isset( $m[ $a ] ) ) {
244 } elseif ( 2 === $n ) {
245 [$a, $b] = func_get_args();
246 if ( isset( $m[ $a ][ $b ] ) ) {
247 return $m[ $a ][ $b ];
249 } elseif ( 3 === $n ) {
250 [$a, $b, $c] = func_get_args();
251 if ( isset( $m[ $a ][ $b ] ) ) {
252 return $m[ $a ][ $b ];
273 public function setupController() {
278 $controllerName = $this->mSiteConfig[
'Cube'][
'Controller'];
279 $controller =& $this->mSiteConfig[ $controllerName ];
280 if ( isset( $controller[
'root'] ) ) {
281 $this->mController =& $this->_createInstance( $controller[
'class'], $controller[
'path'], $controller[
'root'] );
283 $this->mController =& $this->_createInstance( $controller[
'class'], $controller[
'path'] );
285 $this->mController->prepare( $this );
293 public function &getController() {
294 return $this->mController;
305 public function setLanguageManager( &$languageManager ) {
306 $this->mLanguageManager =& $languageManager;
314 public function &getLanguageManager() {
315 return $this->mLanguageManager;
326 public function setDelegateManager( &$delegateManager ) {
327 $this->mDelegateManager =& $delegateManager;
335 public function &getDelegateManager() {
336 return $this->mDelegateManager;
347 public function setServiceManager( &$serviceManager ) {
348 $this->mServiceManager =& $serviceManager;
356 public function &getServiceManager() {
357 return $this->mServiceManager;
373 public function &getRenderSystem( $name ) {
374 $mRS =& $this->_mRenderSystems;
375 if ( isset( $mRS[ $name ] ) ) {
376 return $mRS[ $name ];
382 $config =& $this->mSiteConfig;
383 $chunkName = $config[
'RenderSystems'][ $name ];
384 $chunk =& $config[ $chunkName ];
385 if ( isset( $config[ $chunkName ][
'root'] ) ) {
386 $mRS[ $name ] =& $this->_createInstance( $chunk[
'class'], $chunk[
'path'], $chunk[
'root'] );
388 $mRS[ $name ] =& $this->_createInstance( $chunk[
'class'], $chunk[
'path'] );
391 if ( ! is_object( $mRS[ $name ] ) ) {
395 $mRS[ $name ]->prepare( $this->mController );
397 return $mRS[ $name ];
405 public function setPermissionManager( &$manager ) {
406 $this->mPermissionManager =& $manager;
412 public function &getPermissionManager() {
413 return $this->mPermissionManager;
424 public function setTextFilter( &$textFilter ) {
425 $this->mTextFilter =& $textFilter;
437 public function &getTextFilter() {
438 if ( ! empty( $this->mTextFilter ) ) {
439 return $this->mTextFilter;
441 if ( ! empty( $this->mController ) ) {
442 $this->mController->mSetupTextFilter->call(
new XCube_Ref( $this->mTextFilter ) );
444 return $this->mTextFilter;
461 public function setRoleManager( &$manager ) {
462 $this->mRoleManager =& $manager;
474 public function setContext( &$context ) {
475 $this->mContext =& $context;
484 public function &getContext() {
485 return $this->mContext;
496 public function setSession( &$session ) {
497 $this->mSession =& $session;
505 public function &getSession() {
506 return $this->mSession;
527 public function &_createInstance( $className, $classPath =
null, $root =
null ) {
530 if (
null !== $classPath ) {
531 if (
null === $root ) {
532 $root = $this->mSiteConfig[
'Cube'][
'Root'];
535 if ( is_file( $root . $classPath ) ) {
537 require_once $root . $classPath;
539 require_once $root . $classPath .
'/' . $className .
'.class.php';
543 if ( XC_CLASS_EXISTS( $className ) ) {
544 $ret =
new $className();