/** * @param mixed $value * @param array $currentPath * @return mixed */ protected function processItem($value, array $currentPath) { $isNull = is_null($value); if ($isNull) { $processed = null; } else { $onPath = $this->onPath($currentPath); if ($onPath) { /** @var DateTime $value */ $processed = $value->format('c'); } else { $processed = parent::processItem($value, $currentPath); } } return $processed; }
/** * @param array $value * @param string[] $currentPath * @return mixed */ protected function processHash(array $value, array $currentPath) { // If the hash contains only one item and its key appended to the path // is on the list of list paths, this one item is skipped and the list // is processed directly. $count = count($value); if ($count == 1) { list($key) = array_keys($value); $itemPath = array_merge($currentPath, array($key)); $onPath = $this->onPath($itemPath); if ($onPath) { list($item) = array_values($value); $processed = $this->processItem($item, $currentPath); } else { $processed = parent::processHash($value, $currentPath); } } else { $processed = parent::processHash($value, $currentPath); } return $processed; }
/** * @param mixed $value * @param string[] $currentPath * @return mixed * @throws TpInvalidParameterException */ protected function processItem($value, array $currentPath) { $isNull = is_null($value); if ($isNull) { $processed = parent::processItem($value, $currentPath); } else { $onPath = $this->onPath($currentPath); if ($onPath) { // Pozor, neprojde, pokud časové razítko obsahuje desetinnou část // vteřin. Viz https://bugs.php.net/bug.php?id=51950. $processed = \DateTime::createFromFormat(\DateTime::ISO8601, $value); if ($processed === false) { $errorPathArray = $currentPath; array_unshift($errorPathArray, ''); $errorPathString = implode('/', $errorPathArray); throw new \dlds\thepay\api\exceptions\TpInvalidParameterException($errorPathString); } } else { $processed = parent::processItem($value, $currentPath); } } return $processed; }