Example #1
0
File: db.php Project: tapiau/muyo
 /**
  * @param array|int|null $options
  */
 public function __construct($options = null, $init = true)
 {
     if (empty($this->_alias)) {
         $this->_alias = array_chain(get_class($this), str_replace_dg('_', ''), str_replace_dg('\\', ''), strtolower_dg());
     }
     parent::__construct($options, $init);
     $this->normalizeColumns();
 }
Example #2
0
 /**
  * @return array
  */
 public function changedColumnsDiffGet()
 {
     return array_chain($this->recordColumnsGet(), array_filter_key_dg(function ($val, $name) {
         return $this->changedColumnIs($name);
     }), array_map_val_dg(function ($val, $name) {
         $valueFrom = $this->changedColumnGet($name);
         $valueTo = $val;
         return [$valueFrom, $valueTo];
     }));
 }
Example #3
0
File: arr.php Project: tapiau/muyo
 /**
  * @param array $array
  * @param callable $callable
  * @return array
  */
 function array_filter_key_recursive($array, $callable)
 {
     return array_chain($array, array_filter_key_dg($callable), array_map_val_dg(function ($val) use($callable) {
         if (is_array($val)) {
             return array_filter_key_recursive($val, $callable);
         } else {
             return $val;
         }
     }));
 }
Example #4
0
File: net.php Project: tapiau/muyo
 /**
  * @param string $string
  * @return array
  */
 function http_accept_decode($string)
 {
     return array_chain(explode(',', $string), array_map_val_dg(str_explode_dg(';')), array_map_val_dg(function ($pair) {
         if (1 === count($pair)) {
             $pair[] = 1.0;
         } else {
             debug_enforce(str_startswith($pair[1], 'q='));
             $pair[1] = floatval(str_find_after($pair[1], 'q='));
         }
         return $pair;
     }));
 }
Example #5
0
 /**
  * @param string $directory
  * @param int $order_flag
  * @param resource|null $context
  * @return array
  */
 function directory_list($directory, $order_flag = SCANDIR_SORT_ASCENDING, $context = null)
 {
     debug_enforce(is_dir($directory), "Parameter " . var_dump_human_compact($directory) . " is not a directory.");
     debug_enforce(in_array($order_flag, [SCANDIR_SORT_DESCENDING, SCANDIR_SORT_ASCENDING, SCANDIR_SORT_NONE]), "Invalid order flag " . var_dump_human_compact($order_flag));
     debug_enforce(is_null($context) || is_resource($context), "Invalid resource context " . var_dump_human_compact($context));
     $directory = ensure($directory, str_endswith_dg(DIRECTORY_SEPARATOR), str_append_dg(DIRECTORY_SEPARATOR));
     if (is_null($context)) {
         $ret = scandir($directory, $order_flag);
     } else {
         $ret = scandir($directory, $order_flag, $context);
     }
     debug_enforce(false !== $ret, posix_get_last_error());
     return array_chain($ret, array_filter_key_dg(not_dg(in_array_dg(['..', '.']))), array_map_val_dg(str_prepend_dg($directory)));
 }
Example #6
-1
 /**
  * @param string $term
  * @param array $eqCol
  * @param array $likeCol
  * @param array $additionalSelectCol
  * @return $this
  */
 public function buildSearchCondition($term, array $eqCol = array(), array $likeCol = array(), array $additionalSelectCol = array())
 {
     $collate = 'utf8_general_ci';
     $mappedTerm = str_map($term, function ($char) {
         return ctype_alnum($char) ? $char : ' ';
     });
     $db = $this->getDb();
     $firstOne = true;
     $where = array_chain(explode(' ', $mappedTerm), array_filter_key_dg(not_dg(empty_dg())), array_map_val_dg(function ($termPart) use($db, $likeCol, $eqCol, $collate, &$firstOne) {
         if ($firstOne) {
             $t1 = $db->quote("{$termPart}%", 'string');
             $firstOne = false;
         } else {
             $t1 = $db->quote("%{$termPart}%", 'string');
         }
         $t2 = $db->quote($termPart, 'string');
         $whereLike = array_map_val($likeCol, function ($column) use($collate, $termPart, $t1) {
             return "{$column} COLLATE {$collate} LIKE {$t1}";
         });
         $whereEq = array_map_val($eqCol, function ($column) use($termPart, $t2) {
             return "{$column} = {$t2}";
         });
         $where = array_merge($whereLike, $whereEq);
         return '( ' . implode(' OR ', $where) . ' )';
     }));
     $this->setColumns(array_merge($eqCol, $likeCol, $additionalSelectCol))->setWhere(implode(" AND ", $where));
     return $this;
 }