Search code examples
phplaravelphp-ews

use php-ews with laravel


I'm looking for a way for my laravel 4.1 app to integrate with an exchange server.

I found this script https://github.com/jamesiarmes/php-ews which seems to fit what I need. However I don't now how to integrate it into my laravel app.

I've copied the scripts to a folder in my app folder

I've created a controller in my controller folder:

<?php

require_once('/exchange-ews/ExchangeWebServices.php');
require_once('/exchange-ews/EWSAutodiscover.php');

require_once('/exchange-ews/EWSType/CalendarItemType.php');

/**
* Class to control EWS Exchnage
*/
class EwsController
{
public $server = 'xxxx';
public $username = 'xxx';
public $password = 'xxxx';
public $version = 'xxxx';

public function getCalendarEvent()
{
    $ews = new ExchangeWebServices($server, $username, $password, $version);
}

public function getServer()
{
    $ews = EWSAutodiscover::getEWS($this->$username, $this->password);

    return $ews;
}
}

In my routes i've created the following route:

Route::get('testEWS', function ()
{


$result = EwsController::getServer();

return $result;
});

So far this does nothing. When I call the route all I get is a server error but I'm unable to see what the error is. Simply a white screen.

I don't know enough yet to incorporate a non laravel package in my app. How do I do this?

Thanks

Update

Here's some output from xdebug error log at the point of error:

fl=php:internal
fn=php::ErrorException->__construct
133 7
fl=C:\wamp\www\golfmanager\golfmanager\vendor\laravel\framework\src\Illuminate\Exception\Handler.php
fn=Illuminate\Exception\Handler->handleError
129 12886
cfl=php:internal
cfn=php::error_reporting
calls=1 0 0
131 1
cfl=php:internal
cfn=php::ErrorException->__construct
calls=1 0 0
133 7

Solution

  • In the end the problem - once I started to dig into error logging and bypassing laravels error capturing it was a simple problem.

    The error discovered was it couldnt open the included files.

    I change my paths to base_app() . '/exchange-ews/ExchangeWebServices.php' and the error disappeared.

    I now have another poblem which is for possibly another question.

    Lesson learned: check the logs and display errors first. I also added the following to my route to ensure the errors got displayed ini_set('display_errors',1);

    Thanks