douyinliu8813 2012-05-03 07:40 采纳率: 100%
浏览 58
已采纳

在error_reporting为ON的doc注释中使用@class标记时出现Luracast Restler错误

I have a REST webservice implemented in PHP using Luracast Restler API.

If I add any @class tags to the doc comments in my custom class exposing the public API methods or in the class implementing the iAuthenticate methods performing authentication, restler fails to parse the request if error reporting is ON.

I think the problem is the DocParser class tries to proccess the @class tag as if t where the PHP Class declaration. The method of the class formatClass() generates an undefined index notice. If error reporting is ON this will send headers, so when later Restler tries to send the response it will no be able to change headers to indicate that JSON content is sent and the Cannot modify header information - headers already sent is triggered.

Is there any workaround to this or is just a bug in the Restler Api? (Apart from setting my error reporting level to avoid Notices from being sent).

  • 写回答

1条回答 默认 最新

  • doubeijian2257 2012-05-03 10:25
    关注

    Update: It is fixed in Restler 2.1.5


    It is a bug that exists in Restler 2.1.4 caused by the DocParser as it expects @class comment in a specific format, as shown below

    /**
     * @class ClassName(property=value&property2=value2)
     */
    

    It is used to set a property of another class after initialization. for example, we can use it to tell the XmlFormat to set the root name, define what should be converted as attribute etc., Lets take the known BMI example, adding the PHPDoc comment as shown below,

    <?php
    class BMI {
        /**
        * @class XmlFormat(root_name=self&attribute_names=height,weight)
        */
        function index($height=162.6, $weight=84) {
            $result = new stdClass();
            $cm = $height;
            $kg = $weight;
    
            $meter = $cm / 100;
            $inches = $meter * 39.3700787;
            $feet = round($inches/12);
            $inches = $inches % 12; 
    
            $result->bmi = round($kg/($meter*$meter),2);
            $lb = round($kg/0.45359237,2);
    
            if($result->bmi<18.5){
                $result->message = 'Underweight';
            }elseif ($result->bmi<=24.9){
                $result->message = 'Normal weight';
            }elseif ($result->bmi<=29.9){
                $result->message = 'Overweight';
            }else{
                $result->message = 'Obesity';
            }
            $result->metric = array('height'=>"$cm centimeter", 'weight'=>"$weight kilograms");
            $result->imperial = array('height'=>"$feet feet $inches inches", 'weight'=>"$lb pounds");
            return $result;
        }
    }
    

    returns the following XML

    <?xml version="1.0"?>
    <self>
        <bmi>31.77</bmi>
        <message>Obesity</message>
        <metric height="162.6 centimeter" weight="84 kilograms"/>
        <imperial height="5 feet 4 inches" weight="185.19 pounds"/>
    </self>
    

    Which otherwise will be

    <?xml version="1.0"?>
    <response>
      <bmi>31.77</bmi>
      <message>Obesity</message>
      <metric>
        <height>162.6 centimeter</height>
        <weight>84 kilograms</weight>
      </metric>
      <imperial>
        <height>5 feet 4 inches</height>
        <weight>185.19 pounds</weight>
      </imperial>
    </response>
    

    More use cases and explanations can be found here

    It should not throw the error when @class is defined in unexpected format. We will fix it in the next release.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体