此包已被废弃,不再维护。未建议替代包。

Presentator v2 REST API


README

重要

此仓库是为旧版Presentator v2准备的,并且不再维护。

Presentator v2 REST API服务器实现,用PHP编写,基于Yii2

详细的API参考可以在以下位置找到 - https://presentator.io/docs

此仓库为只读。 请在主Presentator仓库中报告问题并发送pull请求。

要求

  • Apache/Nginx HTTP服务器

  • SQL数据库(MySQL/MariadDB/PostgreSQL)

    对于MySQL 5.6及以下版本和MariaDB 10.1及以下版本,您可能需要设置innodb_large_prefix=1innodb_default_row_format=dynamic以防止迁移错误(见#104)。

  • PHP 7.1+,以下扩展

    Reflection
    PCRE
    SPL
    MBString
    OpenSSL
    Intl
    ICU version
    Fileinfo
    DOM extensions
    GD or Imagick
    

    对于更详细的检查,请在应用程序根目录中运行php requirements.php

    此外,以下是一些推荐的php.ini配置设置

    post_max_size       = 64M
    upload_max_filesize = 64M
    max_execution_time  = 60
    memory_limit        = 256M
    

安装

在开始之前,请确保您已检查项目要求并安装了Composer

  1. 克隆或下载仓库。

    出于安全原因,如果您正在使用共享托管服务,建议将项目文件放置在默认public_html(www)目录之外!

  2. 设置虚拟主机/服务器地址(例如http://api.presentator.local/),并将其指向web/

    默认情况下,初始化后会为您创建一个通用的.htaccess文件。如果您使用nginx,可以查看以下示例配置

  3. 运行以下命令

    # navigate to the project root dir
    cd /path/to/project
    
    # install vendor dependencies
    composer install
    
    # execute the init command and select the appropriate environment:
    # dev     - for development
    # prod    - for production
    # starter - this is used only for the the starter project setup (https://github.com/presentator/presentator-starter)
    php init
  4. 创建一个新的数据库(使用utf8mb4_unicode_ci校对),并相应地调整config/base-local.php中的db、mailer和其他组件配置。

    所有可用的应用程序组件及其默认值都可以在config/base.php中找到。

  5. 调整应用程序参数在config/params-local.php。

    所有可用的应用程序参数及其默认值可以在config/params.php中找到。

  6. 应用数据库迁移。

    php /path/to/project/yii migrate
  7. (可选)设置cron任务以处理未读屏幕评论

    # Every 30 minutes processes all unread screen comments and sends an email to the related users.
    */30 * * * * php /path/to/project/yii mails/process-comments

就这些了! 您应该能够向之前定义的服务器地址发出HTTP请求。

您可能会发现以下控制台命令很有用

# set Super User access rights to a single User model
php /path/to/project/yii users/super test@example.com

# set Regular User access rights to a single User model
php /path/to/project/yii users/regular test@example.com

# regenerates all screen thumbs
php /path/to/project/yii screens/generate-thumbs

开发

运行测试

Presentator使用Codeception作为其主要的测试框架。

运行测试需要额外的数据库,该数据库将在测试之间进行清理。创建一个新的数据库,然后编辑config/test-local.php中的db组件设置,然后运行以下控制台命令

# apply db migrations for the test database
php path/to/project/yii_test migrate

# build the test suites
/path/to/project/vendor/bin/codecept build

# start all application tests
/path/to/project/vendor/bin/codecept run

目前只提供功能测试。

约定

项目使用以下约定

  • (PHP) 每个类都必须遵循接受的PSR标准
  • (PHP) 每个类方法都应该基于 PHPDoc (方法描述是可选的)添加注释块标签。
  • (DB) 使用 InnoDB 表引擎。
  • (DB) 使用 utf8mb4_unicode_ciutf8_unicode_ci 校对。
  • (DB) 表名必须与相应的 AR 模型类名相匹配(例如 UserProjectRel)。
  • (DB) 表列必须使用驼峰式格式(例如 passwordResetToken)。
  • (DB) 必须通过 Yii 迁移应用每个数据库更改。
  • (DB) 在可能的情况下,添加以下格式的命名外键和索引:fk_{FROM_TABLE}_to_{TO_TABLE}idx_{TABLE}_{COLUMN(S)} (例如 fk_ProjectLink_to_Projectidx_ProjectLink_slug)。