Added locale object
This commit is contained in:
parent
29c8954b21
commit
72edaf7ff5
|
@ -2,6 +2,7 @@
|
|||
|
||||
global $utopia, $register, $request, $response, $projectDB, $project, $user, $audit;
|
||||
|
||||
use Appwrite\Database\Document;
|
||||
use Utopia\App;
|
||||
use Utopia\Locale\Locale;
|
||||
use GeoIp2\Database\Reader;
|
||||
|
@ -30,6 +31,7 @@ $utopia->get('/v1/locale')
|
|||
$ip = '79.177.241.94';
|
||||
}
|
||||
|
||||
$output['$collection'] = 'locale';
|
||||
$output['ip'] = $ip;
|
||||
|
||||
$currency = null;
|
||||
|
@ -43,7 +45,7 @@ $utopia->get('/v1/locale')
|
|||
$output['continentCode'] = $record->continent->code;
|
||||
$output['eu'] = (\in_array($record->country->isoCode, $eu)) ? true : false;
|
||||
|
||||
foreach ($currencies as $code => $element) {
|
||||
foreach ($currencies as $element) {
|
||||
if (isset($element['locations']) && isset($element['code']) && \in_array($record->country->isoCode, $element['locations'])) {
|
||||
$currency = $element['code'];
|
||||
}
|
||||
|
@ -62,7 +64,9 @@ $utopia->get('/v1/locale')
|
|||
$response
|
||||
->addHeader('Cache-Control', 'public, max-age='.$time)
|
||||
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + $time).' GMT') // 45 days cache
|
||||
->json($output);
|
||||
;
|
||||
|
||||
$response->dynamic(new Document($output));
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ use Exception;
|
|||
use Appwrite\Database\Document;
|
||||
use Appwrite\Utopia\Response\Result;
|
||||
use Appwrite\Utopia\Response\Result\User;
|
||||
use Appwrite\Utopia\Response\Result\Locale;
|
||||
use Utopia\Response as UtopiaResponse;
|
||||
|
||||
class Response extends UtopiaResponse
|
||||
|
@ -15,6 +16,7 @@ class Response extends UtopiaResponse
|
|||
{
|
||||
$this
|
||||
->setResult(new User())
|
||||
->setResult(new Locale())
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Result;
|
||||
|
||||
use Appwrite\Database\Database;
|
||||
use Appwrite\Utopia\Response\Result;
|
||||
|
||||
class Files extends Result
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->addRule('$id', 'string', 'User ID.', '5e5ea5c16897e')
|
||||
->addRule('name', 'string', 'User name.', 'John Doe')
|
||||
->addRule('email', 'string', 'User email address.', 'john@appwrite.io')
|
||||
->addRule('emailVerification', 'string', 'Email verification status.', true)
|
||||
->addRule('registration', 'integer', 'User registration date in UNIX format.', 1583261121)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName():string
|
||||
{
|
||||
return 'User';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Collection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCollection():string
|
||||
{
|
||||
return Database::SYSTEM_COLLECTION_TOKENS;
|
||||
}
|
||||
}
|
71
src/Appwrite/Utopia/Response/Result/Locale.php
Normal file
71
src/Appwrite/Utopia/Response/Result/Locale.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Result;
|
||||
|
||||
use Appwrite\Utopia\Response\Result;
|
||||
|
||||
class Locale extends Result
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->addRule('ip', [
|
||||
'type' => 'string',
|
||||
'description' => 'User IP address.',
|
||||
'example' => '127.0.0.1',
|
||||
])
|
||||
->addRule('countryCode', [
|
||||
'type' => 'string',
|
||||
'description' => 'Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format',
|
||||
'example' => 'US',
|
||||
])
|
||||
->addRule('country', [
|
||||
'type' => 'string',
|
||||
'description' => 'Country name. This field support localization.',
|
||||
'example' => 'United States',
|
||||
])
|
||||
->addRule('continentCode', [
|
||||
'type' => 'string',
|
||||
'description' => 'Continent code. A two character continent code "AF" for Africa, "AN" for Antarctica, "AS" for Asia, "EU" for Europe, "NA" for North America, "OC" for Oceania, and "SA" for South America.',
|
||||
'example' => 'NA',
|
||||
])
|
||||
->addRule('continent', [
|
||||
'type' => 'string',
|
||||
'description' => 'Continent name. This field support localization.',
|
||||
'example' => 'North America',
|
||||
])
|
||||
->addRule('eu', [
|
||||
'type' => 'Boolean',
|
||||
'description' => 'True if country is part of the Europian Union.',
|
||||
'default' => false,
|
||||
'example' => false,
|
||||
])
|
||||
->addRule('currency', [
|
||||
'type' => 'string',
|
||||
'description' => 'ISO 4217 Email verification status.',
|
||||
'description' => 'Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format',
|
||||
'example' => 'USD',
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName():string
|
||||
{
|
||||
return 'User';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Collection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCollection():string
|
||||
{
|
||||
return 'locale';
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Result;
|
||||
|
||||
use Appwrite\Database\Database;
|
||||
use Appwrite\Utopia\Response\Result;
|
||||
|
||||
class Prefs extends Result
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->addRule('$id', 'string', 'User ID.', '5e5ea5c16897e')
|
||||
->addRule('name', 'string', 'User name.', 'John Doe')
|
||||
->addRule('email', 'string', 'User email address.', 'john@appwrite.io')
|
||||
->addRule('emailVerification', 'string', 'Email verification status.', true)
|
||||
->addRule('registration', 'integer', 'User registration date in UNIX format.', 1583261121)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName():string
|
||||
{
|
||||
return 'User';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Collection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCollection():string
|
||||
{
|
||||
return Database::SYSTEM_COLLECTION_TOKENS;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue