Esempio n. 1
0
 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;
     }
 }
Esempio n. 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');
 }
Esempio n. 3
0
 protected function error($msg, $options = [])
 {
     $msg = strtr($msg, $options);
     $this->stdout($msg . "\n", Console::FG_RED);
     \Mii::error(strtr($msg, $options), 'console');
 }
Esempio n. 4
0
<?php

require __DIR__ . '/vendor/levmorozov/mii/src/Mii.php';
Mii::set_path(['root' => __DIR__, 'app' => __DIR__ . '/app', 'pub' => __DIR__ . '/public', 'tmp' => __DIR__ . '/tmp', 'vendor' => __DIR__ . '/vendor']);
Esempio n. 5
0
 /**
  * Render the current image.
  *
  *     echo $image;
  *
  * [!!] The output of this function is binary and must be rendered with the
  * appropriate Content-Type header or it will not be displayed correctly!
  *
  * @return  string
  */
 public function __toString()
 {
     try {
         // Render the current image
         return $this->render();
     } catch (\Exception $e) {
         // Get the text of the exception
         $error = Exception::text($e);
         \Mii::error($error);
         // Showing any kind of error will be "inside" image data
         return '';
     }
 }
Esempio n. 6
0
 public function report($exception)
 {
     \Mii::error(Exception::text($exception), 'mii');
 }
Esempio n. 7
0
 public function check_csrf_token($token = false)
 {
     if (!$token) {
         if (isset($_POST[$this->csrf_token_name])) {
             $token = $_POST[$this->csrf_token_name];
         } elseif (null !== ($token = $this->get_csrf_from_header())) {
         } else {
             \Mii::error('crsf_token not found', 'mii');
         }
     }
     return $this->csrf_token() === $token;
 }