コード例 #1
0
ファイル: Modules.php プロジェクト: netconstructor/Centurion
 /**
  * Initialize modules
  *
  * @return array[string]Centurion_Application_Module_Bootstrap
  * @throws Centurion_Application_Resource_Exception When bootstrap class was not found
  */
 public function init()
 {
     $bootstrap = $this->getBootstrap();
     $bootstrap->bootstrap('FrontController');
     $front = $bootstrap->getResource('FrontController');
     $modules = $front->getControllerDirectory();
     $default = $front->getDefaultModule();
     $curBootstrapClass = get_class($bootstrap);
     $options = $this->getOptions();
     if (is_array($options) && !empty($options[0])) {
         $diffs = array_diff($options, array_keys($modules));
         if (count($diffs)) {
             throw new Centurion_Application_Resource_Exception(sprintf('The modules %s is not found in your registry (%s)', implode(', ', $diffs), implode(PATH_SEPARATOR, $modules)));
         }
         foreach ($modules as $key => $module) {
             if (!in_array($key, $options) && $key !== $default) {
                 unset($modules[$key]);
                 $front->removeControllerDirectory($key);
             }
         }
         $modules = Centurion_Inflector::sortArrayByArray($modules, array_values($options));
     }
     foreach ($modules as $module => $moduleDirectory) {
         $bootstrapClass = $this->_formatModuleName($module) . '_Bootstrap';
         if (!class_exists($bootstrapClass, false)) {
             $bootstrapPath = dirname($moduleDirectory) . '/Bootstrap.php';
             if (!file_exists($bootstrapPath)) {
                 throw new Centurion_Application_Exception('Module ' . $module . ' has no Bootstrap class', 500);
             }
             include_once $bootstrapPath;
             if ($default != $module && !class_exists($bootstrapClass, false)) {
                 $eMsgTpl = 'Bootstrap file found for module "%s" but bootstrap class "%s" not found';
                 throw new Centurion_Application_Resource_Exception(sprintf($eMsgTpl, $module, $bootstrapClass));
             } elseif ($default == $module) {
                 if (!class_exists($bootstrapClass, false)) {
                     $bootstrapClass = 'Bootstrap';
                     if (!class_exists($bootstrapClass, false)) {
                         throw new Zend_Application_Resource_Exception(sprintf($eMsgTpl, $module, $bootstrapClass));
                     }
                 }
             }
         }
         if ($bootstrapClass == $curBootstrapClass) {
             // If the found bootstrap class matches the one calling this
             // resource, don't re-execute.
             continue;
         }
         $moduleBootstrap = new $bootstrapClass($bootstrap);
         $moduleBootstrap->bootstrap();
         $this->_bootstraps[$module] = $moduleBootstrap;
     }
     return $this->_bootstraps;
 }
コード例 #2
0
ファイル: Install.php プロジェクト: rom1git/Centurion
 public function acl($env)
 {
     $this->bootstrap($env);
     $application = $this->_application;
     $bootstrap = $application->getBootstrap();
     $front = $bootstrap->getResource('FrontController');
     $modules = $front->getControllerDirectory();
     $default = $front->getDefaultModule();
     $curBootstrapClass = get_class($bootstrap);
     $options = $bootstrap->getOption('resources');
     $options = $options['modules'];
     if (is_array($options) && !empty($options[0])) {
         $diffs = array_diff($options, array_keys($modules));
         if (count($diffs)) {
             throw new Centurion_Application_Resource_Exception(sprintf("The modules %s is not found in your registry (%s)", implode(', ', $diffs), implode(PATH_SEPARATOR, $modules)));
         }
         foreach ($modules as $key => $module) {
             if (!in_array($key, $options) && $key !== $default) {
                 unset($modules[$key]);
                 $front->removeControllerDirectory($key);
             }
         }
         $modules = Centurion_Inflector::sortArrayByArray($modules, array_values($options));
     }
     require_once APPLICATION_PATH . '/../library/Centurion/Contrib/auth/models/DbTable/Permission.php';
     require_once APPLICATION_PATH . '/../library/Centurion/Contrib/auth/models/DbTable/Row/Permission.php';
     $permissionTable = Centurion_Db::getSingleton('auth/permission');
     foreach ($modules as $module => $moduleDirectory) {
         echo "\n\n" . 'Scan new module: ' . $module . "\n";
         $bootstrapClass = $this->_formatModuleName($module) . '_Bootstrap';
         $modulePath = dirname($moduleDirectory);
         $dataPath = $modulePath . '/controllers/';
         if (is_dir($dataPath)) {
             $db = Zend_Db_Table::getDefaultAdapter();
             foreach (new DirectoryIterator($dataPath) as $file) {
                 if ($file->isDot() || !$file->isFile()) {
                     continue;
                 }
                 if (substr($file, 0, 5) !== 'Admin') {
                     continue;
                 }
                 $controllerName = substr($file, 5, -14);
                 $object = Centurion_Inflector::tableize($controllerName, '-');
                 $tab = array('index' => 'View %s %s index', 'list' => 'View %s %s list', 'get' => 'View an %s %s', 'post' => 'Create an %s %s', 'new' => 'Access to creation of an %s %s', 'delete' => 'Delete an %s %s', 'put' => 'Update an %s %s', 'batch' => 'Batch an %s %s', 'switch' => 'Switch an %s %s');
                 foreach ($tab as $key => $description) {
                     list($row, $created) = $permissionTable->getOrCreate(array('name' => $module . '_' . $object . '_' . $key));
                     if ($created) {
                         echo 'Create permission: ' . $module . '_' . $object . '_' . $key . "\n";
                         $row->description = sprintf($description, $module, $object);
                         $row->save();
                     }
                 }
             }
         }
     }
     Centurion_Loader_PluginLoader::clean();
     Centurion_Signal::factory('clean_cache')->send($this);
 }
コード例 #3
0
ファイル: Db.php プロジェクト: rom1git/Centurion
 /**
  * @param $env
  * @param bool $acceptAll
  * @param bool $ignoreLaunched
  * @throws Exception
  * @throws Centurion_Application_Resource_Exception
  *
  * @todo: rajouter la gestion des php
  * @todo: refractoring
  */
 public function update($env, $acceptAll = false, $ignoreLaunched = true)
 {
     if ($acceptAll === 'true') {
         $acceptAll = true;
     }
     if ($ignoreLaunched === 'true') {
         $ignoreLaunched = true;
     }
     if ($acceptAll === 'false') {
         $acceptAll = false;
     }
     if ($ignoreLaunched === 'false') {
         $ignoreLaunched = false;
     }
     $this->bootstrap($env);
     $application = $this->_application;
     $bootstrap = $application->getBootstrap();
     $front = $bootstrap->getResource('FrontController');
     $modules = $front->getControllerDirectory();
     $default = $front->getDefaultModule();
     $options = $bootstrap->getOption('resources');
     $options = $options['modules'];
     if (is_array($options) && !empty($options[0])) {
         $diffs = array_diff($options, array_keys($modules));
         if (count($diffs)) {
             throw new Centurion_Application_Resource_Exception(sprintf("The modules %s is not found in your registry (%s)", implode(', ', $diffs), implode(PATH_SEPARATOR, $modules)));
         }
         foreach ($modules as $key => $module) {
             if (!in_array($key, $options) && $key !== $default) {
                 unset($modules[$key]);
                 $front->removeControllerDirectory($key);
             }
         }
         $modules = Centurion_Inflector::sortArrayByArray($modules, array_values($options));
     }
     $db = Zend_Db_Table::getDefaultAdapter();
     foreach ($modules as $module => $moduleDirectory) {
         $modulePath = dirname($moduleDirectory);
         $dataPath = $modulePath . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR;
         echo $dataPath;
         if (is_dir($dataPath)) {
             echo 'Open ' . $dataPath . "\n";
             $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dataPath, FilesystemIterator::SKIP_DOTS | FilesystemIterator::KEY_AS_FILENAME));
             $files = iterator_to_array($files);
             ksort($files);
             $files = array_merge(array('schema.sql' => null, 'data.sql' => null), $files);
             foreach ($files as $file) {
                 if (null == $file) {
                     continue;
                 }
                 if ($file->isDir()) {
                     continue;
                 }
                 if (Centurion_Inflector::extension($file) !== '.sql') {
                     continue;
                 }
                 $choice = null;
                 if (file_exists($file->getPathname() . '.' . APPLICATION_ENV . '.done')) {
                     if ($ignoreLaunched) {
                         continue;
                     }
                     if (!$acceptAll) {
                         echo sprintf('The file %s seems to be already executed. Do you want to launch it?' . "\n", $file->getPathname());
                     }
                 }
                 if (!$acceptAll) {
                     echo sprintf('Find a new file file %s. Do you want to launch it?' . "\n", $file->getPathname());
                 } else {
                     $choice = '1';
                 }
                 if (null == $choice) {
                     do {
                         echo '1) Execute' . "\n";
                         echo '2) Ignore' . "\n";
                         echo '3) Mark it without execute it' . "\n";
                         echo '? ';
                         $choice = trim(fgets(STDIN));
                     } while (!in_array($choice, array('1', '2', '3')));
                 }
                 if ($choice == '2') {
                     echo "\n\n";
                     continue;
                 }
                 if ($choice == '1') {
                     echo sprintf('Exec the file %s' . "\n", $file->getPathname());
                     try {
                         $db->beginTransaction();
                         $query = '';
                         foreach (new SplFileObject($file->getPathname()) as $line) {
                             $query .= $line;
                             if (substr(rtrim($query), -1) == ';') {
                                 $statement = $db->query($query);
                                 $statement->closeCursor();
                                 unset($statement);
                                 $query = '';
                             }
                         }
                         $db->commit();
                     } catch (Exception $e) {
                         $db->rollback();
                         throw $e;
                     }
                 }
                 touch($file->getPathname() . '.' . APPLICATION_ENV . '.done');
                 echo "\n\n";
             }
         }
     }
     Centurion_Loader_PluginLoader::clean();
     Centurion_Signal::factory('clean_cache')->send($this);
 }