PHP code example of ttlphp / workerman-annotation

1. Go to this page and download the library: Download ttlphp/workerman-annotation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ttlphp / workerman-annotation example snippets


'WorkermanAnnotation\\' => array($vendorDir . '/workerman-annotation/src'),


// 启动服务
serverRun();

// 示例
/**
 * @DefineUse(function=true)
 * @DefineParam(name="name", type="string", default="")
 */
class TextAnnotation implements \WorkermanAnnotation\Annotations\iAnnotation {

    /**
     * 注解处理数据生成
     * @param array $params
     * @param array $input
     * @return array
     */
    public function make(array $params, array $input): array {
        return [
            function($params, \Closure $next){ // 返回切入处理器
                // $params 是使用注解的函数参数
                return $next();
            },
            // 返回索引, 可以通过注解处理器索引调用注解函数
            'test' => 'test'
        ];
    }

}