php ews连接到Exchange 2010

I downloaded the PHP ews database from https://github.com/jamesiarmes/php-ews.

Autoloader:

function __autoload ($className){
  preg_match ("/^(([a-zA-Z]{5})_)?(.+)$/",$className,&$treffer); # die ersten 5 Stellen=Verzeichnisname, Weitere Zeichen=Dateiname
  if(file_exists(PROJEKT_DIR.$className.".class.php"))  include_once(PROJEKT_DIR.$className.".class.php"); 
  else{
    $pfad=SCRIPT_DIR."include/";
    if($treffer[2]) $pfad.="classes/".$treffer[2]."/";
    if(file_exists($pfad.$treffer[3].".class.php"))
      include_once($pfad.$treffer[3].".class.php");
    elseif(substr($treffer[3],-7)!="_bvstnd" and class_exists($className."_bvstnd")){
      eval("class  $className extends ".$className."_bvstnd {} ");
    }
        else{
        // Start from the base path and determine the location from the class name,
        $pfad=SCRIPT_DIR."include/php-ews";
        $include_file = $pfad . '/' . str_replace('_', '/', $className) . '.php';

        return (file_exists($include_file) ? require_once $include_file : false);

        }
  }

  #if(file_exists(SCRIPT_DIR."include/".$className.".class.php"))
  #  include_once(SCRIPT_DIR."include/".$className.".class.php");
}

it also load some other files.

Then I started doing the Guide from his site, I started doing this:

<?php

$host = "*********";
$username="**********";
$password="***********";
$version= "***********";

$ews = new ExchangeWebServices($host, $username, $password, $version);


$request = new EWSType_FindFolderType();
$request->Traversal = EWSType_FolderQueryTraversalType::SHALLOW;

$request->FolderShape = new EWSType_FolderResponseShapeType();

$request->FolderShape->BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES;

// configure the view
$request->IndexedPageFolderView = new EWSType_IndexedPageViewType();

$request->IndexedPageFolderView->BasePoint = 'Beginning';
$request->IndexedPageFolderView->Offset = 0;

// set the starting folder as the inbox
$request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType();

$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();

$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::INBOX;

// make the actual call
$response = $ews->FindFolder($request);

?>

At first the Site at the browser just load very long but then tell me something like this: class Exception is undefined. I can't tell the correct message because now this Message doesn´t even show up if I load the script.

The Browser just load infinitely. After this I can't even connect to my server with my PHP files. I have to open my other Browser to connect again.

If I open up the script in my other Browser then I can run the script again but it´s again loading infinity. (I include all my files I need with autoloader so that's not the Problem)

Does anybody have a Problem like that and found a solution?

You have an issue with your autoloader. The default files of that library are loaded like this:

$pfad=SCRIPT_DIR."include/php-ews";
$include_file = $pfad . '/' . str_replace('_', '/', $className) . '.php';

If your autoloader is the first to try and load that exception, it will replace the '_'. If you put an error_log in that autoloader function you will probably see the result of $inlcude_file to be something like

include/php-ews/EWS/Exception

And that file doesn't exist.

So you should fix your autoloader so it can actually find the file.

To be aboslutely clear:

  • you (the code) are looking for the class EWS_Exception
  • this is in the file EWS_Exception.php (in the root of the project)
  • your autoloader cannot find that file as you replace all _

so the sollution is to either fix your autoloader, or just include that EWS_Exception.php file somewhere.