1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* MOJEPANSTWO-API |
4
|
|
|
* |
5
|
|
|
* Copyright © 2017 pudelek.org.pl |
6
|
|
|
* |
7
|
|
|
* @license MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view source file |
10
|
|
|
* that is bundled with this package in the file LICENSE |
11
|
|
|
* |
12
|
|
|
* @author Marcin Pudełek <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Created by Marcin. |
17
|
|
|
* Date: 28.10.2017 |
18
|
|
|
* Time: 20:58 |
19
|
|
|
*/ |
20
|
|
|
declare (strict_types=1); |
21
|
|
|
|
22
|
|
|
namespace mrcnpdlk\MojePanstwo\Model; |
23
|
|
|
|
24
|
|
|
use mrcnpdlk\MojePanstwo\Api; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class ModelAbstract |
28
|
|
|
* |
29
|
|
|
* @package mrcnpdlk\MojePanstwo\Model |
30
|
|
|
*/ |
31
|
|
|
class ModelAbstract extends \stdClass |
32
|
|
|
{ |
33
|
|
|
const CONTEXT = ''; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* ModelAbstract constructor. |
37
|
|
|
* |
38
|
|
|
* @param \stdClass|null $oData |
39
|
|
|
* @param \stdClass|null $oLayers |
40
|
|
|
*/ |
41
|
6 |
|
public function __construct(\stdClass $oData = null, \stdClass $oLayers = null) |
42
|
|
|
{ |
43
|
6 |
|
if (!is_null($oData)) { |
44
|
6 |
|
foreach ($oData as $key => $value) { |
|
|
|
|
45
|
6 |
|
$key = $this->stripProperty($key); |
46
|
6 |
|
if (!property_exists($this, $key)) { |
47
|
|
|
Api::getInstance() |
48
|
|
|
->getClient() |
49
|
|
|
->getLogger() |
50
|
|
|
->warning(sprintf('Property [%s] not exists in object [%s]', $key, get_class($this))) |
51
|
|
|
; |
52
|
6 |
|
} elseif (!is_array($value) && !is_object($value)) { |
53
|
6 |
|
$this->{$key} = is_string($value) && $value === '' ? null : $value; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
6 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Cleaning telephone number |
61
|
|
|
* |
62
|
|
|
* @param $nr |
63
|
|
|
* |
64
|
|
|
* @return string|null |
65
|
|
|
*/ |
66
|
2 |
|
protected function cleanTelephoneNr($nr) |
67
|
|
|
{ |
68
|
2 |
|
if (!empty($value)) { |
|
|
|
|
69
|
|
|
$nr = preg_replace('/[^0-9]/', '', strval($nr)); |
70
|
|
|
|
71
|
|
|
//removing zeros only for national numbers (only single zero at the beginning) |
72
|
|
|
return preg_replace('/^0(?=([1-9]+[0-9]*))/', '', $nr); |
73
|
|
|
} |
74
|
|
|
|
75
|
2 |
|
return null; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Convert string to integer |
80
|
|
|
* |
81
|
|
|
* @param string $value |
82
|
|
|
* |
83
|
|
|
* @return int|null |
84
|
|
|
*/ |
85
|
6 |
|
protected function convertToId($value) |
86
|
|
|
{ |
87
|
6 |
|
return empty($value) ? null : intval($value); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Remove namesoace class from the property name |
92
|
|
|
* |
93
|
|
|
* @param string $property |
94
|
|
|
* |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
6 |
|
protected function stripProperty(string $property) |
98
|
|
|
{ |
99
|
6 |
|
return str_replace(static::CONTEXT . '.', '', $property); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
} |
103
|
|
|
|