Example #1
0
 /**
  * Initializes the module. This creates an new Module object if the 
  * given module path is valid. The function returns the initialized 
  * module or false, if the module can't be initialized.
  * 
  * @access protected
  * @param string $path
  * @param boolean $activateDependencies
  * @return ModuleAbstract
  * 
  * @throws Zepi\Turbo\Exception The module "$path" is not valid
  */
 protected function initializeModule($path, $activateDependencies = false)
 {
     $moduleNamespace = $this->getNamespaceFromModuleJson($path);
     $module = $this->getModule($moduleNamespace);
     // If the module is already initialized, return it
     if ($module instanceof ModuleAbstract) {
         return $module;
     }
     // Try to find and load the module
     if (!file_exists($path . '/Module.php')) {
         throw new Exception('The module "' . $path . '" is not valid!');
     }
     // Look for dependencies and warn the user or activate the dependencies
     $this->handleModuleDependencies($moduleNamespace, $path, $activateDependencies);
     // Load the module
     require_once $path . '/Module.php';
     $moduleClassName = Framework::prepareClassName($moduleNamespace . 'Module');
     // Initialize the module
     $module = new $moduleClassName($this->framework, $moduleNamespace, $path);
     $this->modules[$moduleNamespace] = $module;
     $module->initialize();
     return $module;
 }
Example #2
0
 public function testPrepareClassName()
 {
     $preparedClassName = \Zepi\Turbo\Framework::prepareClassName('Zepi\\Turbo\\Framework');
     $this->assertEquals('\\Zepi\\Turbo\\Framework', $preparedClassName);
 }
Example #3
0
 /**
  * Returns the DataSource type class for the given class
  * 
  * @access public
  * @param string $className
  * @return string
  * 
  * @throws \Zepi\Turbo\Exception Data Source "{className}" does not implement the DataSourceInterface.
  */
 protected function getTypeClass($className)
 {
     $implementedClasses = class_implements($className);
     $frameworkDataSourceInterface = 'Zepi\\Turbo\\FrameworkInterface\\DataSourceInterface';
     // If the class does not implement the DataSourceInterface we cannot use
     // this class as DataSource
     if (!isset($implementedClasses[$frameworkDataSourceInterface])) {
         throw new Exception('Data Source "' . $className . '" does not implement the DataSourceInterface.');
     }
     // Remove the framework interface
     unset($implementedClasses[$frameworkDataSourceInterface]);
     return Framework::prepareClassName(current($implementedClasses));
 }