PHP code example of esd-cloud / saber-cloud-plugin
1. Go to this page and download the library: Download esd-cloud/saber-cloud-plugin 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/ */
esd-cloud / saber-cloud-plugin example snippets
/**
* @RequestMapping("test")
* Interface IRestController
*/
interface IRestController
{
/**
* get请求
* @GetMapping("/")
* @return string
*/
public function hello();
/**
* get请求
* @GetMapping("test/{name}")
* @PathVariable("name")
* @RequestParam("id")
* @param $name
* @param $id
* @return string
*/
public function test($name, $id);
}
/**
* @RestController()
* Class TestController
* @package ESD\Plugins\EasyRoute
*/
class AnnRestController extends EasyController implements IRestController
{
/**
* 找不到方法时调用
* @param $methodName
* @return mixed
*/
protected function defaultMethod(?string $methodName)
{
// TODO: Implement defaultMethod() method.
}
/**
* get请求
* @GetMapping("/")
* @return string
*/
public function hello()
{
return "hello";
}
/**
* get请求
* @GetMapping("test/{name}")
* @PathVariable("name")
* @RequestParam("id")
* @param $name
* @param $id
* @return string
*/
public function test($name, $id)
{
return "hello"
}
}
class RestClientFallback implements RestClient
{
/**
* get请求
* @GetMapping("/")
* @return string
*/
public function hello()
{
return "hello";
}
/**
* get请求
* @GetMapping("test/{name}")
* @PathVariable("name")
* @RequestParam("id")
* @param $name
* @param $id
* @return string
*/
public function test($name, $id)
{
return "test";
}
}
/**
* @Inject()
* @var RestClient
*/
private $restClient;
/**
* get请求
* @GetMapping("/")
* @return string
*/
public function hello()
{
return $this->restClient->hello();
}