1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Gitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gitamin\Composers; |
13
|
|
|
|
14
|
|
|
use DateTime; |
15
|
|
|
use DateTimeZone; |
16
|
|
|
use Illuminate\Contracts\View\View; |
17
|
|
|
use Illuminate\Support\Facades\Config; |
18
|
|
|
|
19
|
|
|
class TimezoneLocaleComposer |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Timezones and Locales composer. |
23
|
|
|
* |
24
|
|
|
* @param \Illuminate\Contracts\View\View $view |
25
|
|
|
*/ |
26
|
|
|
public function compose(View $view) |
27
|
|
|
{ |
28
|
|
|
$enabledLangs = Config::get('langs'); |
29
|
|
|
|
30
|
|
|
$langs = array_map(function ($lang) use ($enabledLangs) { |
31
|
|
|
$locale = basename($lang); |
32
|
|
|
|
33
|
|
|
return [$locale => $enabledLangs[$locale]]; |
34
|
|
|
}, glob(base_path('resources/lang').'/*')); |
35
|
|
|
|
36
|
|
|
$langs = call_user_func_array('array_merge', $langs); |
37
|
|
|
|
38
|
|
|
$regions = [ |
39
|
|
|
'Africa' => DateTimeZone::AFRICA, |
40
|
|
|
'America' => DateTimeZone::AMERICA, |
41
|
|
|
'Antarctica' => DateTimeZone::ANTARCTICA, |
42
|
|
|
'Asia' => DateTimeZone::ASIA, |
43
|
|
|
'Atlantic' => DateTimeZone::ATLANTIC, |
44
|
|
|
'Australia' => DateTimeZone::AUSTRALIA, |
45
|
|
|
'Europe' => DateTimeZone::EUROPE, |
46
|
|
|
'Indian' => DateTimeZone::INDIAN, |
47
|
|
|
'Pacific' => DateTimeZone::PACIFIC, |
48
|
|
|
'UTC' => DateTimeZone::UTC, |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
$timezones = []; |
52
|
|
|
|
53
|
|
|
foreach ($regions as $name => $mask) { |
54
|
|
|
$zones = DateTimeZone::listIdentifiers($mask); |
55
|
|
|
|
56
|
|
|
foreach ($zones as $timezone) { |
57
|
|
|
// Lets sample the time there right now |
58
|
|
|
$time = new DateTime(null, new DateTimeZone($timezone)); |
59
|
|
|
|
60
|
|
|
$ampm = $time->format('H') > 12 ? ' ('.$time->format('g:i a').')' : ''; |
61
|
|
|
|
62
|
|
|
// Remove region name and add a sample time |
63
|
|
|
$timezones[$name][$timezone] = substr($timezone, strlen($name) + 1).' - '.$time->format('H:i').$ampm; |
64
|
|
|
|
65
|
|
|
$timezones[$name] = str_replace('_', ' ', $timezones[$name]); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$view->withTimezones($timezones); |
|
|
|
|
70
|
|
|
$view->withLangs($langs); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.