-
Notifications
You must be signed in to change notification settings - Fork 5
/
Utilities.php
68 lines (61 loc) · 1.46 KB
/
Utilities.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace __\Traits;
trait Utilities
{
/**
* Check if the value is valid email.
*
* @usage __::isEmail('[email protected]');
* >> true
*
* @param string $value
*
* @return bool
*/
public static function isEmail(string $value = null): bool
{
return filter_var($value, FILTER_VALIDATE_EMAIL) != false;
}
/**
* Alis to original time() function which return current time.
*
* @usage __::now();
* >> 1417546029
*
* @return mixed
*/
public static function now()
{
$now = time();
return $now;
}
/**
* Readable wrapper for strpos()
*
* @usage __::stringContains('waffle', 'wafflecone');
* >> true
*
* @param string $needle Substring to search for
* @param string $haystack String to search within
* @param int $offset Index of the $haystack we wish to start at
*
* @return bool
*/
public static function stringContains(string $needle, string $haystack, int $offset = 0): bool
{
return strpos($haystack, $needle, $offset) !== false ? true : false;
}
/**
* Returns the first argument it receives
*
* @usage __::identity('arg1', 'arg2');
* >> 'arg1'
*
* @return mixed
*/
public static function identity()
{
$args = func_get_args();
return isset($args[0]) ? $args[0] : null;
}
}