PHP code example of sandwave-io / office-365-php

1. Go to this page and download the library: Download sandwave-io/office-365-php 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/ */

    

sandwave-io / office-365-php example snippets


 declare(strict_types = 1);

use SandwaveIo\Office365\Office\OfficeClient;

$client = new OfficeClient(
    'https://my.awesome.domain',
    'username',
    'password',
);


[
    'auth' => ['username', 'password'],
    'base_uri' => 'https://somehost',
    'headers' => [
        'Content-Type' => 'text/xml; charset=UTF8'
    ],
]

$mock = new MockHandler([
    new Response(200, ['X-Foo' => 'Bar'], 'Hello, World'),
    new Response(202, ['Content-Length' => 0]),
    new RequestException('Error Communicating with Server', new Request('GET', 'test'))
]);

$handlerStack = HandlerStack::create($mock);

$officeClient = new OfficeClient('username', 'password', ['handler' => $handlerStack]);

$client = new OfficeClient('https://my.awesome.domain', 'username', 'password');
$customer = $client->customer->create('name', ...);

class CustomerCreateListener implements CustomerObserverInterface
{
    public function execute(Customer $customer): void
    {
        echo $customer->getName();
    }
}

$client->webhook->addEventSubscriber(OfficeEvent::CUSTOMER_CREATE, new CustomerCreateListener());
$response = $client->webhook->parse($xml);