Exemple #1
0
 /**
  * @param callable $filter
  * @param callable|array|null $list
  * @return callable
  */
 function list_filter_key_dg($filter, $list = null)
 {
     if (null === $list) {
         $list = tuple_get();
     } elseif (is_array_list($list)) {
         $list = return_dg($list);
     } else {
         debug_assert_type($list, 'callable');
     }
     debug_assert_type($filter, 'callable');
     return function () use($list, $filter) {
         $args = func_get_args();
         $list = call_user_func_array($list, $args);
         return list_filter_key($list, $filter);
     };
 }
Exemple #2
0
 /**
  * @param int|callable $seconds
  * @return callable
  */
 function max_execution_time_set_dg($seconds)
 {
     if (is_numeric($seconds)) {
         $seconds = return_dg($seconds);
     } else {
         debug_enforce_type($seconds, 'callable');
     }
     return function () use($seconds) {
         $args = func_get_args();
         $key = 'max_execution_time';
         $ret = ini_get($key);
         ini_set($key, call_user_func_array($seconds, $args));
         return $ret;
     };
 }
Exemple #3
0
 /**
  * @param string|callable|null $path
  * @return callable
  */
 function loader_require_once_dg($path = null)
 {
     if (null === $path) {
         $path = function () {
             return func_get_arg(0);
         };
     } elseif (is_string($path)) {
         $path = return_dg($path);
     } else {
         debug_enforce_type($path, 'callable');
     }
     return function () use($path) {
         $args = func_get_args();
         return loader_require_once(call_user_func_array($path, $args));
     };
 }
Exemple #4
0
 function debug_enforce_type_dg($type, $var = null)
 {
     if (is_string($type)) {
         $type = return_dg($type);
     } else {
         debug_enforce_type($type, 'callable');
     }
     if (null === $var) {
         $var = tuple_get();
     } else {
         debug_enforce_type($var, 'callable');
     }
     return function () use($type, $var) {
         $args = func_get_args();
         return debug_enforce_type(call_user_func_array($var, $args), call_user_func_array($type, $args));
     };
 }
Exemple #5
0
 /**
  * @param string|callable $column
  * @return callable
  */
 public function propertyExistsDg($column)
 {
     if (is_string($column)) {
         $column = return_dg($column);
     }
     return function () use($column) {
         $args = func_get_args();
         return $this->propertyExists(call_user_func_array($column, $args));
     };
 }
Exemple #6
0
 /**
  * WARNING: Only columns copying supported.
  * @param Lib_Model_Db_Mysql $model
  * @param string|null $thisKeyCol may contain table prefix or not
  * @param string|null $thatKeyCol may contain table prefix or not
  * @param string $conditions
  * @return $this
  */
 public function joinFrom($model, $thisKeyCol, $thatKeyCol = null, $conditions = '')
 {
     if ($thatKeyCol === null) {
         debug_assert($thisKeyCol !== null);
         $thatKeyCol = $model->getPrimaryKey();
     } elseif ($thisKeyCol === null) {
         debug_assert($thatKeyCol !== null);
         $thisKeyCol = $this->getPrimaryKey();
     }
     $this->prefixColumn($model, $thatKeyCol);
     $this->prefixColumn($this, $thisKeyCol);
     $conditions = str_replace('{that}', $model->getAlias(), $conditions);
     $conditions = str_replace('{this}', $this->getAlias(), $conditions);
     $this->mapPartWhere($this->addAliasToConditionDg());
     $model->mapPartWhere($model->addAliasToConditionDg());
     $thisFrom = $this->_select->getPart(Zend_Db_Select::FROM);
     $modelColumns = array_chain($model->_select->getPart(Zend_Db_Select::COLUMNS), array_group_dg(array_get_dg(return_dg(0))), array_map_val_dg(array_chain_dg(array_map_val_dg(function ($descriptor) {
         return null === $descriptor[2] ? $descriptor[1] : [$descriptor[2] => $descriptor[1]];
     }), function ($columns) {
         $outArray = [];
         array_map_val($columns, function ($column) use(&$outArray) {
             if (is_array($column)) {
                 array_map_val($column, function ($column, $alias) use(&$outArray) {
                     $outArray[$alias] = $column;
                 });
             } else {
                 $outArray[] = $column;
             }
         });
         return $outArray;
     })));
     array_each($model->_select->getPart(Zend_Db_Select::FROM), function ($descriptor, $alias) use($modelColumns, $thisFrom, $model, $thisKeyCol, $thatKeyCol, $conditions) {
         debug_enforce(!array_key_exists($alias, $thisFrom), "Alias `{$alias}` already used for table `{$descriptor['tableName']}`");
         switch ($descriptor['joinType']) {
             case Zend_Db_Select::FROM:
                 $this->_select->joinLeft([$model->getAlias() => $model->getTable()], "{$thisKeyCol}={$thatKeyCol} " . $conditions, array_key_exists($alias, $modelColumns) ? $modelColumns[$alias] : [], $descriptor['schema']);
                 break;
             case Zend_Db_Select::INNER_JOIN:
                 $this->_select->joinInner([$alias => $descriptor['tableName']], $descriptor['joinCondition'], array_key_exists($alias, $modelColumns) ? $modelColumns[$alias] : [], $descriptor['schema']);
                 break;
             case Zend_Db_Select::LEFT_JOIN:
                 $this->_select->joinLeft([$alias => $descriptor['tableName']], $descriptor['joinCondition'], array_key_exists($alias, $modelColumns) ? $modelColumns[$alias] : [], $descriptor['schema']);
                 break;
             case Zend_Db_Select::RIGHT_JOIN:
                 $this->_select->joinRight([$alias => $descriptor['tableName']], $descriptor['joinCondition'], array_key_exists($alias, $modelColumns) ? $modelColumns[$alias] : [], $descriptor['schema']);
                 break;
             case Zend_Db_Select::FULL_JOIN:
                 $this->_select->joinFull([$alias => $descriptor['tableName']], $descriptor['joinCondition'], array_key_exists($alias, $modelColumns) ? $modelColumns[$alias] : [], $descriptor['schema']);
                 break;
             case Zend_Db_Select::CROSS_JOIN:
                 $this->_select->joinCross([$alias => $descriptor['tableName']], $descriptor['joinCondition'], array_key_exists($alias, $modelColumns) ? $modelColumns[$alias] : [], $descriptor['schema']);
                 break;
             case Zend_Db_Select::NATURAL_JOIN:
                 $this->_select->joinNatural([$alias => $descriptor['tableName']], $descriptor['joinCondition'], array_key_exists($alias, $modelColumns) ? $modelColumns[$alias] : [], $descriptor['schema']);
                 break;
             default:
                 debug_assert(false, "Unknown join type " . var_dump_human_compact($descriptor['joinType']));
                 break;
         }
     });
     $this->settingsJoin($model);
     return $this;
 }
Exemple #7
0
 function parallel_each_dg($callable, $array = null)
 {
     if ($array === null) {
         $array = tuple_get(0);
     } elseif (!is_callable($array)) {
         $array = return_dg($array);
     }
     return function () use($callable, $array) {
         $args = func_get_args();
         parallel_each(call_user_func_array($array, $args), $callable);
     };
 }
Exemple #8
0
<?php

require __DIR__ . '/../file_system.php';
require __DIR__ . '/../cli.php';
require __DIR__ . '/../debug.php';
require __DIR__ . '/../lst.php';
require __DIR__ . '/../string.php';
require __DIR__ . '/../bool.php';
debug_assert(str_filter('0A--B', not_dg(and_dg(eq_dg(tuple_get(), return_dg('-')), eq_dg(tuple_carry(), tuple_get())))) === '0A-B');
debug_assert(eq_dg(str_filter_dg(not_dg(and_dg(eq_dg(tuple_get(), return_dg('-')), eq_dg(tuple_carry(), tuple_get()))), '0A--B'), return_dg('0A-B')));
debug_assert(eq_dg(str_filter_dg(not_dg(and_dg(eq_dg(tuple_get(), return_dg('-')), eq_dg(tuple_carry(), tuple_get()))), return_dg('0A--B')), return_dg('0A-B')));
debug_assert(call_chain(return_dg('0A--B'), str_filter_dg(not_dg(and_dg(eq_dg(tuple_get(), return_dg('-')), eq_dg(tuple_carry(), tuple_get())))), eq_dg(tuple_get(0), return_dg('0A-B'))));
Exemple #9
0
 /**
  * @param string|callable|null $separator
  * @param array|callable|null
  * @return callable
  */
 function array_implode_dg($separator = null, $array = null)
 {
     if (null === $separator) {
         $separator = return_dg(PHP_EOL);
     } elseif (!is_callable($separator)) {
         $separator = return_dg($separator);
     }
     if (is_null($array)) {
         $array = tuple_get(0);
     } elseif (is_array($array)) {
         $array = return_dg($array);
     } else {
         debug_enforce_type($array, 'callable');
     }
     return function () use($separator, $array) {
         $args = func_get_args();
         return implode(call_user_func_array($separator, $args), call_user_func_array($array, $args));
     };
 }
Exemple #10
0
 /**
  * @param string|callable|null $char
  * @param string|callable|null $placeholder
  * @return string
  */
 function char_accent_map_dg($char = null, $placeholder = null)
 {
     if (null === $char) {
         $char = tuple_get(0);
     } elseif (is_char($char)) {
         $char = return_dg($char);
     } else {
         debug_enforce_type($char, 'callable');
     }
     if (is_null($placeholder)) {
         $placeholder = return_dg('-');
     } elseif (is_string($placeholder)) {
         $placeholder = return_dg($placeholder);
     } else {
         debug_enforce_type($placeholder, 'callable');
     }
     $map = char_accent_map_element();
     return function () use($map, $char, $placeholder) {
         $args = func_get_args();
         $c = call_user_func_array($char, $args);
         $ret = array_key_exists($c, $map) ? $map[$c] : call_user_func_array($placeholder, $args);
         return $ret;
     };
 }
Exemple #11
0
 /**
  * @param callable|string $class
  * @param callable|mixed $arg
  * @return mixed
  */
 function new_1_dg($class, $arg)
 {
     if (!is_callable($class)) {
         $class = return_dg($class);
     }
     if (!is_callable($arg)) {
         $arg = return_dg($arg);
     }
     return function () use($class, $arg) {
         $args = func_get_args();
         $class = call_user_func_array($class, $args);
         $arg = call_user_func_array($arg, $args);
         return new $class($arg);
     };
 }
Exemple #12
0
 /**
  * @param string|callable $string
  * @return callable
  */
 function urlencode_dg($string)
 {
     if (is_string($string)) {
         $string = return_dg($string);
     } else {
         debug_enforce_type($string, 'callable');
     }
     return function () use($string) {
         $args = func_get_args();
         return urlencode(call_user_func_array($string, $args));
     };
 }
Exemple #13
0
 function is_file_dg($path = null)
 {
     if (null === $path) {
         $path = tuple_get(0);
     } elseif (!is_callable($path)) {
         $path = return_dg($path);
     }
     return function () use($path) {
         $args = func_get_args();
         return is_file(call_user_func_array($path, $args));
     };
 }