コード例 #1
0
ファイル: Dump.php プロジェクト: bozhich/PHP-on-Rails
 /**
  *
  */
 public function indexAction()
 {
     die('todo');
     $overwrite = !is_null(Core_Request::getInstance()->getArgv(4)) ? Core_Request::getInstance()->getArgv(4) : false;
     foreach (dibi::getDatabaseInfo()->getTables() as $table_data) {
         if ($table_data->getName() == Migration_MigrationModel::getTableName()) {
             continue;
         }
         $ddl_data = dibi::query('SHOW CREATE TABLE ' . $table_data->getName())->fetch()->toArray();
         $ddl_query = $ddl_data['Create Table'];
         $migration_time = time();
         $migration_name = 'Create' . ucfirst($table_data->getName());
         $migration_name = str_replace(' ', '', $migration_name);
         $migration_name = str_replace('-', '', $migration_name);
         $migration_name = str_replace('_', '', $migration_name);
         $filename = cfg()->migration_path . $migration_name . '.php';
         if (Core_Files::fileSize($filename) && !$overwrite) {
             echo PHP_EOL . 'Migration "Create ' . ucfirst($table_data->getName()) . '" Exists' . PHP_EOL;
             continue;
         }
         $template_data = Core_Files::getContent(cfg()->migration_path . Migration_FilesHelper::TEMPLATE_FILE_NAME);
         $template_data = str_replace('Template', $migration_name, $template_data);
         $template_data = str_replace('__NAME__', $migration_name, $template_data);
         $template_data = str_replace('__CREATED_AT__', $migration_time, $template_data);
         $template_data = str_replace('__CREATED_CFG__', Core_Request::getInstance()->getArgv(1), $template_data);
         $template_data = preg_replace('#//__UP_ACTION__#', $ddl_query, $template_data);
         $down_query = 'DROP TABLE IF EXISTS `' . $table_data->getName() . '`';
         $template_data = preg_replace('#//__DOWN_ACTION__#', $down_query, $template_data);
         Core_Files::putContent($filename, $template_data);
         echo PHP_EOL . 'Migration ' . $filename . ' created' . PHP_EOL;
     }
 }
コード例 #2
0
ファイル: Create.php プロジェクト: bozhich/PHP-on-Rails
 /**
  * @throws Exception
  */
 public function indexAction()
 {
     $migration_time = time();
     $migration_name = time();
     if (!$migration_name) {
         throw new Exception('No migration name given');
     }
     $filename = cfg()->migration_path . $migration_name . '.php';
     if (Core_Files::fileSize($filename)) {
         throw new Exception('Migration with that name exists');
     }
     $template_data = Core_Files::getContent(cfg()->migration_path . Const_Migrations::TEMPLATE_FILE_NAME);
     $template_data = str_replace('Template', $migration_name, $template_data);
     $template_data = str_replace('__NAME__', $migration_name, $template_data);
     $template_data = str_replace('__CREATED_AT__', $migration_time, $template_data);
     $template_data = str_replace('__CREATED_CFG__', Core_Request::getInstance()->getArgv(1), $template_data);
     Core_Files::putContent($filename, $template_data);
     echo PHP_EOL . 'Migration ' . $filename . ' created' . PHP_EOL . PHP_EOL;
 }
コード例 #3
0
ファイル: Packer.php プロジェクト: bozhich/PHP-on-Rails
 /**
  * @param       $hash_id
  * @param array $files
  * @return null|string
  */
 public static function css($hash_id, array $files)
 {
     if (empty($files)) {
         return false;
     }
     $cache_name = '';
     foreach ($files as &$file) {
         $file = cfg()->static_path . 'css' . DS . $file;
         $cache_name .= Core_Files::fileSize($file);
     }
     unset($file);
     $f_name = md5($hash_id . $cache_name) . '.css';
     $f_path = cfg()->cache_path . 'css' . DS . $f_name;
     $f_public = cfg()->cache_address . 'css/' . $f_name;
     if (!is_file($f_path)) {
         // lets empty the directory
         $cache_files = Core_Files::listFiles(cfg()->cache_path . 'css' . DS);
         foreach ($cache_files as $cfile) {
             Core_Files::delete($cfile, true);
         }
         $css_content = '';
         foreach ($files as $file) {
             $content = Core_Files::getContent($file);
             $css_content .= $content;
         }
         $css_content = preg_replace('!/\\*[^*]*\\*+([^/][^*]*\\*+)*/!', '', $css_content);
         // Remove space after colons
         $css_content = str_replace(': ', ':', $css_content);
         // Remove whitespace
         $css_content = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $css_content);
         // now save the file
         Core_Files::putContent($f_path, $css_content);
     }
     return '<link type="text/css" rel="stylesheet" href="' . $f_public . '"/>';
 }