|
| 1 | +<?php |
| 2 | +/*========================================================================= |
| 3 | +MIDAS Server |
| 4 | +Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved. |
| 5 | +69328 Lyon, FRANCE. |
| 6 | +
|
| 7 | +See Copyright.txt for details. |
| 8 | +This software is distributed WITHOUT ANY WARRANTY; without even |
| 9 | +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 10 | +PURPOSE. See the above copyright notices for more information. |
| 11 | +=========================================================================*/ |
| 12 | + |
| 13 | +/** |
| 14 | + * \class MIDAS_ComponentLoader |
| 15 | + * \brief Create component object |
| 16 | + */ |
| 17 | +class MIDAS_ComponentLoader |
| 18 | + { |
| 19 | + /** |
| 20 | + * \fn public loadComponents() |
| 21 | + * \brief Loads components (array or string) |
| 22 | + */ |
| 23 | + public function loadComponents($components, $module = '') |
| 24 | + { |
| 25 | + if(is_string($components)) |
| 26 | + { |
| 27 | + $this->loadComponent($components, $module); |
| 28 | + } |
| 29 | + elseif(is_array($components)) |
| 30 | + { |
| 31 | + foreach($components as $component) |
| 32 | + { |
| 33 | + $this->loadComponent($component, $module); |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * \fn public loadComponent() |
| 40 | + * \brief Loads a component |
| 41 | + */ |
| 42 | + public function loadComponent($component, $module = '') |
| 43 | + { |
| 44 | + $components = Zend_Registry::get('components'); |
| 45 | + if(!isset($components[$module.$component])) |
| 46 | + { |
| 47 | + if($module == '') |
| 48 | + { |
| 49 | + include_once BASE_PATH.'/core/controllers/components/'.$component.'Component.php'; |
| 50 | + $name = $component . 'Component'; |
| 51 | + } |
| 52 | + else |
| 53 | + { |
| 54 | + include_once BASE_PATH.'/modules/'.$module.'/controllers/components/'.$component.'Component.php'; |
| 55 | + $name = ucfirst($module).'_'.$component.'Component'; |
| 56 | + } |
| 57 | + if(class_exists($name)) |
| 58 | + { |
| 59 | + $components[$module.$component] = new $name; |
| 60 | + Zend_Registry::set('components', $components); |
| 61 | + } |
| 62 | + else |
| 63 | + { |
| 64 | + throw new Zend_Exception('Unable to load class '.$name); |
| 65 | + } |
| 66 | + } |
| 67 | + return $components[$module.$component]; |
| 68 | + } |
| 69 | + } |
0 commit comments