PHP code example of dgame / php-soap

1. Go to this page and download the library: Download dgame/php-soap library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dgame / php-soap example snippets


$doc = new DOMDocument();
$doc->loadXML(...);

$mapper = new ClassMapper(
    [
        'Root'    => TestRoot::class,
        'Person'  => TestPerson::class,
        'Car'     => TestCar::class,
        'Phone'   => TestPhone::class,
        'Address' => TestAddress::class
    ]
);
$mapper->appendPattern('/^(?:soap\-?)?env(?:elope)?/iS', 'Root');

$hydrator = new Hydrator($mapper);
$objects  = $hydrator->hydrateDocument($doc);

$this->assertCount(1, $objects);

/** @var TestRoot $root */
$root = $objects[0];

$this->assertNotNull($root);
$this->assertInstanceOf(TestRoot::class, $root);

$persons = $root->getPersons();
$this->assertCount(2, $persons);

$this->assertInstanceOf(TestPerson::class, $persons[0]);
$this->assertEquals('Max Musterman', $persons[0]->getName());
$this->assertInstanceOf(TestCar::class, $persons[0]->getCar());
$this->assertEquals('BMW', $persons[0]->getCar()->getMarke());
$this->assertNotEmpty($persons[0]->getCar()->kennung);
$this->assertEquals('i8', $persons[0]->getCar()->kennung);
$this->assertInstanceOf(TestPhone::class, $persons[0]->getPhone());
$this->assertEquals('iPhone', $persons[0]->getPhone()->getName());
$this->assertEquals(9, $persons[0]->getPhone()->getValue());
$this->assertEquals('Hamburg', $persons[0]->getBirthplace());
$this->assertInstanceOf(TestAddress::class, $persons[0]->getAddress());
$this->assertEquals('Hauptstraße 1', $persons[0]->getAddress()->getStreet());
$this->assertEquals(245698, $persons[0]->getAddress()->getPlz());

$this->assertInstanceOf(TestPerson::class, $persons[1]);
$this->assertEquals('Dr. Dolittle', $persons[1]->getName());
$this->assertInstanceOf(TestCar::class, $persons[1]->getCar());
$this->assertEquals('Audi', $persons[1]->getCar()->getMarke());
$this->assertNotEmpty($persons[0]->getCar()->kennung);
$this->assertEquals('A3', $persons[1]->getCar()->kennung);
$this->assertInstanceOf(TestPhone::class, $persons[1]->getPhone());
$this->assertEquals('Sony', $persons[1]->getPhone()->getName());
$this->assertEquals('Xperia Z3', $persons[1]->getPhone()->getValue());
$this->assertEquals('München', $persons[1]->getBirthplace());
$this->assertInstanceOf(TestAddress::class, $persons[1]->getAddress());
$this->assertEquals('Partkstraße', $persons[1]->getAddress()->getStreet());
$this->assertEquals(365494, $persons[1]->getAddress()->getPlz());

$doc2 = $hydrator->assemble($root);

$this->assertEqualXMLStructure($doc->documentElement, $doc2->documentElement);
        
$envelope = new Envelope();

$security = new Security();
$token    = new UsernameToken('Foo', 'Bar');
$security->appendElement($token);

$header = new Header();
$header->appendElement($security);

$rst = new RequestSecurityToken();
$rst->appendElement(new BiPROVersion('2.1.6.1.1'));

$body = new Body();
$body->appendElement($rst);

$envelope->appendElement($header);
$envelope->appendElement($body);

$assembler = new Assembler();
$envelope->accept($assembler);
      
print $assembler->getDocument()->saveXML();     
        
$envelope = new Envelope();

$security = new Security();
$token    = new SecurityContextToken('bipro:7860072500822840554');
$security->appendElement($token);

$header = new Header();
$header->appendElement($security);

$request = new Request(new BiPROVersion('2.1.4.1.1'));
$request->setConfirm(false);
$shipment = new ListShipments($request);

$body = new Body();
$body->appendElement($shipment);

$envelope->appendElement($header);
$envelope->appendElement($body);

$assembler = new Assembler();
$envelope->accept($assembler);

print $assembler->getDocument()->saveXML();
        
$envelope = new Envelope();

$security = new Security();
$token    = new SecurityContextToken('bipro:7860072500822840554');
$security->appendElement($token);

$header = new Header();
$header->appendElement($security);

$request = new Request(new BiPROVersion('2.1.4.1.1'));
$request->setConsumerId(1);
$request->setId(1);
$request->setConfirm(false);
$shipment = new GetShipment($request);

$body = new Body();
$body->appendElement($shipment);

$envelope->appendElement($header);
$envelope->appendElement($body);

$assembler = new Assembler();
$envelope->accept($assembler);

print $assembler->getDocument()->saveXML();

$envelope = new Envelope();

$security = new Security();
$token    = new SecurityContextToken('bipro:7860072500822840554');
$security->appendElement($token);

$header = new Header();
$header->appendElement($security);

$request = new Request(new BiPROVersion('2.1.4.1.1'));
$request->setConsumerId(1);
$request->setId(1);
$shipment = new AcknowledgeShipment($request);

$body = new Body();
$body->appendElement($shipment);

$envelope->appendElement($header);
$envelope->appendElement($body);

$assembler = new Assembler();
$envelope->accept($assembler);

print $assembler->getDocument()->saveXML();