Example #1
0
 function read($uri)
 {
     if (!($entity = Buffer::get_entity($uri))) {
         // Экземпляра объекта в буфере нет, проверяем массив его атрибутов в буфере
         $info = Buffer::get_info($uri);
         if (empty($info)) {
             try {
                 $q = $this->db->prepare('
                             SELECT * FROM `entity` WHERE `entity`.uri = :uri
                         ');
                 $q->execute(['uri' => $uri]);
                 $row = $q->fetch(DB::FETCH_ASSOC);
             } catch (\Exception $e) {
                 return false;
             }
         }
     }
 }
Example #2
0
 /**
  * @param $cond
  * <code>
  * [
  *      'select' => 'children', //self, children, parents, heirs, protos, child, link
  *      'calc' => 'count', // false, exists, count, [sum, attr], [max, attr], [min, attr], [avg, attr]
  *      'from' => '/contents',
  *      'depth' => 1, // maximum depth
  *      'struct' => 'array', // value, object, array, tree
  *      'where' => [], //filter condition
  *      'order' => [['name', 'asc'], ['value','desc']],
  *      'limit' => [0,100],
  *      'key' => 'name', // attribute name
  *      'access' => true // check read access
  * ];
  * </code>
  * @return array
  */
 function find($cond)
 {
     // select, from, depth
     $dir = $cond['from'] === '' ? DIR : DIR . trim($cond['from'], '/') . '/';
     $objects = [];
     try {
         if ($cond['depth'] > 0) {
             if ($cond['select'] == 'properties') {
                 // Читаем, чтобы инфо о свойства попало в буфер
                 $from = $this->read($cond['from']);
                 // need for Buffer::get_props
                 if ($prop_names = Buffer::get_props($cond['from'])) {
                     foreach ($prop_names as $prop_uri) {
                         // Проверка объекта на соответствие услвоию [where]
                         if ($obj = $this->read($prop_uri)) {
                             if (!$cond['where'] || $obj->verify($cond['where'])) {
                                 $objects[] = $obj;
                                 if ($cond['calc'] == 'exists') {
                                     break;
                                 }
                             }
                         }
                     }
                 }
             } else {
                 if ($cond['select'] == 'children') {
                     // Игнорируемые директории/файлы
                     $ignore = array_flip(['.', '..', '.git']);
                     // Перебор директории в глубь. (Рекурсия на циклах)
                     if ($dh = new \DirectoryIterator($dir)) {
                         $stack = [['name' => '', 'dh' => $dh, 'depth' => $cond['depth'], 'parent' => $cond['from']]];
                         do {
                             $curr = end($stack);
                             while ($curr['dh']->valid()) {
                                 /** @var \DirectoryIterator $file */
                                 $file = $curr['dh']->current();
                                 $cur_dh = $curr['dh'];
                                 if (($name = $file->getFilename()) !== '') {
                                     if (!isset($ignore[$name])) {
                                         $uri = $curr['name'] === '' ? $curr['parent'] : $curr['parent'] . '/' . $curr['name'];
                                         if ($name == $curr['name'] . '.info') {
                                             if (!($obj = Buffer::get_entity($uri))) {
                                                 if (!($info = Buffer::get_info($uri))) {
                                                     // Все сведения об объекте в формате json (если нет класса объекта)
                                                     $f = file_get_contents($file->getPathname());
                                                     $info = json_decode($f, true);
                                                     $error = json_last_error();
                                                     if ($error != JSON_ERROR_NONE) {
                                                         $info = [];
                                                         //                                                        throw new \Exception('Ошибка в "' . $curr['dir'] . $name . '"');
                                                     }
                                                     $info['uri'] = $uri;
                                                     if (!empty($info['file'])) {
                                                         $info['is_default_file'] = false;
                                                         //                                                    $info['is_file'] = true;
                                                         //                                                    $info['value'] = $info['file'];
                                                     }
                                                     if (!empty($info['logic'])) {
                                                         $info['is_default_logic'] = false;
                                                     }
                                                     if (!isset($info['is_default_logic'])) {
                                                         $info['is_default_logic'] = true;
                                                     }
                                                     $info['is_exists'] = true;
                                                 }
                                                 if ($info && empty($info['is_property'])) {
                                                     $info = Buffer::set_info($info);
                                                     $obj = Data::entity($info);
                                                 }
                                             }
                                             // Проверка объекта на соответствие услвоию [where]
                                             if ($obj && !$obj->is_property()) {
                                                 if (!$cond['where'] || $obj->verify($cond['where'])) {
                                                     $objects[] = $obj;
                                                     if ($cond['calc'] == 'exists') {
                                                         break;
                                                     }
                                                 }
                                             }
                                         } else {
                                             if ($curr['depth'] && $file->isDir()) {
                                                 if ($dh = new \DirectoryIterator($file->getPathname())) {
                                                     $stack[] = ['name' => $name, 'dh' => $dh, 'depth' => $curr['depth'] - 1, 'parent' => $uri];
                                                     $curr = end($stack);
                                                 }
                                             }
                                         }
                                     }
                                 }
                                 $cur_dh->next();
                             }
                             array_pop($stack);
                         } while ($stack);
                     }
                 }
             }
         }
     } catch (\Exception $e) {
     }
     // access
     // calc
     if ($cond['calc']) {
         $calc = null;
         if ($cond['calc'] == 'exists') {
             $calc = !empty($objects);
         } else {
             if ($cond['calc'] == 'count') {
                 $calc = count($objects);
             } else {
                 if (is_array($cond['calc']) && count($cond['calc']) == 2) {
                     $attr = $cond['calc'][1];
                     foreach ($objects as $o) {
                         switch ($cond['calc'][0]) {
                             case 'min':
                                 $calc = $calc === null ? $o->attr($attr) : min($o->attr($attr), $calc);
                                 break;
                             case 'max':
                                 $calc = $calc === null ? $o->attr($attr) : max($o->attr($attr), $calc);
                                 break;
                             case 'sum':
                             case 'avg':
                             default:
                                 $calc += $o->attr($attr);
                                 break;
                         }
                     }
                     if ($objects && $cond['calc'][0] == 'avg') {
                         $calc = $calc / count($objects);
                     }
                 }
             }
         }
         return $calc;
     }
     // order
     if ($order = $cond['order']) {
         $order_cnt = count($order);
         usort($objects, function ($a, $b) use($order, $order_cnt) {
             /** @var $a Entity */
             /** @var $b Entity */
             $i = 0;
             do {
                 if (count($order[$i]) == 3) {
                     $a = $a->{$order[$i][0]};
                     $b = $b->{$order[$i][0]};
                     array_shift($order[$i]);
                 }
                 $a = $a ? $a->{$order}[$i][0]() : null;
                 $b = $b ? $b->{$order}[$i][0]() : null;
                 if ($a == $b) {
                     $comp = 0;
                 } else {
                     $comp = $a > $b || $a === null ? 1 : -1;
                     if ($order[$i][1] == 'desc') {
                         $comp = -$comp;
                     }
                 }
                 $i++;
             } while ($comp == 0 && $i < $order_cnt);
             return $comp;
         });
     }
     // limit (not for value and object)
     if ($cond['limit']) {
         $objects = array_slice($objects, $cond['limit'][0], $cond['limit'][1]);
     }
     // struct, key
     if ($cond['struct'] == 'tree') {
         $first_level = mb_substr_count($cond['from'], '/') + 1;
         $tree = [];
         $result = [];
         foreach ($objects as $obj) {
             $tree[$obj->uri()] = ['object' => $obj, 'sub' => []];
             if ($obj->depth() == $first_level) {
                 $key = $cond['key'] ? $obj->attr($cond['key']) : null;
                 if ($key) {
                     $result[$key] =& $tree[$obj->uri()];
                 } else {
                     $result[] =& $tree[$obj->uri()];
                 }
             }
         }
         foreach ($tree as $uri => $obj) {
             $key = $cond['key'] ? $obj['object']->attr($cond['key']) : null;
             $p = $obj['object']->attr('parent');
             if (isset($tree[$p])) {
                 if ($key) {
                     $tree[$p]['sub'][$key] =& $tree[$uri];
                 } else {
                     $tree[$p]['sub'][] =& $tree[$uri];
                 }
             }
         }
         return $result;
     } else {
         if ($cond['struct'] == 'array' && $cond['key']) {
             $result = [];
             /** @var Entity $item */
             foreach ($objects as $item) {
                 $result[$item->attr($cond['key'])] = $item;
             }
             return $result;
         }
     }
     return $objects;
 }
Example #3
0
 static function entity($info)
 {
     $key = isset($info['uri']) ? $info['uri'] : null;
     if (!isset($key) || !($entity = Buffer::get_entity($key))) {
         try {
             $name = basename($info['uri']);
             if (isset($info['uri'])) {
                 if (!empty($info['is_default_logic'])) {
                     if (isset($info['proto'])) {
                         // Класс от прототипа
                         $class = get_class(self::read($info['proto']));
                     } else {
                         // Класс наследуется, но нет прототипа
                         $class = '\\boolive\\core\\data\\Entity';
                     }
                 } else {
                     if (empty($info['uri']) || preg_match('#^[a-zA-Z_0-9\\/]+$#ui', $info['uri'])) {
                         $namespace = str_replace('/', '\\', rtrim($info['uri'], '/'));
                         // Свой класс
                         if (empty($namespace)) {
                             $class = '\\project';
                         } else {
                             if (substr($namespace, 0, 7) === '\\vendor') {
                                 $class = substr($namespace, 7) . '\\' . $name;
                             } else {
                                 $class = $namespace . '\\' . $name;
                             }
                         }
                     } else {
                         $class = '\\boolive\\core\\data\\Entity';
                     }
                 }
             } else {
                 $class = '\\boolive\\core\\data\\Entity';
             }
             if (isset($info['value']) && !isset($info['is_default_value'])) {
                 $info['is_default_value'] = false;
             }
             if (!isset($info['is_default_value'])) {
                 $info['is_default_value'] = true;
             }
             if (!isset($info['value']) && !empty($info['is_default_value']) && !empty($info['proto'])) {
                 $info['value'] = Data::read($info['proto'])->value();
             }
             //                if (!isset($info['is_mandatory']) && isset($info['proto'])){
             //                    $proto = self::read($info['proto']);
             //                    $info['is_mandatory'] = $proto->is_mandatory();
             //                }
             $entity = new $class($info);
         } catch (\ErrorException $e) {
             $entity = new Entity($info);
         }
         if (isset($key)) {
             Buffer::set_entity($entity);
         }
     }
     return $entity;
 }
Example #4
0
 /**
  * Сохранение сущности
  * @param Entity $entity
  * @throws Error
  */
 function write($entity)
 {
     // @todo
     // Смена родителя/прототипа требует соответсвующие сдвиги в таблице отношений
     // При смене uri нужно обновить uri подчиненных
     $attr = $entity->attributes();
     // Локальные id
     $attr['parent'] = isset($attr['parent']) ? $this->localId($attr['parent']) : 0;
     $attr['proto'] = isset($attr['proto']) ? $this->localId($attr['proto']) : 0;
     $attr['author'] = isset($attr['author']) ? $this->localId($attr['author']) : 0;
     //$this->localId(Auth::get_user()->uri());
     // Подбор уникального имени, если указана необходимость в этом
     if ($entity->is_changed('uri') || !$entity->is_exists()) {
         $q = $this->db->prepare('SELECT 1 FROM {objects} WHERE parent=? AND `name`=? LIMIT 0,1');
         $q->execute(array($attr['parent'], $attr['name']));
         if ($q->fetch()) {
             //Выбор записи по шаблону имени с самым большим префиксом
             $q = $this->db->prepare('SELECT `name` FROM {objects} WHERE parent=? AND `name` REGEXP ? ORDER BY CAST((SUBSTRING_INDEX(`name`, "_", -1)+1) AS SIGNED) DESC LIMIT 0,1');
             $q->execute(array($attr['parent'], '^' . $attr['name'] . '(_[0-9]+)?$'));
             if ($row = $q->fetch(DB::FETCH_ASSOC)) {
                 preg_match('|^' . preg_quote($attr['name']) . '(?:_([0-9]+))?$|u', $row['name'], $match);
                 $attr['name'] .= '_' . (isset($match[1]) ? $match[1] + 1 : 1);
             }
         }
         $entity->name($attr['name']);
         $attr['uri'] = $entity->uri();
     }
     Buffer::set_entity($entity);
     // Локальный идентификатор объекта
     $attr['id'] = $this->localId($entity->uri($entity->is_exists()), true, $new_id);
     // Если смена файла, то удалить текущий файл
     if ($entity->is_changed('file')) {
         $current_file = $entity->changes('file');
         if (is_string($current_file)) {
             File::delete($entity->dir(true) . $current_file);
         }
     }
     // Если привязан файл
     if (!$entity->is_default_file()) {
         if ($entity->is_file()) {
             $file_attache = $entity->file();
             if (is_array($file_attache)) {
                 // Загрузка файла
                 if (!($attr['file'] = Data::save_file($entity, $file_attache))) {
                     $attr['file'] = '';
                 }
             } else {
                 $attr['file'] = basename($file_attache);
             }
         } else {
             // файла нет, но нужно отменить наследование файла
             $attr['file'] = '';
         }
     } else {
         $attr['file'] = '';
     }
     // Уникальность order
     // Если изменено на конкретное значение (не максимальное)
     if ($attr['order'] != Entity::MAX_ORDER && (!$entity->is_exists() || $entity->is_changed('order'))) {
         // Проверка, занят или нет новый order
         $q = $this->db->prepare('SELECT 1 FROM {objects} WHERE `parent`=? AND `order`=?');
         $q->execute(array($attr['parent'], $attr['order']));
         if ($q->fetch()) {
             // Сдвиг order существующих записей, чтоб освободить значение для новой
             $q = $this->db->prepare('
                 UPDATE {objects} SET `order` = `order`+1
                 WHERE `parent`=? AND `order`>=?');
             $q->execute(array($attr['parent'], $attr['order']));
         }
         unset($q);
     } else {
         // Новое максимальное значение для order, если объект новый или явно указано order=null
         if (!$entity->is_exists() || $attr['order'] == Entity::MAX_ORDER) {
             // Порядковое значение вычисляется от максимального существующего
             $q = $this->db->prepare('SELECT MAX(`order`) m FROM {objects} WHERE parent=?');
             $q->execute(array($attr['parent']));
             if ($row = $q->fetch(DB::FETCH_ASSOC)) {
                 $attr['order'] = $row['m'] + 1;
             }
             unset($q);
         }
     }
     $this->db->beginTransaction();
     // Если новое имя или родитель, то обновить свой URI и URI подчиненных
     if ($entity->is_changed('name') || $entity->is_changed('parent')) {
         if ($entity->is_exists()) {
             $current_uri = $entity->uri(true);
             $current_name = $entity->is_changed('name') ? $entity->changes('name') : $attr['name'];
             // Текущий URI
             $names = F::splitRight('/', $current_uri, true);
             $uri = (isset($names[0]) ? $names[0] . '/' : '') . $current_name;
             // Новый URI
             $names = F::splitRight('/', $attr['uri'], true);
             $uri_new = (isset($names[0]) ? $names[0] . '/' : '') . $attr['name'];
             $entity->change('uri', $uri_new);
             // @todo Обновление URI подчиенных в базе
             // нужно знать текущий уковень вложенности и локальный id
             //
             //            $q = $this->db->prepare('UPDATE {ids}, {parents} SET {ids}.uri = CONCAT(?, SUBSTRING(uri, ?)) WHERE {parents}.parent_id = ? AND {parents}.object_id = {ids}.id AND {parents}.is_delete=0');
             //            $v = array($uri_new, mb_strlen($uri)+1, $attr['id']);
             //            $q->execute($v);
             //            // Обновление уровней вложенностей в objects
             //            if (!empty($current) && $current['parent']!=$attr['parent']){
             //                $dl = $attr['parent_cnt'] - $current['parent_cnt'];
             //                $q = $this->db->prepare('UPDATE {objects}, {parents} SET parent_cnt = parent_cnt + ? WHERE {parents}.parent_id = ? AND {parents}.object_id = {objects}.id AND {parents}.is_delete=0');
             //                $q->execute(array($dl, $attr['id']));
             //                // Обновление отношений
             //                $this->makeParents($attr['id'], $attr['parent'], $dl, true);
             //            }
             if (!empty($uri) && is_dir(DIR . $uri)) {
                 // Переименование/перемещение папки объекта
                 $dir = DIR . $uri_new;
                 File::rename(DIR . $uri, $dir);
                 if ($entity->is_changed('name')) {
                     // Переименование файла класса
                     File::rename($dir . '/' . $current_name . '.php', $dir . '/' . $attr['name'] . '.php');
                     // Переименование .info файла
                     File::rename($dir . '/' . $current_name . '.info', $dir . '/' . $attr['name'] . '.info');
                 }
             }
             unset($q);
         }
         // Обновить URI подчиненных объектов не фиксируя изменения
         $entity->updateChildrenUri();
     }
     // Если значение больше 255
     if (mb_strlen($attr['value']) > 255) {
         $q = $this->db->prepare('
             INSERT INTO {text} (`id`, `value`)
             VALUES (:id, :value)
             ON DUPLICATE KEY UPDATE `value` = :value
         ');
         $q->execute(array(':id' => $attr['id'], ':value' => $attr['value']));
         $attr['value'] = mb_substr($attr['value'], 0, 255);
         $attr['is_text'] = 1;
     } else {
         $attr['is_text'] = 0;
     }
     // Запись
     $attr_names = array('id', 'parent', 'proto', 'author', 'order', 'name', 'value', 'file', 'is_text', 'is_draft', 'is_hidden', 'is_link', 'is_mandatory', 'is_property', 'is_relative', 'is_default_value', 'is_default_logic', 'created', 'updated');
     $cnt = sizeof($attr_names);
     // Запись объекта (создание или обновление при наличии)
     // Объект идентифицируется по id
     if (!$entity->is_exists()) {
         $q = $this->db->prepare('
             INSERT INTO {objects} (`' . implode('`, `', $attr_names) . '`)
             VALUES (' . str_repeat('?,', $cnt - 1) . '?)
             ON DUPLICATE KEY UPDATE `' . implode('`=?, `', $attr_names) . '`=?
         ');
         $i = 0;
         foreach ($attr_names as $name) {
             $value = $attr[$name];
             $i++;
             $type = is_int($value) ? DB::PARAM_INT : (is_bool($value) ? DB::PARAM_BOOL : (is_null($value) ? DB::PARAM_NULL : DB::PARAM_STR));
             $q->bindValue($i, $value, $type);
             $q->bindValue($i + $cnt, $value, $type);
         }
         $q->execute();
     } else {
         $q = $this->db->prepare('
             UPDATE {objects} SET `' . implode('`=?, `', $attr_names) . '`=? WHERE id = ?
         ');
         $i = 0;
         foreach ($attr_names as $name) {
             $value = $attr[$name];
             $i++;
             $type = is_int($value) ? DB::PARAM_INT : (is_bool($value) ? DB::PARAM_BOOL : (is_null($value) ? DB::PARAM_NULL : DB::PARAM_STR));
             $q->bindValue($i, $value, $type);
         }
         $q->bindValue(++$i, $attr['id']);
         $q->execute();
     }
     $this->db->commit();
     foreach ($entity->children() as $child) {
         Data::write($child);
     }
     return true;
 }
Example #5
0
 function work(Request $request)
 {
     $uri = '';
     //        $s = C::read();
     //        C::writeln(mb_detect_encoding($s,['utf-8','cp866']));
     do {
         try {
             C::write(C::style($uri, [C::COLOR_GRAY_DARK]) . '> ');
             $commands = preg_split('/\\s/ui', trim(C::read()));
             $cmd_count = count($commands);
             if ($commands[0] == 'show') {
                 $new_uri = !empty($commands[1]) ? $uri . '/' . trim($commands[1], ' \\/') : $uri;
                 $obj = Data::read($new_uri);
                 C::writeln(C::style(Trace::format($obj, false)));
             } else {
                 if (mb_strlen($commands[0]) > 1 && ($commands[0][0] == '/' || mb_substr($commands[0], 0, 2) == '..')) {
                     $new_uri = !empty($commands[0]) ? $uri . '/' . trim($commands[0], ' \\/') : $uri;
                     $obj = Data::read($new_uri, false, true);
                     if ($obj && $obj->is_exists()) {
                         $uri = $obj->uri();
                     } else {
                         C::writeln(C::style('Object does not exist', C::COLOR_RED));
                     }
                 } else {
                     if ($commands[0] == 'ls' || $commands[0] == 'children') {
                         $list = Data::find(['from' => $uri, 'select' => empty($commands[1]) || $commands[1] != '-p' ? 'children' : 'properties', 'struct' => 'list', 'limit' => [0, 50]]);
                         foreach ($list as $obj) {
                             C::writeln(C::style($obj->name(), C::COLOR_BLUE));
                         }
                     } else {
                         if (preg_match('/^\\s*select(\\(|=)/ui', $commands[0])) {
                             $cond = Data::normalizeCond($commands[0], false);
                             if (!isset($cond['from'])) {
                                 $cond['from'] = $uri;
                             }
                             $result = Data::find($cond);
                             C::writeln(C::style(Trace::format($result, false)));
                         } else {
                             if ($commands[0] == 'color') {
                                 if (!empty($commands[1])) {
                                     C::use_style($commands[1] == 'off' ? false : null);
                                 } else {
                                     C::use_style(true);
                                 }
                             } else {
                                 if ($cmd_count > 1 && $commands[0] == 'attr') {
                                     $obj = Data::read($uri);
                                     $attr = $commands[1];
                                     if ($obj instanceof Entity && $obj->is_exists() && $obj->is_attr($attr)) {
                                         if ($cmd_count > 2) {
                                             if ($commands[2] === "null") {
                                                 $commands[2] = null;
                                             } else {
                                                 if ($commands[2] === "false") {
                                                     $commands[2] = false;
                                                 } else {
                                                     $commands[2] = trim(trim($commands[2], '"'));
                                                 }
                                             }
                                             $obj->{$attr}($commands[2]);
                                             Data::write($obj);
                                             C::writeln(Trace::format($obj, false));
                                         } else {
                                             C::writeln(C::style($obj->attr($attr)), C::COLOR_PURPLE);
                                         }
                                     }
                                 } else {
                                     if ($cmd_count > 2 && $commands[0] == 'new') {
                                         $new_uri = !empty($commands[1]) ? $uri . '/' . trim($commands[1], ' \\/') : $uri;
                                         list($parent, $name) = F::splitRight('/', $new_uri);
                                         if (!$parent) {
                                             $parent = '';
                                         }
                                         $proto = $commands[2];
                                         $obj = Data::create($proto, $parent, ['name' => $name]);
                                         $signs = array_flip($commands);
                                         if (isset($signs['-m'])) {
                                             $obj->is_mandatory(true);
                                         }
                                         if (isset($signs['-p'])) {
                                             $obj->is_property(true);
                                         }
                                         if (isset($signs['-d'])) {
                                             $obj->is_draft(true);
                                         }
                                         if (isset($signs['-h'])) {
                                             $obj->is_hidden(true);
                                         }
                                         if (isset($signs['-l'])) {
                                             $obj->is_link(true);
                                         }
                                         if (isset($signs['-r'])) {
                                             $obj->is_relative(true);
                                         }
                                         $obj->complete();
                                         Data::write($obj);
                                         C::writeln(Trace::format($obj, false));
                                     } else {
                                         if ($commands[0] == 'complete') {
                                             $obj = Data::read($uri);
                                             $signs = array_flip($commands);
                                             $only_mandatory = !isset($signs['-all']) && !isset($signs['-not-mandatory']);
                                             $only_property = !isset($signs['-all']) && !isset($signs['-not-property']);
                                             $obj->complete($only_mandatory, $only_property);
                                             Data::write($obj);
                                             C::writeln(Trace::format($obj, false));
                                         } else {
                                             C::writeln(C::style('Unknown command', C::COLOR_RED));
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         } catch (Error $e) {
             C::writeln(C::style($e->getMessage(), C::COLOR_RED));
         } catch (\Exception $e) {
             C::writeln(C::style((string) $e, C::COLOR_RED));
         }
         Buffer::clear();
     } while ($commands[0] !== 'exit');
     C::writeln("\nby!");
     //        if (!empty($request['ARG'][2])) {
     //            if ($request['ARG'][2] == 'read') {
     //                $uri = empty($request['ARG'][3]) ? '' : '/' . trim($request['ARG'][3], '/');
     //                $obj = Data::read($uri);
     //                C::writeln(C::style(Trace::style($obj, false)));
     //            } else
     //            if ($request['ARG'][2] == 'find') {
     //                $cond = empty($request['ARG'][3]) ? '' : trim($request['ARG'][3], '/');
     //                $result = Data::find($cond);
     //                C::write(C::style(Trace::style($result, false)));
     //            } else
     //            if ($request['ARG'][2] == 'edit') {
     //                $object = Data::read(empty($request['ARG'][3]) ? '' : '/'.trim($request['ARG'][3], '/'));
     //                $attr = empty($request['ARG'][4]) ? null : $request['ARG'][4];
     //                $value = empty($request['ARG'][5]) ? null : $request['ARG'][5];
     //                if ($object instanceof Entity && $object->is_exists() && $attr){
     //                    $object->{$attr}($value);
     //                    Data::write($object);
     //                    C::write(C::style(Trace::style($object, false)));
     //                }
     //            }else
     //            {
     ////        phpinfo();
     ////        C::writeln(Trace::style($_ENV, false));
     ////        C::writeln(getenv('ANSICON'));
     //                C::writeln(
     //                    C::style(json_encode($request['ARG']), [C::STYLE_BOLD, C::STYLE_UNDERLINE, C::COLOR_BLUE]));
     //                //$a = C::read();
     //                //C::writeln($a);
     //
     ////        fwrite(STDOUT, $colors->getColoredString("Testing Colors class, this is purple string on yellow background.", "purple", "yellow") . "\n");
     ////        $line = fgets(STDIN);
     ////        if(trim($line) != 'yes'){
     ////            echo "ABORTING!\n";
     ////            exit;
     ////        }
     ////        echo "\n";
     ////        echo "Thank you, continuing...\n";
     ////        return true;
     //            }
     //        }
 }