private function getHttpMethodsForController()

in src/privateimpl/ControllerFacts.hack [68:105]


  private function getHttpMethodsForController(
    classname<T> $classname,
  ): ImmSet<HttpMethod> {
    $supported = Set { };
    $cf = $this->classFacts;
    if ($cf->doesImplement(SupportsGetRequests::class, $classname)) {
      $supported[] = HttpMethod::GET;
    }
    if ($cf->doesImplement(SupportsPostRequests::class, $classname)) {
      $supported[] = HttpMethod::POST;
    }

    invariant(
      !$supported->isEmpty(),
      '%s implements %s, but does not implement %s or %s',
      $classname,
      IncludeInUriMap::class,
      SupportsGetRequests::class,
      SupportsPostRequests::class,
    );

    /* This is me being opinionated, not a technical limitation:
     *
     * I think each controller should do one thing. Multiple HTTP methods
     * implies it does multiple things.
     *
     * Returning a set instead of a single method so it's easy to change
     * if someone convinces me that this is a bad idea.
     */
    invariant(
      $supported->count() === 1,
      '%s is marked as supporting multiple HTTP methods; build 1 controller '.
      'per method instead, refactoring common code out (eg to a trait).',
      $classname,
    );

    return $supported->immutable();
  }