php-ews:使用 Classes 的完整路径时未找到 Class 'SoapClient'
php-ews: Class 'SoapClient' not found when using full path to the Classes
在现有的非 OOP 网站上实施 php-ews
。
运行 shell 中的独立 PHP 脚本工作正常。
独立 PHP 脚本使用 use
:
use \jamesiarmes\PhpEws\Client;
use \jamesiarmes\PhpEws\Request\CreateItemType;
但是我不能在网站上的 if 语句中使用 use
,所以我使用完整路径(即 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';
}
}
}
Running standalone PHP script in shell works fine.
但是
I verified that Soap extension is installed.
你是怎么验证的?您知道您可能正在为 CLI 和 Web 服务器环境加载不同的 php.ini
文件。
(例如,在我的 Ubuntu 服务器中,使用 Apache 网络服务器,我有两个
/etc/php5/cli/php.ini
和
/etc/php5/apache2/php.ini
)
没有回答你原来的问题,但是这个:
But I can't use use inside if-statements on the website, so I prepended all Classes using full path (i.e. new \jamesiarmes\PhpEws\Client).
use
语句导入命名空间 classes 属于文件的顶部,在任何括号之外。它们将始终是 "executed",即在当前命名空间内为外部 class 名称创建别名链接(如果没有使用命名空间,则使用根命名空间)- 仅针对当前文件都在里面。所以它不是永久性的,也不会超出当前文件的范围——新文件可能有不同的 use
导入,但如果两个文件中都使用了 class,它们也必须重复任何导入。
请参阅 http://php.net/manual/en/language.namespaces.php for the chapter on namespaces at large and http://php.net/manual/en/language.namespaces.importing.php 以了解如何使用 use
。注意带有非法代码的示例 5:
<?php
namespace Languages;
function toGreenlandic()
{
use Languages\Danish;
// ...
}
?>
使用 use
导入 classes 独立于代码的执行。在解析文件以允许 PHP 知道代码中使用的所有 classes 的完全限定名称时已经发生了。它们只会在代码执行时自动加载,但 use
应保留在文件顶部。
在现有的非 OOP 网站上实施 php-ews
。
运行 shell 中的独立 PHP 脚本工作正常。
独立 PHP 脚本使用 use
:
use \jamesiarmes\PhpEws\Client;
use \jamesiarmes\PhpEws\Request\CreateItemType;
但是我不能在网站上的 if 语句中使用 use
,所以我使用完整路径(即 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';
}
}
}
Running standalone PHP script in shell works fine.
但是
I verified that Soap extension is installed.
你是怎么验证的?您知道您可能正在为 CLI 和 Web 服务器环境加载不同的 php.ini
文件。
(例如,在我的 Ubuntu 服务器中,使用 Apache 网络服务器,我有两个
/etc/php5/cli/php.ini
和
/etc/php5/apache2/php.ini
)
没有回答你原来的问题,但是这个:
But I can't use use inside if-statements on the website, so I prepended all Classes using full path (i.e. new \jamesiarmes\PhpEws\Client).
use
语句导入命名空间 classes 属于文件的顶部,在任何括号之外。它们将始终是 "executed",即在当前命名空间内为外部 class 名称创建别名链接(如果没有使用命名空间,则使用根命名空间)- 仅针对当前文件都在里面。所以它不是永久性的,也不会超出当前文件的范围——新文件可能有不同的 use
导入,但如果两个文件中都使用了 class,它们也必须重复任何导入。
请参阅 http://php.net/manual/en/language.namespaces.php for the chapter on namespaces at large and http://php.net/manual/en/language.namespaces.importing.php 以了解如何使用 use
。注意带有非法代码的示例 5:
<?php
namespace Languages;
function toGreenlandic()
{
use Languages\Danish;
// ...
}
?>
使用 use
导入 classes 独立于代码的执行。在解析文件以允许 PHP 知道代码中使用的所有 classes 的完全限定名称时已经发生了。它们只会在代码执行时自动加载,但 use
应保留在文件顶部。