Search code examples
phpcomposer-phpphp-ews

php-ews: Class 'SoapClient' not found when using full path to the Classes


Implementing php-ews on the existing non-OOP website.

Running standalone PHP script in shell works fine.

Standalone PHP script uses use:

use \jamesiarmes\PhpEws\Client;
use \jamesiarmes\PhpEws\Request\CreateItemType;

But I can't use use inside if-statements on the website, so I prepended all Classes using full path (i.e. new \jamesiarmes\PhpEws\Client).

Now I'm getting this error.

Fatal error: Class 'SoapClient' not found in /home/project/master/vendor/jamesiarmes/php-ntlm/src/SoapClient.php on line 13

I verified that Soap extension is installed. Please help. Thanks.

if ($_REQUEST['action'] == 'export-form-test') {

    require_once 'vendor/autoload.php';

/*
use \jamesiarmes\PhpEws\Client;
use \jamesiarmes\PhpEws\Request\CreateItemType;

use \jamesiarmes\PhpEws\ArrayType\NonEmptyArrayOfAllItemsType;
use \jamesiarmes\PhpEws\ArrayType\NonEmptyArrayOfAttendeesType;

use \jamesiarmes\PhpEws\Enumeration\BodyTypeType;
use \jamesiarmes\PhpEws\Enumeration\CalendarItemCreateOrDeleteOperationType;
use \jamesiarmes\PhpEws\Enumeration\ResponseClassType;
use \jamesiarmes\PhpEws\Enumeration\RoutingType;

use \jamesiarmes\PhpEws\Type\AttendeeType;
use \jamesiarmes\PhpEws\Type\BodyType;
use \jamesiarmes\PhpEws\Type\CalendarItemType;
use \jamesiarmes\PhpEws\Type\EmailAddressType;
*/

    // Replace this with your desired start/end times and guests.
    $start = new DateTime('tomorrow 4:00pm');
    $end = new DateTime('tomorrow 5:00pm');

    // Set connection information.
    $host = '*********';
    $username = '*******';
    $password = '********';
    //$version = Client::VERSION_2016;

    $client = new \jamesiarmes\PhpEws\Client($host, $username, $password);

    // Build the request,
    $request = new \jamesiarmes\PhpEws\Request\CreateItemType();
    $request->SendMeetingInvitations = \jamesiarmes\PhpEws\Enumeration\CalendarItemCreateOrDeleteOperationType::SEND_ONLY_TO_ALL;
    $request->Items = new \jamesiarmes\PhpEws\ArrayType\NonEmptyArrayOfAllItemsType();

    // Build the event to be added.
    $event = new \jamesiarmes\PhpEws\Type\CalendarItemType();
    $event->Start = $start->format('c');
    $event->End = $end->format('c');
    $event->title = 'EWS Test Event';

    // Set the event body.
    $event->Body = new \jamesiarmes\PhpEws\Type\BodyType();
    $event->Body->_ = 'This is the event body';
    $event->Body->BodyType = \jamesiarmes\PhpEws\Enumeration\BodyTypeType::TEXT;

    // Add the event to the request. You could add multiple events to create more
    // than one in a single request.
    $request->Items->CalendarItem[] = $event;

    $response = $client->CreateItem($request);

    // Iterate over the results, printing any error messages or event ids.
    $response_messages = $response->ResponseMessages->CreateItemResponseMessage;
    foreach($response_messages as $response_message) {
        // Make sure the request succeeded.
        if ($response_message->ResponseClass != ResponseClassType::SUCCESS) {
            $return_arr['status'] = 'error';
            continue;
        }

        // Iterate over the created events, printing the id for each.
        foreach($response_message->Items->CalendarItem as $item) {
            $id = $item->ItemId->Id;
            $return_arr['status'] = 'ok';
        }
    }

}

Solution

  • Running standalone PHP script in shell works fine.

    but

    I verified that Soap extension is installed.

    How have you verified? You know you may be loading different php.ini files for CLI and Webserver environments.

    (For example, in my Ubuntu server, with Apache webserver, I have both

    /etc/php5/cli/php.ini

    and

    /etc/php5/apache2/php.ini )