コード例 #1
0
ファイル: LabelTest.php プロジェクト: BenCavens/bpost
 /**
  * Test validation in the setters
  */
 public function testFaultyProperties()
 {
     $label = new Label();
     try {
         $label->setMimeType(str_repeat('a', 9));
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals('Invalid value, possible values are: ' . implode(', ', Label::getPossibleMimeTypeValues()) . '.', $e->getMessage());
     }
 }
コード例 #2
0
ファイル: Bpost.php プロジェクト: BenCavens/bpost
 /**
  * Create labels in bulk, according to the list of order references and the
  * list of barcodes. When there is an order reference specified in the
  * request, the service will return a label of every box of that order. If
  * a certain box was not yet printed, it will have the status PRINTED
  *
  * @param  array  $references       The references for the order
  * @param  string $format           The desired format, allowed values are: A4, A6
  * @param  bool   $withReturnLabels Should return labels be returned?
  * @param  bool   $asPdf            Should we retrieve the PDF-version instead of PNG
  * @return Label[]
  */
 public function createLabelInBulkForOrders(array $references, $format = 'A6', $withReturnLabels = false, $asPdf = false)
 {
     $format = strtoupper($format);
     if (!in_array($format, self::getPossibleLabelFormatValues())) {
         throw new Exception(sprintf('Invalid value, possible values are: %1$s.', implode(', ', self::getPossibleLabelFormatValues())));
     }
     $url = '/labels/' . $format;
     if ($withReturnLabels) {
         $url .= '/withReturnLabels';
     }
     if ($asPdf) {
         $headers = array('Accept: application/vnd.bpost.shm-label-pdf-v3+XML');
     } else {
         $headers = array('Accept: application/vnd.bpost.shm-label-image-v3+XML');
     }
     $headers[] = 'Content-Type: application/vnd.bpost.shm-labelRequest-v3+XML';
     $document = new \DOMDocument('1.0', 'utf-8');
     $document->preserveWhiteSpace = false;
     $document->formatOutput = true;
     $batchLabels = $document->createElement('batchLabels');
     $batchLabels->setAttribute('xmlns', 'http://schema.post.be/shm/deepintegration/v3/');
     foreach ($references as $reference) {
         $batchLabels->appendChild($document->createElement('order', $reference));
     }
     $document->appendChild($batchLabels);
     $xml = $this->doCall($url, $document->saveXML(), $headers, 'POST');
     $labels = array();
     if (isset($xml->label)) {
         foreach ($xml->label as $label) {
             $labels[] = Label::createFromXML($label);
         }
     }
     return $labels;
 }
コード例 #3
0
ファイル: Label.php プロジェクト: BenCavens/bpost
 /**
  * @param  \SimpleXMLElement $xml
  * @return Label
  */
 public static function createFromXML(\SimpleXMLElement $xml)
 {
     $label = new Label();
     if (isset($xml->barcode) && $xml->barcode != '') {
         $label->setBarcode((string) $xml->barcode);
     }
     if (isset($xml->mimeType) && $xml->mimeType != '') {
         $label->setMimeType((string) $xml->mimeType);
     }
     if (isset($xml->bytes) && $xml->bytes != '') {
         $label->setBytes((string) base64_decode($xml->bytes));
     }
     return $label;
 }