使用PHPDoc的智能路由不适用于Restler v3

时间:2013-03-12 02:31:53

标签: php api rest routes restler

我在Restler PHP REST Framework v3中实现智能url路由时遇到了一些问题。基本上看起来好像Restler忽略了我的评论。我在这里附上了我的index.php和tests.inc.php文件。发生了什么,即使使用PHPDoc注释,似乎restler忽略它们并且只响应默认的“tests”调用而不是“some / new / route”,正如我所期望的那样基于提供的路由示例框架。

的index.php

<?php

$root_dir = $_SERVER['DOCUMENT_ROOT'];
$base_dir = getcwd();
$include = "{$base_dir}/include";
require_once("{$include}/config.inc.php");
require_once("{$include}/library-general.inc.php");

//include restler library
$restler_dir = "{$root_dir}/restler/{$settings['restler_version_string']}";
require_once("{$restler_dir}/restler.php");

//restler configuration
use Luracast\Restler\Restler;
use Luracast\Restler\Defaults;

//include database connector class
require_once("{$include}/db_connector_mysql.inc.php");

//include api handler classes
require_once('test.inc.php');
require_once('accounts.inc.php');

//instantiate our restler object; call with argument "true" to run in production mode
$r = new Restler();

//bind api classes
$r->addAPIClass('Tests');
$r->addAPIClass('Accounts');

//set supported formats: JSON ONLY!
$r->setSupportedFormats('JsonFormat');

//handle the request
$r->handle();

test.inc.php

<?php

class Tests {

    private $dbc;
    private $function_log_tag;

    public function __construct () {
        $this->dbc = DB_Connector_MySQL::getConnection();
        $this->response = new stdClass();
    }

    /*
    ** @url GET /some/new/route
    */
    public function get () {
        //load required global variables
        global $settings;

        //set logging tag
        $this->function_log_tag = '[' . __CLASS__ . '::' . __FUNCTION__ . '][v' . $settings['version'] . ']';

        return $this->function_log_tag;
    }
}

我一直在尝试许多不同的事情来尝试找到根本问题。值得注意的是,我似乎无法找到“routes.php”文件,因此我可能认为它可能是服务器上的写入权限问题。无论如何,任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

您的评论不是有效的PHPDoc评论,它只是所有

的常规评论

请查看以下内容以获取正确的语法

<?php

class Tests {

    private $dbc;
    private $function_log_tag;

    public function __construct () {
        $this->dbc = DB_Connector_MySQL::getConnection();
        $this->response = new stdClass();
    }

    /**
    * @url GET /some/new/route
    */
    public function get () {
        //load required global variables
        global $settings;

        //set logging tag
        $this->function_log_tag = '[' . __CLASS__ . '::' . __FUNCTION__ . '][v' . $settings['version'] . ']';

        return $this->function_log_tag;
    }
}

文档评论以/**而不是/*

开头