Author: Nick Sagona, III (nick@popphp.org)
Inheritance: extends AbstractDom
Beispiel #1
0
 /**
  * Build rate request
  *
  * @return void
  */
 protected function buildRequest()
 {
     $package = new Child('Package');
     $package->setAttributes('ID', '1ST');
     $package->addChild(new Child('Service', 'ALL'))->addChild(new Child('ZipOrigination', $this->shipFrom['ZipOrigination']))->addChild(new Child('ZipDestination', $this->shipTo['ZipDestination']))->addChild(new Child('Pounds', $this->weight['Pounds']))->addChild(new Child('Ounces', $this->weight['Ounces']))->addChild(new Child('Container', $this->container))->addChild(new Child('Size', $this->containerSize));
     if (null !== $this->dimensions['Length'] && null !== $this->dimensions['Width'] && null !== $this->dimensions['Height']) {
         $package->addChild(new Child('Width', $this->dimensions['Width']))->addChild(new Child('Length', $this->dimensions['Length']))->addChild(new Child('Height', $this->dimensions['Height']));
         if (null == $this->dimensions['Girth']) {
             $this->dimensions['Girth'] = 2 * $this->dimensions['Width'] + 2 * $this->dimensions['Height'];
         }
         $package->addChild(new Child('Girth', $this->dimensions['Girth']));
     }
     $package->addChild(new Child('Machinable', $this->machinable))->addChild(new Child('DropOffTime', '12:00'))->addChild(new Child('ShipDate', date('Y-m-d')));
     $this->request->addChild($package);
 }
Beispiel #2
0
<?php

require_once '../../bootstrap.php';
use Pop\Dom\Child;
use Pop\Dom\Dom;
try {
    $title = new Child('title', 'This is the title');
    $meta = new Child('meta');
    $meta->setAttributes(array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=utf-8'));
    $head = new Child('head');
    $head->addChildren(array($title, $meta));
    $h1 = new Child('h1', 'This is a header');
    $p = new Child('p', 'This is a paragraph.');
    $div = new Child('div');
    $div->setAttributes('id', 'contentDiv');
    $div->addChildren(array($h1, $p));
    $body = new Child('body');
    $body->addChild($div);
    $html = new Child('html');
    $html->setAttributes(array('xmlns' => 'http://www.w3.org/1999/xhtml', 'xml:lang' => 'en'));
    $html->addChildren(array($head, $body));
    $doc = new Dom(Dom::XHTML11, 'utf-8', $html);
    $doc->render();
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
Beispiel #3
0
 /**
  * Build rate request
  *
  * @return void
  */
 protected function buildRateRequest()
 {
     $rating = new Child('RatingServiceSelectionRequest');
     $request = new Child('Request');
     $transaction = new Child('TransactionReference');
     $pickup = new Child('PickupType');
     $shipment = new Child('Shipment');
     $customer = new Child('CustomerContext', 'Rating and Service');
     $xpci = new Child('XpciVersion', '1.0');
     $requestAction = new Child('RequestAction', 'Rate');
     $requestOption = new Child('RequestOption', 'Shop');
     $transaction->addChild($customer)->addChild($xpci);
     $request->addChild($transaction)->addChild($requestAction)->addChild($requestOption);
     $pickup->addChild(new Child('Code', $this->pickupType))->addChild(new Child('Description', self::$pickupTypes[$this->pickupType]));
     $shipment->addChild(new Child('Description', 'Rate'));
     $shipper = new Child('Shipper');
     $shipper->addChild(new Child('ShipperNumber', $this->userId));
     $shipTo = new Child('ShipTo');
     $shipFrom = new Child('ShipFrom');
     if (null !== $this->shipTo['CompanyName']) {
         $shipTo->addChild(new Child('CompanyName', $this->shipTo['CompanyName']));
     }
     if (null !== $this->shipFrom['CompanyName']) {
         $shipFrom->addChild(new Child('CompanyName', $this->shipFrom['CompanyName']));
     }
     $shipToAddress = new Child('Address');
     foreach ($this->shipTo as $key => $value) {
         if ($key !== 'CompanyName') {
             $shipToAddress->addChild(new Child($key, $value));
         }
     }
     $shipFromAddress = new Child('Address');
     foreach ($this->shipFrom as $key => $value) {
         if ($key !== 'CompanyName') {
             $shipFromAddress->addChild(new Child($key, $value));
         }
     }
     $shipTo->addChild($shipToAddress);
     $shipFrom->addChild($shipFromAddress);
     $shipper->addChild($shipFromAddress);
     $service = new Child('Service');
     $service->addChild(new Child('Code', $this->service))->addChild(new Child('Description', self::$services[$this->service]));
     $package = new Child('Package');
     $packageType = new Child('PackagingType');
     $packageType->addChild(new Child('Code', $this->packageType))->addChild(new Child('Description', self::$packagingTypes[$this->packageType]));
     $package->addChild($packageType)->addChild(new Child('Description', 'Rate'));
     if (null !== $this->dimensions['Length'] && null !== $this->dimensions['Width'] && null !== $this->dimensions['Height']) {
         $dimensions = new Child('Dimensions');
         $unit = new Child('UnitOfMeasurement');
         $unit->addChild(new Child('Code', $this->dimensions['UnitOfMeasurement']));
         $dimensions->addChild($unit)->addChild(new Child('Length', $this->dimensions['Length']))->addChild(new Child('Width', $this->dimensions['Width']))->addChild(new Child('Height', $this->dimensions['Height']));
         $package->addChild($dimensions);
     }
     $weight = new Child('PackageWeight');
     $unit = new Child('UnitOfMeasurement');
     $unit->addChild(new Child('Code', $this->weight['UnitOfMeasurement']));
     $weight->addChild($unit)->addChild(new Child('Weight', $this->weight['Weight']));
     $package->addChild($weight);
     $shipment->addChild($shipper)->addChild($shipTo)->addChild($shipFrom)->addChild($service)->addChild($package);
     $rating->addChild($request)->addChild($pickup)->addChild($shipment);
     $this->rateRequest->addChild($rating);
 }
Beispiel #4
0
 /**
  * Constructor
  *
  * Instantiate the form object
  *
  * @param  string $action
  * @param  string $method
  * @param  array  $fields
  * @param  string $indent
  * @return \Pop\Form\Form
  */
 public function __construct($action = null, $method = 'post', array $fields = null, $indent = null)
 {
     // Set the form's action and method.
     $this->action = null !== $action ? $action : $_SERVER['REQUEST_URI'];
     $this->method = $method;
     // Create the parent DOM element and the form child element.
     parent::__construct(null, 'utf-8', null, $indent);
     $this->form = new Child('form', null, null, false, $indent);
     $this->form->setAttributes(array('action' => $this->action, 'method' => $this->method));
     $this->addChild($this->form);
     if (null !== $fields) {
         $this->setFields($fields);
     }
 }
Beispiel #5
0
 public function testRender()
 {
     $d = new Dom(Dom::XHTML11, 'utf-8', new Child('p', 'This is another paragraph'));
     $d->addChild(new Child('p', 'This is a paragraph'));
     $code = $d->render(true);
     ob_start();
     $d->render();
     $output = ob_get_clean();
     $this->assertContains('<p>', $code);
     $this->assertContains('<p>', $output);
 }
Beispiel #6
0
 /**
  * Method to render the feed and its items
  *
  * @param  boolean $ret
  * @return mixed
  */
 public function render($ret = false)
 {
     if ($this->feedType == Writer::JSON || $this->feedType == Writer::PHP) {
         $this->output = null;
         if ($this->feedType == Writer::JSON) {
             $this->output = json_encode($this->data);
         } else {
             if ($this->feedType == Writer::PHP) {
                 $this->output = serialize($this->data);
             }
         }
         if ($ret) {
             return $this->output;
         } else {
             if (!headers_sent()) {
                 header("HTTP/1.1 200 OK");
                 header("Content-type: " . $this->contentType);
             }
             echo $this->output;
         }
     } else {
         return parent::render($ret);
     }
 }