Aptana中的PHP格式错误

时间:2011-12-08 14:50:39

标签: php eclipse formatting aptana formatter

尝试格式化以下代码时出错: 代码是从http://tareqalam.wordpress.com/2010/07/07/paypal-recurring-payment-integrated-with-codeigniter/

复制粘贴的
<?php

class callerservice extends Model {

var $API_UserName;

var $API_Password;

var $API_Signature;

var $API_Endpoint ;

var $version;

var $subject;
 var $CI;
 var $USE_PROXY;
 var $PROXY_HOST;
 var $PROXY_PORT;

function callerservice()
 {
 // Call the Model constructor
 parent::Model();

$this->CI =& get_instance();
 $this->CI->load->helper(‘url’);
 $this->CI->load->helper(‘form’);
 $this->CI->load->library(‘session’);

$this->CI->load->config(‘paypal_constants’);

$this->API_UserName = $this->CI->config->item(‘API_USERNAME’);

$this->API_Password = $this->CI->config->item(‘API_PASSWORD’);

$this->API_Signature = $this->CI->config->item(‘API_SIGNATURE’);

$this->API_Endpoint = $this->CI->config->item(‘API_ENDPOINT’);

$this->subject = $this->CI->config->item(‘SUBJECT’);

$this->version = $this->CI->config->item(‘VERSION’);

$this->USE_PROXY = $this->CI->config->item(‘USE_PROXY’);

$this->PROXY_HOST = $this->CI->config->item(‘PROXY_HOST’);

$this->PROXY_PORT = $this->CI->config->item(‘PROXY_PORT’);

}

/**
 * hash_call: Function to perform the API call to PayPal using API signature
 * @methodName is name of API  method.
 * @nvpStr is nvp string.
 * returns an associtive array containing the response from the server.
 */

function hash_call($methodName,$nvpStr)
 {
 //declaring of global variables
 //global $API_Endpoint,$version,$API_UserName,$API_Password,$API_Signature,$nvp_Header, $subject;

//setting the curl parameters.
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,$this->API_Endpoint);
 curl_setopt($ch, CURLOPT_VERBOSE, 1);

//turning off the server and peer verification(TrustManager Concept).
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
 curl_setopt($ch, CURLOPT_POST, 1);
 //if USE_PROXY constant set to TRUE in Constants.php, then only proxy will be enabled.
 //Set proxy name to PROXY_HOST and port number to PROXY_PORT in constants.php
 if($this->USE_PROXY)
 curl_setopt ($ch, CURLOPT_PROXY, $this->PROXY_HOST.”:”.$this->PROXY_PORT);

//check if version is included in $nvpStr else include the version.
 if(strlen(str_replace(‘VERSION=’, ”, strtoupper($nvpStr))) == strlen($nvpStr)) {
 $nvpStr = “&VERSION=” . urlencode($this->version) . $nvpStr;
 }

$nvpreq=”METHOD=”.urlencode($methodName).$nvpStr;

//setting the nvpreq as POST FIELD to curl
 curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq);

//getting response from server
 $response = curl_exec($ch);

//convrting NVPResponse to an Associative Array
 $nvpResArray=$this->deformatNVP($response);
 $nvpReqArray=$this->deformatNVP($nvpreq);
 $ASESSION['nvpReqArray']=$nvpReqArray;

if (curl_errno($ch)) {
 // moving to display page to display curl errors
 $ASESSION['curl_error_no']=curl_errno($ch) ;
 $ASESSION['curl_error_msg']=curl_error($ch);
 print_r($ch);exit;
 //$this->redirect(‘error’);
 } else {
 //closing the curl
 curl_close($ch);
 }
 $this->CI->session->set_userdata($ASESSION);

return $nvpResArray;
 }

/** This function will take NVPString and convert it to an Associative Array and it will decode the response.
 * It is usefull to search for a particular key and displaying arrays.
 * @nvpstr is NVPString.
 * @nvpArray is Associative Array.
 */

function deformatNVP($nvpstr)
 {

$intial=0;
 $nvpArray = array();

while(strlen($nvpstr)){
 //postion of Key
 $keypos= strpos($nvpstr,’=');
 //position of value
 $valuepos = strpos($nvpstr,’&’) ? strpos($nvpstr,’&’): strlen($nvpstr);

/*getting the Key and Value values and storing in a Associative Array*/
 $keyval=substr($nvpstr,$intial,$keypos);
 $valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1);
 //decoding the respose
 $nvpArray[urldecode($keyval)] =urldecode( $valval);
 $nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr));
 }
 return $nvpArray;
 }

}
 ?>

then create a file paypal_constants.php in config folder

<?php

class callerservice extends Model {

var $API_UserName;

var $API_Password;

var $API_Signature;

var $API_Endpoint ;

var $version;

var $subject;
 var $CI;
 var $USE_PROXY;
 var $PROXY_HOST;
 var $PROXY_PORT;

function callerservice()
 {
 // Call the Model constructor
 parent::Model();

$this->CI =& get_instance();
 $this->CI->load->helper(‘url’);
 $this->CI->load->helper(‘form’);
 $this->CI->load->library(‘session’);

$this->CI->load->config(‘paypal_constants’);

$this->API_UserName = $this->CI->config->item(‘API_USERNAME’);

$this->API_Password = $this->CI->config->item(‘API_PASSWORD’);

$this->API_Signature = $this->CI->config->item(‘API_SIGNATURE’);

$this->API_Endpoint = $this->CI->config->item(‘API_ENDPOINT’);

$this->subject = $this->CI->config->item(‘SUBJECT’);

$this->version = $this->CI->config->item(‘VERSION’);

$this->USE_PROXY = $this->CI->config->item(‘USE_PROXY’);

$this->PROXY_HOST = $this->CI->config->item(‘PROXY_HOST’);

$this->PROXY_PORT = $this->CI->config->item(‘PROXY_PORT’);

}

/**
 * hash_call: Function to perform the API call to PayPal using API signature
 * @methodName is name of API  method.
 * @nvpStr is nvp string.
 * returns an associtive array containing the response from the server.
 */

function hash_call($methodName,$nvpStr)
 {
 //declaring of global variables
 //global $API_Endpoint,$version,$API_UserName,$API_Password,$API_Signature,$nvp_Header, $subject;

//setting the curl parameters.
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,$this->API_Endpoint);
 curl_setopt($ch, CURLOPT_VERBOSE, 1);

//turning off the server and peer verification(TrustManager Concept).
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
 curl_setopt($ch, CURLOPT_POST, 1);
 //if USE_PROXY constant set to TRUE in Constants.php, then only proxy will be enabled.
 //Set proxy name to PROXY_HOST and port number to PROXY_PORT in constants.php
 if($this->USE_PROXY)
 curl_setopt ($ch, CURLOPT_PROXY, $this->PROXY_HOST.”:”.$this->PROXY_PORT);

//check if version is included in $nvpStr else include the version.
 if(strlen(str_replace(‘VERSION=’, ”, strtoupper($nvpStr))) == strlen($nvpStr)) {
 $nvpStr = “&VERSION=” . urlencode($this->version) . $nvpStr;
 }

$nvpreq=”METHOD=”.urlencode($methodName).$nvpStr;

//setting the nvpreq as POST FIELD to curl
 curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq);

//getting response from server
 $response = curl_exec($ch);

//convrting NVPResponse to an Associative Array
 $nvpResArray=$this->deformatNVP($response);
 $nvpReqArray=$this->deformatNVP($nvpreq);
 $ASESSION['nvpReqArray']=$nvpReqArray;

if (curl_errno($ch)) {
 // moving to display page to display curl errors
 $ASESSION['curl_error_no']=curl_errno($ch) ;
 $ASESSION['curl_error_msg']=curl_error($ch);
 print_r($ch);exit;
 //$this->redirect(‘error’);
 } else {
 //closing the curl
 curl_close($ch);
 }
 $this->CI->session->set_userdata($ASESSION);

return $nvpResArray;
 }

/** This function will take NVPString and convert it to an Associative Array and it will decode the response.
 * It is usefull to search for a particular key and displaying arrays.
 * @nvpstr is NVPString.
 * @nvpArray is Associative Array.
 */

function deformatNVP($nvpstr)
 {

$intial=0;
 $nvpArray = array();

while(strlen($nvpstr)){
 //postion of Key
 $keypos= strpos($nvpstr,’=');
 //position of value
 $valuepos = strpos($nvpstr,’&’) ? strpos($nvpstr,’&’): strlen($nvpstr);

/*getting the Key and Value values and storing in a Associative Array*/
 $keyval=substr($nvpstr,$intial,$keypos);
 $valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1);
 //decoding the respose
 $nvpArray[urldecode($keyval)] =urldecode( $valval);
 $nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr));
 }
 return $nvpArray;
 }

}
 ?>

错误打印在Aptana的错误日志中,

-- Error Details --
Date: Thu Dec 08 15:32:24 CET 2011
Message: Error while formatting the code in your editor.Please submit a bug report through Studio's support and include the relevant code which triggered this error.
Severity: Error
Product: Aptana Studio 3 3.0.6.201110251455 (com.aptana.rcp.product)
Plugin: com.aptana.formatter.epl
Session Data:
eclipse.buildId=unknown
java.version=1.6.0_29
java.vendor=Apple Inc.
BootLoader constants: OS=macosx, ARCH=x86, WS=cocoa, NL=en_US
Framework arguments:  -keyring /Users/alex/.eclipse_keyring -showlocation
Command-line arguments:  -os macosx -ws cocoa -arch x86 -keyring /Users/alex/.eclipse_keyring -consoleLog -showlocation


Error
Thu Dec 08 15:32:24 CET 2011
Error while formatting the code in your editor.Please submit a bug report through Studio's support and include the relevant code which triggered this error.

我遇到了Aptana / Eclipse的错误还是其他事情发生了?

提前致谢,

亚历

1 个答案:

答案 0 :(得分:2)

2011年12月8日14:52:

问题是由于错误的引号和撇号:“”''用'替换它们'和'错误记录但是:)

Eclipse:http://bugs.eclipse.org/bugs/show_bug.cgi?id=366045

Aptana:https://jira.appcelerator.org/browse/APSTUD-4680