为什么即使在包含适当的命名空间之后也会出现致命错误?

时间:2015-06-03 05:21:06

标签: php exception exception-handling fatal-error pushwoosh

以下是我的程序编写使用php-pushwoosh库发送推送通知:

<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);

use Gomoob\Pushwoosh\Client\Pushwoosh;
use Gomoob\Pushwoosh\Model\Request\CreateMessageRequest;
use Gomoob\Pushwoosh\Model\Notification\Notification;
use Gomoob\Pushwoosh\Exception;

require __DIR__.'/vendor/autoload.php';

/*require('../config.php');
require('../common.php');*/

$data = json_decode(file_get_contents('php://input'), true);

$auth_token = $data['auth_token'];
$app_code   = $data['app_code'];
$page_no    = $data['page_no'];
$page_total = $data['page_total'];

define('PW_AUTH', $auth_token);
define('PW_APPLICATION', $app_code);

// Create a Pushwoosh client
$pushwoosh = Pushwoosh::create()
    ->setApplication(PW_AUTH)
    ->setAuth(PW_APPLICATION);

if(!empty($page_no) && !empty($page_total)) {

  if (!Phpfox::isUser()) {
    $flag = false;
    $response["error"] = "error";
    $response["message"] = "Please login";
    echoRespnse(401, $response);

  } else {    

    $notificaions = Phpfox::getService('notification')->getAllNotifications($page_no,$page_total);

    if(!empty($notificaions)) {
      $notificaions = walk_recursive_remove($notificaions, 'unset_null_children');
      for($i=0;$i<count($notificaions);$i++) {
        $notificaions[$i]['message'] = stripslashes(strip_tags($notificaions[$i]['message']));
        $notificaions[$i]['profile_image'] = image_creator($notificaions[$i]['user_image']);
      }
      $notifications_data = json_encode($notifications);      
    } 
  }  
} else {
  $notifications_data = "Error in request";
}   

// Create a request for the '/createMessage' Web Service
$request = CreateMessageRequest::create()
    ->addNotification(Notification::create()->setContent($notifications_data));

// Call the REST Web Service
$response = $pushwoosh->createMessage($request);

// Check if its ok
if($response->isOk()) {
  print 'Great, my message has been sent !';
} else {
  print 'Oops, the sent failed :-( '; 
  print 'Status code : ' . $response->getStatusCode()." ";
  print 'Status message : ' . $response->getStatusMessage();
}
?>

在服务器上执行后,我遇到了致命的错误:

Fatal error: Uncaught exception 'Gomoob\Pushwoosh\Exception`\PushwooshException' with message 'None of the 'application' or 'applicationsGroup' properties are set !' in /var/www/api/gomoob-php-pushwoosh/vendor/gomoob/php-pushwoosh/src/main/php/Gomoob/Pushwoosh/Client/Pushwoosh.php:106 Stack trace: #0 /var/www/api/gomoob-php-pushwoosh/push_notifications.php(61): Gomoob\Pushwoosh\Client\Pushwoosh->createMessage(Object(Gomoob\Pushwoosh\Model\Request\CreateMessageRequest)) #1 {main} thrown in /var/www/api/gomoob-php-pushwoosh/vendor/gomoob/php-pushwoosh/src/main/php/Gomoob/Pushwoosh/Client/Pushwoosh.php on line 106`

如果您想检查我所包含的名称空间的层次结构,您可以查看此php-pushwoosh namespace hierarchy

提前致谢。

1 个答案:

答案 0 :(得分:0)

你在这方面有问题,因为PW_AUTH&amp; PW_APPLICATION未定义。

// Create a Pushwoosh client
$pushwoosh = Pushwoosh::create()
    ->setApplication(PW_AUTH)
    ->setAuth(PW_APPLICATION);

您必须定义PW_AUTH&amp; PW_APPLICATION常量,也必须交换它,setAuth使用PW_APPLICATION