Beispiel #1
0
 /**
  * Returns a new route options object, instantiated with an entry according to the given arguments.
  *
  * @since 1.0.0
  * @since 1.1.0 Make use of late static binding (i.e., return a new instance of `static` instead of `self`).
  * @since 1.1.0 Temporarily removed the `RequestHandler` type hint from the `$handler` parameter.
  * @since 2.0.0 Added the removed `RequestHandler` type hint for the `$handler` parameter.
  *
  * @param RequestHandler $handler Optional. Request handler object. Defaults to null.
  * @param Arguments      $args    Optional. Endpoint arguments object. Defaults to null.
  * @param string         $methods Optional. Comma-separated HTTP verbs. Defaults to self::DEFAULT_METHODS.
  * @param array          $options Optional. Additional options array. Defaults to empty array.
  *
  * @return static Route options object.
  */
 public static function from_arguments(RequestHandler $handler = null, Arguments $args = null, $methods = self::DEFAULT_METHODS, array $options = [])
 {
     if ($handler) {
         $options['callback'] = [$handler, 'handle_request'];
     }
     if ($args) {
         $options['args'] = $args->to_array();
     }
     $options['methods'] = (string) $methods;
     return new static($options);
 }
Beispiel #2
0
 /**
  * Returns an array of options for the endpoint, or an array of arrays for multiple methods.
  *
  * @see   register_rest_route()
  * @since 1.0.0
  *
  * @return array Route options.
  */
 public function get_options()
 {
     return $this->options->to_array();
 }