Search code examples
phpclassphp-ews

php autoload not loading correctly?


Using php-ews I try to create a calendar event by example (just to get the hang of it):

require $server_path.'scripts/ews/vendor/autoload.php';
use garethp\ews\API;
use garethp\ews\API\Enumeration;
use garethp\ews\API\Type;

$ews = API::withUsernameAndPassword($exchange_host, $_SESSION["user_data"]["u_email"], $_SESSION["user_data"]["u_pwd"]);

Seems to work without errors.

// Start building the request.
$calendar = $ews->getCalendar();

$start = new DateTime('8:00 AM');
$end = new DateTime('9:00 AM');

$request = array(
    'Items' => array(
        'CalendarItem' => array(
            'Start' => $start->format('c'),
            'End' => $end->format('c'),
            'Body' => array(
                'BodyType' => Enumeration\BodyTypeType::HTML,
                '_value' => 'This is <b>the</b> body'
            ),
            'ItemClass' => Enumeration\ItemClassType::APPOINTMENT,
            'Sensitivity' => Enumeration\SensitivityChoicesType::NORMAL,
            'Categories' => array('Testing', 'php-ews'),
            'Importance' => Enumeration\ImportanceChoicesType::NORMAL
        )
    ),
    'SendMeetingInvitations' => Enumeration\CalendarItemCreateOrDeleteOperationType::SEND_TO_NONE
);

$request = Type::buildFromArray($request);
$response = $ews->CreateItem($request);

I get:

PHP Fatal error: Call to undefined method garethp\ews\API::CreateItem() in

in the execute part ($ews->CreateItem())


Solution

  • Please take a look at my examples/, they cover exactly this. The firs thing to note is that creating Calendar events is incredibly simplified, so your long request isn't entirely needed. That being said, if you want to access the functions directly, you can't do

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

    you need to do

    $response = $ews->getClient()->CreateItem($request);
    

    More info on building requests manually can be found here.