Пример #1
0
 function getDateTime($time, $zone = null)
 {
     if (is_a($time, 'DateTime')) {
         return $time;
     }
     $zone = $this->getZone($zone);
     if (Tool::isInt($time)) {
         $Date = new \DateTime(null, $zone);
         $Date->setTimestamp($time);
         return $Date;
     }
     return new \DateTime($time, $zone);
 }
Пример #2
0
 static function age($value, $min = null, $max = null)
 {
     $time = new Time($value);
     $age = $time->diff(new Time('now'));
     if (Tool::isInt($max) && $age->y > $max) {
         Debug::toss(['type' => 'age_max', 'detail' => $max], 'InputException');
     }
     if (Tool::isInt($min) && $age->y < $min) {
         Debug::toss(['type' => 'age_min', 'detail' => $min], 'InputException');
     }
 }
Пример #3
0
 static function pretty($data, $caller = false)
 {
     if (!$caller) {
         $caller = self::caller();
     }
     $string = '[' . $caller['file'] . ':' . $caller['line'] . '](#' . self::$pretty_increment . ') : ';
     if (!is_string($data)) {
         #JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, and JSON_UNESCAPED_UNICODE options were added.
         $json = Tool::flat_json_encode($data, JSON_PRETTY_PRINT);
         $start_bracket = '[\\[\\{]+';
         $end_bracket = '[\\]\\}]+';
         $start_line = '(?<=\\n|^)';
         $end_line = '(?=\\n|$)';
         # condense start brackets
         $json = preg_replace('@' . $start_line . '(\\s*' . $start_bracket . ')\\n\\s*@', '$1', $json);
         # condense end brackets
         $json = preg_replace('@\\n\\s*(' . $end_bracket . ',?)' . $end_line . '@', '$1', $json);
         $string .= $json;
     } else {
         $string .= $data;
     }
     self::$pretty_increment++;
     return $string;
 }
Пример #4
0
 /**
 	@param	dict	dictionary to update on query
 */
 protected function namedId($table, $name, &$dict = null)
 {
     if (Tool::isInt($name)) {
         return $name;
     }
     $id = $this->value($table, ['name' => $name], 'id');
     if ($dict !== null) {
         $dict[$name] = $id;
     }
     return $id;
 }
Пример #5
0
 function int($v)
 {
     if (!Tool::isInt($v)) {
         self::error();
     }
     return $v;
 }
Пример #6
0
 static function endJson($content, $encode = true)
 {
     header('Content-type: application/json');
     if ($encode) {
         echo \Grithin\Tool::json_encode($content);
     } else {
         echo $content;
     }
     exit;
 }