Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Loading EWSTypes #35

Open
ityndall opened this Issue · 2 comments

3 participants

@ityndall

Personally, it's a PIA to load each individual EWSType. In addition, I don't want to load all of them by looping over all the classes in EWSType directory.

<?php
/**
 * load the needed EWSTypes
 * 
 * @author Ian Tyndall <http://blog.ianty.com>
 */
class EWSType_Factory {
    /**
     * type loader
     */
    public static function type($type)
    {
        if (include_once 'EWSType/' . $type . 'Type.php') {
            $classname = "EWSType_$type" . 'Type';
            return new $classname;
        } else {
            throw new Exception('Type not found');
        }
    }
} // end class EWSType_Factory

This updates the first example you provided to this:

<?php
require_once('ExchangeWebServices.php');
require_once('EWS_Exception.php');
require_once('EWSType.php');
require_once('EWSType_Factory.php');
require_once('NTLMSoapClient.php');
require_once('NTLMSoapClient/Exchange.php');

$host = 'foo-ews.mysite.com';
$username = 'username'; 
$password = 'password';

$ews = new ExchangeWebServices($host, $username, $password);
$traversal = EWSType_Factory::type('FolderQueryTraversal');
$shape_names = EWSType_Factory::type('DefaultShapeNames');
$folderid_names = EWSType_Factory::type('DistinguishedFolderIdName');

// start building the find folder request
$request = EWSType_Factory::type('FindFolder');
$request->Traversal = $traversal::SHALLOW;
$request->FolderShape = EWSType_Factory::type('FolderResponseShape');
$request->FolderShape->BaseShape = $shape_names::ALL_PROPERTIES;

// configure the view
$request->IndexedPageFolderView = EWSType_Factory::type('IndexedPageView');
$request->IndexedPageFolderView->BasePoint = 'Beginning';
$request->IndexedPageFolderView->Offset = 0;

// set the starting folder as the inbox
$request->ParentFolderIds = EWSType_Factory::type('NonEmptyArrayOfBaseFolderIds');
$request->ParentFolderIds->DistinguishedFolderId = EWSType_Factory::type('DistinguishedFolderId');
$request->ParentFolderIds->DistinguishedFolderId->Id = $folderid_names::INBOX;

// make the actual call
$response = $ews->FindFolder($request);
echo '<pre>'.print_r($response, true).'</pre>';
@jamesiarmes
Owner

A much better way to tackle this issue would be to provide an autoload implementation that could be registered with spl_autoload_register(). I have planned to tackle this after issue #4, but if somebody would like to contribute one via a pull request in the interim I would be open to reviewing and possibly merging it.

@ameir

I use the following; feel free to use or adapt it if you'd like:
#36 (comment)

@jamesiarmes jamesiarmes added this to the Version 1.0 milestone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.