Restler 3.0 - 未定义索引:BasicAuthentication
Restler 3.0 - Undefined index: BasicAuthentication
当我 运行 我的 GET /user 使用基本身份验证时(请参阅下面的 class 代码),用户名和密码已通过身份验证。但我的 xml 回复是:
<br />
<b>Notice</b>: Undefined index: BasicAuthentication in <b>/...Web/api/vendor/Luracast/Restler/Restler.php</b> on line <b>600</b><br />
<?xml version="1.0" encoding="UTF-8"?>
<response>
<prod1>yyyy-mm-dd</prod1>
<prod2>yyyy-mm-dd</prod2>
</response>
在error_log中显示用户已通过身份验证,并且userInfo数组:
[Tue Jul 14 14:56:30.239048 2015] [:error] [pid 35839] [client 192.168.42.59:59671] BasicAuthentication:__isAllowed:authorized:userInfo:Array\n(\n [Signed Up] => 2013-10-03 15:06:33\n [Last Updated] => 2013-10-03\n [Subscribed to Mailing List] => Yes\n [HRA Free Membership] => Expire: 0000-00-00\n [HRA SILVER 3 Months Membership] => Expire: 9999-12-31\n)\n
我为 class BasicAuthentication implements iAuthenticate
使用的模板与我之前使用的模板相同。但是我以前没有看到这个通知。
从User.php抓取$userInfo时也可能导致错误:
$userInfo = BasicAuthentication::$userInfo();
这是我在User.php中抓取public static $userInfo = array();
时的错误:
Fatal error: Cannot redeclare class BasicAuthentication in ...Web/api/public/v1/BasicAuthentication.php on line 26
用户 class 文件 (User.php):
/**
* All methods in this class are protected
* @access protected
* @class BasicAuthentication {@requires member}
*/
class User {
/**
* Retrieve User information
*
* Return some user information
*
* @throttle 200
*
* @throws 400 Bad Request - parameter values are wrong
* @throws 401 Unauthorized
* @return array
*/
function index() {
$userInfo = BasicAuthentication::$userInfo();
//$userInfo = array("prod1" => "yyyy-mm-dd","prod2" => "yyyy-mm-dd");
return $userInfo;
}
}
BasicAuthentication.php:
use Luracast\Restler\iAuthenticate;
use Luracast\Restler\RestException;
use Luracast\Restler\Resources;
class BasicAuthentication implements iAuthenticate {
const REALM = 'Restricted API';
public static $requires = 'non-member';
public static $role = 'non-member';
public static $active = FALSE;
public static $email = 0;
public static $userId = 0;
public static $userInfo = 0;
public static $userLevel = 0;
public static $productId = 0;
public static $productName = 0;
function __isAllowed() {
self::$email = 0;
self::$userId = 0;
self::$userLevel = 0;
self::$userInfo = array();
self::$active = FALSE;
self::$role = 'non-member';
self::$productId = 0;
self::$productName = 0;
if (isset($_SERVER ['PHP_AUTH_USER']) && isset($_SERVER ['PHP_AUTH_PW'])) {
// ...snip... validation code
}
header('WWW-Authenticate: Basic realm="' . self::REALM . '"');
error_log("BasicAuthentication:__isAllowed:failed - no user specified");
throw new RestException(401, 'Basic Authentication Required');
return FALSE;
}
/**
*
* @access private
*/
public static function verifyAccess(array $m) {
$requires = isset($m ['class'] ['BasicAuthentication'] ['properties'] ['requires']) ? $m ['class'] ['BasicAuthentication'] ['properties'] ['requires'] : false;
error_log("BasicAuthentication:verifyAccess:requires:" . $requires);
return $requires ? static::$role == $requires : true;
}
/**
*
* @access private
*/
public static function email() {
return self::$email;
}
/**
*
* @access private
*/
public static function userId() {
return self::$userId;
}
/**
*
* @access private
*/
public static function active() {
return self::$active;
}
/**
*
* @access private
*/
public static function userLevel() {
return self::$userLevel;
}
/**
*
* @access private
*/
public static function userInfo() {
return self::$userInfo;
}
/**
*
* @access private
*/
public function __getWWWAuthenticateString() {
return 'Basic realm="' . self::REALM . '"';
}
}
有什么想法吗?
我删除了 API 版本控制,错误消失了。
index.php:
#$r->setAPIVersion(1);
当 v2 需要测试时,我会重新访问它;)
当我 运行 我的 GET /user 使用基本身份验证时(请参阅下面的 class 代码),用户名和密码已通过身份验证。但我的 xml 回复是:
<br />
<b>Notice</b>: Undefined index: BasicAuthentication in <b>/...Web/api/vendor/Luracast/Restler/Restler.php</b> on line <b>600</b><br />
<?xml version="1.0" encoding="UTF-8"?>
<response>
<prod1>yyyy-mm-dd</prod1>
<prod2>yyyy-mm-dd</prod2>
</response>
在error_log中显示用户已通过身份验证,并且userInfo数组:
[Tue Jul 14 14:56:30.239048 2015] [:error] [pid 35839] [client 192.168.42.59:59671] BasicAuthentication:__isAllowed:authorized:userInfo:Array\n(\n [Signed Up] => 2013-10-03 15:06:33\n [Last Updated] => 2013-10-03\n [Subscribed to Mailing List] => Yes\n [HRA Free Membership] => Expire: 0000-00-00\n [HRA SILVER 3 Months Membership] => Expire: 9999-12-31\n)\n
我为 class BasicAuthentication implements iAuthenticate
使用的模板与我之前使用的模板相同。但是我以前没有看到这个通知。
从User.php抓取$userInfo时也可能导致错误:
$userInfo = BasicAuthentication::$userInfo();
这是我在User.php中抓取public static $userInfo = array();
时的错误:
Fatal error: Cannot redeclare class BasicAuthentication in ...Web/api/public/v1/BasicAuthentication.php on line 26
用户 class 文件 (User.php):
/**
* All methods in this class are protected
* @access protected
* @class BasicAuthentication {@requires member}
*/
class User {
/**
* Retrieve User information
*
* Return some user information
*
* @throttle 200
*
* @throws 400 Bad Request - parameter values are wrong
* @throws 401 Unauthorized
* @return array
*/
function index() {
$userInfo = BasicAuthentication::$userInfo();
//$userInfo = array("prod1" => "yyyy-mm-dd","prod2" => "yyyy-mm-dd");
return $userInfo;
}
}
BasicAuthentication.php:
use Luracast\Restler\iAuthenticate;
use Luracast\Restler\RestException;
use Luracast\Restler\Resources;
class BasicAuthentication implements iAuthenticate {
const REALM = 'Restricted API';
public static $requires = 'non-member';
public static $role = 'non-member';
public static $active = FALSE;
public static $email = 0;
public static $userId = 0;
public static $userInfo = 0;
public static $userLevel = 0;
public static $productId = 0;
public static $productName = 0;
function __isAllowed() {
self::$email = 0;
self::$userId = 0;
self::$userLevel = 0;
self::$userInfo = array();
self::$active = FALSE;
self::$role = 'non-member';
self::$productId = 0;
self::$productName = 0;
if (isset($_SERVER ['PHP_AUTH_USER']) && isset($_SERVER ['PHP_AUTH_PW'])) {
// ...snip... validation code
}
header('WWW-Authenticate: Basic realm="' . self::REALM . '"');
error_log("BasicAuthentication:__isAllowed:failed - no user specified");
throw new RestException(401, 'Basic Authentication Required');
return FALSE;
}
/**
*
* @access private
*/
public static function verifyAccess(array $m) {
$requires = isset($m ['class'] ['BasicAuthentication'] ['properties'] ['requires']) ? $m ['class'] ['BasicAuthentication'] ['properties'] ['requires'] : false;
error_log("BasicAuthentication:verifyAccess:requires:" . $requires);
return $requires ? static::$role == $requires : true;
}
/**
*
* @access private
*/
public static function email() {
return self::$email;
}
/**
*
* @access private
*/
public static function userId() {
return self::$userId;
}
/**
*
* @access private
*/
public static function active() {
return self::$active;
}
/**
*
* @access private
*/
public static function userLevel() {
return self::$userLevel;
}
/**
*
* @access private
*/
public static function userInfo() {
return self::$userInfo;
}
/**
*
* @access private
*/
public function __getWWWAuthenticateString() {
return 'Basic realm="' . self::REALM . '"';
}
}
有什么想法吗?
我删除了 API 版本控制,错误消失了。
index.php:
#$r->setAPIVersion(1);
当 v2 需要测试时,我会重新访问它;)