1. Go to this page and download the library: Download yokel/yapi 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/ */
// GET http://yoursite.name/my_api/test/result.json
\Yapi\Yapi::getInstance()->run(
[
'test' => '\YourNameSpace\YourController'
],
'/my_api/',
function() {
// do some action
}
);
# Export/YapiController.php
interface YapiController {
/**
* Возвращает кастомный обработчки результата (для разных форматов)
* @param string $format
* @return mixed
*/
public function getResultHandler(string $format);
}
namespace YourNameSpace;
use Yapi\Export\YapiController;
class Test implements YapiController {
public function getResultHandler(string $format) {
if ($format === 'custom') {
// Для обработки результатов в формате custom будет использован класс \YourNameSpace\CustomResultHandler
return '\YourNameSpace\CustomResultHandler';
} else {
return null;
}
}
public function result($params) {
return 'some result as text';
}
}
namespace YourNameSpace;
use Yapi\Export\YapiResultHandler;
class CustomResultHandler implements YapiResultHandler {
/**
* Приведём результат в верхний регистр
* @param $result - результат, полученный от контроллера
*/
public function handle($result) {
echo strtoupper($result);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.