Ejemplo n.º 1
0
 /**
  * Check if this key is a file backend
  * @param  string  $key
  * @return false|$info
  */
 private function isFile($key)
 {
     if ($this->redis->type($key) == 'string') {
         $info = Str::unserialize($this->redis->get($key));
         if (is_array($info) && isset($info['keystonefile'])) {
             return $info;
         }
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * Format each entity column according to its store attribute rules
  * @return void
  */
 public function format()
 {
     $map = $this->store->properties();
     foreach ($map as $property => $options) {
         $type = isset($options['type']) ? $options['type'] : null;
         if (isset($type)) {
             // Get options and defaults
             $size = isset($options['size']) ? $options['size'] : null;
             $round = isset($options['round']) ? $options['round'] : null;
             $nullable = isset($options['nullable']) ? $options['nullable'] : false;
             $default = isset($options['default']) ? $options['default'] : null;
             $trim = isset($options['trim']) ? $options['trim'] : true;
             $ucwords = isset($options['ucwords']) ? $options['ucwords'] : false;
             $lowercase = isset($options['lowercase']) ? $options['lowercase'] : false;
             $uppercase = isset($options['uppercase']) ? $options['uppercase'] : false;
             $multiline = isset($options['multiline']) ? $options['multiline'] : false;
             $utf8 = isset($options['utf-8']) ? $options['utf-8'] : false;
             $value = $this->{$property};
             if (!$value) {
                 // Value is empty, set to proper empty values
                 switch ($type) {
                     case "string":
                     case "json":
                         $value = $default ?: $nullable ? null : '';
                         break;
                     case "integer":
                         $value = $default ?: $nullable ? null : 0;
                         break;
                     case "decimal":
                         $value = $default ?: $nullable ? null : 0.0;
                         break;
                     case "boolean":
                         $value = $default ?: false;
                         break;
                 }
             } else {
                 if ($type == 'json') {
                     $value = json_encode($value);
                 }
                 // If not multiline, strip carriage returns
                 if (!$multiline) {
                     $value = strtr($value, ["\r\n" => " ", "\n" => " ", "\r" => " "]);
                 }
                 // Don't allow UTF-8
                 if (!$utf8) {
                     $encoding = mb_detect_encoding($value);
                     if ($encoding != "ASCII") {
                         #$value = utf8_encode($value);
                         $value = Str::toAscii($value);
                     }
                 }
                 // Trim if true (default=true)
                 if ($trim) {
                     $value = trim($value);
                 }
                 switch ($type) {
                     case "string":
                         if ($lowercase) {
                             $value = strtolower($value);
                         }
                         if ($uppercase) {
                             $value = strtoupper($value);
                         }
                         if ($ucwords) {
                             $value = ucwords(strtolower($value));
                         }
                         break;
                     case "integer":
                         $value = (int) $value;
                         break;
                     case "decimal":
                         if (isset($size)) {
                             // Add one to offset the decimal point in calculations
                             $options['size']++;
                             $size++;
                         }
                         if (isset($round)) {
                             $value = round((double) $value, $round);
                         } else {
                             $value = (double) $value;
                         }
                         break;
                     case "boolean":
                         $value = (bool) $value;
                         break;
                 }
                 if (isset($size) && strlen($value) > $size) {
                     // Column size overflow
                     $this->fireEvent('overflow', array_merge($options, ['value' => $value, 'value_size' => strlen($value), 'repository' => $this->repository]));
                     $value = substr($value, 0, $size);
                 }
             }
             $this->{$property} = $value;
         }
     }
 }