10-rest_register.php 702 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace cx_newsletter;
  3. use \register_rest_route;
  4. class rest_register
  5. implements rest_register_interface {
  6. public function __construct(string $namespace) {
  7. $this->namespace = $namespace;
  8. }
  9. public function register(rest_endpoint $endpoint) : self {
  10. $parameters = [
  11. 'methods' => $endpoint->get_method(),
  12. 'callback' => [$endpoint, 'action']
  13. ];
  14. register_rest_route(
  15. $this->get_namespace(),
  16. $endpoint->get_route(),
  17. $parameters
  18. );
  19. return $this;
  20. }
  21. public function get_namespace() : string {
  22. return $this->namespace;
  23. }
  24. private string $namespace;
  25. }