Application Plugin Development Guidelines

Application Plugin Requirements

  • Plugins must not contain any infringing code, icons, images, etc.
  • The source code of the plugin must be complete and must not be encrypted.
  • The plugin must provide complete functionality and cannot be a simple feature.
  • Complete feature descriptions and documentation must be provided.
  • The use of coroutine functionality within plugins is not recommended, as users may not have enabled coroutines.

Application Plugin Identification

Each application plugin has a unique identifier composed of letters. This identifier affects the source directory name, class namespace, and database table prefix of the plugin.

Assuming the developer uses foo as the plugin identifier, the directory for the plugin source code would be {main_project}/plugin/foo, the corresponding plugin namespace would be plugin\foo, and the table prefix would be foo_.

Since the identifier must be globally unique, developers need to check whether the identifier is available before development. The checking address is Application Identifier Check.

Database

  • Table names are composed of lowercase letters a-z and underscores _.
  • Plugin data tables should use the plugin identifier as a prefix, for example, the article table for the foo plugin would be foo_article.
  • The primary key of the table should be indexed as id.
  • The storage engine must uniformly use the InnoDB engine.
  • The character set must uniformly use utf8mb4_general_ci.
  • Database ORM can use either Laravel or think-orm.
  • It is recommended to use DateTime for time fields.

Code Standards

PSR Standards

Code should adhere to PSR4 loading standards.

Class Names in Upper Camel Case

<?php

namespace plugin\foo\app\controller;

class ArticleController
{

}

Class Properties and Methods in Lower Camel Case

<?php

namespace plugin\foo\app\controller;

class ArticleController
{
    /**
     * Methods that do not require authentication
     * @var array
     */
    protected $noNeedAuth = ['getComments'];

    /**
     * Get Comments
     * @param Request $request
     * @return Response
     * @throws BusinessException
     */
    public function getComments(Request $request): Response
    {

    }
}

Comments

Class properties and functions must include comments, including an overview, parameters, and return types.

Indentation

Code should use 4 spaces for indentation instead of tabs.

Control Flow

Control flow keywords (if, for, while, foreach, etc.) should be followed by a space, and the opening brace for the control statement should be on the same line as the closing parenthesis.

foreach ($users as $uid => $user) {

}

Temporary Variable Naming

It is recommended to use lower camel case for naming (not mandatory).

$articleCount = 100;