Ejemplo n.º 1
0
 /**
  * retourne la langue de la requête.
  *
  * @return string|null
  */
 public function language()
 {
     return Str::slice($this->locale(), 0, 2);
 }
Ejemplo n.º 2
0
 /**
  * fillTable, remplir un table pour permet le developpement.
  *
  * @param string|array $table [optional]
  * @param int $n
  * @param array $desciption [
  *      "column" => [
  *          "field" => "name",
  *          "type": "int|longint|bigint|mediumint|smallint|tinyint",
  *          "auto" => false|true
  *      ]
  * @return mixed
  */
 public static function fillTable($table = null, $n = 1, $desciption = [])
 {
     if (is_int($table)) {
         $n = $table;
         $table = null;
     }
     if (!is_string($table)) {
         $table = static::$table;
     }
     $database = Database::table($table);
     if (static::$data === null) {
         static::$data = $desciption;
     }
     $r = 0;
     for ($i = 0; $i < $n; $i++) {
         $data = [];
         foreach (static::$data as $column) {
             if (in_array($column['type'], ['int', 'longint', 'bigint', 'mediumint', 'smallint', 'tinyint'])) {
                 if ($column['auto']) {
                     $value = null;
                 } else {
                     $value = Filler::number();
                 }
             } else {
                 if (in_array($column['type'], ['date', 'datetime'])) {
                     $value = Filler::date();
                 } else {
                     if (in_array($column['type'], ['double', 'float'])) {
                         $value = Filler::float();
                     } else {
                         if ($column['type'] == 'timestamp') {
                             $value = time();
                         } else {
                             if ($column['type'] == 'enum') {
                                 $value = $column['default'];
                             } else {
                                 if (preg_match('/text$/', $column['type'])) {
                                     $value = Str::slice(Filler::string(), 0, 1000);
                                 } else {
                                     $value = Str::slice(Filler::string(), 0, rand(1, $column['size']));
                                 }
                             }
                         }
                     }
                 }
             }
             $data[$column['field']] = $value;
         }
         $r += $database->insert($data);
     }
     return $r;
 }