IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
|
|
|
|
| 72 | 72 | */ |
| 73 | 73 | protected $endpoints = array(); |
| 74 | 74 | |
| | 75 | /** |
| | 76 | * The route map is an associative array with path regexes as the keys. The |
| | 77 | * value is an indexed array with the callback function/method as the first |
| | 78 | * item, and a bitmask of HTTP methods as the second item (see the class |
| | 79 | * constants). |
| | 80 | * |
| | 81 | * @access protected |
| | 82 | * @var array Route map of the routes |
| | 83 | */ |
| | 84 | protected $route_map = array(); |
| | 85 | |
| 75 | 86 | /** |
| 76 | 87 | * Options defined for the routes. |
| 77 | 88 | * |
| … |
… |
|
| 673 | 684 | } |
| 674 | 685 | } |
| 675 | 686 | |
| | 687 | /** |
| | 688 | * Retrieves the route map. |
| | 689 | * |
| | 690 | * @access public |
| | 691 | * |
| | 692 | * @return array Route map of the routes. |
| | 693 | */ |
| | 694 | public function get_route_map() { |
| | 695 | return $this->route_map; |
| | 696 | } |
| | 697 | |
| | 698 | /** |
| | 699 | * Sets the route map. |
| | 700 | * |
| | 701 | * @access public |
| | 702 | * |
| | 703 | * @param array $route_map Route map of the routes. |
| | 704 | */ |
| | 705 | public function set_route_map( $route_map ) { |
| | 706 | $this->route_map = $route_map; |
| | 707 | } |
| | 708 | |
| 676 | 709 | /** |
| 677 | 710 | * Retrieves the route map. |
| 678 | 711 | * |
| … |
… |
|
| 695 | 728 | * `'/path/regex' => array( array( $callback, $bitmask ), ...)`. |
| 696 | 729 | */ |
| 697 | 730 | public function get_routes() { |
| | 731 | $endpoints = $this->get_route_map(); |
| 698 | 732 | |
| 699 | | /** |
| 700 | | * Filters the array of available endpoints. |
| 701 | | * |
| 702 | | * @since 4.4.0 |
| 703 | | * |
| 704 | | * @param array $endpoints The available endpoints. An array of matching regex patterns, each mapped |
| 705 | | * to an array of callbacks for the endpoint. These take the format |
| 706 | | * `'/path/regex' => array( $callback, $bitmask )` or |
| 707 | | * `'/path/regex' => array( array( $callback, $bitmask ). |
| 708 | | */ |
| 709 | | $endpoints = apply_filters( 'rest_endpoints', $this->endpoints ); |
| | 733 | if ( empty( $endpoints ) ) { |
| | 734 | /** |
| | 735 | * Filters the array of available endpoints. |
| | 736 | * |
| | 737 | * @since 4.4.0 |
| | 738 | * |
| | 739 | * @param array $endpoints The available endpoints. An array of matching regex patterns, each mapped |
| | 740 | * to an array of callbacks for the endpoint. These take the format |
| | 741 | * `'/path/regex' => array( $callback, $bitmask )` or |
| | 742 | * `'/path/regex' => array( array( $callback, $bitmask ). |
| | 743 | */ |
| | 744 | $endpoints = apply_filters( 'rest_endpoints', $this->endpoints ); |
| 710 | 745 | |
| 711 | | // Normalise the endpoints. |
| 712 | | $defaults = array( |
| 713 | | 'methods' => '', |
| 714 | | 'accept_json' => false, |
| 715 | | 'accept_raw' => false, |
| 716 | | 'show_in_index' => true, |
| 717 | | 'args' => array(), |
| 718 | | ); |
| | 746 | // Normalise the endpoints. |
| | 747 | $defaults = array( |
| | 748 | 'methods' => '', |
| | 749 | 'accept_json' => false, |
| | 750 | 'accept_raw' => false, |
| | 751 | 'show_in_index' => true, |
| | 752 | 'args' => array(), |
| | 753 | ); |
| 719 | 754 | |
| 720 | | foreach ( $endpoints as $route => &$handlers ) { |
| | 755 | foreach ( $endpoints as $route => &$handlers ) { |
| 721 | 756 | |
| 722 | | if ( isset( $handlers['callback'] ) ) { |
| 723 | | // Single endpoint, add one deeper. |
| 724 | | $handlers = array( $handlers ); |
| 725 | | } |
| | 757 | if ( isset( $handlers['callback'] ) ) { |
| | 758 | // Single endpoint, add one deeper. |
| | 759 | $handlers = array( $handlers ); |
| | 760 | } |
| 726 | 761 | |
| 727 | | if ( ! isset( $this->route_options[ $route ] ) ) { |
| 728 | | $this->route_options[ $route ] = array(); |
| 729 | | } |
| | 762 | if ( ! isset( $this->route_options[ $route ] ) ) { |
| | 763 | $this->route_options[ $route ] = array(); |
| | 764 | } |
| 730 | 765 | |
| 731 | | foreach ( $handlers as $key => &$handler ) { |
| | 766 | foreach ( $handlers as $key => &$handler ) { |
| 732 | 767 | |
| 733 | | if ( ! is_numeric( $key ) ) { |
| 734 | | // Route option, move it to the options. |
| 735 | | $this->route_options[ $route ][ $key ] = $handler; |
| 736 | | unset( $handlers[ $key ] ); |
| 737 | | continue; |
| 738 | | } |
| | 768 | if ( ! is_numeric( $key ) ) { |
| | 769 | // Route option, move it to the options. |
| | 770 | $this->route_options[ $route ][ $key ] = $handler; |
| | 771 | unset( $handlers[ $key ] ); |
| | 772 | continue; |
| | 773 | } |
| 739 | 774 | |
| 740 | | $handler = wp_parse_args( $handler, $defaults ); |
| | 775 | $handler = wp_parse_args( $handler, $defaults ); |
| 741 | 776 | |
| 742 | | // Allow comma-separated HTTP methods. |
| 743 | | if ( is_string( $handler['methods'] ) ) { |
| 744 | | $methods = explode( ',', $handler['methods'] ); |
| 745 | | } elseif ( is_array( $handler['methods'] ) ) { |
| 746 | | $methods = $handler['methods']; |
| 747 | | } else { |
| 748 | | $methods = array(); |
| 749 | | } |
| | 777 | // Allow comma-separated HTTP methods. |
| | 778 | if ( is_string( $handler['methods'] ) ) { |
| | 779 | $methods = explode( ',', $handler['methods'] ); |
| | 780 | } elseif ( is_array( $handler['methods'] ) ) { |
| | 781 | $methods = $handler['methods']; |
| | 782 | } else { |
| | 783 | $methods = array(); |
| | 784 | } |
| 750 | 785 | |
| 751 | | $handler['methods'] = array(); |
| | 786 | $handler['methods'] = array(); |
| 752 | 787 | |
| 753 | | foreach ( $methods as $method ) { |
| 754 | | $method = strtoupper( trim( $method ) ); |
| 755 | | $handler['methods'][ $method ] = true; |
| | 788 | foreach ( $methods as $method ) { |
| | 789 | $method = strtoupper( trim( $method ) ); |
| | 790 | $handler['methods'][ $method ] = true; |
| | 791 | } |
| 756 | 792 | } |
| 757 | 793 | } |
| | 794 | $this->set_route_map( $endpoints ); |
| 758 | 795 | } |
| 759 | 796 | |
| 760 | 797 | return $endpoints; |