Added resolve and Object
This commit is contained in:
parent
fe5f4da4cc
commit
367ac04f29
|
@ -1 +1 @@
|
|||
src/isolib
|
||||
src/Isolib
|
4
Makefile
4
Makefile
|
@ -2,11 +2,11 @@ clean:
|
|||
rm -rf build
|
||||
|
||||
update:
|
||||
ppm --generate-package="src/isolib"
|
||||
ppm --generate-package="src/Isolib"
|
||||
|
||||
build:
|
||||
mkdir build
|
||||
ppm --no-intro --compile="src/isolib" --directory="build"
|
||||
ppm --no-intro --compile="src/Isolib" --directory="build"
|
||||
|
||||
install:
|
||||
ppm --no-intro --no-prompt --fix-conflict --install="build/net.intellivoid.isolib.ppm"
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace Isolib;
|
||||
|
||||
use Isolib\Objects\IsoData;
|
||||
|
||||
class Isolib
|
||||
{
|
||||
/**
|
||||
* ISO Data
|
||||
*
|
||||
* @var IsoData[]
|
||||
*/
|
||||
private $IsoData;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $Indexer;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$data_file = json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'data.json'), true);
|
||||
|
||||
foreach($data_file as $datum)
|
||||
{
|
||||
$IsoData = IsoData::fromArray($datum);
|
||||
$this->IsoData[strtoupper($IsoData->Iso31662)] = $IsoData;
|
||||
|
||||
$this->Indexer['country'][strtoupper($IsoData->Name)] = strtoupper($IsoData->Iso31662);
|
||||
$this->Indexer['alpha2'][strtoupper($IsoData->Alpha2)] = strtoupper($IsoData->Iso31662);
|
||||
$this->Indexer['alpha3'][strtoupper($IsoData->Alpha3)] = strtoupper($IsoData->Iso31662);
|
||||
$this->Indexer['country_code'][(string)$IsoData->CountryCode] = strtoupper($IsoData->Iso31662);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the given input into ISO Data
|
||||
*
|
||||
* @param string $input
|
||||
* @return IsoData|null
|
||||
*/
|
||||
public function resolve(string $input): ?IsoData
|
||||
{
|
||||
$input = strtoupper($input);
|
||||
|
||||
if(isset($this->IsoData[$input]))
|
||||
return $this->IsoData[$input];
|
||||
|
||||
if(isset($this->Indexer['alpha2'][$input]))
|
||||
return $this->IsoData[$this->Indexer['alpha2'][$input]];
|
||||
|
||||
if(isset($this->Indexer['alpha3'][$input]))
|
||||
return $this->IsoData[$this->Indexer['alpha3'][$input]];
|
||||
|
||||
if(isset($this->Indexer['country_code'][$input]))
|
||||
return $this->IsoData[$this->Indexer['country_code'][$input]];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return IsoData[]
|
||||
*/
|
||||
public function getIsoData(): array
|
||||
{
|
||||
return $this->IsoData;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
<?php
|
||||
|
||||
/** @noinspection PhpMissingFieldTypeInspection */
|
||||
|
||||
namespace Isolib\Objects;
|
||||
|
||||
class IsoData
|
||||
{
|
||||
/**
|
||||
* The full country name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $Name;
|
||||
|
||||
/**
|
||||
* Alpha-2 Code (Two-Letter)
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $Alpha2;
|
||||
|
||||
/**
|
||||
* Alpha-3 Code (Three-letter)
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $Alpha3;
|
||||
|
||||
/**
|
||||
* The country code
|
||||
*
|
||||
* @var int|null
|
||||
*/
|
||||
public $CountryCode;
|
||||
|
||||
/**
|
||||
* The Unique ISO-3166-2 Code
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $Iso31662;
|
||||
|
||||
/**
|
||||
* The region the country is based in
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $Region;
|
||||
|
||||
/**
|
||||
* The subregion the country is based in
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $SubRegion;
|
||||
|
||||
/**
|
||||
* The intermediate region the country is based in
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $IntermediateRegion;
|
||||
|
||||
/**
|
||||
* The region code
|
||||
*
|
||||
* @var int|null
|
||||
*/
|
||||
public $RegionCode;
|
||||
|
||||
/**
|
||||
* Sub-region code
|
||||
*
|
||||
* @var int|null
|
||||
*/
|
||||
public $SubRegionCode;
|
||||
|
||||
/**
|
||||
* Intermediate region code
|
||||
*
|
||||
* @var int|null
|
||||
*/
|
||||
public $IntermediateRegionCode;
|
||||
|
||||
/**
|
||||
* Returns an array representation of the object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->Name,
|
||||
'alpha-2' => $this->Alpha2,
|
||||
'alpha-3' => $this->Alpha3,
|
||||
'country-code' => $this->CountryCode,
|
||||
'iso_3166-2' => $this->Iso31662,
|
||||
'region' => $this->Region,
|
||||
'sub-region' => $this->SubRegion,
|
||||
'intermediate-region' => $this->IntermediateRegion,
|
||||
'region-code' => $this->RegionCode,
|
||||
'sub-region-code' => $this->SubRegionCode,
|
||||
'intermediate-region-code' => $this->IntermediateRegionCode
|
||||
];
|
||||
}
|
||||
|
||||
public static function fromArray(array $data): IsoData
|
||||
{
|
||||
$IsoData = new IsoData();
|
||||
|
||||
foreach($data as $key => $value)
|
||||
{
|
||||
if(strlen($value) == 0)
|
||||
unset($data[$key]);
|
||||
}
|
||||
|
||||
if(isset($data['name']))
|
||||
$IsoData->Name = $data['name'];
|
||||
|
||||
if(isset($data['alpha-2']))
|
||||
$IsoData->Alpha2 = $data['alpha-2'];
|
||||
|
||||
if(isset($data['alpha-3']))
|
||||
$IsoData->Alpha3 = $data['alpha-3'];
|
||||
|
||||
if(isset($data['country-code']))
|
||||
$IsoData->CountryCode = $data['country-code'];
|
||||
|
||||
if(isset($data['iso_3166-2']))
|
||||
$IsoData->Iso31662 = $data['iso_3166-2'];
|
||||
|
||||
if(isset($data['region']))
|
||||
$IsoData->Region = $data['region'];
|
||||
|
||||
if(isset($data['sub-region']))
|
||||
$IsoData->SubRegion = $data['sub-region'];
|
||||
|
||||
if(isset($data['intermediate-region']))
|
||||
$IsoData->IntermediateRegion = $data['intermediate-region'];
|
||||
|
||||
if(isset($data['region-code']))
|
||||
$IsoData->RegionCode = $data['region-code'];
|
||||
|
||||
if(isset($data['sub-region-code']))
|
||||
$IsoData->SubRegionCode = $data['sub-region-code'];
|
||||
|
||||
if(isset($data['intermediate-region-code']))
|
||||
$IsoData->IntermediateRegionCode = $data['intermediate-region-code'];
|
||||
|
||||
return $IsoData;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"package": {
|
||||
"package_name": "net.intellivoid.isolib",
|
||||
"name": "isolib",
|
||||
"version": "1.0.0.0",
|
||||
"author": "Zi Xing Narrakas",
|
||||
"organization": "Intellivoid Technologies",
|
||||
"description": "A library for managing & resolving ISO codes",
|
||||
"url": "https://github.com/intellivoid/isolib",
|
||||
"dependencies": [],
|
||||
"configuration": {
|
||||
"autoload_method": "generated_spl",
|
||||
"main": null,
|
||||
"post_installation": [],
|
||||
"pre_installation": []
|
||||
}
|
||||
},
|
||||
"components": [
|
||||
{
|
||||
"required": true,
|
||||
"file": "Isolib.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "Objects/IsoData.php"
|
||||
}
|
||||
],
|
||||
"files": [
|
||||
"package.json",
|
||||
"data.json"
|
||||
]
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace isolib\Objects;
|
||||
|
||||
class Result
|
||||
{
|
||||
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace isolib;
|
||||
|
||||
class isolib
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
{
|
||||
"package": {
|
||||
"package_name": "net.intellivoid.isolib",
|
||||
"name": "isolib",
|
||||
"version": "1.0.0.0",
|
||||
"author": "Zi Xing Narrakas",
|
||||
"organization": "Intellivoid Technologies",
|
||||
"description": "A library for managing & resolving ISO codes",
|
||||
"url": "https://github.com/intellivoid/isolib",
|
||||
"dependencies": [],
|
||||
"configuration": {
|
||||
"autoload_method": "generated_spl",
|
||||
"main": null,
|
||||
"post_installation": [],
|
||||
"pre_installation": []
|
||||
}
|
||||
},
|
||||
"components": [
|
||||
{
|
||||
"required": true,
|
||||
"file": "Abstracts/CountryFilterMode.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "Abstracts/CaptchaType.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "Classes/Validate.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "Classes/Security.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "vCaptcha.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "Exceptions/DatabaseException.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "Exceptions/CaptchaInstanceNotFoundException.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "Exceptions/InvalidCaptchaNameException.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "Objects/SampleCaptchaInstance.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "Objects/CaptchaInstance.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "Objects/CaptchaInstance/FirewallOptions.php"
|
||||
},
|
||||
{
|
||||
"required": true,
|
||||
"file": "Managers/CaptchaInstanceManager.php"
|
||||
}
|
||||
],
|
||||
"files": [
|
||||
"package.json"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
use Isolib\Isolib;
|
||||
|
||||
include 'ppm';
|
||||
include 'net.intellivoid.isolib';
|
||||
|
||||
$IsoLib = new IsoLib();
|
||||
var_dump($IsoLib->resolve('Canada'));
|
||||
var_dump($IsoLib->resolve('ca'));
|
||||
var_dump($IsoLib->resolve('FRA'));
|
Loading…
Reference in New Issue