first commit
This commit is contained in:
63
wp-content/plugins/elementor/data/v2/base/endpoint/index.php
Normal file
63
wp-content/plugins/elementor/data/v2/base/endpoint/index.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
namespace Elementor\Data\V2\Base\Endpoint;
|
||||
|
||||
use Elementor\Data\V2\Base\Endpoint;
|
||||
use WP_REST_Server;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Index extends Endpoint {
|
||||
public function get_name() {
|
||||
return 'index';
|
||||
}
|
||||
|
||||
public function get_format() {
|
||||
return "{$this->controller->get_full_name()}/{id}";
|
||||
}
|
||||
|
||||
public function get_public_name() {
|
||||
return '';
|
||||
}
|
||||
|
||||
public function get_items( $request ) {
|
||||
return $this->controller->get_items( $request );
|
||||
}
|
||||
|
||||
public function get_item( $id, $request ) {
|
||||
return $this->controller->get_item( $request );
|
||||
}
|
||||
|
||||
public function create_items( $request ) {
|
||||
return $this->controller->create_items( $request );
|
||||
}
|
||||
|
||||
public function create_item( $id, $request ) {
|
||||
return $this->controller->create_item( $request );
|
||||
}
|
||||
|
||||
public function update_items( $request ) {
|
||||
return $this->controller->update_items( $request );
|
||||
}
|
||||
|
||||
public function update_item( $id, $request ) {
|
||||
return $this->controller->update_item( $request );
|
||||
}
|
||||
|
||||
public function delete_items( $request ) {
|
||||
return $this->controller->delete_items( $request );
|
||||
}
|
||||
|
||||
public function delete_item( $id, $request ) {
|
||||
return $this->controller->delete_item( $request );
|
||||
}
|
||||
|
||||
public function register_items_route( $methods = WP_REST_Server::READABLE, $args = [] ) {
|
||||
parent::register_items_route( $methods, array_merge( $this->controller->get_items_args( $methods ), $args ) );
|
||||
}
|
||||
|
||||
public function register_item_route( $methods = WP_REST_Server::READABLE, $args = [], $route = '/' ) {
|
||||
parent::register_item_route( $methods, array_merge( $this->controller->get_item_args( $methods ), $args ), $route );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
namespace Elementor\Data\V2\Base\Endpoint\Index;
|
||||
|
||||
use Elementor\Data\V2\Base\Endpoint\Index;
|
||||
use Elementor\Data\V2\Manager;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
/**
|
||||
* class AllChildren, is optional endpoint.
|
||||
* Used in cases where the endpoints are static & there no use of dynamic endpoints( alpha/{id} ), eg:
|
||||
* 'settings' - controller
|
||||
* 'settings/products' - endpoint
|
||||
* 'settings/partners' - endpoint
|
||||
*
|
||||
* When 'settings' is requested, it should return results of all endpoints ( except it self ):
|
||||
* 'settings/products
|
||||
* 'settings/partners'
|
||||
* By running 'get_items' of each endpoint.
|
||||
*/
|
||||
class AllChildren extends Index {
|
||||
public function get_format() {
|
||||
return $this->controller->get_name() . '/index';
|
||||
}
|
||||
|
||||
/*
|
||||
* Retrieves a result(s) of all controller endpoint(s), items.
|
||||
*
|
||||
* Run overall endpoints of the current controller.
|
||||
*
|
||||
* Example, scenario:
|
||||
* 'settings' - controller
|
||||
* 'settings/products' - endpoint
|
||||
* 'settings/partners' - endpoint
|
||||
* Result:
|
||||
* [
|
||||
* 'products' => [
|
||||
* 0 => ...
|
||||
* 1 => ...
|
||||
* ],
|
||||
* 'partners' => [
|
||||
* 0 => ...
|
||||
* 1 => ...
|
||||
* ],
|
||||
* ]
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$response = [];
|
||||
|
||||
foreach ( $this->controller->get_sub_controllers() as $controller ) {
|
||||
$controller_route = $this->get_controller()->get_base_route() . '/' . $controller->get_name();
|
||||
$result = Manager::instance()->run_request( $controller_route );
|
||||
|
||||
if ( ! $result->is_error() ) {
|
||||
$response[ $controller->get_name() ] = $result->get_data();
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $this->controller->endpoints as $endpoint ) {
|
||||
// Skip self.
|
||||
if ( $endpoint === $this ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result = Manager::instance()->run_request( $endpoint->get_base_route() );
|
||||
|
||||
if ( ! $result->is_error() ) {
|
||||
$response[ $endpoint->get_name() ] = $result->get_data();
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace Elementor\Data\V2\Base\Endpoint\Index;
|
||||
|
||||
use Elementor\Data\V2\Base\Endpoint\Index;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
/**
|
||||
* Class SubIndexEndpoint is default `Base\Endpoint\Index` of `SubController`,
|
||||
* it was created to handle base_route and format for child controller, index endpoint.
|
||||
* In case `SubController` were used and the default method of `Controller::register_index_endpoint` ain't overridden.
|
||||
* this class will give support to have such routes, eg: 'alpha/{id}/beta/{sub_id}' without using additional endpoints.
|
||||
*/
|
||||
final class Sub_Index_Endpoint extends Index {
|
||||
/***
|
||||
* @var \Elementor\Data\V2\Base\Controller
|
||||
*/
|
||||
public $controller;
|
||||
|
||||
public function get_format() {
|
||||
return $this->controller->get_parent()->get_name() . '/{id}/' . $this->controller->get_name() . '/{sub_id}';
|
||||
}
|
||||
|
||||
public function get_base_route() {
|
||||
$parent_controller = $this->controller->get_parent();
|
||||
$parent_index_endpoint = $parent_controller->index_endpoint;
|
||||
$parent_controller_route = '';
|
||||
|
||||
// In case `$parent_index_endpoint` is AllChildren, it cannot support id_arg_name.
|
||||
if ( ! $parent_index_endpoint instanceof AllChildren ) {
|
||||
$parent_controller_route = "(?P<{$parent_index_endpoint->id_arg_name}>[\w]+)";
|
||||
}
|
||||
|
||||
return untrailingslashit('/' . implode( '/', array_filter( [
|
||||
trim( $parent_index_endpoint->get_base_route(), '/' ),
|
||||
$parent_controller_route,
|
||||
$this->controller->get_name(),
|
||||
$this->get_public_name(),
|
||||
] ) ) );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user