1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Providers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
6
|
|
|
use Illuminate\Support\Facades\Schema; |
7
|
|
|
use Illuminate\Support\Facades\Validator; |
8
|
|
|
|
9
|
|
|
class AppServiceProvider extends ServiceProvider |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Bootstrap any application services. |
13
|
|
|
* |
14
|
|
|
* @return void |
15
|
|
|
*/ |
16
|
5 |
|
public function boot() |
17
|
|
|
{ |
18
|
|
|
// Fixes incompatibility with MySQL < 5.7.7 |
19
|
5 |
|
Schema::defaultStringLength(191); |
20
|
|
|
|
21
|
|
|
// Create {{ $view_name }} provider in blade templates |
22
|
5 |
|
view()->composer('*', function($view) { |
23
|
|
|
$view_name = str_replace('.', '-', $view->getName()); |
24
|
|
|
view()->share('view_name', $view_name); |
25
|
5 |
|
}); |
26
|
|
|
|
27
|
5 |
|
Validator::extend('phone', function($attribute, $value, $parameters, $validator) { |
|
|
|
|
28
|
|
|
return preg_match('%^(?:(?:\(?(?:00|\+)([1-4]\d\d|[1-9]\d?)\)?)?[\-\.\ \\\/]?)?((?:\(?\d{1,}\)?[\-\.\ \\\/]?){0,})(?:[\-\.\ \\\/]?(?:#|ext\.?|extension|x)[\-\.\ \\\/]?(\d+))?$%i', $value) && strlen($value) >= 10; |
29
|
5 |
|
}); |
30
|
|
|
|
31
|
5 |
|
Validator::replacer('phone', function($message, $attribute, $rule, $parameters) { |
|
|
|
|
32
|
|
|
return str_replace(':attribute', $attribute, ':attribute is invalid phone number'); |
33
|
5 |
|
}); |
34
|
|
|
|
35
|
|
|
//Validator rule for names |
36
|
5 |
|
Validator::extend('name', function($attribute, $value, $parameters, $validator) { |
|
|
|
|
37
|
|
|
return preg_match('#(^[[:alnum:]])([\w\-\.\' ]*)([\w\-\.\']$)#', $value); |
38
|
5 |
|
}); |
39
|
|
|
|
40
|
5 |
|
Validator::replacer('name', function($message, $attribute, $rule, $parameters) { |
|
|
|
|
41
|
|
|
return str_replace(':attribute', $attribute, ':attribute is invalid you can only use letters, numbers, underscores, dashes, spaces, periods and it must start with a letter or number'); |
42
|
5 |
|
}); |
43
|
|
|
|
44
|
|
|
//Validator rule for user full names |
45
|
5 |
|
Validator::extend('full_name', function($attribute, $value, $parameters, $validator) { |
|
|
|
|
46
|
|
|
return preg_match('#(^[[:alpha:]])([[:alpha:]\_\-\. ]*)([[:alpha:]\_\-\.]$)#', $value); |
47
|
5 |
|
}); |
48
|
|
|
|
49
|
5 |
|
Validator::replacer('full_name', function($message, $attribute, $rule, $parameters) { |
|
|
|
|
50
|
|
|
return str_replace(':attribute', $attribute, ':attribute is invalid you can only use letters, underscores, dashes, spaces, periods and it must start with a letter'); |
51
|
5 |
|
}); |
52
|
|
|
|
53
|
|
|
//Validator rule for values |
54
|
5 |
|
Validator::extend('value_string', function($attribute, $value, $parameters, $validator) { |
|
|
|
|
55
|
|
|
return preg_match('#(^[[:alnum:]\+\-])([\w\+\-\.\'\, ]*$)#', $value); |
56
|
5 |
|
}); |
57
|
|
|
|
58
|
5 |
|
Validator::replacer('value_string', function($message, $attribute, $rule, $parameters) { |
|
|
|
|
59
|
|
|
return str_replace(':attribute', $attribute, ':attribute is invalid you can only use alphanumerics spaces +-_.\', and it must start with a alphanumeric or a plus or minus'); |
60
|
5 |
|
}); |
61
|
|
|
|
62
|
|
|
//Validator rule for types |
63
|
5 |
|
Validator::extend('type_name', function($attribute, $value, $parameters, $validator) { |
|
|
|
|
64
|
|
|
return preg_match('#(^[[:alpha:]\_])([\w]*$)#', $value); |
65
|
5 |
|
}); |
66
|
|
|
|
67
|
5 |
|
Validator::replacer('type_name', function($message, $attribute, $rule, $parameters) { |
|
|
|
|
68
|
|
|
return str_replace(':attribute', $attribute, ':attribute is invalid you can only use alphanumerics, underscores and it must start with a letter or underscore'); |
69
|
5 |
|
}); |
70
|
|
|
|
71
|
|
|
//Validator rule for error messages |
72
|
5 |
|
Validator::extend('error_string', function($attribute, $value, $parameters, $validator) { |
|
|
|
|
73
|
|
|
return preg_match('#(^[\w])([\w\-\.\'\, ]*$)#', $value); |
74
|
5 |
|
}); |
75
|
|
|
|
76
|
5 |
|
Validator::replacer('error_string', function($message, $attribute, $rule, $parameters) { |
|
|
|
|
77
|
|
|
return str_replace(':attribute', $attribute, ':attribute is invalid you can only use alphanumerics spaces _.\', and it must start with a alphanumeric or underscore'); |
78
|
5 |
|
}); |
79
|
|
|
|
80
|
|
|
//Validator rule for mac addresses |
81
|
5 |
|
Validator::extend('mac', function($attribute, $value, $parameters, $validator) { |
|
|
|
|
82
|
|
|
return preg_match('#^(([[:xdigit:]]{2}){6})$#', $value); |
83
|
5 |
|
}); |
84
|
|
|
|
85
|
5 |
|
Validator::replacer('mac', function($message, $attribute, $rule, $parameters) { |
|
|
|
|
86
|
|
|
return str_replace(':attribute', $attribute, ':attribute is invalid you must provide a valid mac address like 000000000000'); |
87
|
5 |
|
}); |
88
|
|
|
|
89
|
|
|
//Validator rule for versions |
90
|
5 |
|
Validator::extend('version', function($attribute, $value, $parameters, $validator) { |
|
|
|
|
91
|
|
|
return preg_match('#(^[0-9])(([\+\-\.][[:alnum:]]+)*$)#', $value); |
92
|
5 |
|
}); |
93
|
|
|
|
94
|
5 |
|
Validator::replacer('version', function($message, $attribute, $rule, $parameters) { |
|
|
|
|
95
|
|
|
return str_replace(':attribute', $attribute, ':attribute is invalid you can only use alphanumerics +-. and it must start with a number and end with an alphanumeric'); |
96
|
5 |
|
}); |
97
|
|
|
|
98
|
|
|
//Validator rule for uuid |
99
|
5 |
|
Validator::extend('uuid', function($attribute, $value, $parameters, $validator) { |
|
|
|
|
100
|
|
|
return preg_match('#^([[:xdigit:]]{8})(-[[:xdigit:]]{4}){3}(-[[:xdigit:]]{12})$#', $value); |
101
|
5 |
|
}); |
102
|
|
|
|
103
|
5 |
|
Validator::replacer('uuid', function($message, $attribute, $rule, $parameters) { |
|
|
|
|
104
|
|
|
return str_replace(':attribute', $attribute, ':attribute is invalid you must provide five groups of hexadecimals in the form 8-4-4-4-12'); |
105
|
5 |
|
}); |
106
|
5 |
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Register any application services. |
110
|
|
|
* |
111
|
|
|
* @return void |
112
|
|
|
*/ |
113
|
5 |
|
public function register() |
114
|
|
|
{ |
115
|
|
|
// |
116
|
5 |
|
} |
117
|
|
|
} |
118
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.