jamesiarmes / php-ews

PHP Exchange Web Services
http://jamesarmes.com/php-ews/
MIT License
566 stars 304 forks source link

Class 'ItemResponseShapeType' not found #600

Open victorpictor76 opened 3 years ago

victorpictor76 commented 3 years ago

Version (e.g. 1.0, dev-master): 1.0.0 PHP version: 5.4.16 Microsoft Exchange version: 2019

Description of problem:

Hi there! I'm new to this project, I'd like to read a mailbox's calendar, and process the data. I've only tried an example so far, but could not get it to work.

Example request:

// Formatted example request.

require_once '/etc/vendor/autoload.php';

use \jamesiarmes\PhpEws\Client;
use \jamesiarmes\PhpEws\Request\FindItemType;

use \jamesiarmes\PhpEws\ArrayType\NonEmptyArrayOfBaseFolderIdsType;

use \jamesiarmes\PhpEws\Enumeration\DistinguishedFolderIdNameType;
use \jamesiarmes\PhpEws\Enumeration\ResponseClassType;

use \jamesiarmes\PhpEws\Type\ContactsViewType;
use \jamesiarmes\PhpEws\Type\DistinguishedFolderIdType;

$start_date = new Datetime('today -1 months');
$end_date = new Datetime('today +1 months');

$timezone = 'W. Europe Standard Time';

$host = 'webmail.site.eu';
$username = 'user';
$password = 'password';
$version = Client::VERSION_2016;

$client = new Client($host, $username, $password, $version);

$client->setTimezone($timezone);

$request = new FindItemType();
$request->ParentFolderIds = new NonEmptyArrayOfBaseFolderIdsType();

$request->ItemShape = new ItemResponseShapeType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;
$folder_id = new DistinguishedFolderIdType();
$folder_id->Id = DistinguishedFolderIdNameType::CALENDAR;
$request->ParentFolderIds->DistinguishedFolderId[] = $folder_id;
$request->Traversal = ItemQueryTraversalType::SHALLOW;
$request->CalendarView = new CalendarViewType();
$request->CalendarView->StartDate = $start_date->format('c');
$request->CalendarView->EndDate = $end_date->format('c');
$request->ConnectionTimeout = 60;

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

$response_messages = $response->ResponseMessages->FindItemResponseMessage;
foreach ($response_messages as $response_message) {
  $items = $response_message->RootFolder->Items->CalendarItem;
..
    foreach ($items as $event){
        $id = $event->ItemId->Id;
        $subject = $event->Subject;
         }
}

Example response:

PHP Fatal error:  Class 'ItemResponseShapeType' not found in /etc/vendor/php-ews/php-ews/src/feff.php on line 34

// Formatted example response.

Additional details:

jameswillhoite commented 2 years ago

This is old, but you do not have a "use" statement for ItemResponseShapeType. Or you have to fully qualify the Namespace for that object.

$request->ItemShape = new jamesiarmes\PhpEws\Type\ItemResponseShapeType(); $request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;