1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\Str; |
4
|
|
|
use Illuminate\Support\Carbon; |
5
|
|
|
use Illuminate\Support\HtmlString; |
6
|
|
|
use Illuminate\Container\Container; |
7
|
|
|
use Illuminate\Queue\CallQueuedClosure; |
8
|
|
|
use Illuminate\Contracts\Bus\Dispatcher; |
9
|
|
|
use Illuminate\Queue\SerializableClosure; |
10
|
|
|
use Illuminate\Contracts\Auth\Access\Gate; |
|
|
|
|
11
|
|
|
use Illuminate\Contracts\Support\Responsable; |
12
|
|
|
use Illuminate\Contracts\Routing\UrlGenerator; |
13
|
|
|
use Illuminate\Foundation\Bus\PendingDispatch; |
14
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
|
|
|
15
|
|
|
use Illuminate\Contracts\Debug\ExceptionHandler; |
16
|
|
|
use Illuminate\Contracts\Routing\ResponseFactory; |
17
|
|
|
use Illuminate\Contracts\Auth\Factory as AuthFactory; |
18
|
|
|
use Illuminate\Contracts\View\Factory as ViewFactory; |
19
|
|
|
use Illuminate\Http\Exceptions\HttpResponseException; |
|
|
|
|
20
|
|
|
use Illuminate\Contracts\Cookie\Factory as CookieFactory; |
21
|
|
|
use Symfony\Component\Debug\Exception\FatalThrowableError; |
22
|
|
|
use Illuminate\Database\Eloquent\Factory as EloquentFactory; |
23
|
|
|
use Illuminate\Contracts\Validation\Factory as ValidationFactory; |
24
|
|
|
use Illuminate\Contracts\Broadcasting\Factory as BroadcastFactory; |
25
|
|
|
use Illuminate\Support\Facades\DB; |
26
|
|
|
|
27
|
|
|
if (!function_exists('version')) { |
28
|
|
|
function version() |
29
|
|
|
{ |
30
|
|
|
$version=new Version( |
31
|
|
|
'0.0.0', |
32
|
|
|
base_path() |
33
|
|
|
); |
34
|
|
|
return $version->getVersion(); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if (!function_exists('getCustomUrl')) { |
39
|
|
|
function getCustomUrl() |
40
|
|
|
{ |
41
|
|
|
$customUrlCached=Cache::tags(['custom'])->get('url'); |
42
|
|
|
|
43
|
|
|
if ($customUrlCached==null) { |
44
|
|
|
$urls=DB::table("custom_url")->where(["available"=>1])->get()->all(); |
45
|
|
|
Cache::tags(['custom'])->put('url', $urls, 1200); |
46
|
|
|
return $urls; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $customUrlCached; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if (!function_exists('emailVerified')) { |
54
|
|
|
function emailVerified() |
55
|
|
|
{ |
56
|
|
|
if(Auth::check()){ |
57
|
|
|
return !is_null(Auth::user()->email_verified_at); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return null; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if (! function_exists('babel_path')) { |
65
|
|
|
/** |
66
|
|
|
* Get the path to the application folder. |
67
|
|
|
* |
68
|
|
|
* @param string $path |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
function babel_path($path = '') |
72
|
|
|
{ |
73
|
|
|
return app('path').DIRECTORY_SEPARATOR.'Babel'.($path ? DIRECTORY_SEPARATOR.$path : $path); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
if (! function_exists('glob_recursive')) { |
78
|
|
|
/** |
79
|
|
|
* Find pathnames matching a pattern recursively. |
80
|
|
|
* |
81
|
|
|
* @param string $pattern The pattern. No tilde expansion or parameter substitution is done. |
82
|
|
|
* @param int $flags Valid flags: GLOB_MARK |
83
|
|
|
* @return array|false an array containing the matched files/directories, an empty array if no file matched or false on error. |
84
|
|
|
*/ |
85
|
|
|
function glob_recursive($pattern, $flags = 0) |
86
|
|
|
{ |
87
|
|
|
$files = glob($pattern, $flags); |
88
|
|
|
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) { |
89
|
|
|
$files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags)); |
|
|
|
|
90
|
|
|
} |
91
|
|
|
return $files; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
if (!function_exists('adminMenu')) { |
96
|
|
|
function adminMenu() |
97
|
|
|
{ |
98
|
|
|
return json_decode(file_get_contents(app_path('Admin/menu.json')),true); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
if (!function_exists('getOpenSearchXML')) { |
103
|
|
|
function getOpenSearchXML() |
104
|
|
|
{ |
105
|
|
|
$url=config("app.url"); |
106
|
|
|
|
107
|
|
|
return '<?xml version="1.0" encoding="UTF-8"?> |
108
|
|
|
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/"> |
109
|
|
|
<ShortName>NOJ</ShortName> |
110
|
|
|
<Description>Gracefully Search NOJ Problems and others.</Description> |
111
|
|
|
<InputEncoding>UTF-8</InputEncoding> |
112
|
|
|
<Image width="16" height="16" type="image/x-icon">'.$url.'/favicon.ico</Image> |
113
|
|
|
<Url type="text/html" method="get" template="'.$url.'/search/?q={searchTerms}&tab=problems&opensearch=1" /> |
114
|
|
|
<moz:SearchForm>'.$url.'/search</moz:SearchForm> |
115
|
|
|
</OpenSearchDescription>'; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
if (!function_exists('delFile')) { |
120
|
|
|
function delFile($dirName) |
121
|
|
|
{ |
122
|
|
|
if (file_exists($dirName) && $handle=opendir($dirName)) { |
123
|
|
|
while (false!==($item = readdir($handle))) { |
124
|
|
|
if ($item!= "." && $item != "..") { |
125
|
|
|
if (file_exists($dirName.'/'.$item) && is_dir($dirName.'/'.$item)) { |
126
|
|
|
delFile($dirName.'/'.$item); |
127
|
|
|
} else { |
128
|
|
|
if (unlink($dirName.'/'.$item)) { |
129
|
|
|
return true; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
closedir($handle); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: