src/Serializer.php
public function validateImport(TranslatableInterface $translatable, $targetLang, $xmlString) {
    $xmlString = Converter::filterXmlControlCharacters($xmlString);

    $error = $this->errorStart();

    // XML does not support most named HTML entities (eg, &nbsp;), but should be
    // able to handle the UTF-8 uncoded entity characters just fine.
    $xml = $this->serializerSimplexmlLoadString($xmlString);

    $this->errorStop($error);

    if (!$xml) {
      return FALSE;
    }

    $errorArgs = array(
      '%lang' => $targetLang,
      '%srclang' => $this->sourceLang,
      '%name' => $translatable->getLabel(),
      '%id' => $translatable->getIdentifier(),
    );

    // Check if our phase information is there.
    $phase = $xml->xpath("//phase[@phase-name='extraction']");
    if ($phase) {
      $phase = reset($phase);
    }
    else {
      $this->log(LogLevel::ERROR, 'Phase missing from XML.', $errorArgs);
      return FALSE;
    }

    // Check if the project can be loaded.
    if (!isset($phase['job-id']) || ($translatable->getIdentifier() != (string) $phase['job-id'])) {
      $this->log(LogLevel::ERROR, 'The project id is missing in the XML.', $errorArgs);
      return FALSE;
    }
    elseif ($translatable->getIdentifier() != (string) $phase['job-id']) {
      $this->log(LogLevel::ERROR, 'The project id is invalid in the XML. Correct id: %id.', $errorArgs);
      return FALSE;
    }

    // Compare source language.
    if (!isset($xml->file['source-language'])) {
      $this->log(LogLevel::ERROR, 'The source language is missing in the XML.', $errorArgs);
      return FALSE;
    }
    elseif ($xml->file['source-language'] != $this->sourceLang) {
      $this->log(LogLevel::ERROR, 'The source language is invalid in the XML. Correct langcode: %srclang.', $errorArgs);
      return FALSE;
    }

    // Compare target language.
    if (!isset($xml->file['target-language'])) {
      $this->log(LogLevel::ERROR, 'The target language is missing in the XML.', $errorArgs);
      return FALSE;
    }
    elseif ($targetLang != Data::normalizeLangcode($xml->file['target-language'])) {
      $errorArgs['%wrong'] = $xml->file['target-language'];
      $this->log(LogLevel::ERROR, 'The target language %wrong is invalid in the XML. Correct langcode: %lang.', $errorArgs);
      return FALSE;
    }

    // Validation successful.
    return TRUE;
  }
public function validateImport(TranslatableInterface $translatable, $targetLang, $xmlString) {
    $xmlString = Converter::filterXmlControlCharacters($xmlString);

    $error = $this->errorStart();

    // XML does not support most named HTML entities (eg, &nbsp;), but should be
    // able to handle the UTF-8 uncoded entity characters just fine.
    $xml = $this->serializerSimplexmlLoadString($xmlString);

    $this->errorStop($error);

    if (!$xml) {
      return FALSE;
    }

    $errorArgs = array(
      '%lang' => $targetLang,
      '%srclang' => $this->sourceLang,
      '%name' => $translatable->getLabel(),
      '%id' => $translatable->getIdentifier(),
    );

    // Check if our phase information is there.
    $phase = $xml->xpath("//phase[@phase-name='extraction']");
    if ($phase) {
      $phase = reset($phase);
    }
    else {
      $this->log(LogLevel::ERROR, 'Phase missing from XML.', $errorArgs);
      return FALSE;
    }

    // Check if the project can be loaded.
    if (!isset($phase['job-id']) || ($translatable->getIdentifier() != (string) $phase['job-id'])) {
      $this->log(LogLevel::ERROR, 'The project id is missing in the XML.', $errorArgs);
      return FALSE;
    }
    elseif ($translatable->getIdentifier() != (string) $phase['job-id']) {
      $this->log(LogLevel::ERROR, 'The project id is invalid in the XML. Correct id: %id.', $errorArgs);
      return FALSE;
    }

    // Compare source language.
    if (!isset($xml->file['source-language'])) {
      $this->log(LogLevel::ERROR, 'The source language is missing in the XML.', $errorArgs);
      return FALSE;
    }
    elseif ($xml->file['source-language'] != $this->sourceLang) {
      $this->log(LogLevel::ERROR, 'The source language is invalid in the XML. Correct langcode: %srclang.', $errorArgs);
      return FALSE;
    }

    // Compare target language.
    if (!isset($xml->file['target-language'])) {
      $this->log(LogLevel::ERROR, 'The target language is missing in the XML.', $errorArgs);
      return FALSE;
    }
    elseif ($targetLang != Data::normalizeLangcode($xml->file['target-language'])) {
      $errorArgs['%wrong'] = $xml->file['target-language'];
      $this->log(LogLevel::ERROR, 'The target language %wrong is invalid in the XML. Correct langcode: %lang.', $errorArgs);
      return FALSE;
    }

    // Validation successful.
    return TRUE;
  }
public function validateImport ( TranslatableInterface $ translatable , $ targetLang , $ xmlString ) { $ xmlString = Converter :: filterXmlControlCharacters ( $ xmlString ) ; $ error = $ this -> errorStart ( ) ; // XML does not support most named HTML entities (eg, &nbsp;), but should be // able to handle the UTF-8 uncoded entity characters just fine. $ xml = $ this -> serializerSimplexmlLoadString ( $ xmlString ) ; $ this -> errorStop ( $ error ) ; if ( ! $ xml ) { return FALSE ; } $ errorArgs = array ( '%lang' => $ targetLang , '%srclang' => $ this -> sourceLang , '%name' => $ translatable -> getLabel ( ) , '%id' => $ translatable -> getIdentifier ( ) , ) ; // Check if our phase information is there. $ phase = $ xml -> xpath ( "//phase[@phase-name='extraction']" ) ; if ( $ phase ) { $ phase = reset ( $ phase ) ; } else { $ this -> log ( LogLevel :: ERROR , 'Phase missing from XML.' , $ errorArgs ) ; return FALSE ; } // Check if the project can be loaded. if ( ! isset ( $ phase [ 'job-id' ] ) || ( $ translatable -> getIdentifier ( ) != ( string ) $ phase [ 'job-id' ] ) ) { $ this -> log ( LogLevel :: ERROR , 'The project id is missing in the XML.' , $ errorArgs ) ; return FALSE ; } elseif ( $ translatable -> getIdentifier ( ) != ( string ) $ phase [ 'job-id' ] ) { $ this -> log ( LogLevel :: ERROR , 'The project id is invalid in the XML. Correct id: %id.' , $ errorArgs ) ; return FALSE ; } // Compare source language. if ( ! isset ( $ xml -> file [ 'source-language' ] ) ) { $ this -> log ( LogLevel :: ERROR , 'The source language is missing in the XML.' , $ errorArgs ) ; return FALSE ; } elseif ( $ xml -> file [ 'source-language' ] != $ this -> sourceLang ) { $ this -> log ( LogLevel :: ERROR , 'The source language is invalid in the XML. Correct langcode: %srclang.' , $ errorArgs ) ; return FALSE ; } // Compare target language. if ( ! isset ( $ xml -> file [ 'target-language' ] ) ) { $ this -> log ( LogLevel :: ERROR , 'The target language is missing in the XML.' , $ errorArgs ) ; return FALSE ; } elseif ( $ targetLang != Data :: normalizeLangcode ( $ xml -> file [ 'target-language' ] ) ) { $ errorArgs [ '%wrong' ] = $ xml -> file [ 'target-language' ] ; $ this -> log ( LogLevel :: ERROR , 'The target language %wrong is invalid in the XML. Correct langcode: %lang.' , $ errorArgs ) ; return FALSE ; } // Validation successful. return TRUE ; }
Validates an import.

@param TranslatableInterface $translatable
A translatable object.
@param string $targetLang
The target language for this translatable.
@param string $xmlString
The XLIFF data as a string to validate.

@return bool
Returns TRUE on success or FALSE on failure.
Validates an import .