@@ -733,7 +733,7 @@ function zone_admin_search_form() {
zone_ajax_nonce_action : $action;
$nonce = wp_create_nonce( $this->_get_nonce_key( $action ) );
@@ -761,7 +761,7 @@ function ajax_return( $status, $content = '', $action = '' ) {
exit;
}
- function ajax_add_post() {
+ public function ajax_add_post() {
$zone_id = $this->_get_post_var( 'zone_id', 0, 'absint' );
$post_id = $this->_get_post_var( 'post_id', 0, 'absint' );
@@ -794,7 +794,7 @@ function ajax_add_post() {
$this->ajax_return( $status, $content );
}
- function ajax_remove_post() {
+ public function ajax_remove_post() {
$zone_id = $this->_get_post_var( 'zone_id', 0, 'absint' );
$post_id = $this->_get_post_var( 'post_id', 0, 'absint' );
@@ -820,7 +820,7 @@ function ajax_remove_post() {
$this->ajax_return( $status, $content );
}
- function ajax_reorder_posts() {
+ public function ajax_reorder_posts() {
$zone_id = $this->_get_post_var( 'zone_id', 0, 'absint' );
$post_ids = (array) $this->_get_post_var( 'posts', array(), 'absint' );
@@ -847,7 +847,7 @@ function ajax_reorder_posts() {
}
// TODO: implement in front-end
- function ajax_move_zone_post( $from_zone, $to_zone, $post_id ) {
+ public function ajax_move_zone_post( $from_zone, $to_zone, $post_id ) {
$from_zone_id = $this->_get_post_var( 'from_zone_id', 0, 'absint' );
$to_zone_id = $this->_get_post_var( 'to_zone_id', 0, 'absint' );
@@ -862,7 +862,7 @@ function ajax_move_zone_post( $from_zone, $to_zone, $post_id ) {
$this->remove_zone_posts( $from_zone_id, $post_id );
}
- function ajax_search_posts() {
+ public function ajax_search_posts() {
$q = $this->_get_request_var( 'term', '', 'stripslashes' );
@@ -930,7 +930,7 @@ function ajax_search_posts() {
}
}
- function ajax_update_lock() {
+ public function ajax_update_lock() {
$zone_id = $this->_get_post_var( 'zone_id', 0, 'absint' );
$this->verify_nonce( $this->zone_ajax_nonce_action );
@@ -946,7 +946,7 @@ function ajax_update_lock() {
}
}
- function get_supported_post_types() {
+ public function get_supported_post_types() {
if ( $this->post_types !== null ) {
return $this->post_types;
}
@@ -968,7 +968,7 @@ function get_supported_post_types() {
* @param string|array $post_types A post type string or array of post type strings to register.
* @return bool True if any post types were added, false if not.
*/
- function register_zone_post_type( $post_types = '' ) {
+ public function register_zone_post_type( $post_types = '' ) {
$did_register_post_types = false;
@@ -993,7 +993,7 @@ function register_zone_post_type( $post_types = '' ) {
return $did_register_post_types;
}
- function insert_zone( $slug, $name = '', $details = array() ) {
+ public function insert_zone( $slug, $name = '', $details = array() ) {
// slug cannot be empty
if ( empty( $slug ) ) {
@@ -1017,7 +1017,7 @@ function insert_zone( $slug, $name = '', $details = array() ) {
return wp_insert_term( $name, $this->zone_taxonomy, $args );
}
- function update_zone( $zone, $data = array() ) {
+ public function update_zone( $zone, $data = array() ) {
$zone_id = $this->get_zone_id( $zone );
if ( $this->zone_exists( $zone_id ) ) {
@@ -1046,7 +1046,7 @@ function update_zone( $zone, $data = array() ) {
return new WP_Error( 'invalid-zone', __( 'Sorry, that zone doesn\'t exist.', 'zoninator' ) );
}
- function delete_zone( $zone ) {
+ public function delete_zone( $zone ) {
$zone_id = $this->get_zone_id( $zone );
$meta_key = $this->get_zone_meta_key( $zone );
@@ -1075,7 +1075,7 @@ function delete_zone( $zone ) {
* @param bool $append
* @return bool|WP_Error
*/
- function add_zone_posts( $zone, $posts, $append = false ) {
+ public function add_zone_posts( $zone, $posts, $append = false ) {
$zone = $this->get_zone( $zone );
$meta_key = $this->get_zone_meta_key( $zone );
@@ -1112,7 +1112,7 @@ function add_zone_posts( $zone, $posts, $append = false ) {
*
* @return bool|WP_Error
*/
- function remove_zone_posts( $zone, $posts = null ) {
+ public function remove_zone_posts( $zone, $posts = null ) {
$zone = $this->get_zone( $zone );
$meta_key = $this->get_zone_meta_key( $zone );
@@ -1135,7 +1135,7 @@ function remove_zone_posts( $zone, $posts = null ) {
do_action( 'zoninator_remove_zone_posts', $posts, $zone );
}
- function get_zone_posts( $zone, $args = array() ) {
+ public function get_zone_posts( $zone, $args = array() ) {
// Check cache first
if ( $posts = $this->get_zone_posts_from_cache( $zone, $args ) ) {
return $posts;
@@ -1150,7 +1150,7 @@ function get_zone_posts( $zone, $args = array() ) {
return $posts;
}
- function get_zone_query( $zone, $args = array() ) {
+ public function get_zone_query( $zone, $args = array() ) {
$meta_key = $this->get_zone_meta_key( $zone );
$defaults = array(
@@ -1191,7 +1191,7 @@ function get_zone_query( $zone, $args = array() ) {
return new WP_Query( $args );
}
- function get_last_post_in_zone( $zone ) {
+ public function get_last_post_in_zone( $zone ) {
return $this->get_single_post_in_zone(
$zone,
array(
@@ -1200,11 +1200,11 @@ function get_last_post_in_zone( $zone ) {
);
}
- function get_first_post_in_zone( $zone ) {
+ public function get_first_post_in_zone( $zone ) {
return $this->get_single_post_in_zone( $zone );
}
- function get_prev_post_in_zone( $zone, $post_id ) {
+ public function get_prev_post_in_zone( $zone, $post_id ) {
// TODO: test this works
$order = $this->get_post_order_in_zone( $zone, $post_id );
@@ -1217,7 +1217,7 @@ function get_prev_post_in_zone( $zone, $post_id ) {
);
}
- function get_next_post_in_zone( $zone, $post_id ) {
+ public function get_next_post_in_zone( $zone, $post_id ) {
// TODO: test this works
$order = $this->get_post_order_in_zone( $zone, $post_id );
@@ -1230,7 +1230,7 @@ function get_next_post_in_zone( $zone, $post_id ) {
);
}
- function get_single_post_in_zone( $zone, $args = array() ) {
+ public function get_single_post_in_zone( $zone, $args = array() ) {
$args = wp_parse_args(
$args,
@@ -1249,7 +1249,7 @@ function get_single_post_in_zone( $zone, $args = array() ) {
return false;
}
- function get_zones_for_post( $post_id ) {
+ public function get_zones_for_post( $post_id ) {
// TODO: build this out
// get_object_terms
@@ -1273,7 +1273,7 @@ function get_zones_for_post( $post_id ) {
// return $zones;
}
- function get_zones( $args = array() ) {
+ public function get_zones( $args = array() ) {
$args = wp_parse_args(
$args,
@@ -1298,7 +1298,7 @@ function get_zones( $args = array() ) {
return false;
}
- function get_zone( $zone ) {
+ public function get_zone( $zone ) {
if ( is_int( $zone ) ) {
$field = 'id';
} elseif ( is_string( $zone ) ) {
@@ -1323,7 +1323,7 @@ function get_zone( $zone ) {
return $this->_fill_zone_details( $zone );
}
- function lock_zone( $zone, $user_id = 0 ) {
+ public function lock_zone( $zone, $user_id = 0 ) {
$zone_id = $this->get_zone_id( $zone );
if ( ! $zone_id ) {
@@ -1344,7 +1344,7 @@ function lock_zone( $zone, $user_id = 0 ) {
}
// Not really needed with transients...
- function unlock_zone( $zone ) {
+ public function unlock_zone( $zone ) {
$zone_id = $this->get_zone_id( $zone );
if ( ! $zone_id ) {
@@ -1357,7 +1357,7 @@ function unlock_zone( $zone ) {
return null;
}
- function is_zone_locked( $zone ) {
+ public function is_zone_locked( $zone ) {
$zone_id = $this->get_zone_id( $zone );
if ( ! $zone_id ) {
return false;
@@ -1376,12 +1376,12 @@ function is_zone_locked( $zone ) {
}
}
- function zone_exists( $zone ) {
+ public function zone_exists( $zone ) {
$zone_id = $this->get_zone_id( $zone );
return (bool) term_exists( $zone_id, $this->zone_taxonomy );
}
- function get_zone_id( $zone ) {
+ public function get_zone_id( $zone ) {
if ( is_int( $zone ) ) {
return $zone;
}
@@ -1394,12 +1394,12 @@ function get_zone_id( $zone ) {
return (int) $zone;
}
- function get_zone_meta_key( $zone ) {
+ public function get_zone_meta_key( $zone ) {
$zone_id = $this->get_zone_id( $zone );
return $this->zone_meta_prefix . $zone_id;
}
- function get_zone_slug( $zone ) {
+ public function get_zone_slug( $zone ) {
if ( is_int( $zone ) ) {
$zone = $this->get_zone( $zone );
}
@@ -1411,14 +1411,14 @@ function get_zone_slug( $zone ) {
return $this->get_formatted_zone_slug( $zone );
}
- function get_formatted_zone_slug( $slug ) {
+ public function get_formatted_zone_slug( $slug ) {
return $slug; // legacy function -- slugs can no longer be changed
}
- function get_unformatted_zone_slug( $slug ) {
+ public function get_unformatted_zone_slug( $slug ) {
return $slug; // legacy function -- slugs can no longer be changed
}
- function get_post_id( $post ) {
+ public function get_post_id( $post ) {
if ( is_int( $post ) ) {
return $post;
} elseif ( is_array( $post ) ) {
@@ -1430,14 +1430,14 @@ function get_post_id( $post ) {
return false;
}
- function get_post_order( $post, $zone ) {
+ public function get_post_order( $post, $zone ) {
$post_id = $this->get_post_id( $post );
$meta_key = $this->get_zone_meta_key( $zone );
return get_metadata( 'post', $post_id, $meta_key, true );
}
- function verify_nonce( $action ) {
+ public function verify_nonce( $action ) {
$action = $this->_get_nonce_key( $action );
$nonce = $this->_get_request_var( $action );
@@ -1450,7 +1450,7 @@ function verify_nonce( $action ) {
}
}
- function verify_access( $action = '', $zone_id = null ) {
+ public function verify_access( $action = '', $zone_id = null ) {
// TODO: should check if zone locked
$verify_function = '';
@@ -1472,11 +1472,11 @@ function verify_access( $action = '', $zone_id = null ) {
}
}
- function _unauthorized_access() {
+ public function _unauthorized_access() {
wp_die( __( 'Sorry, you\'re not supposed to do that...', 'zoninator' ) );
}
- function _fill_zone_details( $zone ) {
+ public function _fill_zone_details( $zone ) {
if ( ! empty( $zone->zoninator_parsed ) && $zone->zoninator_parsed ) {
return $zone;
}
@@ -1498,7 +1498,7 @@ function _fill_zone_details( $zone ) {
return $zone;
}
- function do_zoninator_feeds() {
+ public function do_zoninator_feeds() {
$query_var = get_query_var( $this->zone_taxonomy );
if ( ! empty( $query_var ) ) {
@@ -1577,19 +1577,19 @@ private function status_header_with_message( $status, $message ) {
}
// TODO: Caching needs to be testing properly before being implemented!
- function get_zone_cache_key( $zone, $args = array() ) {
+ public function get_zone_cache_key( $zone, $args = array() ) {
return '';
}
- function get_zone_posts_from_cache( $zone, $args = array() ) {
+ public function get_zone_posts_from_cache( $zone, $args = array() ) {
return false;
}
- function add_zone_posts_to_cache( $posts, $zone, $args = array() ) {
+ public function add_zone_posts_to_cache( $posts, $zone, $args = array() ) {
}
// Handle 4.2 term-splitting
- function split_shared_term( $old_term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) {
+ public function split_shared_term( $old_term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) {
if ( $this->zone_taxonomy === $taxonomy ) {
do_action( 'zoninator_split_shared_term', $old_term_id, $new_term_id, $term_taxonomy_id );
@@ -1604,11 +1604,11 @@ function split_shared_term( $old_term_id, $new_term_id, $term_taxonomy_id, $taxo
}
}
- function _empty_zone_posts_cache( $meta_key ) {
+ public function _empty_zone_posts_cache( $meta_key ) {
return; // TODO: implement
}
- function _get_message( $message_id, $encode = false ) {
+ public function _get_message( $message_id, $encode = false ) {
$message = '';
if ( ! empty( $this->zone_messages[ $message_id ] ) ) {
@@ -1622,36 +1622,36 @@ function _get_message( $message_id, $encode = false ) {
return $message;
}
- function _get_nonce_key( $action ) {
+ public function _get_nonce_key( $action ) {
return sprintf( '%s-%s', $this->zone_nonce_prefix, $action );
}
- function _current_user_can_add_zones() {
+ public function _current_user_can_add_zones() {
return current_user_can( $this->_get_add_zones_cap() );
}
- function _current_user_can_edit_zones( $zone_id ) {
+ public function _current_user_can_edit_zones( $zone_id ) {
$has_cap = current_user_can( $this->_get_edit_zones_cap() );
return apply_filters( 'zoninator_current_user_can_edit_zone', $has_cap, $zone_id );
}
- function _current_user_can_manage_zones() {
+ public function _current_user_can_manage_zones() {
return current_user_can( $this->_get_manage_zones_cap() );
}
- function _get_add_zones_cap() {
+ public function _get_add_zones_cap() {
return apply_filters( 'zoninator_add_zone_cap', 'edit_others_posts' );
}
- function _get_edit_zones_cap() {
+ public function _get_edit_zones_cap() {
return apply_filters( 'zoninator_edit_zone_cap', 'edit_others_posts' );
}
- function _get_manage_zones_cap() {
+ public function _get_manage_zones_cap() {
return apply_filters( 'zoninator_manage_zone_cap', 'edit_others_posts' );
}
- function _get_zone_page_url( $args = array() ) {
+ public function _get_zone_page_url( $args = array() ) {
$url = menu_page_url( $this->key, false );
foreach ( $args as $arg_key => $arg_value ) {
@@ -1661,19 +1661,19 @@ function _get_zone_page_url( $args = array() ) {
return $url;
}
- function _validate_date_filter( $date ) {
+ public function _validate_date_filter( $date ) {
return preg_match( '/(\d{4})-(\d{2})-(\d{2})/', $date );
}
- function _validate_category_filter( $cat ) {
+ public function _validate_category_filter( $cat ) {
return $cat && get_term_by( 'id', $cat, 'category' );
}
- function _sanitize_value( $var ) {
+ public function _sanitize_value( $var ) {
return htmlentities( stripslashes( $var ) );
}
- function _get_value_or_default( $var, $object, $default = '', $sanitize_callback = '' ) {
+ public function _get_value_or_default( $var, $object, $default = '', $sanitize_callback = '' ) {
if ( is_object( $object ) ) {
$value = empty( $object->$var ) ? $default : $object->$var;
} elseif ( is_array( $object ) ) {
@@ -1689,14 +1689,14 @@ function _get_value_or_default( $var, $object, $default = '', $sanitize_callback
return $value;
}
- function _get_request_var( $var, $default = '', $sanitize_callback = '' ) {
+ public function _get_request_var( $var, $default = '', $sanitize_callback = '' ) {
return $this->_get_value_or_default( $var, $_REQUEST, $default, $sanitize_callback );
}
- function _get_get_var( $var, $default = '', $sanitize_callback = '' ) {
+ public function _get_get_var( $var, $default = '', $sanitize_callback = '' ) {
return $this->_get_value_or_default( $var, $_GET, $default, $sanitize_callback );
}
- function _get_post_var( $var, $default = '', $sanitize_callback = '' ) {
+ public function _get_post_var( $var, $default = '', $sanitize_callback = '' ) {
return $this->_get_value_or_default( $var, $_POST, $default, $sanitize_callback );
}
@@ -1761,7 +1761,7 @@ public function get_admin_zone_posts( $zone_or_id ) {
* @param $zone_slug_or_id
* @return array|WP_Error
*/
- function get_zone_feed( $zone_slug_or_id ) {
+ public function get_zone_feed( $zone_slug_or_id ) {
$zone_id = $this->get_zone( $zone_slug_or_id );
if ( empty( $zone_id ) ) {
From 91fdd5dfb40310af820a65737893f9ebc06a2538 Mon Sep 17 00:00:00 2001
From: Gary Jones
Date: Wed, 14 Aug 2024 11:27:23 +0100
Subject: [PATCH 38/56] CS: Rector with CodingStyle
SymplifyQuoteEscapeRector
---
includes/class-zoninator-api-controller.php | 2 +-
rector.php | 1 -
zoninator.php | 8 ++++----
3 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/includes/class-zoninator-api-controller.php b/includes/class-zoninator-api-controller.php
index f0c3923..d156752 100644
--- a/includes/class-zoninator-api-controller.php
+++ b/includes/class-zoninator-api-controller.php
@@ -482,7 +482,7 @@ private function _bad_request( $code, $message ) {
*/
private function _permissions_check( $action, $zone_id = null ) {
if ( ! $this->instance->check( $action, $zone_id ) ) {
- return new WP_Error( self::PERMISSION_DENIED, __( 'Sorry, you\'re not supposed to do that...', 'zoninator' ) );
+ return new WP_Error( self::PERMISSION_DENIED, __( "Sorry, you're not supposed to do that...", 'zoninator' ) );
}
return true;
}
diff --git a/rector.php b/rector.php
index fc12e3f..33d39cb 100644
--- a/rector.php
+++ b/rector.php
@@ -30,7 +30,6 @@
),
MakeInheritedMethodVisibilitySameAsParentRector::class,
NewlineAfterStatementRector::class,
- SymplifyQuoteEscapeRector::class,
)
)
->withPhpSets( php74: true )
diff --git a/zoninator.php b/zoninator.php
index ec776cc..b278535 100644
--- a/zoninator.php
+++ b/zoninator.php
@@ -1043,7 +1043,7 @@ public function update_zone( $zone, $data = array() ) {
return wp_update_term( $zone_id, $this->zone_taxonomy, $args );
}
- return new WP_Error( 'invalid-zone', __( 'Sorry, that zone doesn\'t exist.', 'zoninator' ) );
+ return new WP_Error( 'invalid-zone', __( "Sorry, that zone doesn't exist.", 'zoninator' ) );
}
public function delete_zone( $zone ) {
@@ -1060,13 +1060,13 @@ public function delete_zone( $zone ) {
$delete = wp_delete_term( $zone_id, $this->zone_taxonomy );
if ( ! $delete ) {
- return new WP_Error( 'delete-zone', __( 'Sorry, we couldn\'t delete the zone.', 'zoninator' ) );
+ return new WP_Error( 'delete-zone', __( "Sorry, we couldn't delete the zone.", 'zoninator' ) );
} else {
do_action( 'zoninator_delete_zone', $zone_id );
return $delete;
}
}
- return new WP_Error( 'invalid-zone', __( 'Sorry, that zone doesn\'t exist.', 'zoninator' ) );
+ return new WP_Error( 'invalid-zone', __( "Sorry, that zone doesn't exist.", 'zoninator' ) );
}
/**
@@ -1473,7 +1473,7 @@ public function verify_access( $action = '', $zone_id = null ) {
}
public function _unauthorized_access() {
- wp_die( __( 'Sorry, you\'re not supposed to do that...', 'zoninator' ) );
+ wp_die( __( "Sorry, you're not supposed to do that...", 'zoninator' ) );
}
public function _fill_zone_details( $zone ) {
From a8d4a300a2d3743f354f7d2f46ae7254fcf5edcd Mon Sep 17 00:00:00 2001
From: Gary Jones
Date: Wed, 14 Aug 2024 11:48:08 +0100
Subject: [PATCH 39/56] CS: Rector with CodingStyle
NewlineAfterStatementRector
---
functions.php | 1 +
includes/class-zoninator-api-controller.php | 39 +++++--
.../class-zoninator-api-schema-converter.php | 2 +
includes/class-zoninator-api.php | 1 +
.../class-zoninator-rest-bootstrap.php | 4 +
.../class-zoninator-rest-classloader.php | 9 +-
.../class-zoninator-rest-controller.php | 10 +-
.../class-zoninator-rest-environment.php | 11 +-
.../class-zoninator-rest-model.php | 24 ++++
.../class-zoninator-rest-type.php | 1 +
...ninator-rest-controller-bundle-builder.php | 3 +
...class-zoninator-rest-controller-action.php | 2 +
...class-zoninator-rest-controller-bundle.php | 1 +
.../class-zoninator-rest-controller-crud.php | 4 +
...ss-zoninator-rest-controller-extension.php | 4 +
.../class-zoninator-rest-controller-model.php | 2 +
.../class-zoninator-rest-controller-route.php | 1 +
.../data/class-zoninator-rest-data-mapper.php | 3 +
.../class-zoninator-rest-data-serializer.php | 1 +
...ninator-rest-data-store-customposttype.php | 5 +
...class-zoninator-rest-data-store-option.php | 2 +
...class-zoninator-rest-field-declaration.php | 24 ++++
...ninator-rest-field-declaration-builder.php | 4 +
.../class-zoninator-rest-interfaces-type.php | 4 +
...class-zoninator-rest-model-declaration.php | 1 +
.../class-zoninator-rest-model-definition.php | 12 ++
.../class-zoninator-rest-model-settings.php | 3 +
...ss-zoninator-rest-model-validationdata.php | 2 +
...inator-rest-model-declaration-settings.php | 3 +
...oninator-rest-model-definition-builder.php | 5 +
.../class-zoninator-rest-type-boolean.php | 1 +
.../class-zoninator-rest-type-integer.php | 1 +
.../class-zoninator-rest-type-nullable.php | 2 +
.../type/class-zoninator-rest-type-number.php | 1 +
.../class-zoninator-rest-type-registry.php | 2 +
.../type/class-zoninator-rest-type-string.php | 2 +
.../class-zoninator-rest-type-typedarray.php | 1 +
rector.php | 7 +-
tests/bootstrap.php | 2 +
.../class-zoninator-api-controller-test.php | 3 +
widget.zone-posts.php | 13 ++-
zoninator.php | 104 +++++++++++++-----
42 files changed, 274 insertions(+), 53 deletions(-)
diff --git a/functions.php b/functions.php
index 74ad95c..43d6e68 100644
--- a/functions.php
+++ b/functions.php
@@ -75,6 +75,7 @@ function z_get_loop_post_id_or_default( $post_id = 0 ) {
$post_id = $post->ID;
}
}
+
return $post_id;
}
diff --git a/includes/class-zoninator-api-controller.php b/includes/class-zoninator-api-controller.php
index d156752..4bccc49 100644
--- a/includes/class-zoninator-api-controller.php
+++ b/includes/class-zoninator-api-controller.php
@@ -7,27 +7,41 @@
* Class Zoninator_Api_Controller
*/
class Zoninator_Api_Controller extends Zoninator_REST_Controller {
- public const ZONE_ITEM_URL_REGEX = '/zones/(?P[\d]+)';
- public const ZONE_ITEM_POSTS_URL_REGEX = '/zones/(?P[\d]+)/posts';
+ public const ZONE_ITEM_URL_REGEX = '/zones/(?P[\d]+)';
+
+ public const ZONE_ITEM_POSTS_URL_REGEX = '/zones/(?P[\d]+)/posts';
+
public const ZONE_ITEM_POSTS_POST_REGEX = '/zones/(?P[\d]+)/posts/(?P\d+)';
- public const INVALID_ZONE_ID = 'invalid-zone-id';
- public const INVALID_POST_ID = 'invalid-post-id';
- public const ZONE_ID_POST_ID_REQUIRED = 'zone-id-post-id-required';
+ public const INVALID_ZONE_ID = 'invalid-zone-id';
+
+ public const INVALID_POST_ID = 'invalid-post-id';
+
+ public const ZONE_ID_POST_ID_REQUIRED = 'zone-id-post-id-required';
+
public const ZONE_ID_POST_IDS_REQUIRED = 'zone-id-post-ids-required';
- public const ZONE_ID_REQUIRED = 'zone-id-required';
- public const ZONE_FEED_ERROR = 'zone-feed-error';
- public const TERM_REQUIRED = 'term-required';
- public const PERMISSION_DENIED = 'permission-denied';
- public const ZONE_NOT_FOUND = 'zone-not-found';
- public const POST_NOT_FOUND = 'post-not-found';
- public const INVALID_ZONE_SETTINGS = 'invalid-zone-settings';
+
+ public const ZONE_ID_REQUIRED = 'zone-id-required';
+
+ public const ZONE_FEED_ERROR = 'zone-feed-error';
+
+ public const TERM_REQUIRED = 'term-required';
+
+ public const PERMISSION_DENIED = 'permission-denied';
+
+ public const ZONE_NOT_FOUND = 'zone-not-found';
+
+ public const POST_NOT_FOUND = 'post-not-found';
+
+ public const INVALID_ZONE_SETTINGS = 'invalid-zone-settings';
+
/**
* Instance
*
* @var Zoninator
*/
private $instance;
+
/**
* Key Value Translation array
*
@@ -484,6 +498,7 @@ private function _permissions_check( $action, $zone_id = null ) {
if ( ! $this->instance->check( $action, $zone_id ) ) {
return new WP_Error( self::PERMISSION_DENIED, __( "Sorry, you're not supposed to do that...", 'zoninator' ) );
}
+
return true;
}
}
diff --git a/includes/class-zoninator-api-schema-converter.php b/includes/class-zoninator-api-schema-converter.php
index 2100d08..e0db40d 100644
--- a/includes/class-zoninator-api-schema-converter.php
+++ b/includes/class-zoninator-api-schema-converter.php
@@ -22,6 +22,7 @@ public function as_schema( $model_definition ) {
$required[] = $field_declaration->get_data_transfer_name();
}
}
+
$schema = array(
'$schema' => 'http://json-schema.org/schema#',
'title' => $model_definition->get_name(),
@@ -64,6 +65,7 @@ public function as_args( $model_definition ) {
$result[ $field_declaration->get_data_transfer_name() ] = $arg;
}
+
return $result;
}
}
diff --git a/includes/class-zoninator-api.php b/includes/class-zoninator-api.php
index 1ed8510..d1ecf0f 100644
--- a/includes/class-zoninator-api.php
+++ b/includes/class-zoninator-api.php
@@ -7,6 +7,7 @@ class Zoninator_Api {
* @var Zoninator
*/
private $instance;
+
/**
* Bootstrap
*
diff --git a/lib/zoninator_rest/class-zoninator-rest-bootstrap.php b/lib/zoninator_rest/class-zoninator-rest-bootstrap.php
index 003556a..3930365 100644
--- a/lib/zoninator_rest/class-zoninator-rest-bootstrap.php
+++ b/lib/zoninator_rest/class-zoninator-rest-bootstrap.php
@@ -75,6 +75,7 @@ public static function create( $class_loader = null ) {
$base_dir = self::get_base_dir();
$class_loader = new Zoninator_REST_Classloader( $prefix, $base_dir );
}
+
return new self( $class_loader );
}
@@ -87,6 +88,7 @@ public function run() {
if ( ! self::is_compatible() ) {
return false;
}
+
$this->load()
->environment()->start();
return true;
@@ -102,6 +104,7 @@ public function register_autoload() {
if ( function_exists( 'spl_autoload_register' ) ) {
spl_autoload_register( array( $this->class_loader(), 'load_class' ), true );
}
+
return $this;
}
@@ -188,6 +191,7 @@ public function environment() {
if ( null === $this->environment ) {
$this->environment = new Zoninator_REST_Environment( $this );
}
+
return $this->environment;
}
}
diff --git a/lib/zoninator_rest/class-zoninator-rest-classloader.php b/lib/zoninator_rest/class-zoninator-rest-classloader.php
index 2bf45a2..c1eba3d 100644
--- a/lib/zoninator_rest/class-zoninator-rest-classloader.php
+++ b/lib/zoninator_rest/class-zoninator-rest-classloader.php
@@ -20,13 +20,15 @@ class Zoninator_REST_Classloader implements Zoninator_REST_Interfaces_Classloade
*
* @var array The loaded class map.
*/
- private $loaded_classes;
+ private $loaded_classes = array();
+
/**
* The prefix to use (e.g. Mixtape)
*
* @var string
*/
private $prefix;
+
/**
* The directory the loader looks for classes.
*
@@ -43,9 +45,8 @@ class Zoninator_REST_Classloader implements Zoninator_REST_Interfaces_Classloade
* @throws Exception Throws if an invalid directory is provided.
*/
public function __construct( $prefix, $base_dir ) {
- $this->loaded_classes = array();
- $this->prefix = $prefix;
- $this->base_dir = $base_dir;
+ $this->prefix = $prefix;
+ $this->base_dir = $base_dir;
if ( ! is_dir( $this->base_dir ) ) {
throw new Exception( 'base_dir does not exist: ' . $this->base_dir );
}
diff --git a/lib/zoninator_rest/class-zoninator-rest-controller.php b/lib/zoninator_rest/class-zoninator-rest-controller.php
index b539716..4704b15 100644
--- a/lib/zoninator_rest/class-zoninator-rest-controller.php
+++ b/lib/zoninator_rest/class-zoninator-rest-controller.php
@@ -13,10 +13,13 @@
* Class Zoninator_REST_Controller
*/
class Zoninator_REST_Controller extends WP_REST_Controller implements Zoninator_REST_Interfaces_Controller {
- public const HTTP_CREATED = 201;
- public const HTTP_OK = 200;
+ public const HTTP_CREATED = 201;
+
+ public const HTTP_OK = 200;
+
public const HTTP_BAD_REQUEST = 400;
- public const HTTP_NOT_FOUND = 404;
+
+ public const HTTP_NOT_FOUND = 404;
/**
* The bundle this belongs to.
@@ -31,6 +34,7 @@ class Zoninator_REST_Controller extends WP_REST_Controller implements Zoninator_
* @var string
*/
protected $base;
+
/**
* Our Handlers
*
diff --git a/lib/zoninator_rest/class-zoninator-rest-environment.php b/lib/zoninator_rest/class-zoninator-rest-environment.php
index 22f1bd8..73ed772 100644
--- a/lib/zoninator_rest/class-zoninator-rest-environment.php
+++ b/lib/zoninator_rest/class-zoninator-rest-environment.php
@@ -20,8 +20,10 @@
*/
class Zoninator_REST_Environment {
public const REGISTRABLE = 'IRegistrable';
- public const BUNDLES = 'Bundles';
- public const MODELS = 'Models';
+
+ public const BUNDLES = 'Bundles';
+
+ public const MODELS = 'Models';
/**
* This environment's registered REST bundles
@@ -116,6 +118,7 @@ public function model( $class ) {
if ( ! class_exists( $class ) ) {
throw new Zoninator_REST_Exception( $class . ' does not exist' );
}
+
Zoninator_REST_Expect::that( isset( $this->model_definitions[ $class ] ), $class . ' definition does not exist' );
return $this->model_definitions[ $class ];
}
@@ -189,6 +192,7 @@ public function start() {
*/
$bundle->register( $this );
}
+
$this->has_started = true;
do_action( 'mt_environment_after_start', $this );
}
@@ -269,6 +273,7 @@ public function define_var( $name, $thing = null, $append = false ) {
if ( $append && ! $this->has_variable( $name ) ) {
$this->variables[ $name ] = array();
}
+
if ( null !== $thing ) {
if ( $append ) {
$this->variables[ $name ][] = $thing;
@@ -276,6 +281,7 @@ public function define_var( $name, $thing = null, $append = false ) {
$this->variables[ $name ] = $thing;
}
}
+
return $this;
}
@@ -359,6 +365,7 @@ public function rest_api( $maybe_bundle_or_prefix = null ) {
if ( is_string( $maybe_bundle_or_prefix ) ) {
$builder->with_prefix( $maybe_bundle_or_prefix );
}
+
$builder->with_environment( $this );
}
diff --git a/lib/zoninator_rest/class-zoninator-rest-model.php b/lib/zoninator_rest/class-zoninator-rest-model.php
index 89f5bc1..66b8900 100644
--- a/lib/zoninator_rest/class-zoninator-rest-model.php
+++ b/lib/zoninator_rest/class-zoninator-rest-model.php
@@ -74,6 +74,7 @@ public function __construct( $data = array(), $args = array() ) {
unset( $args['deserialize'] );
$data = $this->deserialize( $data );
}
+
$this->raw_data = $data;
$data_keys = array_keys( $data );
@@ -121,11 +122,13 @@ public function set( $field, $value ) {
if ( isset( $args['deserializing'] ) && $args['deserializing'] ) {
$value = $this->deserialize_field( $field_declaration, $value );
}
+
if ( null !== $field_declaration->before_set() ) {
$val = $this->call( $field_declaration->before_set(), array( $value, $field_declaration->get_name() ) );
} else {
$val = $field_declaration->cast_value( $value );
}
+
$this->data[ $field_declaration->get_name() ] = $val;
return $this;
}
@@ -155,9 +158,11 @@ public function validate() {
$validation_errors[] = $is_valid->get_error_data();
}
}
+
if ( $validation_errors !== array() ) {
return $this->validation_error( $validation_errors );
}
+
return true;
}
@@ -182,8 +187,10 @@ public function sanitize() {
} else {
$value = $field_declaration->get_type()->sanitize( $value );
}
+
$this->set( $field_name, $value );
}
+
return $this;
}
@@ -208,6 +215,7 @@ protected function run_field_validations( $field_declaration ) {
if ( $field_declaration->is_kind( Zoninator_REST_Field_Declaration::DERIVED ) ) {
return true;
}
+
$value = $this->get( $field_declaration->get_name() );
if ( $field_declaration->is_required() && empty( $value ) ) {
// translators: %s is usually a field name.
@@ -228,6 +236,7 @@ protected function run_field_validations( $field_declaration ) {
}
}
}
+
return true;
}
@@ -301,6 +310,7 @@ public function get_fields( $filter_by_type = null ) {
$filtered[] = $field_declaration;
}
}
+
return $filtered;
}
@@ -322,6 +332,7 @@ private function initialize_field_map( $declared_field_builders ) {
$field = $field_builder->build();
$fields[ $field->get_name() ] = $field;
}
+
return $fields;
}
@@ -335,6 +346,7 @@ public function get_data_store() {
if ( ! isset( self::$data_stores_by_class_name[ $class_name ] ) ) {
self::$data_stores_by_class_name[ $class_name ] = new Zoninator_REST_Data_Store_Nil();
}
+
return self::$data_stores_by_class_name[ $class_name ];
}
@@ -408,6 +420,7 @@ public function update_from_array( $data, $updating = false ) {
foreach ( $mapped_data as $name => $value ) {
$this->set( $name, $value );
}
+
return $this->sanitize();
}
@@ -439,8 +452,10 @@ public function get_dto_field_mappings() {
if ( ! $field_declaration->supports_output_type( 'json' ) ) {
continue;
}
+
$mappings[ $field_declaration->get_data_transfer_name() ] = $field_declaration->get_name();
}
+
return $mappings;
}
@@ -478,6 +493,7 @@ private function map_data( $data, $updating = false ) {
if ( $field->is_kind( Zoninator_REST_Field_Declaration::DERIVED ) ) {
continue;
}
+
$dto_name = $field->get_data_transfer_name();
$field_name = $field->get_name();
if ( isset( $data[ $dto_name ] ) && ! ( $updating && $field->is_primary() ) ) {
@@ -485,6 +501,7 @@ private function map_data( $data, $updating = false ) {
$request_data[ $field_name ] = $value;
}
}
+
return $request_data;
}
@@ -501,6 +518,7 @@ private function call( $method, $args = array() ) {
if ( is_callable( $method ) ) {
return call_user_func_array( $method, $args );
}
+
Zoninator_REST_Expect::that( method_exists( $this, $method ), $method . ' does not exist' );
return call_user_func_array( array( $this, $method ), $args );
}
@@ -559,6 +577,7 @@ public static function from_raw_data( $post ) {
foreach ( $raw_meta_data as $key => $value_arr ) {
$flattened_meta[ $key ] = $value_arr[0];
}
+
$merged_data = array_merge( $raw_post_data, $flattened_meta );
return self::create(
@@ -598,8 +617,10 @@ public function deserialize( $data ) {
// just provide a default.
$value = $declaration->get_default_value();
}
+
$raw_data[ $key ] = $declaration->cast_value( $value );
}
+
return $raw_data;
}
@@ -638,6 +659,7 @@ private function deserialize_field( $field_declaration, $value ) {
if ( isset( $deserializer ) && ! empty( $deserializer ) ) {
return $this->call( $deserializer, array( $value ) );
}
+
return $value;
}
@@ -654,6 +676,7 @@ private function serialize_field( $field_declaration, $value ) {
if ( isset( $serializer ) && ! empty( $serializer ) ) {
return $this->call( $serializer, array( $value ) );
}
+
return $value;
}
@@ -670,6 +693,7 @@ public function permissions_check( $request, $action ) {
$permissions_provider = self::$permissions_providers_by_class_name[ $class_name ];
return call_user_func_array( array( $permissions_provider, 'permissions_check' ), array( $request, $action ) );
}
+
return true;
}
diff --git a/lib/zoninator_rest/class-zoninator-rest-type.php b/lib/zoninator_rest/class-zoninator-rest-type.php
index 163f80f..e41f5d8 100644
--- a/lib/zoninator_rest/class-zoninator-rest-type.php
+++ b/lib/zoninator_rest/class-zoninator-rest-type.php
@@ -19,6 +19,7 @@ class Zoninator_REST_Type implements Zoninator_REST_Interfaces_Type {
* @var string
*/
protected $identifier;
+
/**
* Mixtape_Type constructor.
*
diff --git a/lib/zoninator_rest/controller/bundle/class-zoninator-rest-controller-bundle-builder.php b/lib/zoninator_rest/controller/bundle/class-zoninator-rest-controller-bundle-builder.php
index c6385b1..e9188de 100644
--- a/lib/zoninator_rest/controller/bundle/class-zoninator-rest-controller-bundle-builder.php
+++ b/lib/zoninator_rest/controller/bundle/class-zoninator-rest-controller-bundle-builder.php
@@ -20,12 +20,14 @@ class Zoninator_REST_Controller_Bundle_Builder implements Zoninator_REST_Interfa
* @var string
*/
private $bundle_prefix;
+
/**
* Endpoint Builders.
*
* @var array
*/
private $endpoint_builders = array();
+
/**
* Bundle.
*
@@ -51,6 +53,7 @@ public function build() {
if ( is_a( $this->bundle, 'Zoninator_REST_Interfaces_Controller_Bundle' ) ) {
return $this->bundle;
}
+
return new Zoninator_REST_Controller_Bundle( $this->bundle_prefix, $this->endpoint_builders );
}
diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-action.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-action.php
index 494ae63..00ed599 100644
--- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-action.php
+++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-action.php
@@ -159,8 +159,10 @@ private function expect_callable( $callable_func ) {
if ( is_string( $callable_func ) && method_exists( $this->controller, $callable_func ) ) {
return array( $this->controller, $callable_func );
}
+
Zoninator_REST_Expect::that( is_callable( $callable_func ), 'Callable Expected: $callable_func' );
}
+
return $callable_func;
}
}
diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php
index 9fe0c04..16a712c 100644
--- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php
+++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-bundle.php
@@ -27,6 +27,7 @@ class Zoninator_REST_Controller_Bundle implements Zoninator_REST_Interfaces_Cont
* @var array
*/
protected $endpoints = array();
+
/**
* Environment.
*
diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-crud.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-crud.php
index af73b72..9d5567d 100644
--- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-crud.php
+++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-crud.php
@@ -145,10 +145,12 @@ public function delete_item( $request ) {
if ( empty( $id ) ) {
return $this->bad_request( 'No Model ID provided' );
}
+
$model = $this->model_prototype->get_data_store()->get_entity( $id );
if ( null === $model ) {
return $this->not_found( 'Model does not exist' );
}
+
$result = $this->model_data_store->delete( $model );
return $this->ok( $result );
}
@@ -188,6 +190,7 @@ protected function add_links( $model ) {
),
);
}
+
if ( $model->has( 'author' ) ) {
$result['author'] = array(
array(
@@ -195,6 +198,7 @@ protected function add_links( $model ) {
),
);
}
+
return $result;
}
}
diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-extension.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-extension.php
index f8a7bcb..366cedc 100644
--- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-extension.php
+++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-extension.php
@@ -16,18 +16,21 @@ class Zoninator_REST_Controller_Extension implements Zoninator_REST_Interfaces_R
* @var Zoninator_REST_Environment
*/
private $environment;
+
/**
* Object to extend
*
* @var string
*/
private $object_to_extend;
+
/**
* Model def.
*
* @var Zoninator_REST_Model_Definition
*/
private $model_definition;
+
/**
* Model Definition name, This should be a valid Model definition at registration time, otherwise register will throw
*
@@ -60,6 +63,7 @@ public function register( $environment ) {
if ( ! $this->model_definition ) {
return new WP_Error( 'model-not-found' );
}
+
$fields = $this->model_definition->get_fields();
foreach ( $fields as $field ) {
$this->register_field( $field );
diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-model.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-model.php
index 84e2f62..888b2fa 100644
--- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-model.php
+++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-model.php
@@ -97,6 +97,7 @@ public function get_item_schema() {
$required[] = $field_declaration->get_data_transfer_name();
}
}
+
$schema = array(
'$schema' => 'http://json-schema.org/schema#',
'title' => $model_definition->get_name(),
@@ -143,6 +144,7 @@ protected function prepare_dto( $entity ) {
foreach ( $entity->get_items() as $model ) {
$results[] = $this->model_to_dto( $model );
}
+
return $results;
}
diff --git a/lib/zoninator_rest/controller/class-zoninator-rest-controller-route.php b/lib/zoninator_rest/controller/class-zoninator-rest-controller-route.php
index 43491c4..a7432f5 100644
--- a/lib/zoninator_rest/controller/class-zoninator-rest-controller-route.php
+++ b/lib/zoninator_rest/controller/class-zoninator-rest-controller-route.php
@@ -69,6 +69,7 @@ public function as_array() {
*/
$result['actions'][] = $route_action->as_array();
}
+
return $result;
}
}
diff --git a/lib/zoninator_rest/data/class-zoninator-rest-data-mapper.php b/lib/zoninator_rest/data/class-zoninator-rest-data-mapper.php
index 929aff2..3c39113 100644
--- a/lib/zoninator_rest/data/class-zoninator-rest-data-mapper.php
+++ b/lib/zoninator_rest/data/class-zoninator-rest-data-mapper.php
@@ -19,6 +19,7 @@ class Zoninator_REST_Data_Mapper {
* @var Zoninator_REST_Data_Serializer
*/
private $serializer;
+
/**
* Definition
*
@@ -64,8 +65,10 @@ public function raw_data_to_model_data( $data, $field_declarations ) {
} else {
$value = $declaration->get_default_value();
}
+
$raw_data[ $key ] = $declaration->cast_value( $value );
}
+
return $raw_data;
}
diff --git a/lib/zoninator_rest/data/class-zoninator-rest-data-serializer.php b/lib/zoninator_rest/data/class-zoninator-rest-data-serializer.php
index 320155b..8c06716 100644
--- a/lib/zoninator_rest/data/class-zoninator-rest-data-serializer.php
+++ b/lib/zoninator_rest/data/class-zoninator-rest-data-serializer.php
@@ -54,6 +54,7 @@ public function serialize( $field_declaration, $value ) {
if ( isset( $serializer ) && ! empty( $serializer ) ) {
return $this->model_declaration->call( $serializer, array( $value ) );
}
+
return $value;
}
}
diff --git a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-customposttype.php b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-customposttype.php
index e5b36ac..e7887c5 100644
--- a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-customposttype.php
+++ b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-customposttype.php
@@ -50,6 +50,7 @@ public function get_entities( $filter = null ) {
foreach ( $posts as $post ) {
$collection[] = $this->create_from_post( $post );
}
+
return new Zoninator_REST_Model_Collection( $collection );
}
@@ -83,6 +84,7 @@ private function create_from_post( $post ) {
foreach ( $raw_meta_data as $key => $value_arr ) {
$flattened_meta[ $key ] = $value_arr[0];
}
+
$merged_data = array_merge( $raw_post_data, $flattened_meta );
return $this->get_model_prototype()->create(
@@ -126,6 +128,7 @@ public function delete( $model, $args = array() ) {
do_action( 'mixtape_data_store_delete_model_fail', $model, $id );
return new WP_Error( 'delete-failed', 'delete-failed' );
}
+
return $result;
}
@@ -144,6 +147,7 @@ public function upsert( $model ) {
if ( ! isset( $fields['post_type'] ) ) {
$fields['post_type'] = $this->post_type;
}
+
if ( isset( $fields['ID'] ) && empty( $fields['ID'] ) ) {
// ID of 0 is not acceptable on CPTs, so remove it.
unset( $fields['ID'] );
@@ -156,6 +160,7 @@ public function upsert( $model ) {
do_action( 'mixtape_data_store_model_upsert_error', $model );
return $id_or_error;
}
+
$model->set( 'id', absint( $id_or_error ) );
foreach ( $meta_fields as $meta_key => $meta_value ) {
if ( $updating ) {
diff --git a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-option.php b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-option.php
index de3c80a..cfe905a 100644
--- a/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-option.php
+++ b/lib/zoninator_rest/data/store/class-zoninator-rest-data-store-option.php
@@ -89,6 +89,7 @@ public function delete( $model, $args = array() ) {
}
}
}
+
return true;
}
@@ -108,6 +109,7 @@ public function upsert( $model ) {
add_option( $option_name, $option_value );
}
}
+
return true;
}
}
diff --git a/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php b/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php
index d70ca00..f55e149 100644
--- a/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php
+++ b/lib/zoninator_rest/field/class-zoninator-rest-field-declaration.php
@@ -29,78 +29,91 @@ class Zoninator_REST_Field_Declaration {
* possible to update their values from callables
*/
public const DERIVED = 'derived';
+
/**
* Map From
*
* @var null|string
*/
private $map_from;
+
/**
* The field kind
*
* @var string
*/
private $kind;
+
/**
* Field name
*
* @var string
*/
private $name;
+
/**
* Is this a primary field?
*
* @var bool
*/
private $primary;
+
/**
* Is this a required field?
*
* @var bool
*/
private $required;
+
/**
* Outputs
*
* @var array
*/
private $supported_outputs;
+
/**
* Description
*
* @var string
*/
private $description;
+
/**
* Data Transfer Name
*
* @var null|string
*/
private $data_transfer_name;
+
/**
* Validations
*
* @var null|array
*/
private $validations;
+
/**
* Default Value
*
* @var null|mixed
*/
private $default_value;
+
/**
* Field Choices
*
* @var null|array
*/
private $choices;
+
/**
* Type
*
* @var null|Zoninator_REST_Interfaces_Type
*/
private $type;
+
/**
* Acceptable field kinds
*
@@ -111,18 +124,21 @@ class Zoninator_REST_Field_Declaration {
self::META,
self::DERIVED,
);
+
/**
* A custom function to call before serialization
*
* @var null|callable
*/
private $serializer;
+
/**
* A custom function to call before deserialization
*
* @var null|callable
*/
private $deserializer;
+
/**
* A custom function to use for sanitizing the field value before setting it.
* Used when receiving values from untrusted sources (e.g. a web form of a REST API request)
@@ -130,24 +146,28 @@ class Zoninator_REST_Field_Declaration {
* @var null|callable
*/
private $sanitizer;
+
/**
* A custom filtering callable triggered before setting the field with the value
*
* @var null|callable
*/
private $before_set;
+
/**
* A custom filtering callable triggered before returning the field value
*
* @var null|callable
*/
private $before_get;
+
/**
* Used by derived fields: The function to use to get the field value
*
* @var null|callable
*/
private $reader;
+
/**
* Used by derived fields: The function to use to update the field value
*
@@ -165,6 +185,7 @@ public function __construct( $args ) {
if ( ! isset( $args['name'] ) || empty( $args['name'] ) || ! is_string( $args['name'] ) ) {
throw new Zoninator_REST_Exception( 'every field declaration should have a (non-empty) name string' );
}
+
if ( ! isset( $args['kind'] ) || ! in_array( $args['kind'], $this->field_kinds, true ) ) {
throw new Zoninator_REST_Exception( 'every field should have a kind (one of ' . implode( ',', $this->field_kinds ) . ')' );
}
@@ -236,6 +257,7 @@ public function is_kind( $kind ) {
if ( ! in_array( $kind, $this->field_kinds, true ) ) {
return false;
}
+
return $this->kind === $kind;
}
@@ -285,6 +307,7 @@ public function as_item_schema_property() {
if ( $this->get_choices() ) {
$schema['enum'] = (array) $this->get_choices();
}
+
return $schema;
}
@@ -344,6 +367,7 @@ public function get_description() {
if ( $this->description !== null && ! empty( $this->description ) ) {
return $this->description;
}
+
return ucfirst( str_replace( '_', ' ', $this->get_name() ) );
}
diff --git a/lib/zoninator_rest/field/declaration/class-zoninator-rest-field-declaration-builder.php b/lib/zoninator_rest/field/declaration/class-zoninator-rest-field-declaration-builder.php
index be1f932..b5117d2 100644
--- a/lib/zoninator_rest/field/declaration/class-zoninator-rest-field-declaration-builder.php
+++ b/lib/zoninator_rest/field/declaration/class-zoninator-rest-field-declaration-builder.php
@@ -159,6 +159,7 @@ public function with_type( $value_type ) {
if ( ! is_a( $value_type, 'Zoninator_REST_Interfaces_Type' ) ) {
throw new Zoninator_REST_Exception( get_class( $value_type ) . ' is not a Mixtape_Interfaces_Type' );
}
+
return $this->with( 'type', $value_type );
}
@@ -192,6 +193,7 @@ public function with_validations( $validations ) {
if ( is_callable( $validations ) || ! is_array( $validations ) ) {
$validations = array( $validations );
}
+
return $this->with( 'validations', $validations );
}
@@ -226,6 +228,7 @@ public function with_choices( $choices ) {
if ( empty( $choices ) ) {
return $this;
}
+
return $this->with( 'choices', is_array( $choices ) ? $choices : array( $choices ) );
}
@@ -252,6 +255,7 @@ public function derived( $func = null ) {
if ( $func ) {
$this->with_map_from( $func );
}
+
return $this->with_kind( Zoninator_REST_Field_Declaration::DERIVED );
}
diff --git a/lib/zoninator_rest/interfaces/class-zoninator-rest-interfaces-type.php b/lib/zoninator_rest/interfaces/class-zoninator-rest-interfaces-type.php
index 1ba208c..78cc4f5 100644
--- a/lib/zoninator_rest/interfaces/class-zoninator-rest-interfaces-type.php
+++ b/lib/zoninator_rest/interfaces/class-zoninator-rest-interfaces-type.php
@@ -21,16 +21,19 @@ interface Zoninator_REST_Interfaces_Type {
* @return mixed
*/
public function cast( $value );
+
/**
* The default value
*/
public function default_value();
+
/**
* The type's name
*
* @return string
*/
public function name();
+
/**
* Sanitize this value
*
@@ -39,6 +42,7 @@ public function name();
* @return mixed
*/
public function sanitize( $value );
+
/**
* Get this type's JSON Schema.
*
diff --git a/lib/zoninator_rest/model/class-zoninator-rest-model-declaration.php b/lib/zoninator_rest/model/class-zoninator-rest-model-declaration.php
index efbebbd..cc3ff54 100644
--- a/lib/zoninator_rest/model/class-zoninator-rest-model-declaration.php
+++ b/lib/zoninator_rest/model/class-zoninator-rest-model-declaration.php
@@ -89,6 +89,7 @@ public function call( $method, $args = array() ) {
if ( is_callable( $method ) ) {
return $this->perform_call( $method, $args );
}
+
Zoninator_REST_Expect::that( method_exists( $this, $method ), $method . ' does not exist' );
return $this->perform_call( array( $this, $method ), $args );
}
diff --git a/lib/zoninator_rest/model/class-zoninator-rest-model-definition.php b/lib/zoninator_rest/model/class-zoninator-rest-model-definition.php
index 682b18e..cb08871 100644
--- a/lib/zoninator_rest/model/class-zoninator-rest-model-definition.php
+++ b/lib/zoninator_rest/model/class-zoninator-rest-model-definition.php
@@ -20,18 +20,21 @@ class Zoninator_REST_Model_Definition implements Zoninator_REST_Interfaces_Permi
* @var Zoninator_REST_Environment
*/
private $environment;
+
/**
* Field Declarations
*
* @var array
*/
private $field_declarations;
+
/**
* Model class
*
* @var string
*/
private $model_class;
+
/**
* Data Store
*
@@ -123,6 +126,7 @@ public function set_data_store( $data_store ) {
} else {
$this->data_store = $data_store;
}
+
// at this point we should have a data store.
Zoninator_REST_Expect::is_a( $this->data_store, 'Zoninator_REST_Interfaces_Data_Store' );
@@ -172,6 +176,7 @@ public function get_field_declarations( $filter_by_type = null ) {
$filtered[] = $field_declaration;
}
}
+
return $filtered;
}
@@ -187,6 +192,7 @@ public function create_instance( $data ) {
if ( is_array( $data ) ) {
return new Zoninator_REST_Model( $this, $data );
}
+
throw new Zoninator_REST_Exception( 'does not understand entity' );
}
@@ -206,6 +212,7 @@ public function update_model_from_array( $model, $data, $updating = false ) {
foreach ( $mapped_data as $name => $value ) {
$model->set( $name, $value );
}
+
return $model->sanitize();
}
@@ -245,8 +252,10 @@ public function get_dto_field_mappings() {
if ( ! $field_declaration->supports_output_type( 'json' ) ) {
continue;
}
+
$mappings[ $field_declaration->get_data_transfer_name() ] = $field_declaration->get_name();
}
+
return $mappings;
}
@@ -306,6 +315,7 @@ private function map_data( $data, $updating = false ) {
if ( $field->is_kind( Zoninator_REST_Field_Declaration::DERIVED ) ) {
continue;
}
+
$dto_name = $field->get_data_transfer_name();
$field_name = $field->get_name();
if ( isset( $data[ $dto_name ] ) && ! ( $updating && $field->is_primary() ) ) {
@@ -313,6 +323,7 @@ private function map_data( $data, $updating = false ) {
$request_data[ $field_name ] = $value;
}
}
+
return $request_data;
}
@@ -334,6 +345,7 @@ private function initialize_field_map( $declared_field_builders ) {
$field = $field_builder->build();
$fields[ $field->get_name() ] = $field;
}
+
return $fields;
}
}
diff --git a/lib/zoninator_rest/model/class-zoninator-rest-model-settings.php b/lib/zoninator_rest/model/class-zoninator-rest-model-settings.php
index 797442b..c158831 100644
--- a/lib/zoninator_rest/model/class-zoninator-rest-model-settings.php
+++ b/lib/zoninator_rest/model/class-zoninator-rest-model-settings.php
@@ -67,6 +67,7 @@ public function declare_fields() {
$fields[] = $field_builder;
}
}
+
return $fields;
}
@@ -132,6 +133,7 @@ private function field_declaration_builder_from_data( $env, $field_data ) {
// convert our default value as well.
$default_value = $this->bit_to_bool( $default_value );
}
+
$field_builder
->with_serializer( array( $this, 'bool_to_bit' ) )
->with_deserializer( array( $this, 'bit_to_bool' ) );
@@ -145,6 +147,7 @@ private function field_declaration_builder_from_data( $env, $field_data ) {
if ( $default_value ) {
$field_builder->with_default( $default_value );
}
+
$field_builder
->with_description( $description )
->with_dto_name( $field_name )
diff --git a/lib/zoninator_rest/model/class-zoninator-rest-model-validationdata.php b/lib/zoninator_rest/model/class-zoninator-rest-model-validationdata.php
index afa83a7..10fde3c 100644
--- a/lib/zoninator_rest/model/class-zoninator-rest-model-validationdata.php
+++ b/lib/zoninator_rest/model/class-zoninator-rest-model-validationdata.php
@@ -19,12 +19,14 @@ class Zoninator_REST_Model_ValidationData {
* @var mixed
*/
private $value;
+
/**
* The model
*
* @var Zoninator_REST_Interfaces_Model
*/
private $model;
+
/**
* The field
*
diff --git a/lib/zoninator_rest/model/declaration/class-zoninator-rest-model-declaration-settings.php b/lib/zoninator_rest/model/declaration/class-zoninator-rest-model-declaration-settings.php
index 10f5d12..9ed8af3 100644
--- a/lib/zoninator_rest/model/declaration/class-zoninator-rest-model-declaration-settings.php
+++ b/lib/zoninator_rest/model/declaration/class-zoninator-rest-model-declaration-settings.php
@@ -65,6 +65,7 @@ public function declare_fields( $env ) {
$fields[] = $field_builder;
}
}
+
return $fields;
}
@@ -132,6 +133,7 @@ private function field_declaration_builder_from_data( $env, $field_data ) {
// convert our default value as well.
$default_value = $this->bit_to_bool( $default_value );
}
+
$field_builder
->with_serializer( array( $this, 'bool_to_bit' ) )
->with_deserializer( array( $this, 'bit_to_bool' ) );
@@ -145,6 +147,7 @@ private function field_declaration_builder_from_data( $env, $field_data ) {
if ( $default_value ) {
$field_builder->with_default( $default_value );
}
+
$field_builder
->with_description( $description )
->with_dto_name( $field_name )
diff --git a/lib/zoninator_rest/model/definition/class-zoninator-rest-model-definition-builder.php b/lib/zoninator_rest/model/definition/class-zoninator-rest-model-definition-builder.php
index 855945d..6abf95c 100644
--- a/lib/zoninator_rest/model/definition/class-zoninator-rest-model-definition-builder.php
+++ b/lib/zoninator_rest/model/definition/class-zoninator-rest-model-definition-builder.php
@@ -19,18 +19,21 @@ class Zoninator_REST_Model_Definition_Builder implements Zoninator_REST_Interfac
* @var Zoninator_REST_Interfaces_Model_Declaration
*/
private $declaration;
+
/**
* Data Store
*
* @var Zoninator_REST_Interfaces_Data_Store
*/
private $data_store;
+
/**
* Environment
*
* @var Zoninator_REST_Environment
*/
private $environment;
+
/**
* Permissions Provider
*
@@ -56,11 +59,13 @@ public function with_declaration( $declaration ) {
if ( is_string( $declaration ) && class_exists( $declaration ) ) {
$declaration = new $declaration();
}
+
Zoninator_REST_Expect::is_a( $declaration, 'Zoninator_REST_Interfaces_Model_Declaration' );
$this->declaration = $declaration;
if ( is_a( $declaration, 'Zoninator_REST_Interfaces_Permissions_Provider' ) ) {
$this->with_permissions_provider( $declaration );
}
+
return $this;
}
diff --git a/lib/zoninator_rest/type/class-zoninator-rest-type-boolean.php b/lib/zoninator_rest/type/class-zoninator-rest-type-boolean.php
index a093ff3..a5ec9d1 100644
--- a/lib/zoninator_rest/type/class-zoninator-rest-type-boolean.php
+++ b/lib/zoninator_rest/type/class-zoninator-rest-type-boolean.php
@@ -40,6 +40,7 @@ public function cast( $value ) {
if ( 'false' === $value ) {
return false;
}
+
return (bool) $value;
}
}
diff --git a/lib/zoninator_rest/type/class-zoninator-rest-type-integer.php b/lib/zoninator_rest/type/class-zoninator-rest-type-integer.php
index 238f825..6359ac9 100644
--- a/lib/zoninator_rest/type/class-zoninator-rest-type-integer.php
+++ b/lib/zoninator_rest/type/class-zoninator-rest-type-integer.php
@@ -50,6 +50,7 @@ public function cast( $value ) {
if ( ! is_numeric( $value ) ) {
return $this->default_value();
}
+
return $this->unsigned ? absint( $value ) : intval( $value, 10 );
}
diff --git a/lib/zoninator_rest/type/class-zoninator-rest-type-nullable.php b/lib/zoninator_rest/type/class-zoninator-rest-type-nullable.php
index f5fc232..badcefb 100644
--- a/lib/zoninator_rest/type/class-zoninator-rest-type-nullable.php
+++ b/lib/zoninator_rest/type/class-zoninator-rest-type-nullable.php
@@ -47,6 +47,7 @@ public function cast( $value ) {
if ( null === $value ) {
return null;
}
+
return $this->item_type_definition->cast( $value );
}
@@ -60,6 +61,7 @@ public function sanitize( $value ) {
if ( null === $value ) {
return null;
}
+
return $this->item_type_definition->sanitize( $value );
}
diff --git a/lib/zoninator_rest/type/class-zoninator-rest-type-number.php b/lib/zoninator_rest/type/class-zoninator-rest-type-number.php
index b3663c8..d9b4b6e 100644
--- a/lib/zoninator_rest/type/class-zoninator-rest-type-number.php
+++ b/lib/zoninator_rest/type/class-zoninator-rest-type-number.php
@@ -40,6 +40,7 @@ public function cast( $value ) {
if ( ! is_numeric( $value ) ) {
return $this->default_value();
}
+
return floatval( $value );
}
diff --git a/lib/zoninator_rest/type/class-zoninator-rest-type-registry.php b/lib/zoninator_rest/type/class-zoninator-rest-type-registry.php
index 98a54f1..a92681d 100644
--- a/lib/zoninator_rest/type/class-zoninator-rest-type-registry.php
+++ b/lib/zoninator_rest/type/class-zoninator-rest-type-registry.php
@@ -70,6 +70,7 @@ public function definition( $type ) {
if ( empty( $item_type ) ) {
throw new Zoninator_REST_Exception( $type . ': invalid syntax' );
}
+
$item_type_definition = $this->definition( $item_type );
if ( 'array' === $container_type ) {
@@ -87,6 +88,7 @@ public function definition( $type ) {
if ( ! isset( $types[ $type ] ) ) {
throw new Zoninator_REST_Exception();
}
+
return $types[ $type ];
}
diff --git a/lib/zoninator_rest/type/class-zoninator-rest-type-string.php b/lib/zoninator_rest/type/class-zoninator-rest-type-string.php
index 040d06c..41b7ae5 100644
--- a/lib/zoninator_rest/type/class-zoninator-rest-type-string.php
+++ b/lib/zoninator_rest/type/class-zoninator-rest-type-string.php
@@ -51,8 +51,10 @@ public function cast( $value ) {
foreach ( $value as $v ) {
$cast_ones[] = $this->cast( $v );
}
+
return '(' . implode( ',', $cast_ones ) . ')';
}
+
return (string) $value;
}
}
diff --git a/lib/zoninator_rest/type/class-zoninator-rest-type-typedarray.php b/lib/zoninator_rest/type/class-zoninator-rest-type-typedarray.php
index 573c28a..ec64bcd 100644
--- a/lib/zoninator_rest/type/class-zoninator-rest-type-typedarray.php
+++ b/lib/zoninator_rest/type/class-zoninator-rest-type-typedarray.php
@@ -54,6 +54,7 @@ public function cast( $value ) {
foreach ( $value as $v ) {
$new_value[] = $this->item_type_definition->cast( $v );
}
+
return $new_value;
}
diff --git a/rector.php b/rector.php
index 33d39cb..5749366 100644
--- a/rector.php
+++ b/rector.php
@@ -3,12 +3,9 @@
declare(strict_types=1);
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
-use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
-use Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector;
use Rector\Config\RectorConfig;
use Rector\Php54\Rector\Array_\LongArrayToShortArrayRector;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
-use Rector\Visibility\Rector\ClassMethod\ExplicitPublicClassMethodRector;
return RectorConfig::configure()
->withPaths(
@@ -28,8 +25,10 @@
DisallowedEmptyRuleFixerRector::class => array(
__DIR__ . '/lib/zoninator_rest/type/class-zoninator-rest-type-registry.php',
),
+ // Child classes can legitimately relax the visibility of a method, so while this
+ // might not be desirable, changing them from public to the original parent-defined
+ // protected would count as a breaking change.
MakeInheritedMethodVisibilitySameAsParentRector::class,
- NewlineAfterStatementRector::class,
)
)
->withPhpSets( php74: true )
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 69c2bc9..8804db1 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -4,6 +4,7 @@
if ( ! $_tests_dir ) {
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
}
+
if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) {
echo sprintf('Could not find %s/includes/functions.php, have you run bin/install-wp-tests.sh ?', $_tests_dir) . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
exit( 1 );
@@ -16,6 +17,7 @@ function _manually_load_plugin(): void {
$file = $thispath . '/../zoninator.php';
require_once realpath( $file );
}
+
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
require $_tests_dir . '/includes/bootstrap.php';
diff --git a/tests/unit/class-zoninator-api-controller-test.php b/tests/unit/class-zoninator-api-controller-test.php
index 5cf927d..11b4f4e 100644
--- a/tests/unit/class-zoninator-api-controller-test.php
+++ b/tests/unit/class-zoninator-api-controller-test.php
@@ -97,6 +97,7 @@ public function request( $endpoint, $method, $args = array() ) {
foreach ( $args as $key => $value ) {
$request->set_param( $key, $value );
}
+
return $this->rest_server->dispatch( $request );
}
@@ -390,6 +391,7 @@ private function _insert_a_post() {
if ( is_wp_error( $insert ) ) {
throw new Exception( 'Error' );
}
+
return $insert;
}
@@ -398,6 +400,7 @@ private function create_a_zone( $slug, $title ) {
if ( is_wp_error( $result ) ) {
return $result;
}
+
return $result['term_id'] ?? 0;
}
diff --git a/widget.zone-posts.php b/widget.zone-posts.php
index 71a2ff0..c7d6ce9 100644
--- a/widget.zone-posts.php
+++ b/widget.zone-posts.php
@@ -61,7 +61,9 @@ public function widget( $args, $instance ) {
description ) && $show_description ) : ?>
description ); ?>
-
+
@@ -70,7 +72,9 @@ public function widget( $args, $instance ) {
ID ) ); ?>
-
+
@@ -82,6 +86,7 @@ public function widget( $args, $instance ) {
// Save is blocked while the cache flush is in progress.
return;
}
+
wp_cache_set( 'widget-zone-posts', $cache, 'widget' );
}
@@ -141,7 +146,9 @@ public function form( $instance ) {
-
+
diff --git a/zoninator.php b/zoninator.php
index b278535..7a91015 100644
--- a/zoninator.php
+++ b/zoninator.php
@@ -40,25 +40,39 @@
class Zoninator {
- public $key = 'zoninator';
- public $zone_taxonomy = 'zoninator_zones';
- public $zone_term_prefix = 'zone-';
- public $zone_meta_prefix = '_zoninator_order_';
- public $zone_nonce_prefix = 'zone-nonce';
+ public $key = 'zoninator';
+
+ public $zone_taxonomy = 'zoninator_zones';
+
+ public $zone_term_prefix = 'zone-';
+
+ public $zone_meta_prefix = '_zoninator_order_';
+
+ public $zone_nonce_prefix = 'zone-nonce';
+
public $zone_ajax_nonce_action = 'ajax-action';
- public $zone_lock_period = 30; // number of seconds a lock is valid for
- public $zone_max_lock_period = 600; // max number of seconds for all locks in a session
+
+ // Number of seconds a lock is valid for.
+ public $zone_lock_period = 30;
+
+ // Max number of seconds for all locks in a session.
+ public $zone_max_lock_period = 600;
public $post_types;
+
public $zone_detail_defaults = array(
'description' => '',
- // Add additional properties here!
+ // Add additional properties here!
);
+
public $zone_messages;
+
public $posts_per_page = 10;
+
/**
* @var Zoninator_Api
*/
public $rest_api;
+
/**
* @var array|string[] Default post types that support zones.
*/
@@ -316,20 +330,26 @@ public function admin_page() {
-
-
+
-
+
-
+
@@ -362,8 +382,10 @@ public function admin_page_zone_tabs( $zones, $active_zone_id = 0 ) {
name ); ?>name ); ?>
-
-
+
@@ -397,7 +419,9 @@ public function admin_page_zone_edit( $zone = null ) {