路由

$app 集成了 Hyperf 路由器的所有方法。

  1. <?php
  2. use Hyperf\Nano\Factory\AppFactory;
  3. require_once __DIR__ . '/vendor/autoload.php';
  4. $app = AppFactory::create();
  5. $app->addGroup('/nano', function () use ($app) {
  6. $app->addRoute(['GET', 'POST'], '/{id:\d+}', function($id) {
  7. return '/nano/'.$id;
  8. });
  9. $app->put('/{name:.+}', function($name) {
  10. return '/nano/'.$name;
  11. });
  12. });
  13. $app->run();