namespace Elementor\Data\V2\Base;
use Elementor\Data\V2\Manager;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
abstract class Endpoint extends Base_Route {
* @var \Elementor\Data\V2\Base\Controller|\Elementor\Data\V2\Base\Endpoint
* Loaded sub endpoint(s).
* @var \Elementor\Data\V2\Base\Endpoint[]
protected $sub_endpoints = [];
abstract public function get_name();
* The formats that generated using this function, will be used only be `Data\Manager::run()`.
abstract public function get_format();
* @return \Elementor\Data\V2\Base\Controller
public function get_controller() {
return $this->controller;
* @return \Elementor\Data\V2\Base\Controller|\Elementor\Data\V2\Base\Endpoint
public function get_parent() {
public function get_public_name() {
return $this->get_name();
* Get full command name ( including index ).
public function get_full_command() {
$parent = $this->get_parent();
if ( $parent instanceof Controller ) {
return $this->controller->get_full_name() . '/' . $this->get_name();
return $this->get_name_ancestry();
* Get name ancestry format, example: 'alpha/beta/delta'.
public function get_name_ancestry() {
$ancestors = $this->get_ancestors();
foreach ( $ancestors as $ancestor ) {
$ancestors_names [] = $ancestor->get_name();
return implode( '/', $ancestors_names );
* @param \Elementor\Data\V2\Base\Endpoint $endpoint
* @return \Elementor\Data\V2\Base\Endpoint
public function register_sub_endpoint( Endpoint $endpoint ) {
$command = $endpoint->get_full_command();
$format = $endpoint->get_format();
$this->sub_endpoints[ $command ] = $endpoint;
Manager::instance()->register_endpoint_format( $command, $format );
* @return \Elementor\Data\V2\Base\Endpoint[]
private function get_ancestors() {
$ancestors [] = $current;
$current = $current->get_parent();
return array_reverse( $ancestors );
* @param \Elementor\Data\V2\Base\Controller|\Elementor\Data\V2\Base\Endpoint $parent
public function __construct( $parent, $route = '/' ) {
// In case, its behave like sub-endpoint.
if ( ! ( $parent instanceof Controller ) ) {
$controller = $parent->get_controller();
parent::__construct( $controller, $route );