示例#1
0
文件: Simple.php 项目: levmorozov/mii
 public function __construct($config = [])
 {
     foreach ($config as $key => $value) {
         $this->{$key} = $value;
     }
     if ($this->base_path) {
         $this->base_path = \Mii::resolve($this->base_path);
     } else {
         $this->base_path = path('app') . '/messages';
     }
     if ($this->language === null) {
         $this->language = \Mii::$app->language;
     }
 }
示例#2
0
 public function before()
 {
     $config = config('migrate', []);
     foreach ($config as $name => $value) {
         $this->{$name} = $value;
     }
     if (empty($this->migrations_paths)) {
         $this->migrations_paths = [path('app') . '/migrations'];
     }
     try {
         $this->applied_migrations = DB::select('SELECT `name`, `date` FROM `' . $this->migrate_table . '`')->index_by('name')->all();
     } catch (\Exception $e) {
         $this->info('Trying to create table :table', [':table' => $this->migrate_table]);
         DB::update('CREATE TABLE `' . $this->migrate_table . '` (
           `name` varchar(180) NOT NULL,
           `date` int(11),
            PRIMARY KEY (`name`)
         );');
         $this->applied_migrations = [];
     }
     $files = [];
     for ($i = 0; $i < count($this->migrations_paths); $i++) {
         $this->migrations_paths[$i] = \Mii::resolve($this->migrations_paths[$i]);
     }
     foreach ($this->migrations_paths as $migrations_path) {
         if (!is_dir($migrations_path)) {
             $this->warning('Directory :dir does not exist', [':dir' => $migrations_path]);
             mkdir($migrations_path, 0775);
         }
         $scan = scandir($migrations_path);
         foreach ($scan as $file) {
             if ($file[0] == '.') {
                 continue;
             }
             $info = pathinfo($file);
             if ($info['extension'] !== 'php') {
                 continue;
             }
             $name = $info['filename'];
             $this->migrations_list[$name] = ['name' => $name, 'file' => $migrations_path . '/' . $file, 'applied' => isset($this->applied_migrations[$name]), 'date' => 0];
         }
     }
     uksort($this->migrations_list, 'strnatcmp');
 }