@@ -71,95 +71,95 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function __construct($defaultTimezone = 'UTC', $serializeTimezone = null, $deserializeTimezone = null) |
73 | 73 | { |
74 | - $this->defaultTimezone = new \DateTimeZone($defaultTimezone); |
|
75 | - $this->serializeTimezone = $serializeTimezone ? new \DateTimeZone($serializeTimezone) : null; |
|
76 | - $this->deserializeTimezone = $deserializeTimezone ? new \DateTimeZone($deserializeTimezone) : null; |
|
74 | + $this->defaultTimezone = new \DateTimeZone ($defaultTimezone); |
|
75 | + $this->serializeTimezone = $serializeTimezone ? new \DateTimeZone ($serializeTimezone) : null; |
|
76 | + $this->deserializeTimezone = $deserializeTimezone ? new \DateTimeZone ($deserializeTimezone) : null; |
|
77 | 77 | } |
78 | 78 | |
79 | - public function deserializeDateIntervalXml(XmlDeserializationVisitor $visitor, $data, array $type){ |
|
80 | - $attributes = $data->attributes('xsi', true); |
|
79 | + public function deserializeDateIntervalXml(XmlDeserializationVisitor $visitor, $data, array $type) { |
|
80 | + $attributes = $data->attributes ('xsi', true); |
|
81 | 81 | if (isset($attributes['nil'][0]) && (string) $attributes['nil'][0] === 'true') { |
82 | 82 | return null; |
83 | 83 | } |
84 | - return new \DateInterval((string)$data); |
|
84 | + return new \DateInterval ((string) $data); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | public function serializeDate(XmlSerializationVisitor $visitor, \DateTime $date, array $type, Context $context) |
88 | 88 | { |
89 | - $date = $this->prepareDateTimeBeforeSerialize($date); |
|
90 | - $v = $date->format('Y-m-d'); |
|
89 | + $date = $this->prepareDateTimeBeforeSerialize ($date); |
|
90 | + $v = $date->format ('Y-m-d'); |
|
91 | 91 | |
92 | - return $visitor->visitSimpleString($v, $type, $context); |
|
92 | + return $visitor->visitSimpleString ($v, $type, $context); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | public function deserializeDate(XmlDeserializationVisitor $visitor, $data, array $type) |
96 | 96 | { |
97 | - $attributes = $data->attributes('xsi', true); |
|
98 | - if (isset($attributes['nil'][0]) && (string)$attributes['nil'][0] === 'true') { |
|
97 | + $attributes = $data->attributes ('xsi', true); |
|
98 | + if (isset($attributes['nil'][0]) && (string) $attributes['nil'][0] === 'true') { |
|
99 | 99 | return null; |
100 | 100 | } |
101 | - if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})(Z|([+-]\d{2}:\d{2}))?$/', $data)) { |
|
102 | - throw new RuntimeException(sprintf('Invalid date "%s", expected valid XML Schema date string.', $data)); |
|
101 | + if (!preg_match ('/^(\d{4})-(\d{2})-(\d{2})(Z|([+-]\d{2}:\d{2}))?$/', $data)) { |
|
102 | + throw new RuntimeException (sprintf ('Invalid date "%s", expected valid XML Schema date string.', $data)); |
|
103 | 103 | } |
104 | 104 | |
105 | - return $this->parseDateTime($data, $type); |
|
105 | + return $this->parseDateTime ($data, $type); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | public function serializeDateTime(XmlSerializationVisitor $visitor, \DateTime $date, array $type, Context $context) |
109 | 109 | { |
110 | - $date = $this->prepareDateTimeBeforeSerialize($date); |
|
111 | - $v = $date->format(\DateTime::W3C); |
|
110 | + $date = $this->prepareDateTimeBeforeSerialize ($date); |
|
111 | + $v = $date->format (\DateTime::W3C); |
|
112 | 112 | |
113 | - return $visitor->visitSimpleString($v, $type, $context); |
|
113 | + return $visitor->visitSimpleString ($v, $type, $context); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | public function deserializeDateTime(XmlDeserializationVisitor $visitor, $data, array $type) |
117 | 117 | { |
118 | - $attributes = $data->attributes('xsi', true); |
|
119 | - if (isset($attributes['nil'][0]) && (string)$attributes['nil'][0] === 'true') { |
|
118 | + $attributes = $data->attributes ('xsi', true); |
|
119 | + if (isset($attributes['nil'][0]) && (string) $attributes['nil'][0] === 'true') { |
|
120 | 120 | return null; |
121 | 121 | } |
122 | 122 | |
123 | - return $this->parseDateTime($data, $type); |
|
123 | + return $this->parseDateTime ($data, $type); |
|
124 | 124 | |
125 | 125 | } |
126 | 126 | |
127 | 127 | public function serializeTime(XmlSerializationVisitor $visitor, \DateTime $date, array $type, Context $context) |
128 | 128 | { |
129 | - $date = $this->prepareDateTimeBeforeSerialize($date); |
|
130 | - $v = $date->format('H:i:s'); |
|
131 | - if ($date->getTimezone()->getOffset($date) !== $this->defaultTimezone->getOffset($date)) { |
|
132 | - $v .= $date->format('P'); |
|
129 | + $date = $this->prepareDateTimeBeforeSerialize ($date); |
|
130 | + $v = $date->format ('H:i:s'); |
|
131 | + if ($date->getTimezone ()->getOffset ($date) !== $this->defaultTimezone->getOffset ($date)) { |
|
132 | + $v .= $date->format ('P'); |
|
133 | 133 | } |
134 | - return $visitor->visitSimpleString($v, $type, $context); |
|
134 | + return $visitor->visitSimpleString ($v, $type, $context); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | public function deserializeTime(XmlDeserializationVisitor $visitor, $data, array $type) |
138 | 138 | { |
139 | - $attributes = $data->attributes('xsi', true); |
|
140 | - if (isset($attributes['nil'][0]) && (string)$attributes['nil'][0] === 'true') { |
|
139 | + $attributes = $data->attributes ('xsi', true); |
|
140 | + if (isset($attributes['nil'][0]) && (string) $attributes['nil'][0] === 'true') { |
|
141 | 141 | return null; |
142 | 142 | } |
143 | 143 | |
144 | 144 | if ($this->deserializeTimezone) { |
145 | - return $this->parseDateTime($data, $type); |
|
145 | + return $this->parseDateTime ($data, $type); |
|
146 | 146 | } |
147 | 147 | |
148 | - $data = (string)$data; |
|
148 | + $data = (string) $data; |
|
149 | 149 | |
150 | - return new \DateTime($data, $this->defaultTimezone); |
|
150 | + return new \DateTime ($data, $this->defaultTimezone); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | private function parseDateTime($data, array $type) |
154 | 154 | { |
155 | - $timezone = isset($type['params'][1]) ? new \DateTimeZone($type['params'][1]) : $this->defaultTimezone; |
|
156 | - $datetime = new \DateTime((string)$data, $timezone); |
|
155 | + $timezone = isset($type['params'][1]) ? new \DateTimeZone ($type['params'][1]) : $this->defaultTimezone; |
|
156 | + $datetime = new \DateTime ((string) $data, $timezone); |
|
157 | 157 | if (false === $datetime) { |
158 | - throw new RuntimeException(sprintf('Invalid datetime "%s", expected valid XML Schema dateTime string.', $data)); |
|
158 | + throw new RuntimeException (sprintf ('Invalid datetime "%s", expected valid XML Schema dateTime string.', $data)); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | if ($this->deserializeTimezone) { |
162 | - $datetime->setTimezone($this->deserializeTimezone); |
|
162 | + $datetime->setTimezone ($this->deserializeTimezone); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | return $datetime; |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | { |
170 | 170 | if ($this->serializeTimezone) { |
171 | 171 | $dateCopy = clone $date; |
172 | - $dateCopy->setTimezone($this->serializeTimezone); |
|
172 | + $dateCopy->setTimezone ($this->serializeTimezone); |
|
173 | 173 | return $dateCopy; |
174 | 174 | } |
175 | 175 |