1

php-ews在现有的非 OOP 网站上实施。

在 shell 中运行独立的 PHP 脚本可以正常工作。

独立的 PHP 脚本使用use

use \jamesiarmes\PhpEws\Client;
use \jamesiarmes\PhpEws\Request\CreateItemType;

但是我不能use在网站上使用内部 if 语句,所以我使用完整路径(即new \jamesiarmes\PhpEws\Client)在所有类前面添加。

现在我收到了这个错误。

Fatal error: Class 'SoapClient' not found in /home/project/master/vendor/jamesiarmes/php-ntlm/src/SoapClient.php on line 13

我确认已安装 Soap 扩展。请帮忙。谢谢。

if ($_REQUEST['action'] == 'export-form-test') {

    require_once 'vendor/autoload.php';

/*
use \jamesiarmes\PhpEws\Client;
use \jamesiarmes\PhpEws\Request\CreateItemType;

use \jamesiarmes\PhpEws\ArrayType\NonEmptyArrayOfAllItemsType;
use \jamesiarmes\PhpEws\ArrayType\NonEmptyArrayOfAttendeesType;

use \jamesiarmes\PhpEws\Enumeration\BodyTypeType;
use \jamesiarmes\PhpEws\Enumeration\CalendarItemCreateOrDeleteOperationType;
use \jamesiarmes\PhpEws\Enumeration\ResponseClassType;
use \jamesiarmes\PhpEws\Enumeration\RoutingType;

use \jamesiarmes\PhpEws\Type\AttendeeType;
use \jamesiarmes\PhpEws\Type\BodyType;
use \jamesiarmes\PhpEws\Type\CalendarItemType;
use \jamesiarmes\PhpEws\Type\EmailAddressType;
*/

    // Replace this with your desired start/end times and guests.
    $start = new DateTime('tomorrow 4:00pm');
    $end = new DateTime('tomorrow 5:00pm');

    // Set connection information.
    $host = '*********';
    $username = '*******';
    $password = '********';
    //$version = Client::VERSION_2016;

    $client = new \jamesiarmes\PhpEws\Client($host, $username, $password);

    // Build the request,
    $request = new \jamesiarmes\PhpEws\Request\CreateItemType();
    $request->SendMeetingInvitations = \jamesiarmes\PhpEws\Enumeration\CalendarItemCreateOrDeleteOperationType::SEND_ONLY_TO_ALL;
    $request->Items = new \jamesiarmes\PhpEws\ArrayType\NonEmptyArrayOfAllItemsType();

    // Build the event to be added.
    $event = new \jamesiarmes\PhpEws\Type\CalendarItemType();
    $event->Start = $start->format('c');
    $event->End = $end->format('c');
    $event->title = 'EWS Test Event';

    // Set the event body.
    $event->Body = new \jamesiarmes\PhpEws\Type\BodyType();
    $event->Body->_ = 'This is the event body';
    $event->Body->BodyType = \jamesiarmes\PhpEws\Enumeration\BodyTypeType::TEXT;

    // Add the event to the request. You could add multiple events to create more
    // than one in a single request.
    $request->Items->CalendarItem[] = $event;

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

    // Iterate over the results, printing any error messages or event ids.
    $response_messages = $response->ResponseMessages->CreateItemResponseMessage;
    foreach($response_messages as $response_message) {
        // Make sure the request succeeded.
        if ($response_message->ResponseClass != ResponseClassType::SUCCESS) {
            $return_arr['status'] = 'error';
            continue;
        }

        // Iterate over the created events, printing the id for each.
        foreach($response_message->Items->CalendarItem as $item) {
            $id = $item->ItemId->Id;
            $return_arr['status'] = 'ok';
        }
    }

}
4

2 回答 2

1

没有回答你原来的问题,但这个问题:

但我不能在网站上的 if 语句中使用 use,所以我使用完整路径(即 new \jamesiarmes\PhpEws\Client)在所有类前面添加。

use导入命名空间类的语句属于文件顶部,在任何括号之外。它们将始终被“执行”,即在当前命名空间内为外部类名创建别名链接(如果没有使用命名空间,则使用根命名空间) - 仅适用于它们所在的当前文件。所以它是没有任何永久性或超出当前文件的内容 - 新文件可能有不同的use导入,但如果在两个文件中都使用了一个类,它们也必须重复任何导入。

请参阅http://php.net/manual/en/language.namespaces.php以了解有关整个名称空间的章节,并参阅http://php.net/manual/en/language.namespaces.importing.php以了解具体使用use情况。注意带有非法代码的示例 5:

<?php
namespace Languages;

function toGreenlandic()
{
    use Languages\Danish;

    // ...
}
?>

导入类use独立于代码的执行。在解析文件以允许 PHP 知道代码中使用的所有类的完全限定名时,它已经发生了。它们只会在代码执行时自动加载,但use应保留在文件的顶部。

于 2017-01-11T00:12:20.587 回答
1

在 shell 中运行独立的 PHP 脚本可以正常工作。

我确认已安装 Soap 扩展。

你是如何验证的?您知道您可能正在php.ini为 CLI 和 Web 服务器环境加载不同的文件。

(例如,在我的 Ubuntu 服务器中,使用 Apache 网络服务器,我同时拥有

/etc/php5/cli/php.ini

/etc/php5/apache2/php.ini)

于 2017-01-09T13:35:36.533 回答