You are here

public function FileApi::lastModified in TMGMT Translator Smartling 8.3

Same name and namespace in other branches
  1. 8.4 vendor/smartling/api-sdk-php/src/File/FileApi.php \Smartling\File\FileApi::lastModified()
  2. 8.2 api-sdk-php/src/File/FileApi.php \Smartling\File\FileApi::lastModified()
  3. 8.2 vendor/smartling/api-sdk-php/src/File/FileApi.php \Smartling\File\FileApi::lastModified()

Requests last-modified value for all locales for file

Parameters

string $fileUri: Value that uniquely identifies the uploaded file. This ID can be used to request the file back.

ParameterInterface $params:

Return value

array Data about uploaded file.

Throws

\Smartling\Exceptions\SmartlingApiException

See also

http://docs.smartling.com/pages/API/v2/FileAPI/Last-Modified/All-Locales/

File

vendor/smartling/api-sdk-php/src/File/FileApi.php, line 427

Class

FileApi
Class FileApi

Namespace

Smartling\File

Code

public function lastModified($fileUri, ParameterInterface $params = null) {
  $result = $this
    ->getLastModified($fileUri, $params);
  if (!is_array($result) || !array_key_exists('items', $result) || !is_array($result['items'])) {
    throw new SmartlingApiException(vsprintf('No data found for file %s.', [
      $fileUri,
    ]));
  }

  /** @noinspection OffsetOperationsInspection */
  foreach ($result['items'] as &$item) {
    if (!isset($item['lastModified'])) {
      throw new SmartlingApiException('Property "lastModified" is not found.');
    }

    // Smartling returns UTC dates. Let's define this explicitly and
    // avoid issues when default php timezone is not UTC.
    $date = \DateTime::createFromFormat(self::PATTERN_DATE_TIME_ISO_8601, $item['lastModified'], new \DateTimeZone('UTC'));
    if (!$date instanceof \DateTime) {
      throw new SmartlingApiException(vsprintf('Can\'t parse formatted time string: %s.', [
        $item['lastModified'],
      ]));
    }
    $item['lastModified'] = $date;
  }
  return $result;
}