1. Go to this page and download the library: Download dreamyi12/apidoc 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/ */
dreamyi12 / apidoc example snippets
if (isset($param['xxx'])) {
$model = $model->where('xxx',$param['xxxx']);
}
if (isset($param['xxx'])) {
$model = $model->where('xxx',$param['xxxx']);
}
$model->get();
//$model->update($data);
//$model->delete();
....
use Dreamyi12\ApiDoc\Annotation\Collector\CustomCollector;
use Dreamyi12\ApiDoc\Annotation\Enums\EnumClass;
use Dreamyi12\ApiDoc\Annotation\Validator\CustomValidator;
use Dreamyi12\ApiDoc\Validation\Rule\CustomValidatorFactory;
/**
* @CustomValidator(name="enum")
**/
class EnumValidator extends CustomValidatorFactory
{
public function handle(array $data, $value, string $field, string $filed_name, array $options = []): array
{
if (empty($options)) {
return [true, ''];
}
[$enumType] = $options;
$enumClass = CustomCollector::getAnnotationByClasses(EnumClass::class, $enumType);
$enums = $enumClass::getEnums();
$err = $this->translator->trans('validation.enum', ['attribute' => $filed_name]);
if (is_array($value)) {
foreach ($value as $item) {
if (!empty($item) && !isset($enums[$item])) return [false, $err];
}
} else {
return [isset($enums[$value]), $err];
}
return [true, ''];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.