示例#1
0
<?php

use zf\Data;
return ['schema' => function ($schema) {
    if ($this->errors = $this->validator->validate($this->body, $schema)) {
        $this->emit('validationfailed', ['errors' => $this->errors]);
    }
}, 'param' => function (...$args) {
    $line = implode(',', $args);
    list($type, $name, $comment) = Data::explode(' ', $line, 3, '');
    $name = ltrim($name, '$');
    if (isset($this->params->{$name})) {
        if ($type === 'int') {
            $this->params->{$name} = intval($this->params->{$name});
        } elseif ($type === 'float') {
            $this->params->{$name} = floatval($this->params->{$name});
        } elseif ($type === 'bool') {
            $this->params->{$name} = boolval($this->params->{$name});
        } elseif ($type === 'array') {
            if (!is_array($this->params->{$name})) {
                return 400;
            } else {
                if ($type !== 'string') {
                    return [500, 'unknow param type ' . $type];
                }
            }
        }
    } else {
        $this->params->{$name} = null;
    }
}, 'mockup' => function ($mockup) {