new
? Имхо, это перебор. Не отвалятся у вас руки три лишних символа написать, и это будет куда нагляднее чем непонятные излишние функции.function exportConstruct<P extends any[], T>(classFromExport: { new (...args: P): T; }):
(...args: P) => T {
return (...args) => new classFromExport(...args);
}
function exportCallable<T extends { new (...args: any[]): any; }>(classFromExport: T) {
return new Proxy(classFromExport, {
apply(ctor, _, args) {
return new ctor(...args);
}
}) as T & ((...args: ConstructorParameters<T>) => InstanceType<T>);
}
const Lol = exportCallable(class Lol extends BaseLol {
constructor(public name: string) {
super();
this.name = name.toUpperCase();
}
});
Lol('qwe');
abstract class Newable {
static new<P extends any[], T>(this: { new (...args: P): T; }, ...args: P): T {
return (new this(...args)) as T
}
}
class BaseLol extends Newable { /* ... */ }
class Lol extends BaseLol {
constructor(public name: string) {
super();
this.name = name.toUpperCase();
}
}
Lol.new('qwe');
function generator($str, $params) {
$result = [$str];
foreach ($params as $key => $param) {
$values = is_array($params[$key]) ? $params[$key] : [$params[$key]];
$copy = unserialize(serialize($result));
foreach ($values as $val) {
foreach ($result as &$oneResult) {
$oneResult = str_replace(sprintf("{%s}", $key), $val, $oneResult);
}
if ($val != end($values)) {
$result = array_merge($copy, $result);
}
}
}
return $result;
}
function generator($str, $params) {
$result = [];
if (count($params)) {
$key = key($params);
$values = is_array($params[$key]) ? $params[$key] : [ $params[$key] ];
unset($params[$key]);
foreach ($values as $val) {
array_push($result, ...generator(str_replace("{{$key}}", $val, $str), $params));
}
} else {
$result[] = $str;
}
return $result;
}
+------------+-------------+------------+----------+
| company_id | day_of_week | start_time | end_time |
+------------+-------------+------------+----------+
| 1 | 0 | 09:00 | 18:00 |
| 1 | 1 | 09:00 | 18:00 |
+------------+-------------+------------+----------+
+------------+-------------+-------------+-----------+
| company_id | day_of_week | start_break | end_break |
+------------+-------------+-------------+-----------+
| 1 | 0 | 12:00 | 12:30 |
| 1 | 0 | 15:30 | 15:55 |
+------------+-------------+-------------+-----------+
<?php
function getColors($item_colors, $result = []){
preg_match_all('/(\w+),|(\w+)\/(\w+)/', $item_colors, $colors);
foreach ($colors as $key => $value) {
if ($key === 0) continue;
array_push($result, ...$value);
}
return array_filter($result);
}
$item_colors = "Vario Base Unit with steel, large, black/orange";
echo implode(' ', getColors($item_colors));
//steel large black orange
var_dump(getColors($item_colors));
// array(4) {
// [0]=>
// string(5) "steel"
// [1]=>
// string(5) "large"
// [5]=>
// string(5) "black"
// [8]=>
// string(6) "orange"
// }
<?php
$item_colors = "Vario Base Unit with steel, large, black/orange";
$result = [];
foreach (explode(', ', str_replace('Vario Base Unit with ','', $item_colors)) as $color) {
$colors = explode('/', $color);
count($colors) === 2 ? array_push($result, ...$colors) : array_push($result, $color);
}
echo implode(' ', $result);
//steel large black orange
var_dump($result);
// array(4) {
// [0]=>
// string(5) "steel"
// [1]=>
// string(5) "large"
// [2]=>
// string(5) "black"
// [3]=>
// string(6) "orange"
// }
<?php
$item_colors = "Vario Base Unit with steel, large, black/orange";
$result = eval('return '.str_replace(['Vario Base Unit with ', '/', ', '], ['["',', ', '", "'], $item_colors).'"];');
echo implode(' ', $result);
//steel large black orange
var_dump($result);
// array(4) {
// [0]=>
// string(5) "steel"
// [1]=>
// string(5) "large"
// [2]=>
// string(5) "black"
// [3]=>
// string(6) "orange"
// }