I'm trying to use PHP-EWS library, to make a connection with Exchange. So I declared two libraries like this :

function mymodule_libraries_info() {
    $libraries = array(
        'php-ews-master' => array(
            'name' => 'php-ews-master',
            'vendor url' => 'https://github.com/jamesiarmes/php-ews/',
            'download url' => 'https://github.com/jamesiarmes/php-ews/archive/master.zip',
            'version callback' => 'mymodule_callback',
            'files' => array(
                'php' => array(
                    //Main classes
                    //Others classes
                    'src/Request/FindItemType.php' => array('autoload' => TRUE),
        //Soap connection
        'php-ntlm' => array(
            'name' => 'php-ntlm',
            'vendor url' => 'https://github.com/jamesiarmes/php-ntlm/',
            'download url' => 'https://github.com/jamesiarmes/php-ntlm/archive/master.zip',
            'version callback' => 'mymodule_callback',
            'files' => array(
                'php' => array(

    return $libraries;

Next, in a custom function, I used the main function to connect my user :

//Load libraries

$timezone = 'Eastern Standard Time';
$email = 'myuser.onmicrosoft.com';
$pass = 'mypass';
$client = new \jamesiarmes\PhpEws\Client('outlook.office365.com', $email, $pass);

My first question is, why I need to use the full namespace \jamesiarmes\PhpEws\Client to use the class and not just Client ? After the connection I want to get all events from the calendar of this user. So the first class used is \jamesiarmes\PhpEws\Request\FindItemType. I put it in my library files and used it, but I got this error :

Fatal error: Class 'jamesiarmes\PhpEws\Request\BaseRequestType' not found in /usr/share/myapp/sites/all/libraries/php-ews-master/src/Request/FindItemType.php on line 14

I got this error because the class \jamesiarmes\PhpEws\Request\FindItemType extends another class BaseRequestType

class FindItemType extends BaseRequestType

Why, when I included the class \jamesiarmes\PhpEws\Request\FindItemType aren't the classes loaded or extends in this class not loaded ? In the librarie, there is a class called ClassMap.php which list all classes used by the library, there is maybe a way to use this class to load all classes ?

I tried to use this librarie out of drupal with composer and autoload.php. And I just need to call this, and it works :

require_once './vendor/autoload.php';
use \jamesiarmes\PhpEws\Client; 
use \jamesiarmes\PhpEws\Request\FindItemType;

So maybe in drupal I don't have this autoload which load automatically all the classes used ? I tried a lot of things but for the moment, It's work when I call all the classes one by one in my files declarations in the librarie, but the array is too big...

Thank you if you can help me

  • My problem isn't solved. If someone have an idea ? I tried to use X autoload module like this in my HOOK_libraries_infos : 'xautoload' => function($adapter) { $adapter->namespaceRoot('jamesiarmes\PhpEws', 'src'); }, but it's not working...
    – Cracs
    Mar 15 '17 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.