PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Geezmo/Bootstrap.php

https://bitbucket.org/baruffaldi/framework-php-geezmo
PHP | 87 lines | 51 code | 12 blank | 24 comment | 10 complexity | de15af4382e25ec7baa17d1178d7f2db MD5 | raw file
  1. <?php
  2. /**
  3. * This file is part of geezmo-core.
  4. *
  5. * geezmo-core is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * geezmo-core is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with geezmo-core. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * @author Filippo Baruffaldi <filippo@baruffaldi.info>
  19. * @copyright geezmo-kit
  20. * @package geezmo
  21. * @subpackage core
  22. */
  23. class Geezmo_Bootstrap
  24. {
  25. public function loadComponent ( $component, $module = NULL )
  26. {
  27. if ( is_null( $module ) )
  28. $fileName = Zend_Registry::getInstance()->environment['path']['bootstrap'] . "$component.php";
  29. else $fileName = Zend_Registry::getInstance()->environment['path']['modules'] .
  30. DIRECTORY_SEPARATOR . $module .
  31. DIRECTORY_SEPARATOR . 'bootstrap' .
  32. DIRECTORY_SEPARATOR . "$component.php";
  33. if ( file_exists( $fileName ) )
  34. require_once $fileName;
  35. if ( is_null( $module ) && file_exists( $fileName ) )
  36. Zend_Registry::getInstance()->environment['loadedComponent'][] = $component;
  37. elseif ( file_exists( $fileName ) ) Zend_Registry::getInstance()->environment['loadedModulesComponent'][$module][] = $component;
  38. }
  39. public function loadModule ( $moduleName )
  40. {
  41. $module = Zend_Registry::getInstance()->environment['path']['modules'] .
  42. DIRECTORY_SEPARATOR . $moduleName;
  43. // *** ( global ) Set new include path
  44. if ( file_exists( $module . DIRECTORY_SEPARATOR . 'library' ) )
  45. set_include_path( get_include_path( ) . PATH_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'library' );
  46. $uri = explode( '/', $_SERVER['REQUEST_URI'] );
  47. // *** ( request ) Bootstrap Components
  48. if ( count( $uri ) >= 3 && $uri[0] == $moduleName )
  49. {
  50. foreach ( Zend_Registry::getInstance()->environment['loadedComponent'] as $component )
  51. Geezmo_Bootstrap::loadComponent( $component, $moduleName );
  52. foreach ( glob( $module . DIRECTORY_SEPARATOR . 'bootstrap' . DIRECTORY_SEPARATOR . '*.php' ) as $moduleComponent )
  53. {
  54. if ( ! in_array( substr( basename( $moduleComponent ), 0, -4 ), Zend_Registry::getInstance()->environment['loadedComponent'] ) )
  55. Geezmo_Bootstrap::loadComponent( substr( basename( $moduleComponent ), 0, -4 ), $moduleName );
  56. }
  57. }
  58. // *** ( global ) Load Configurations
  59. foreach ( glob( $module . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . '*.ini' ) as $configFile )
  60. {
  61. $configName = preg_replace( '/.ini/', NULL, basename( $configFile ) );
  62. $confs[$configName] = new Zend_Config_Ini( $configFile,
  63. Zend_Registry::getInstance()->environment['type'],
  64. TRUE );
  65. }
  66. }
  67. public function loadModules ( )
  68. {
  69. foreach ( glob( Zend_Registry::getInstance()->environment['path']['modules'] . '*' ) as $module )
  70. {
  71. $moduleName = basename( $module );
  72. Geezmo_Bootstrap::loadModule( $moduleName );
  73. }
  74. }
  75. }