-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTakeaway.php
More file actions
70 lines (55 loc) · 2.09 KB
/
Copy pathTakeaway.php
File metadata and controls
70 lines (55 loc) · 2.09 KB
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
69
70
<?php
namespace Takeaway;
use Takeaway\Http\Requests\GetCountriesRequest;
class Takeaway
{
public const CFG_BASE_URL = 'BASE_URL';
public const CFG_LANGUAGE = 'LANGUAGE';
public const CFG_PASSWORD = 'PASSWORD';
public const CFG_VERSION = 'VERSION';
public const CFG_SYSTEM_VERSION = 'SYSTEM_VERSION';
public const CFG_APP_VERSION = 'APP_VERSION';
public const CFG_APP_NAME = 'APP_NAME';
protected static $configuration = [
self::CFG_BASE_URL => 'https://nl.citymeal.com/android/android.php',
self::CFG_LANGUAGE => 'nl',
self::CFG_PASSWORD => '4ndro1d',
self::CFG_VERSION => '5.7',
self::CFG_SYSTEM_VERSION => '24',
self::CFG_APP_VERSION => '4.15.3.2',
self::CFG_APP_NAME => 'Takeaway.com',
];
public static function configure($config): void
{
static::$configuration = array_merge(static::$configuration, $config);
}
public static function getConfigValue($name)
{
return static::$configuration[$name] ?? '';
}
public static function setConfigValue($name, $value)
{
return $configuration[$name] = $value;
}
public static function getCountries()
{
return (new GetCountriesRequest())->getData()['countries'];
}
public static function getCountryByCode($countryCode)
{
$countries = self::getCountries();
$countries = array_values(array_filter($countries, function ($country) use ($countryCode) {
return $country->countryCode === $countryCode;
}));
return $countries[0] ?? null;
}
public static function getCountryByLocale($countryLocale)
{
$countries = self::getCountries();
$countries = array_values(array_filter($countries, function ($country) use ($countryLocale) {
echo $country->locale.' - '.$countryLocale.' --> '.strcasecmp($country->locale, $countryLocale).PHP_EOL;
return strcasecmp($country->locale, $countryLocale) === 0;
}));
return $countries[0] ?? null;
}
}