Commit 561b9170 authored by Артем Волков's avatar Артем Волков 👽
Browse files

update

parent c2c7018c
......@@ -7,21 +7,24 @@ use KptV11Parser\Parcel;
class CadastralBlock
{
private $ut;
private $fileName;
public $parcels;
public function __construct(array $cadBlock, Utils $ut)
public function __construct(array $cadBlock, Utils $ut, string $fileName)
{
$this->ut = $ut;
$this->fileName = $fileName;
$this->parcels = [];
if (!isset($cadBlock['name']) || !isset($cadBlock['val'])) {
throw new \Exception("Cadastral block is invalid.");
throw new \Exception("Cadastral block is invalid. File: " . $this->fileName);
}
if ($cadBlock['name'] !== 'cadastral_block') {
throw new \Exception("Cadastral block is invalid.");
throw new \Exception("Cadastral block is invalid. File: " . $this->fileName);
}
if (!$this->ut::validateArray($cadBlock['val'])) {
throw new \Exception("Cadastral block is empty.");
throw new \Exception("Cadastral block is empty. File: " . $this->fileName);
}
foreach ($cadBlock['val'] as $item) {
if (!isset($item['name']) || !isset($item['val'])) {
......@@ -31,14 +34,14 @@ class CadastralBlock
continue;
}
if (!$this->ut::validateArray($item['val'])) {
throw new \Exception("Objects data is empty.");
throw new \Exception("Objects data is empty. File: " . $this->fileName);
}
$baseData = $item['val'][0];
if (!isset($baseData['name']) || !isset($baseData['val'])) {
throw new \Exception("Objects base data is incorrect.");
throw new \Exception("Objects base data is incorrect. File: " . $this->fileName);
}
if (!$this->ut::validateArray($baseData['val'])) {
throw new \Exception("Objects base data is empty.");
throw new \Exception("Objects base data is empty. File: " . $this->fileName);
}
foreach ($baseData['val'] as $objectRecords) {
if (!isset($objectRecords['name']) || !isset($objectRecords['val'])) {
......@@ -48,10 +51,10 @@ class CadastralBlock
continue;
}
if (!$this->ut::validateArray($objectRecords['val'])) {
throw new \Exception("Parcels data is empty.");
throw new \Exception("Parcels data is empty. File: " . $this->fileName);
}
foreach ($objectRecords['val'] as $landRecord) {
$this->parcels[] = new Parcel($landRecord, $this->ut);
$this->parcels[] = new Parcel($landRecord, $this->ut, $this->fileName);
}
}
}
......
......@@ -12,6 +12,7 @@ require_once $vendorPath . DIRECTORY_SEPARATOR . 'autoload.php';
class Parcel
{
private $ut;
private $fileName;
public $cadastralNumber;
public $objectTypeCode;
public $objectTypeValue;
......@@ -55,41 +56,42 @@ class Parcel
public $costValue;
public $wkt;
public function __construct(array $landRecord, Utils $ut)
public function __construct(array $landRecord, Utils $ut, string $fileName)
{
$this->ut = $ut;
$this->fileName = $fileName;
if (!isset($landRecord['name']) || !isset($landRecord['val'])) {
throw new \Exception("Parcel record is invalid.");
throw new \Exception("Parcel record is invalid. File: " . $this->fileName);
}
if (!$this->ut::validateArray($landRecord['val'])) {
throw new \Exception("Parcel record is empty.");
throw new \Exception("Parcel record is empty. File: " . $this->fileName);
}
foreach ($landRecord['val'] as $item) {
if (!isset($item['name']) || !isset($item['val'])) {
throw new \Exception("Parcel record data is incorrect.");
throw new \Exception("Parcel record data is incorrect. File: " . $this->fileName);
break;
}
if (!$this->ut::validateArray($item['val'])) {
throw new \Exception("Parcel record data is incorrect.");
throw new \Exception("Parcel record data is incorrect. File: " . $this->fileName);
break;
}
if ($item['name'] === 'object') {
$obj = $item['val'];
foreach ($obj as $o) {
if (!isset($o['name']) || !isset($o['val'])) {
throw new \Exception("Object data is incorrect.");
throw new \Exception("Object data is incorrect. File: " . $this->fileName);
break;
}
if (!$this->ut::validateArray($o['val'])) {
throw new \Exception("Cost data is incorrect.");
throw new \Exception("Cost data is incorrect. File: " . $this->fileName);
break;
}
if ($o['name'] === 'common_data') {
$cd = $o['val'];
foreach ($cd as $c) {
if (!isset($c['name']) || !isset($c['val'])) {
throw new \Exception("Common data is incorrect.");
throw new \Exception("Common data is incorrect. File: " . $this->fileName);
break 2;
}
if ($c['name'] === 'cad_number') {
......@@ -98,7 +100,9 @@ class Parcel
}
if ($c['name'] === 'type') {
if (!$this->ut::validateArray($c['val'])) {
throw new \Exception("Common data object type is incorrect.");
throw new \Exception(
"Common data object type is incorrect. File: " . $this->fileName
);
break 2;
}
foreach ($c['val'] as $tp) {
......@@ -132,21 +136,21 @@ class Parcel
if ($item['name'] === 'params') {
foreach ($item['val'] as $parameter) {
if (!isset($parameter['name']) || !isset($parameter['val'])) {
throw new \Exception("Parameter data is incorrect.");
throw new \Exception("Parameter data is incorrect. File: " . $this->fileName);
break 2;
}
if (!$this->ut::validateArray($parameter['val'])) {
throw new \Exception("Parameter record data is empty.");
throw new \Exception("Parameter record data is empty. File: " . $this->fileName);
break 2;
}
if ($parameter['name'] === 'category') {
$cat = $parameter['val'][0];
if (!isset($cat['name']) || !isset($cat['val'])) {
throw new \Exception("Category data is incorrect.");
throw new \Exception("Category data is incorrect. File: " . $this->fileName);
break 2;
}
if (!$this->ut::validateArray($cat['val'])) {
throw new \Exception("Category data is empty.");
throw new \Exception("Category data is empty. File: " . $this->fileName);
break 2;
}
foreach ($cat['val'] as $catItem) {
......@@ -165,11 +169,11 @@ class Parcel
$pu = $parameter['val'][0];
if (!isset($pu['name']) || !isset($pu['val'])) {
throw new \Exception("Permitted use data is incorrect.");
throw new \Exception("Permitted use data is incorrect. File: " . $this->fileName);
break 2;
}
if (!$this->ut::validateArray($pu['val'])) {
throw new \Exception("Permitted use data is empty.");
throw new \Exception("Permitted use data is empty. File: " . $this->fileName);
break 2;
}
foreach ($pu['val'] as $p) {
......@@ -184,7 +188,7 @@ class Parcel
$ar = $parameter['val'];
foreach ($ar as $a) {
if (!isset($a['name']) || !isset($a['val'])) {
throw new \Exception("Area data is incorrect.");
throw new \Exception("Area data is incorrect. File: " . $this->fileName);
break 2;
}
if ($a['name'] === 'value') {
......@@ -204,27 +208,27 @@ class Parcel
$cl = $item['val'][0];
if (!isset($cl['name']) || !isset($cl['val'])) {
throw new \Exception("Cad_links data is incorrect.");
throw new \Exception("Cad_links data is incorrect. File: " . $this->fileName);
break;
}
if (!$this->ut::validateArray($cl['val'])) {
throw new \Exception("Cad_links data is empty.");
throw new \Exception("Cad_links data is empty. File: " . $this->fileName);
break;
}
if (!$this->ut::validateArray($cl['val'][0])) {
throw new \Exception("Cad_links data is empty.");
throw new \Exception("Cad_links data is empty. File: " . $this->fileName);
break;
}
if (!isset($cl['val'][0]['name']) || !isset($cl['val'][0]['val'])) {
throw new \Exception("Cad_links data is incorrect.");
throw new \Exception("Cad_links data is incorrect. File: " . $this->fileName);
break;
}
if (!$this->ut::validateArray($cl['val'][0]['val'])) {
throw new \Exception("Cad_links data is empty.");
throw new \Exception("Cad_links data is empty. File: " . $this->fileName);
break;
}
if (!isset($cl['val'][0]['val'][0]['name']) || !isset($cl['val'][0]['val'][0]['val'])) {
throw new \Exception("Cad_links data is incorrect.");
throw new \Exception("Cad_links data is incorrect. File: " . $this->fileName);
break;
}
$this->cadLinks = $cl['val'][0]['val'][0]['val'];
......@@ -232,11 +236,11 @@ class Parcel
}
if ($item['name'] === 'cost') {
if (!$this->ut::validateArray($item['val'][0])) {
throw new \Exception("Cost data is incorrect.");
throw new \Exception("Cost data is incorrect. File: " . $this->fileName);
break;
}
if (!isset($item['val'][0]['name']) || !isset($item['val'][0]['val'])) {
throw new \Exception("Cost data is incorrect.");
throw new \Exception("Cost data is incorrect. File: " . $this->fileName);
break;
}
$this->costValue = $item['val'][0]['val'];
......@@ -249,17 +253,17 @@ class Parcel
if ($item['name'] === 'address_location') {
foreach ($item['val'] as $addrBlock) {
if (!isset($addrBlock['name']) || !isset($addrBlock['val'])) {
throw new \Exception("Address block data is incorrect.");
throw new \Exception("Address block data is incorrect. File: " . $this->fileName);
break;
}
if (!$this->ut::validateArray($addrBlock['val'])) {
throw new \Exception("Address block data is empty.");
throw new \Exception("Address block data is empty. File: " . $this->fileName);
break;
}
if ($addrBlock['name'] === 'address_type') {
foreach ($addrBlock['val'] as $at) {
if (!isset($at['name']) || !isset($at['val'])) {
throw new \Exception("Address block type data is incorrect.");
throw new \Exception("Address block type data is incorrect. File: " . $this->fileName);
break;
}
if ($at['name'] === 'code') {
......@@ -284,32 +288,36 @@ class Parcel
if ($addrBlock['name'] === 'address') {
foreach ($addrBlock['val'] as $a) {
if (!isset($a['name']) || !isset($a['val'])) {
throw new \Exception("Address data is incorrect.");
throw new \Exception("Address data is incorrect. File: " . $this->fileName);
break 2;
}
if ($a['name'] === 'address_fias') {
if (!$this->ut::validateArray($a['val'])) {
throw new \Exception("Address data is empty.");
throw new \Exception("Address data is empty. File: " . $this->fileName);
break 2;
}
$af = $a['val'];
foreach ($af as $afi) {
if (!isset($afi['name']) || !isset($afi['val'])) {
throw new \Exception("Address data is incorrect.");
throw new \Exception("Address data is incorrect. File: " . $this->fileName);
break 3;
}
if (!$this->ut::validateArray($afi['val'])) {
throw new \Exception("Address data is empty.");
throw new \Exception("Address data is empty. File: " . $this->fileName);
break 3;
}
if ($afi['name'] === 'detailed_level') {
foreach ($afi['val'] as $dl) {
if (!isset($dl['name']) || !isset($dl['val'])) {
throw new \Exception("Detailed level data is incorrect.");
throw new \Exception(
"Detailed level data is incorrect. File: " . $this->fileName
);
break 4;
}
if (!$this->ut::validateArray($dl['val'])) {
throw new \Exception("Detailed level data is empty.");
throw new \Exception(
"Detailed level data is empty. File: " . $this->fileName
);
break 4;
}
//@todo - examples with `other`
......@@ -361,14 +369,18 @@ class Parcel
foreach ($afi['val'] as $ls) {
$stringTypes = ['fias', 'okato', 'kladr', 'oktmo', 'postal_code'];
if (!isset($ls['name']) || !isset($ls['val'])) {
throw new \Exception("Level settlement data is incorrect.");
throw new \Exception(
"Level settlement data is incorrect. File: " . $this->fileName
);
break 4;
}
if (
!$this->ut::validateArray($ls['val'])
&& !in_array($ls['name'], $stringTypes)
) {
throw new \Exception("Level settlement data is empty.");
throw new \Exception(
"Level settlement data is empty. File: " . $this->fileName
);
break 4;
}
if (in_array($ls['name'], $stringTypes)) {
......
......@@ -9,17 +9,19 @@ class Processor
private $ut;
private $xml;
public $cadastralBlocks;
private $fileName;
public function __construct(array $xml, Utils $ut)
public function __construct(array $xml, Utils $ut, string $fileName)
{
$this->ut = $ut;
$this->fileName = $fileName;
$this->cadastralBlocks = [];
if (count($xml) === 0) {
throw new \Exception("XML file is empty.");
throw new \Exception("XML file is empty. File: " . $this->fileName);
}
if (!isset($xml[0]['name']) || !isset($xml[0]['val'])) {
throw new \Exception("XML file is empty.");
throw new \Exception("XML file is empty. File: " . $this->fileName);
}
if (!$this->ut::validateArray($xml[0]['val'])) {
throw new \Exception("XML file is empty.");
......@@ -30,16 +32,16 @@ class Processor
}
if ($kptUnit['name'] === 'cadastral_blocks') {
if (!$ut::validateArray($kptUnit['val'])) {
throw new \Exception("Cadastral block is empty.");
throw new \Exception("Cadastral block is empty. File: " . $this->fileName);
break;
}
foreach ($kptUnit['val'] as $cadBlock) {
$this->cadastralBlocks[] = new CadastralBlock($cadBlock, $this->ut);
$this->cadastralBlocks[] = new CadastralBlock($cadBlock, $this->ut, $this->fileName);
}
}
}
if (count($this->cadastralBlocks) === 0) {
throw new \Exception("Cadastral blocks node is not found");
throw new \Exception("Cadastral blocks node is not found. File: " . $this->fileName);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment