datatable.directory codebase https://datatable.directory/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
datatable.directory/app/helpers.php

67 lines
1.5 KiB

6 years ago
<?php
6 years ago
const VALI_NAME = 'string|regex:/^[a-z0-9_.-]+$/i|max:255';
const VALI_PASSWORD = 'string|min:6|max:1024';
const VALI_EMAIL = 'string|email|max:255';
const VALI_TEXT = 'string|max:4095';
const VALI_LINE = 'string|max:255';
6 years ago
// global helpers
function authed() {
return ! \Auth::guest();
}
function guest() {
return \Auth::guest();
}
function user() {
return \Auth::user();
}
function ellipsis($s, $len) {
return \MightyPork\Utils\Str::ellipsis($s, $len);
}
function faker() {
static $fac = null;
if ($fac !== null) return $fac;
return $fac = Faker\Factory::create();
}
6 years ago
/**
* Recursively expand validation rules
*
* @param $arr
* @return array
*/
function vali($arr) {
$result = [];
foreach ($arr as $key => $rules) {
// top level
if (is_array($rules)) {
$ar = [];
foreach ($rules as $rule) {
if (is_string($rule) && strpos($rule, '|') !== false) {
foreach (explode('|', $rule) as $rr) {
$ar[] = $rr;
}
} else if (is_array($rule)) {
// nested array, assume no further recursion
foreach ($rule as $rr) {
$ar[] = $rr;
}
} else {
// Rule
$ar[] = $rule;
}
}
$result[$key] = $ar;
} else {
// string or Rule
$result[$key] = $rules;
}
}
return $result;
}