first commit
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\GlobalClasses\Utils;
|
||||
|
||||
use Elementor\Core\Base\Document;
|
||||
use Elementor\Core\Utils\Collection;
|
||||
use Elementor\Modules\AtomicWidgets\Elements\Atomic_Element_Base;
|
||||
use Elementor\Modules\AtomicWidgets\Elements\Atomic_Widget_Base;
|
||||
use Elementor\Plugin;
|
||||
|
||||
class Atomic_Elements_Utils {
|
||||
|
||||
public static function is_classes_prop( $prop ) {
|
||||
return 'plain' === $prop::KIND && 'classes' === $prop->get_key();
|
||||
}
|
||||
|
||||
public static function get_element_type( $element ) {
|
||||
return 'widget' === $element['elType'] ? $element['widgetType'] : $element['elType'];
|
||||
}
|
||||
|
||||
public static function get_element_instance( $element_type ) {
|
||||
$widget = Plugin::$instance->widgets_manager->get_widget_types( $element_type );
|
||||
$element = Plugin::$instance->elements_manager->get_element_types( $element_type );
|
||||
|
||||
return $widget ?? $element;
|
||||
}
|
||||
|
||||
public static function is_atomic_element( $element_instance ) {
|
||||
if ( ! $element_instance ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
$element_instance instanceof Atomic_Element_Base ||
|
||||
$element_instance instanceof Atomic_Widget_Base
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\GlobalClasses\Utils;
|
||||
|
||||
class Error_Builder {
|
||||
private string $message;
|
||||
private int $status;
|
||||
private string $code;
|
||||
|
||||
private function __construct( $code, $status = 500 ) {
|
||||
$this->code = $code;
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
public static function make( $code, $status = 500 ) {
|
||||
return new self( $code, $status );
|
||||
}
|
||||
|
||||
public function set_status( int $status ) {
|
||||
$this->status = $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function set_message( string $message ) {
|
||||
$this->message = $message;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function build() {
|
||||
return new \WP_Error( $this->code, $this->message, [ 'status' => $this->status ] );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\GlobalClasses\Utils;
|
||||
|
||||
class Response_Builder {
|
||||
private $data;
|
||||
private int $status;
|
||||
private array $meta = [];
|
||||
private bool $empty = false;
|
||||
|
||||
const NO_CONTENT = 204;
|
||||
|
||||
private function __construct( $data, $status ) {
|
||||
$this->data = $data;
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
public static function make( $data = null, $status = 200 ) {
|
||||
return new self( $data, $status );
|
||||
}
|
||||
|
||||
public function set_meta( array $meta ) {
|
||||
$this->meta = $meta;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function set_status( int $status ) {
|
||||
$this->status = $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function no_content() {
|
||||
return $this->set_status( static::NO_CONTENT );
|
||||
}
|
||||
|
||||
public function build() {
|
||||
$res_data = static::NO_CONTENT === $this->status
|
||||
? null
|
||||
: [
|
||||
'data' => $this->data,
|
||||
'meta' => $this->meta,
|
||||
];
|
||||
|
||||
return new \WP_REST_Response( $res_data, $this->status );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user