From 39c12e361a098629f7b521432200ac5790746c55 Mon Sep 17 00:00:00 2001 From: Ivan Ruzevic Date: Fri, 5 Apr 2019 13:20:20 +0200 Subject: [PATCH 01/23] init --- .gitignore | 0 README.md | 1 + composer.json | 40 ++++++++++++ phpunit.xml | 0 src/class-main.php | 114 ++++++++++++++++++++++++++++++++++ src/interface-registrable.php | 33 ++++++++++ src/interface-renderable.php | 27 ++++++++ src/interface-service.php | 38 ++++++++++++ 8 files changed, 253 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 composer.json create mode 100644 phpunit.xml create mode 100644 src/class-main.php create mode 100644 src/interface-registrable.php create mode 100644 src/interface-renderable.php create mode 100644 src/interface-service.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..e69de29bb diff --git a/README.md b/README.md new file mode 100644 index 000000000..6d1f9c618 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# WordPress Libs diff --git a/composer.json b/composer.json new file mode 100644 index 000000000..7fdeb05f3 --- /dev/null +++ b/composer.json @@ -0,0 +1,40 @@ +{ + "name": "eightshift/libs", + "description": "WordPress libs developed by Eightshift theme to use in WordPress boilerplate.", + "type": "composer-plugin", + "keywords": [ + "composer", "installer", "plugin" + ], + "homepage": "https://eightshift.com/", + "license": "MIT", + "authors": [ + { + "name": "Eightshift team", + "email": "team@eightshift.com", + "homepage": "https://eightshift.com/", + "role": "Developer / IT Manager" + } + ], + "support": { + "issues": "https://github.com/infinum/wordpress-libs/issues", + "source": "https://github.com/infinum/wordpress-libs" + }, + "require": { + "php": "^5.6|^7", + "composer-plugin-api": "^1.0" + }, + "require-dev": { + "composer/composer": "*", + "sensiolabs/security-checker": "^4.1.0", + "phpcompatibility/php-compatibility": "^9.0" + }, + "autoload": { + "psr-4": { + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "extra": { + }, + "scripts": { + } +} diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 000000000..e69de29bb diff --git a/src/class-main.php b/src/class-main.php new file mode 100644 index 000000000..92706757d --- /dev/null +++ b/src/class-main.php @@ -0,0 +1,114 @@ +register_assets_manifest_data(); + } + /** + * Register the individual services of this plugin. + * + * @throws Exception\Invalid_Service If a service is not valid. + */ + public function register_services() { + // Bail early so we don't instantiate services twice. + if ( ! empty( $this->services ) ) { + return; + } + $classes = $this->get_service_classes(); + $this->services = array_map( + [ $this, 'instantiate_service' ], + $classes + ); + array_walk( + $this->services, + function( Service $service ) { + $service->register(); + } + ); + } + /** + * Register bundled asset manifest + * + * @throws Exception\Missing_Manifest Throws error if manifest is missing. + * @return void + */ + public function register_assets_manifest_data() { + // phpcs:disable + $response = ( file( get_template_directory() . '/skin/public/manifest.json' ) ); + // phpcs:enable + if ( ! $response ) { + $error_message = esc_html__( 'manifest.json is missing. Bundle the theme before using it.', 'developer-portal' ); + throw Exception\Missing_Manifest::message( $error_message ); + } + define( 'INF_ASSETS_MANIFEST', implode( ' ', $response ) ); + } + /** + * Instantiate a single service. + * + * @param string $class Service class to instantiate. + * + * @return Service + * @throws Exception\Invalid_Service If the service is not valid. + */ + private function instantiate_service( $class ) { + if ( ! class_exists( $class ) ) { + throw Exception\Invalid_Service::from_service( $class ); + } + $service = new $class(); + if ( ! $service instanceof Service ) { + throw Exception\Invalid_Service::from_service( $service ); + } + return $service; + } + /** + * Get the list of services to register. + * + * A list of classes which contain hooks. + * + * @return array Array of fully qualified class names. + */ + private function get_service_classes() { + return [ + + // Admin. + + ]; + } +} diff --git a/src/interface-registrable.php b/src/interface-registrable.php new file mode 100644 index 000000000..f8aa2b49b --- /dev/null +++ b/src/interface-registrable.php @@ -0,0 +1,33 @@ + Date: Fri, 5 Apr 2019 14:03:22 +0200 Subject: [PATCH 02/23] init --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7fdeb05f3..76c348577 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "eightshift/libs", + "name": "infinum/wordpress-libs", "description": "WordPress libs developed by Eightshift theme to use in WordPress boilerplate.", "type": "composer-plugin", "keywords": [ From 322103daa37110545385decfc8bb98c797eb89df Mon Sep 17 00:00:00 2001 From: Ivan Ruzevic Date: Fri, 5 Apr 2019 14:04:12 +0200 Subject: [PATCH 03/23] composer.json --- composer.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/composer.json b/composer.json index 76c348577..486dff9e1 100644 --- a/composer.json +++ b/composer.json @@ -32,9 +32,5 @@ "psr-4": { "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" } - }, - "extra": { - }, - "scripts": { } } From 47c337478f2dd4e6ab979c95d8e0ff4ada0e4600 Mon Sep 17 00:00:00 2001 From: Ivan Ruzevic Date: Fri, 5 Apr 2019 14:09:23 +0200 Subject: [PATCH 04/23] composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 486dff9e1..ae6c33f93 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ }, "autoload": { "psr-4": { - "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + "Eightshift_Libs\\": "src/" } } } From e228fa8da09b193f67e895bc0e627374b8fa39ff Mon Sep 17 00:00:00 2001 From: Ivan Ruzevic Date: Fri, 5 Apr 2019 14:12:30 +0200 Subject: [PATCH 05/23] composer.json --- composer.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/composer.json b/composer.json index ae6c33f93..07551c83a 100644 --- a/composer.json +++ b/composer.json @@ -24,9 +24,6 @@ "composer-plugin-api": "^1.0" }, "require-dev": { - "composer/composer": "*", - "sensiolabs/security-checker": "^4.1.0", - "phpcompatibility/php-compatibility": "^9.0" }, "autoload": { "psr-4": { From 8932fca4dc1d51b10f43795cc1ec85b3177ca099 Mon Sep 17 00:00:00 2001 From: Ivan Ruzevic Date: Fri, 5 Apr 2019 14:13:33 +0200 Subject: [PATCH 06/23] composer.json --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 07551c83a..b4b859ea4 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,6 @@ { "name": "infinum/wordpress-libs", "description": "WordPress libs developed by Eightshift theme to use in WordPress boilerplate.", - "type": "composer-plugin", "keywords": [ "composer", "installer", "plugin" ], From f9acdbb0daf5af978296a58d186e90dddae13f7a Mon Sep 17 00:00:00 2001 From: Ivan Ruzevic Date: Fri, 5 Apr 2019 15:29:38 +0200 Subject: [PATCH 07/23] adding files --- src/class-main.php | 21 ++++--- src/exception/class-failed-to-load-view.php | 35 +++++++++++ src/exception/class-invalid-callback.php | 34 ++++++++++ src/exception/class-invalid-post-id.php | 31 +++++++++ src/exception/class-invalid-service.php | 34 ++++++++++ src/exception/class-invalid-uri.php | 33 ++++++++++ src/exception/class-missing-manifest.php | 28 +++++++++ src/exception/general-exception-interface.php | 19 ++++++ src/interface-registrable.php | 2 - src/interface-renderable.php | 2 - src/interface-service.php | 2 - src/rest-routes/interface-field-callable.php | 27 ++++++++ src/rest-routes/interface-field.php | 24 +++++++ src/rest-routes/interface-rest-callable.php | 24 +++++++ src/rest-routes/interface-route.php | 63 +++++++++++++++++++ 15 files changed, 366 insertions(+), 13 deletions(-) create mode 100644 src/exception/class-failed-to-load-view.php create mode 100644 src/exception/class-invalid-callback.php create mode 100644 src/exception/class-invalid-post-id.php create mode 100644 src/exception/class-invalid-service.php create mode 100644 src/exception/class-invalid-uri.php create mode 100644 src/exception/class-missing-manifest.php create mode 100644 src/exception/general-exception-interface.php create mode 100644 src/rest-routes/interface-field-callable.php create mode 100644 src/rest-routes/interface-field.php create mode 100644 src/rest-routes/interface-rest-callable.php create mode 100644 src/rest-routes/interface-route.php diff --git a/src/class-main.php b/src/class-main.php index 92706757d..d8dd5cb2e 100644 --- a/src/class-main.php +++ b/src/class-main.php @@ -20,6 +20,7 @@ * version of the theme. */ class Main implements Registrable { + /** * Array of instantiated services. * @@ -52,6 +53,7 @@ public function register_services() { return; } $classes = $this->get_service_classes(); + $this->services = array_map( [ $this, 'instantiate_service' ], $classes @@ -63,6 +65,15 @@ function( Service $service ) { } ); } + + /** + * Provide menifest json url location. + * + * @return string + */ + protected function get_manifest_url() : string { + return get_template_directory() . '/skin/public/manifest.json'; + } /** * Register bundled asset manifest * @@ -71,7 +82,7 @@ function( Service $service ) { */ public function register_assets_manifest_data() { // phpcs:disable - $response = ( file( get_template_directory() . '/skin/public/manifest.json' ) ); + $response = ( file( $this->get_manifest_url() ) ); // phpcs:enable if ( ! $response ) { $error_message = esc_html__( 'manifest.json is missing. Bundle the theme before using it.', 'developer-portal' ); @@ -104,11 +115,7 @@ private function instantiate_service( $class ) { * * @return array Array of fully qualified class names. */ - private function get_service_classes() { - return [ - - // Admin. - - ]; + protected function get_service_classes() { + return []; } } diff --git a/src/exception/class-failed-to-load-view.php b/src/exception/class-failed-to-load-view.php new file mode 100644 index 000000000..2f27c3582 --- /dev/null +++ b/src/exception/class-failed-to-load-view.php @@ -0,0 +1,35 @@ +getMessage() + ); + + return new static( $message, $exception->getCode(), $exception ); + } +} diff --git a/src/exception/class-invalid-callback.php b/src/exception/class-invalid-callback.php new file mode 100644 index 000000000..8769428ff --- /dev/null +++ b/src/exception/class-invalid-callback.php @@ -0,0 +1,34 @@ + Date: Fri, 5 Apr 2019 15:49:47 +0200 Subject: [PATCH 08/23] adding files --- src/class-main.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/class-main.php b/src/class-main.php index d8dd5cb2e..800fd4a44 100644 --- a/src/class-main.php +++ b/src/class-main.php @@ -81,13 +81,19 @@ protected function get_manifest_url() : string { * @return void */ public function register_assets_manifest_data() { - // phpcs:disable - $response = ( file( $this->get_manifest_url() ) ); - // phpcs:enable - if ( ! $response ) { + + $manifest = $this->get_manifest_url(); + if ( ! file_exists( $manifest ) ) { $error_message = esc_html__( 'manifest.json is missing. Bundle the theme before using it.', 'developer-portal' ); throw Exception\Missing_Manifest::message( $error_message ); } + + $response = file( $manifest ); + if ( ! $response ) { + $error_message = esc_html__( 'manifest.json is no valid. Bundle the theme before using it.', 'developer-portal' ); + throw Exception\Missing_Manifest::message( $error_message ); + } + define( 'INF_ASSETS_MANIFEST', implode( ' ', $response ) ); } /** From e240651fd6dd7fbd3115178d2dd4f2e7e58dccf4 Mon Sep 17 00:00:00 2001 From: Ivan Ruzevic Date: Fri, 5 Apr 2019 15:58:59 +0200 Subject: [PATCH 09/23] adding files --- src/class-main.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/class-main.php b/src/class-main.php index 800fd4a44..c02479568 100644 --- a/src/class-main.php +++ b/src/class-main.php @@ -19,7 +19,7 @@ * Also maintains the unique identifier of this theme as well as the current * version of the theme. */ -class Main implements Registrable { +class Main implements Service { /** * Array of instantiated services. @@ -88,13 +88,7 @@ public function register_assets_manifest_data() { throw Exception\Missing_Manifest::message( $error_message ); } - $response = file( $manifest ); - if ( ! $response ) { - $error_message = esc_html__( 'manifest.json is no valid. Bundle the theme before using it.', 'developer-portal' ); - throw Exception\Missing_Manifest::message( $error_message ); - } - - define( 'INF_ASSETS_MANIFEST', implode( ' ', $response ) ); + define( 'INF_ASSETS_MANIFEST', implode( ' ', file( $manifest ) ) ); } /** * Instantiate a single service. From 7649063116725ca38a647990f94775a1e04d56fa Mon Sep 17 00:00:00 2001 From: Ivan Ruzevic Date: Fri, 5 Apr 2019 16:05:47 +0200 Subject: [PATCH 10/23] naming --- README.md | 2 +- composer.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6d1f9c618..efa97f0c2 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# WordPress Libs +# Eightshift Libs diff --git a/composer.json b/composer.json index b4b859ea4..d9fe252be 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "infinum/wordpress-libs", + "name": "infinum/eightshift-libs", "description": "WordPress libs developed by Eightshift theme to use in WordPress boilerplate.", "keywords": [ "composer", "installer", "plugin" @@ -15,8 +15,8 @@ } ], "support": { - "issues": "https://github.com/infinum/wordpress-libs/issues", - "source": "https://github.com/infinum/wordpress-libs" + "issues": "https://github.com/infinum/eightshift-libs/issues", + "source": "https://github.com/infinum/eightshift-libs" }, "require": { "php": "^5.6|^7", From d9ec7b8700aad2a57d3c940662f670d276c246b7 Mon Sep 17 00:00:00 2001 From: Ivan Ruzevic Date: Fri, 5 Apr 2019 16:49:22 +0200 Subject: [PATCH 11/23] adding blocks --- src/blocks/class-base-block.php | 129 +++++++++++++++++++ src/blocks/class-blocks.php | 100 ++++++++++++++ src/blocks/interface-block.php | 42 ++++++ src/class-main.php | 5 + src/interface-renderable.php | 1 + src/interface-service.php | 1 + src/rest-routes/interface-field-callable.php | 1 + src/rest-routes/interface-rest-callable.php | 1 + src/rest-routes/interface-route.php | 1 + 9 files changed, 281 insertions(+) create mode 100644 src/blocks/class-base-block.php create mode 100644 src/blocks/class-blocks.php create mode 100644 src/blocks/interface-block.php diff --git a/src/blocks/class-base-block.php b/src/blocks/class-base-block.php new file mode 100644 index 000000000..403c8e8a8 --- /dev/null +++ b/src/blocks/class-base-block.php @@ -0,0 +1,129 @@ + array( + 'type' => self::BLOCK_DEFAULT_TYPE, + 'default' => self::BLOCK_NAMESPACE . '/' . static::NAME, + ), + 'rootClass' => array( + 'type' => self::BLOCK_DEFAULT_TYPE, + 'default' => 'block-' . static::NAME, + ), + 'jsClass' => array( + 'type' => self::BLOCK_DEFAULT_TYPE, + 'default' => 'js-block-' . static::NAME, + ), + ); + + $this->attributes = array_merge( $this->attributes, $default_attributes ); + } + + /** + * Renders the block using a template in Infinum\Blocks\Templates namespace/folder. + * Template file must have the same name as the class-blockname file, for example: + * + * Block: class-heading.php + * Template: heading.php + * + * @param array $attributes Array of attributes as defined in block's index.js. + * @param string $content Block's content. + * + * @throws \Exception On missing attributes OR missing template. + * @echo string + * + * @since 1.0.0 + */ + public function render( array $attributes, string $content ) : string { + + // Block must have a defined name to find it's template. + // Make sure the class (block) extending this class (abstract Base_Block) + // has defined it's own name. + if ( static::NAME === self::NAME ) { + throw new \Exception( esc_html__( 'Trying to add_default_attributes() for block that hasnt defined NAME', 'infinum' ) ); + } + + $template_path = 'src/blocks/' . static::NAME . '/view/' . static::NAME . '.php'; + $template = locate_template( $template_path ); + + if ( empty( $template ) ) { + throw new \Exception( sprintf( esc_html__( 'Missing view template for block called: %1$s | Expecting a template in path: %2$s', 'infinum' ), static::NAME, $template_path ) ); + } + + // If everything is ok, return the contents of the template (return, NOT echo). + ob_start(); + include $template; + $output = ob_get_clean(); + unset( $template ); + return $output; + } +} diff --git a/src/blocks/class-blocks.php b/src/blocks/class-blocks.php new file mode 100644 index 000000000..404f4773e --- /dev/null +++ b/src/blocks/class-blocks.php @@ -0,0 +1,100 @@ +list = array( + 'section' => new Section\Section(), + 'heading' => new Heading\Heading(), + 'cf7-form' => new Cf7_Form\Cf7_Form(), + 'paragraph' => new Paragraph\Paragraph(), + 'image' => new Image\Image(), + 'image-gallery' => new Image_Gallery\Image_Gallery(), + 'cta-box' => new Cta_Box\Cta_Box(), + 'button' => new Button\Button(), + 'testimonials' => new Testimonials\Testimonials(), + 'gallery' => new Gallery\Gallery(), + 'location-map' => new Location_Map\Location_Map(), + 'image-text' => new Image_Text\Image_Text(), + ); + } + + /** + * Register all the hooks + * + * @since 1.0.0 + */ + public function register() : void { + add_action( 'init', [ $this, 'register_blocks' ] ); + } + + /** + * Add a new action to the collection to be registered with WordPress. + * + * @throws \Exception If there's a block in $this->list that doesn't extend "Block" class. + * + * @return void + * + * @since 1.0.0 + */ + public function register_blocks() : void { + if ( ! empty( $this->list ) ) { + foreach ( $this->list as $block ) { + if ( ! ( $block instanceof Block ) ) { + throw new \Exception( 'Trying to register a block that doesn\'t extend "Block" class' ); + } + $this->register_block( $block ); + } + } + } + + /** + * Registers a dynamic block with a corresponding render_callback defined in the block itself + * + * @param Block $block Block object. + * + * @return void + */ + protected function register_block( Block $block ) { + + $block->add_default_attributes(); + + register_block_type( + $block::BLOCK_NAMESPACE . '/' . $block::NAME, + array( + 'render_callback' => array( $block, 'render' ), + 'attributes' => $block->attributes, + ) + ); + + } +} diff --git a/src/blocks/interface-block.php b/src/blocks/interface-block.php new file mode 100644 index 000000000..4a7034030 --- /dev/null +++ b/src/blocks/interface-block.php @@ -0,0 +1,42 @@ +register_assets_manifest_data(); } + /** * Register the individual services of this plugin. * @@ -74,6 +76,7 @@ function( Service $service ) { protected function get_manifest_url() : string { return get_template_directory() . '/skin/public/manifest.json'; } + /** * Register bundled asset manifest * @@ -90,6 +93,7 @@ public function register_assets_manifest_data() { define( 'INF_ASSETS_MANIFEST', implode( ' ', file( $manifest ) ) ); } + /** * Instantiate a single service. * @@ -108,6 +112,7 @@ private function instantiate_service( $class ) { } return $service; } + /** * Get the list of services to register. * diff --git a/src/interface-renderable.php b/src/interface-renderable.php index 83dae45ca..02933a468 100644 --- a/src/interface-renderable.php +++ b/src/interface-renderable.php @@ -14,6 +14,7 @@ * An object that can be rendered. */ interface Renderable { + /** * Render the current Renderable. * diff --git a/src/interface-service.php b/src/interface-service.php index e239cb725..adaf77152 100644 --- a/src/interface-service.php +++ b/src/interface-service.php @@ -16,6 +16,7 @@ * @since 1.0.0 */ interface Service extends Registrable { + /** * Theme Name Constant * diff --git a/src/rest-routes/interface-field-callable.php b/src/rest-routes/interface-field-callable.php index af8c51f84..4b0134691 100644 --- a/src/rest-routes/interface-field-callable.php +++ b/src/rest-routes/interface-field-callable.php @@ -12,6 +12,7 @@ * Field interface that adds/extends fields in routes */ interface Field_Callable { + /** * Method that returns rest response * diff --git a/src/rest-routes/interface-rest-callable.php b/src/rest-routes/interface-rest-callable.php index d50de5c18..da4cb6148 100644 --- a/src/rest-routes/interface-rest-callable.php +++ b/src/rest-routes/interface-rest-callable.php @@ -12,6 +12,7 @@ * Route interface that adds routes */ interface Rest_Callable { + /** * Method that returns rest response * diff --git a/src/rest-routes/interface-route.php b/src/rest-routes/interface-route.php index ff5306070..757b3f785 100644 --- a/src/rest-routes/interface-route.php +++ b/src/rest-routes/interface-route.php @@ -14,6 +14,7 @@ * Route interface that adds routes */ interface Route extends Service { + /** * Alias for GET transport method. * From 4544172f2f18b5535a0ba0bc5c9015377acf100f Mon Sep 17 00:00:00 2001 From: Ivan Ruzevic Date: Mon, 8 Apr 2019 10:38:23 +0200 Subject: [PATCH 12/23] tests folder --- tests/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/.gitkeep diff --git a/tests/.gitkeep b/tests/.gitkeep new file mode 100644 index 000000000..e69de29bb From 6935f97c742f9d8c1af87e7bb503a3581f4024ff Mon Sep 17 00:00:00 2001 From: Ivan Ruzevic Date: Mon, 8 Apr 2019 10:51:40 +0200 Subject: [PATCH 13/23] adding custom post type --- src/custom-post-type/class-base-post-type.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/custom-post-type/class-base-post-type.php diff --git a/src/custom-post-type/class-base-post-type.php b/src/custom-post-type/class-base-post-type.php new file mode 100644 index 000000000..52945c51a --- /dev/null +++ b/src/custom-post-type/class-base-post-type.php @@ -0,0 +1,42 @@ +get_post_type_slug(), $this->get_post_type_arguments() ) + ); + } + + /** + * Get the slug to use for the custom post type. + * + * @return string Custom post type slug. + */ + abstract protected function get_post_type_slug() : string; + + /** + * Get the arguments that configure the custom post type. + * + * @return array Array of arguments. + */ + abstract protected function get_post_type_arguments() : array; +} From c97dffb699c6e18e0555b5b6463fc91d086cf513 Mon Sep 17 00:00:00 2001 From: Ivan Ruzevic Date: Mon, 8 Apr 2019 11:44:49 +0200 Subject: [PATCH 14/23] adding custom post type --- .../class-label-generator.php | 119 ++++++++++++++++++ src/exception/class-failed-to-load-view.php | 2 +- src/exception/class-invalid-callback.php | 2 +- src/exception/class-invalid-nouns.php | 34 +++++ src/exception/class-invalid-post-id.php | 2 +- src/exception/class-invalid-service.php | 2 +- src/exception/class-invalid-uri.php | 2 +- 7 files changed, 158 insertions(+), 5 deletions(-) create mode 100644 src/custom-post-type/class-label-generator.php create mode 100644 src/exception/class-invalid-nouns.php diff --git a/src/custom-post-type/class-label-generator.php b/src/custom-post-type/class-label-generator.php new file mode 100644 index 000000000..e94b6b57e --- /dev/null +++ b/src/custom-post-type/class-label-generator.php @@ -0,0 +1,119 @@ + esc_html_x( '%3$s', 'Post Type General Name', 'developer-portal' ), /* phpcs:disable */ + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'singular_name' => esc_html_x( '%1$s', 'Post Type Singular Name', 'developer-portal' ), /* phpcs:disable */ + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'menu_name' => esc_html__( '%3$s', 'developer-portal' ), /* phpcs:disable */ + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'name_admin_bar' => esc_html__( '%1$s', 'developer-portal' ), /* phpcs:disable */ + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'archives' => esc_html__( '%1$s Archives', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'attributes' => esc_html__( '%1$s Attributes', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'parent_item_colon' => esc_html__( 'Parent %1$s:', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'all_items' => esc_html__( 'All %3$s', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'add_new_item' => esc_html__( 'Add New %1$s', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'add_new' => esc_html__( 'Add New', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'new_item' => esc_html__( 'New %1$s', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'edit_item' => esc_html__( 'Edit %1$s', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'update_item' => esc_html__( 'Update %1$s', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'view_item' => esc_html__( 'View %1$s', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'view_items' => esc_html__( 'View %3$s', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'search_items' => esc_html__( 'Search %1$s', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'not_found' => esc_html__( 'Not found', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'not_found_in_trash' => esc_html__( 'Not found in Trash', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'featured_image' => esc_html__( 'Featured Image', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'set_featured_image' => esc_html__( 'Set featured image', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'remove_featured_image' => esc_html__( 'Remove featured image', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'use_featured_image' => esc_html__( 'Use as featured image', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'insert_into_item' => esc_html__( 'Insert into %2$s', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'uploaded_to_this_item' => esc_html__( 'Uploaded to this %2$s', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'items_list' => esc_html__( '%3$s list', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'items_list_navigation' => esc_html__( '%3$s list navigation', 'developer-portal' ), + /* Translators: %1$s uc singular, %2$s lc singular, %3$s uc plural, %4$s lc plural. */ + 'filter_items_list' => esc_html__( 'Filter %4$s list', 'developer-portal' ), + ]; + + return array_map( + function( $label ) use ( $nouns ) { + return sprintf( + $label, + $nouns[ self::SINGULAR_NAME_UC ], + $nouns[ self::SINGULAR_NAME_LC ], + $nouns[ self::PLURAL_NAME_UC ], + $nouns[ self::PLURAL_NAME_LC ] + ); + }, + $label_templates + ); + } +} diff --git a/src/exception/class-failed-to-load-view.php b/src/exception/class-failed-to-load-view.php index 2f27c3582..6472dcdbc 100644 --- a/src/exception/class-failed-to-load-view.php +++ b/src/exception/class-failed-to-load-view.php @@ -25,7 +25,7 @@ class Failed_To_Load_View extends \RuntimeException implements General_Exception */ public static function view_exception( $uri, $exception ) { $message = sprintf( - 'Could not load the View URI "%1$s". Reason: "%2$s".', + esc_html__( 'Could not load the View URI "%1$s". Reason: "%2$s".', 'eightshift-libs' ), $uri, $exception->getMessage() ); diff --git a/src/exception/class-invalid-callback.php b/src/exception/class-invalid-callback.php index 8769428ff..b2be30552 100644 --- a/src/exception/class-invalid-callback.php +++ b/src/exception/class-invalid-callback.php @@ -23,7 +23,7 @@ class Invalid_Callback extends \InvalidArgumentException implements General_Exce */ public static function from_callback( $callback ) { $message = sprintf( - 'The callback "%s" is not recognized and cannot be registered.', + esc_html__( 'The callback "%s" is not recognized and cannot be registered.', 'eightshift-libs' ), is_object( $callback ) ? get_class( $callback ) : (string) $callback diff --git a/src/exception/class-invalid-nouns.php b/src/exception/class-invalid-nouns.php new file mode 100644 index 000000000..3aef98123 --- /dev/null +++ b/src/exception/class-invalid-nouns.php @@ -0,0 +1,34 @@ + Date: Mon, 8 Apr 2019 11:49:16 +0200 Subject: [PATCH 15/23] adding custom post type --- src/custom-post-type/class-base-post-type.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/custom-post-type/class-base-post-type.php b/src/custom-post-type/class-base-post-type.php index 52945c51a..54b8072ff 100644 --- a/src/custom-post-type/class-base-post-type.php +++ b/src/custom-post-type/class-base-post-type.php @@ -22,7 +22,10 @@ abstract class Base_Post_Type implements Service { */ public function register() : void { add_action( - 'init', register_post_type( $this->get_post_type_slug(), $this->get_post_type_arguments() ) + 'init', + function() { + register_post_type( $this->get_post_type_slug(), $this->get_post_type_arguments() ); + } ); } From 76b95e7030653bca96496cc9096458458aa6af9c Mon Sep 17 00:00:00 2001 From: Ivan Ruzevic Date: Mon, 8 Apr 2019 11:55:13 +0200 Subject: [PATCH 16/23] adding custom taxonomy --- src/custom-taxonomy/class-base-taxonomy.php | 56 +++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/custom-taxonomy/class-base-taxonomy.php diff --git a/src/custom-taxonomy/class-base-taxonomy.php b/src/custom-taxonomy/class-base-taxonomy.php new file mode 100644 index 000000000..c87e992e0 --- /dev/null +++ b/src/custom-taxonomy/class-base-taxonomy.php @@ -0,0 +1,56 @@ +get_taxonomy_slug(), + [ $this->get_post_type_slug() ], + $this->get_taxonomy_arguments() + ); + } + ); + } + + /** + * Get the slug of the custom taxonomy + * + * @return string Custom taxonomy slug. + */ + abstract protected function get_taxonomy_slug() : string; + + /** + * Get the post type slug to use the taxonomy to + * + * @return string Custom post type slug. + */ + abstract protected function get_post_type_slug() : string; + + /** + * Get the arguments that configure the custom taxonomy. + * + * @return array Array of arguments. + */ + abstract protected function get_taxonomy_arguments() : array; +} From 543aef3784f7a56f05f89851a6346d91afee5749 Mon Sep 17 00:00:00 2001 From: Ivan Ruzevic Date: Mon, 8 Apr 2019 12:00:28 +0200 Subject: [PATCH 17/23] adding custom taxonomy --- src/exception/class-failed-to-load-view.php | 2 +- src/exception/class-invalid-callback.php | 2 +- src/exception/class-invalid-nouns.php | 2 +- src/exception/class-invalid-post-id.php | 2 +- src/exception/class-invalid-service.php | 2 +- src/exception/class-invalid-uri.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/exception/class-failed-to-load-view.php b/src/exception/class-failed-to-load-view.php index 6472dcdbc..8cdf772e0 100644 --- a/src/exception/class-failed-to-load-view.php +++ b/src/exception/class-failed-to-load-view.php @@ -25,7 +25,7 @@ class Failed_To_Load_View extends \RuntimeException implements General_Exception */ public static function view_exception( $uri, $exception ) { $message = sprintf( - esc_html__( 'Could not load the View URI "%1$s". Reason: "%2$s".', 'eightshift-libs' ), + esc_html__( 'Could not load the View URI: %1$s. Reason: %2$s.', 'eightshift-libs' ), $uri, $exception->getMessage() ); diff --git a/src/exception/class-invalid-callback.php b/src/exception/class-invalid-callback.php index b2be30552..c9c80e8c1 100644 --- a/src/exception/class-invalid-callback.php +++ b/src/exception/class-invalid-callback.php @@ -23,7 +23,7 @@ class Invalid_Callback extends \InvalidArgumentException implements General_Exce */ public static function from_callback( $callback ) { $message = sprintf( - esc_html__( 'The callback "%s" is not recognized and cannot be registered.', 'eightshift-libs' ), + esc_html__( 'The callback %s is not recognized and cannot be registered.', 'eightshift-libs' ), is_object( $callback ) ? get_class( $callback ) : (string) $callback diff --git a/src/exception/class-invalid-nouns.php b/src/exception/class-invalid-nouns.php index 3aef98123..0d7f34b53 100644 --- a/src/exception/class-invalid-nouns.php +++ b/src/exception/class-invalid-nouns.php @@ -25,7 +25,7 @@ class Invalid_Nouns extends \InvalidArgumentException implements General_Excepti */ public static function from_key( string $key ) { $message = sprintf( - esc_html__( 'The array of nouns passed into the Label_Generator is missing the "%s" noun.', 'eightshift-libs' ), + esc_html__( 'The array of nouns passed into the Label_Generator is missing the %s noun.', 'eightshift-libs' ), $key ); diff --git a/src/exception/class-invalid-post-id.php b/src/exception/class-invalid-post-id.php index 3d721f5c4..449ddcd53 100644 --- a/src/exception/class-invalid-post-id.php +++ b/src/exception/class-invalid-post-id.php @@ -22,7 +22,7 @@ class Invalid_Post_ID extends \InvalidArgumentException implements General_Excep */ public static function from_id( $id ) { $message = sprintf( - esc_html__( 'The post ID "%d" is not valid.', 'eightshift-libs' ), + esc_html__( 'The post ID %d is not valid.', 'eightshift-libs' ), $id ); diff --git a/src/exception/class-invalid-service.php b/src/exception/class-invalid-service.php index 9f54ae193..3f35ac348 100644 --- a/src/exception/class-invalid-service.php +++ b/src/exception/class-invalid-service.php @@ -23,7 +23,7 @@ class Invalid_Service extends \InvalidArgumentException implements General_Excep */ public static function from_service( $service ) { $message = sprintf( - esc_html__( 'The service "%s" is not recognized and cannot be registered.', 'eightshift-libs' ), + esc_html__( 'The service %s is not recognized and cannot be registered.', 'eightshift-libs' ), is_object( $service ) ? get_class( $service ) : (string) $service diff --git a/src/exception/class-invalid-uri.php b/src/exception/class-invalid-uri.php index 8d0fc3073..9b0fa8a52 100644 --- a/src/exception/class-invalid-uri.php +++ b/src/exception/class-invalid-uri.php @@ -24,7 +24,7 @@ class Invalid_URI extends \InvalidArgumentException implements General_Exception */ public static function from_uri( $uri ) { $message = sprintf( - esc_html__( 'The View URI "%s" is not accessible or readable.', 'eightshift-libs' ), + esc_html__( 'The View URI %s is not accessible or readable.', 'eightshift-libs' ), $uri ); From fffcd4853ce216b5aa6d0ab92caf8fc0a9ddf45d Mon Sep 17 00:00:00 2001 From: Ivan Ruzevic Date: Mon, 8 Apr 2019 16:58:44 +0200 Subject: [PATCH 18/23] adding blocks --- README.md | 2 + composer.json | 2 +- src/blocks/class-base-block.php | 74 +++++++++---- src/blocks/class-blocks.php | 100 ------------------ src/blocks/interface-block.php | 24 ++++- src/class-main.php | 34 ++++-- src/custom-post-type/class-base-post-type.php | 10 +- .../class-label-generator.php | 42 +++++++- src/custom-taxonomy/class-base-taxonomy.php | 10 ++ src/exception/class-failed-to-load-view.php | 2 + src/exception/class-invalid-callback.php | 2 + src/exception/class-invalid-nouns.php | 4 +- src/exception/class-invalid-post-id.php | 31 ------ src/exception/class-invalid-service.php | 2 + src/exception/class-invalid-uri.php | 33 ------ src/exception/class-missing-block-name.php | 28 +++++ src/exception/class-missing-block-view.php | 34 ++++++ src/exception/class-missing-manifest.php | 2 + src/interface-registrable.php | 4 +- src/interface-renderable.php | 2 + src/interface-service.php | 2 - src/rest-routes/interface-field-callable.php | 2 + src/rest-routes/interface-field.php | 2 + src/rest-routes/interface-rest-callable.php | 2 + src/rest-routes/interface-route.php | 17 ++- 25 files changed, 260 insertions(+), 207 deletions(-) delete mode 100644 src/blocks/class-blocks.php delete mode 100644 src/exception/class-invalid-post-id.php delete mode 100644 src/exception/class-invalid-uri.php create mode 100644 src/exception/class-missing-block-name.php create mode 100644 src/exception/class-missing-block-view.php diff --git a/README.md b/README.md index efa97f0c2..a0af4f34f 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ # Eightshift Libs + +This is a collection of Abstract classes and interfaces and some implementation methods used in WordPress boilerplate. This is and abstract implementations of WordPress methods that can be easily tested and reused. diff --git a/composer.json b/composer.json index d9fe252be..98b0a0275 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "infinum/eightshift-libs", - "description": "WordPress libs developed by Eightshift theme to use in WordPress boilerplate.", + "description": "WordPress libs developed by Eightshift team to use in WordPress boilerplate.", "keywords": [ "composer", "installer", "plugin" ], diff --git a/src/blocks/class-base-block.php b/src/blocks/class-base-block.php index 403c8e8a8..8d9a6c984 100644 --- a/src/blocks/class-base-block.php +++ b/src/blocks/class-base-block.php @@ -1,6 +1,6 @@ [ $this, 'render' ], + 'attributes' => $this->get_attributes(), + ) + ); + } + ); + } /** * Adds default attributes that are dynamically built for all blocks. @@ -60,32 +73,54 @@ abstract class Base_Block implements Block { * * @throws \Exception On missing block name. * - * @return void + * @return array + * + * @since 1.0.0 */ - public function add_default_attributes() : void { + public function get_default_attributes() : array { // Make sure the class (block) extending this class (abstract Base_Block) // has defined it's own name. if ( static::NAME === self::NAME ) { - throw new \Exception( esc_html__( 'Trying to add_default_attributes() for block that hasnt defined NAME', 'infinum' ) ); + throw Missing_Block_Name::message(); } - $default_attributes = array( + return [ 'blockName' => array( - 'type' => self::BLOCK_DEFAULT_TYPE, + 'type' => self::BLOCK_DEFAULT_ATTRIBUTE_TYPE, 'default' => self::BLOCK_NAMESPACE . '/' . static::NAME, ), 'rootClass' => array( - 'type' => self::BLOCK_DEFAULT_TYPE, + 'type' => self::BLOCK_DEFAULT_ATTRIBUTE_TYPE, 'default' => 'block-' . static::NAME, ), 'jsClass' => array( - 'type' => self::BLOCK_DEFAULT_TYPE, + 'type' => self::BLOCK_DEFAULT_ATTRIBUTE_TYPE, 'default' => 'js-block-' . static::NAME, ), - ); + ]; + } + + /** + * Get block attributes assigned inside block class. + * + * @return array + * + * @since 1.0.0 + */ + public function get_block_attributes() : array { + return []; + } - $this->attributes = array_merge( $this->attributes, $default_attributes ); + /** + * Get all block attributes. Default and block attributes. + * + * @return array + * + * @since 1.0.0 + */ + public function get_attributes() : array { + return array_merge( $this->get_default_attributes(), $this->get_block_attributes() ); } /** @@ -109,14 +144,15 @@ public function render( array $attributes, string $content ) : string { // Make sure the class (block) extending this class (abstract Base_Block) // has defined it's own name. if ( static::NAME === self::NAME ) { - throw new \Exception( esc_html__( 'Trying to add_default_attributes() for block that hasnt defined NAME', 'infinum' ) ); + throw Missing_Block_Name::message(); + throw Missing_Block_View::message(); } $template_path = 'src/blocks/' . static::NAME . '/view/' . static::NAME . '.php'; $template = locate_template( $template_path ); if ( empty( $template ) ) { - throw new \Exception( sprintf( esc_html__( 'Missing view template for block called: %1$s | Expecting a template in path: %2$s', 'infinum' ), static::NAME, $template_path ) ); + throw Missing_Block_View::message( static::NAME, $template_path ); } // If everything is ok, return the contents of the template (return, NOT echo). diff --git a/src/blocks/class-blocks.php b/src/blocks/class-blocks.php deleted file mode 100644 index 404f4773e..000000000 --- a/src/blocks/class-blocks.php +++ /dev/null @@ -1,100 +0,0 @@ -list = array( - 'section' => new Section\Section(), - 'heading' => new Heading\Heading(), - 'cf7-form' => new Cf7_Form\Cf7_Form(), - 'paragraph' => new Paragraph\Paragraph(), - 'image' => new Image\Image(), - 'image-gallery' => new Image_Gallery\Image_Gallery(), - 'cta-box' => new Cta_Box\Cta_Box(), - 'button' => new Button\Button(), - 'testimonials' => new Testimonials\Testimonials(), - 'gallery' => new Gallery\Gallery(), - 'location-map' => new Location_Map\Location_Map(), - 'image-text' => new Image_Text\Image_Text(), - ); - } - - /** - * Register all the hooks - * - * @since 1.0.0 - */ - public function register() : void { - add_action( 'init', [ $this, 'register_blocks' ] ); - } - - /** - * Add a new action to the collection to be registered with WordPress. - * - * @throws \Exception If there's a block in $this->list that doesn't extend "Block" class. - * - * @return void - * - * @since 1.0.0 - */ - public function register_blocks() : void { - if ( ! empty( $this->list ) ) { - foreach ( $this->list as $block ) { - if ( ! ( $block instanceof Block ) ) { - throw new \Exception( 'Trying to register a block that doesn\'t extend "Block" class' ); - } - $this->register_block( $block ); - } - } - } - - /** - * Registers a dynamic block with a corresponding render_callback defined in the block itself - * - * @param Block $block Block object. - * - * @return void - */ - protected function register_block( Block $block ) { - - $block->add_default_attributes(); - - register_block_type( - $block::BLOCK_NAMESPACE . '/' . $block::NAME, - array( - 'render_callback' => array( $block, 'render' ), - 'attributes' => $block->attributes, - ) - ); - - } -} diff --git a/src/blocks/interface-block.php b/src/blocks/interface-block.php index 4a7034030..619468760 100644 --- a/src/blocks/interface-block.php +++ b/src/blocks/interface-block.php @@ -20,9 +20,29 @@ interface Block { * - rootClass: Block's root (base) BEM CSS class, built in "block/$name" format (example: block-heading) * - jsClass: Block's js selector class, built in "js-block-$name" format (example: js-block-heading) * - * @return void + * @return array + * + * @since 1.0.0 + */ + public function get_default_attributes() : array; + + /** + * Get block attributes assigned inside block class. + * + * @return array + * + * @since 1.0.0 + */ + public function get_block_attributes() : array; + + /** + * Get all block attributes. Default and block attributes. + * + * @return array + * + * @since 1.0.0 */ - public function add_default_attributes() : void; + public function get_attributes() : array; /** * Renders the block using a template in Infinum\Blocks\Templates namespace/folder. diff --git a/src/class-main.php b/src/class-main.php index 710f4a465..dd73f36b6 100644 --- a/src/class-main.php +++ b/src/class-main.php @@ -19,7 +19,7 @@ * Also maintains the unique identifier of this theme as well as the current * version of the theme. */ -class Main implements Service { +abstract class Main implements Service { /** * Array of instantiated services. @@ -36,6 +36,10 @@ class Main implements Service { * themn in one place. * * @throws Exception\Invalid_Service If a service is not valid. + * + * @return void + * + * @since 1.0.0 */ public function register() : void { @@ -48,13 +52,19 @@ public function register() : void { * Register the individual services of this plugin. * * @throws Exception\Invalid_Service If a service is not valid. + * + * @return void + * + * @since 1.0.0 */ - public function register_services() { + public function register_services() : void { + // Bail early so we don't instantiate services twice. if ( ! empty( $this->services ) ) { return; } - $classes = $this->get_service_classes(); + + $classes = $this->get_service_classes(); $this->services = array_map( [ $this, 'instantiate_service' ], @@ -72,6 +82,8 @@ function( Service $service ) { * Provide menifest json url location. * * @return string + * + * @since 1.0.0 */ protected function get_manifest_url() : string { return get_template_directory() . '/skin/public/manifest.json'; @@ -81,9 +93,12 @@ protected function get_manifest_url() : string { * Register bundled asset manifest * * @throws Exception\Missing_Manifest Throws error if manifest is missing. + * * @return void + * + * @since 1.0.0 */ - public function register_assets_manifest_data() { + public function register_assets_manifest_data() : void { $manifest = $this->get_manifest_url(); if ( ! file_exists( $manifest ) ) { @@ -99,17 +114,22 @@ public function register_assets_manifest_data() { * * @param string $class Service class to instantiate. * - * @return Service * @throws Exception\Invalid_Service If the service is not valid. + * + * @return Service + * + * @since 1.0.0 */ private function instantiate_service( $class ) { if ( ! class_exists( $class ) ) { throw Exception\Invalid_Service::from_service( $class ); } + $service = new $class(); if ( ! $service instanceof Service ) { throw Exception\Invalid_Service::from_service( $service ); } + return $service; } @@ -119,8 +139,10 @@ private function instantiate_service( $class ) { * A list of classes which contain hooks. * * @return array Array of fully qualified class names. + * + * @since 1.0.0 */ - protected function get_service_classes() { + protected function get_service_classes() : array { return []; } } diff --git a/src/custom-post-type/class-base-post-type.php b/src/custom-post-type/class-base-post-type.php index 54b8072ff..8b5b55e9e 100644 --- a/src/custom-post-type/class-base-post-type.php +++ b/src/custom-post-type/class-base-post-type.php @@ -12,13 +12,15 @@ /** * Abstract class Base_Post_Type. - * - * @since 1.0.0 */ abstract class Base_Post_Type implements Service { /** * Register custom post type and taxonomy. + * + * @return void + * + * @since 1.0.0 */ public function register() : void { add_action( @@ -33,6 +35,8 @@ function() { * Get the slug to use for the custom post type. * * @return string Custom post type slug. + * + * @since 1.0.0 */ abstract protected function get_post_type_slug() : string; @@ -40,6 +44,8 @@ abstract protected function get_post_type_slug() : string; * Get the arguments that configure the custom post type. * * @return array Array of arguments. + * + * @since 1.0.0 */ abstract protected function get_post_type_arguments() : array; } diff --git a/src/custom-post-type/class-label-generator.php b/src/custom-post-type/class-label-generator.php index e94b6b57e..f20d52c41 100644 --- a/src/custom-post-type/class-label-generator.php +++ b/src/custom-post-type/class-label-generator.php @@ -12,16 +12,52 @@ /** * Class that generates lables for custom post type - * - * @since 1.0.0 */ final class Label_Generator { + /** + * Singular name UC Constant + * + * @var string + * + * @since 1.0.0 + */ const SINGULAR_NAME_UC = 'singular_name_uc'; + + /** + * Singular name LC Constant + * + * @var string + * + * @since 1.0.0 + */ const SINGULAR_NAME_LC = 'singular_name_lc'; + + /** + * Plural name UC Constant + * + * @var string + * + * @since 1.0.0 + */ const PLURAL_NAME_UC = 'plural_name_uc'; + + /** + * Plural name LC Constant + * + * @var string + * + * @since 1.0.0 + */ const PLURAL_NAME_LC = 'plural_name_lc'; + /** + * Requiered Nons Constant + * + * @var string + * + * @since 1.0.0 + */ const REQUIRED_NOUNS = [ self::SINGULAR_NAME_UC, self::SINGULAR_NAME_LC, @@ -37,6 +73,8 @@ final class Label_Generator { * * @return string[] array Array of labels. * @throws Invalid_Nouns Invalid nouns exception. + * + * @since 1.0.0 */ public function get_generated_labels( array $nouns ) : array { diff --git a/src/custom-taxonomy/class-base-taxonomy.php b/src/custom-taxonomy/class-base-taxonomy.php index c87e992e0..60097b1a6 100644 --- a/src/custom-taxonomy/class-base-taxonomy.php +++ b/src/custom-taxonomy/class-base-taxonomy.php @@ -19,6 +19,10 @@ abstract class Base_Taxonomy implements Service { /** * Register custom taxonomy. + * + * @return void + * + * @since 1.0.0 */ public function register() : void { add_action( @@ -37,6 +41,8 @@ function() { * Get the slug of the custom taxonomy * * @return string Custom taxonomy slug. + * + * @since 1.0.0 */ abstract protected function get_taxonomy_slug() : string; @@ -44,6 +50,8 @@ abstract protected function get_taxonomy_slug() : string; * Get the post type slug to use the taxonomy to * * @return string Custom post type slug. + * + * @since 1.0.0 */ abstract protected function get_post_type_slug() : string; @@ -51,6 +59,8 @@ abstract protected function get_post_type_slug() : string; * Get the arguments that configure the custom taxonomy. * * @return array Array of arguments. + * + * @since 1.0.0 */ abstract protected function get_taxonomy_arguments() : array; } diff --git a/src/exception/class-failed-to-load-view.php b/src/exception/class-failed-to-load-view.php index 8cdf772e0..fbe5843b8 100644 --- a/src/exception/class-failed-to-load-view.php +++ b/src/exception/class-failed-to-load-view.php @@ -22,6 +22,8 @@ class Failed_To_Load_View extends \RuntimeException implements General_Exception * @param \Exception $exception Exception that was thrown by the view file. * * @return static + * + * @since 1.0.0 */ public static function view_exception( $uri, $exception ) { $message = sprintf( diff --git a/src/exception/class-invalid-callback.php b/src/exception/class-invalid-callback.php index c9c80e8c1..a88560ce4 100644 --- a/src/exception/class-invalid-callback.php +++ b/src/exception/class-invalid-callback.php @@ -20,6 +20,8 @@ class Invalid_Callback extends \InvalidArgumentException implements General_Exce * @param string $callback Class name of the callback that was not recognized. * * @return static + * + * @since 1.0.0 */ public static function from_callback( $callback ) { $message = sprintf( diff --git a/src/exception/class-invalid-nouns.php b/src/exception/class-invalid-nouns.php index 0d7f34b53..867b35d9e 100644 --- a/src/exception/class-invalid-nouns.php +++ b/src/exception/class-invalid-nouns.php @@ -6,8 +6,6 @@ * @package Eightshift_Libs\Exception */ -declare( strict_types=1 ); - namespace Eightshift_Libs\Exception; /** @@ -22,6 +20,8 @@ class Invalid_Nouns extends \InvalidArgumentException implements General_Excepti * @param string $key Asset handle that is not valid. * * @return static + * + * @since 1.0.0 */ public static function from_key( string $key ) { $message = sprintf( diff --git a/src/exception/class-invalid-post-id.php b/src/exception/class-invalid-post-id.php deleted file mode 100644 index 449ddcd53..000000000 --- a/src/exception/class-invalid-post-id.php +++ /dev/null @@ -1,31 +0,0 @@ - Date: Mon, 8 Apr 2019 17:29:57 +0200 Subject: [PATCH 19/23] linting --- .gitignore | 1 + composer.json | 13 + composer.lock | 389 ++++++++++++++++++ phpcs.xml.dist | 22 + src/blocks/class-base-block.php | 11 +- src/blocks/interface-block.php | 2 +- src/class-main.php | 2 +- src/custom-post-type/class-base-post-type.php | 2 +- .../class-label-generator.php | 26 +- src/custom-taxonomy/class-base-taxonomy.php | 2 +- src/exception/class-failed-to-load-view.php | 2 +- src/exception/class-invalid-callback.php | 2 +- src/exception/class-invalid-nouns.php | 2 +- src/exception/class-invalid-service.php | 2 +- src/exception/class-missing-block-name.php | 2 +- src/exception/class-missing-block-view.php | 5 +- src/exception/class-missing-manifest.php | 4 +- src/exception/general-exception-interface.php | 2 +- src/interface-registrable.php | 2 +- src/interface-renderable.php | 2 +- src/interface-service.php | 2 +- src/rest-routes/interface-field-callable.php | 3 +- src/rest-routes/interface-field.php | 2 +- src/rest-routes/interface-rest-callable.php | 3 +- src/rest-routes/interface-route.php | 80 ++-- 25 files changed, 506 insertions(+), 79 deletions(-) create mode 100644 composer.lock create mode 100644 phpcs.xml.dist diff --git a/.gitignore b/.gitignore index e69de29bb..22d0d82f8 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +vendor diff --git a/composer.json b/composer.json index 98b0a0275..46b00002a 100644 --- a/composer.json +++ b/composer.json @@ -23,10 +23,23 @@ "composer-plugin-api": "^1.0" }, "require-dev": { + "infinum/coding-standards-wp": "*", + "dealerdirect/phpcodesniffer-composer-installer": "^0.5" }, "autoload": { "psr-4": { "Eightshift_Libs\\": "src/" } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "config": { + "sort-packages": true, + "optimize-autoloader": true, + "process-timeout": 2000 + }, + "scripts": { + "check-cs": "@php ./vendor/bin/phpcs --extensions=php --ignore=/vendor/", + "fix-cs": "@php ./vendor/bin/phpcbf --extensions=php --ignore=/vendor/" } } diff --git a/composer.lock b/composer.lock new file mode 100644 index 000000000..89e4cfa14 --- /dev/null +++ b/composer.lock @@ -0,0 +1,389 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "d55064de69258c66f6641394ff38aa85", + "packages": [], + "packages-dev": [ + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v0.5.0", + "source": { + "type": "git", + "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", + "reference": "e749410375ff6fb7a040a68878c656c2e610b132" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/e749410375ff6fb7a040a68878c656c2e610b132", + "reference": "e749410375ff6fb7a040a68878c656c2e610b132", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0", + "php": "^5.3|^7", + "squizlabs/php_codesniffer": "^2|^3" + }, + "require-dev": { + "composer/composer": "*", + "phpcompatibility/php-compatibility": "^9.0", + "sensiolabs/security-checker": "^4.1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "time": "2018-10-26T13:21:45+00:00" + }, + { + "name": "infinum/coding-standards-wp", + "version": "0.4.1", + "source": { + "type": "git", + "url": "https://github.com/infinum/coding-standards-wp.git", + "reference": "87aa3608eb064308291f8f7f3d3d30a8fd1ea296" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/infinum/coding-standards-wp/zipball/87aa3608eb064308291f8f7f3d3d30a8fd1ea296", + "reference": "87aa3608eb064308291f8f7f3d3d30a8fd1ea296", + "shasum": "" + }, + "require": { + "php": ">=5.6", + "phpcompatibility/phpcompatibility-wp": "^2.0", + "squizlabs/php_codesniffer": "^3.3.0", + "wp-coding-standards/wpcs": "^1.0.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3", + "phpcompatibility/php-compatibility": "^9.0", + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0", + "roave/security-advisories": "dev-master" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/infinum/coding-standards-wp/graphs/contributors" + } + ], + "description": "Infinum WordPress Coding Standards", + "homepage": "https://github.com/infinum/coding-standards-wp", + "keywords": [ + "Eightshift", + "Infinum", + "phpcs", + "standards", + "wordpress" + ], + "time": "2018-11-15T12:49:58+00:00" + }, + { + "name": "phpcompatibility/php-compatibility", + "version": "9.1.1", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibility.git", + "reference": "2b63c5d284ab8857f7b1d5c240ddb507a6b2293c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/2b63c5d284ab8857f7b1d5c240ddb507a6b2293c", + "reference": "2b63c5d284ab8857f7b1d5c240ddb507a6b2293c", + "shasum": "" + }, + "require": { + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.3 || ^3.0.2" + }, + "conflict": { + "squizlabs/php_codesniffer": "2.6.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors" + }, + { + "name": "Wim Godden", + "homepage": "https://github.com/wimg", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + } + ], + "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.", + "homepage": "http://techblog.wimgodden.be/tag/codesniffer/", + "keywords": [ + "compatibility", + "phpcs", + "standards" + ], + "time": "2018-12-30T23:16:27+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-paragonie", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", + "reference": "9160de79fcd683b5c99e9c4133728d91529753ea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/9160de79fcd683b5c99e9c4133728d91529753ea", + "reference": "9160de79fcd683b5c99e9c4133728d91529753ea", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by the Paragonie polyfill libraries.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "paragonie", + "phpcs", + "polyfill", + "standards" + ], + "time": "2018-12-16T19:10:44+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-wp", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git", + "reference": "cb303f0067cd5b366a41d4fb0e254fb40ff02efd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/cb303f0067cd5b366a41d4fb0e254fb40ff02efd", + "reference": "cb303f0067cd5b366a41d4fb0e254fb40ff02efd", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0", + "phpcompatibility/phpcompatibility-paragonie": "^1.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "phpcs", + "standards", + "wordpress" + ], + "time": "2018-10-07T18:31:37+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.4.1", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "5b4333b4010625d29580eb4a41f1e53251be6baa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/5b4333b4010625d29580eb4a41f1e53251be6baa", + "reference": "5b4333b4010625d29580eb4a41f1e53251be6baa", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2019-03-19T03:22:27+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git", + "reference": "f328bcafd97377e8e5e5d7b244d5ddbf301a3a5c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/f328bcafd97377e8e5e5d7b244d5ddbf301a3a5c", + "reference": "f328bcafd97377e8e5e5d7b244d5ddbf301a3a5c", + "shasum": "" + }, + "require": { + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.9.0 || ^3.0.2" + }, + "require-dev": { + "phpcompatibility/php-compatibility": "^9.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", + "keywords": [ + "phpcs", + "standards", + "wordpress" + ], + "time": "2018-12-18T09:43:51+00:00" + } + ], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": true, + "prefer-lowest": false, + "platform": { + "php": "^5.6|^7" + }, + "platform-dev": [] +} diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 000000000..6ece537b3 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,22 @@ + + + Loader for the Infinum coding standards for WordPress. + + + + + 0 + + + + 0 + + + + 0 + + + + 0 + + diff --git a/src/blocks/class-base-block.php b/src/blocks/class-base-block.php index 8d9a6c984..593744834 100644 --- a/src/blocks/class-base-block.php +++ b/src/blocks/class-base-block.php @@ -2,7 +2,7 @@ /** * File that holds base abstract class for Gutenberg blocks registration * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Blocks */ @@ -130,22 +130,21 @@ public function get_attributes() : array { * Block: class-heading.php * Template: heading.php * - * @param array $attributes Array of attributes as defined in block's index.js. - * @param string $content Block's content. + * @param array $attributes Array of attributes as defined in block's index.js. + * @param string $content Block's content. * * @throws \Exception On missing attributes OR missing template. - * @echo string + * @echo string * * @since 1.0.0 */ - public function render( array $attributes, string $content ) : string { + public function render( array $attributes, string $content ) : string { //phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed // Block must have a defined name to find it's template. // Make sure the class (block) extending this class (abstract Base_Block) // has defined it's own name. if ( static::NAME === self::NAME ) { throw Missing_Block_Name::message(); - throw Missing_Block_View::message(); } $template_path = 'src/blocks/' . static::NAME . '/view/' . static::NAME . '.php'; diff --git a/src/blocks/interface-block.php b/src/blocks/interface-block.php index 619468760..5cda47201 100644 --- a/src/blocks/interface-block.php +++ b/src/blocks/interface-block.php @@ -2,7 +2,7 @@ /** * Interface for blocks. * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Blocks */ diff --git a/src/class-main.php b/src/class-main.php index dd73f36b6..8cd93f510 100644 --- a/src/class-main.php +++ b/src/class-main.php @@ -2,7 +2,7 @@ /** * File containing the main theme class * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Core */ diff --git a/src/custom-post-type/class-base-post-type.php b/src/custom-post-type/class-base-post-type.php index 8b5b55e9e..e22dbfdf8 100644 --- a/src/custom-post-type/class-base-post-type.php +++ b/src/custom-post-type/class-base-post-type.php @@ -2,7 +2,7 @@ /** * File that holds base abstract class for custom post type registration * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Custom_Post_Type */ diff --git a/src/custom-post-type/class-label-generator.php b/src/custom-post-type/class-label-generator.php index f20d52c41..9aa251c5f 100644 --- a/src/custom-post-type/class-label-generator.php +++ b/src/custom-post-type/class-label-generator.php @@ -2,7 +2,7 @@ /** * File containing label generator class * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Custom_Post_Type */ @@ -40,7 +40,7 @@ final class Label_Generator { * * @since 1.0.0 */ - const PLURAL_NAME_UC = 'plural_name_uc'; + const PLURAL_NAME_UC = 'plural_name_uc'; /** * Plural name LC Constant @@ -49,7 +49,7 @@ final class Label_Generator { * * @since 1.0.0 */ - const PLURAL_NAME_LC = 'plural_name_lc'; + const PLURAL_NAME_LC = 'plural_name_lc'; /** * Requiered Nons Constant @@ -142,16 +142,16 @@ public function get_generated_labels( array $nouns ) : array { ]; return array_map( - function( $label ) use ( $nouns ) { - return sprintf( - $label, - $nouns[ self::SINGULAR_NAME_UC ], - $nouns[ self::SINGULAR_NAME_LC ], - $nouns[ self::PLURAL_NAME_UC ], - $nouns[ self::PLURAL_NAME_LC ] - ); - }, - $label_templates + function( $label ) use ( $nouns ) { + return sprintf( + $label, + $nouns[ self::SINGULAR_NAME_UC ], + $nouns[ self::SINGULAR_NAME_LC ], + $nouns[ self::PLURAL_NAME_UC ], + $nouns[ self::PLURAL_NAME_LC ] + ); + }, + $label_templates ); } } diff --git a/src/custom-taxonomy/class-base-taxonomy.php b/src/custom-taxonomy/class-base-taxonomy.php index 60097b1a6..0db369850 100644 --- a/src/custom-taxonomy/class-base-taxonomy.php +++ b/src/custom-taxonomy/class-base-taxonomy.php @@ -2,7 +2,7 @@ /** * File that holds base abstract class for custom taxonomy registration * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Custom_Taxonomy */ diff --git a/src/exception/class-failed-to-load-view.php b/src/exception/class-failed-to-load-view.php index fbe5843b8..2a6e3b038 100644 --- a/src/exception/class-failed-to-load-view.php +++ b/src/exception/class-failed-to-load-view.php @@ -2,7 +2,7 @@ /** * File containing failed to load view class * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Exception */ diff --git a/src/exception/class-invalid-callback.php b/src/exception/class-invalid-callback.php index a88560ce4..4a400ace1 100644 --- a/src/exception/class-invalid-callback.php +++ b/src/exception/class-invalid-callback.php @@ -2,7 +2,7 @@ /** * File containing the invalid callback exception class * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Exception */ diff --git a/src/exception/class-invalid-nouns.php b/src/exception/class-invalid-nouns.php index 867b35d9e..c1256b0cd 100644 --- a/src/exception/class-invalid-nouns.php +++ b/src/exception/class-invalid-nouns.php @@ -2,7 +2,7 @@ /** * File containing invalid nouns exception * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Exception */ diff --git a/src/exception/class-invalid-service.php b/src/exception/class-invalid-service.php index bf9b7d31b..e36095435 100644 --- a/src/exception/class-invalid-service.php +++ b/src/exception/class-invalid-service.php @@ -2,7 +2,7 @@ /** * File containing the invalid service exception class * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Exception */ diff --git a/src/exception/class-missing-block-name.php b/src/exception/class-missing-block-name.php index d014e1bf1..11f43bb6c 100644 --- a/src/exception/class-missing-block-name.php +++ b/src/exception/class-missing-block-name.php @@ -2,7 +2,7 @@ /** * File containing invalid Block name exception * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Exception */ diff --git a/src/exception/class-missing-block-view.php b/src/exception/class-missing-block-view.php index 46b2d965e..e7d7ecc65 100644 --- a/src/exception/class-missing-block-view.php +++ b/src/exception/class-missing-block-view.php @@ -2,7 +2,7 @@ /** * File containing invalid Block view exception * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Exception */ @@ -16,7 +16,8 @@ class Missing_Block_View extends \InvalidArgumentException implements General_Ex /** * Create a new instance of the exception for an missing block view. * - * @param string $key Asset handle that is not valid. + * @param string $name Block name. + * @param string $path Path to block on disk. * * @return static * diff --git a/src/exception/class-missing-manifest.php b/src/exception/class-missing-manifest.php index 147c63ed8..1b346ea88 100644 --- a/src/exception/class-missing-manifest.php +++ b/src/exception/class-missing-manifest.php @@ -2,7 +2,7 @@ /** * File containing the failure exception class when assets aren't bundled * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Exception */ @@ -18,7 +18,7 @@ class Missing_Manifest extends \InvalidArgumentException implements General_Exce * a manifest file is missing. * * @param string $message Error message to show on - * thrown exception. + * thrown exception. * * @return static * diff --git a/src/exception/general-exception-interface.php b/src/exception/general-exception-interface.php index e0dcec8c0..c5db6146b 100644 --- a/src/exception/general-exception-interface.php +++ b/src/exception/general-exception-interface.php @@ -2,7 +2,7 @@ /** * File containing general exception interface * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Exception */ diff --git a/src/interface-registrable.php b/src/interface-registrable.php index 8325a2aff..05d4c7ed4 100644 --- a/src/interface-registrable.php +++ b/src/interface-registrable.php @@ -2,7 +2,7 @@ /** * File that holds the registrable interface. * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Core */ diff --git a/src/interface-renderable.php b/src/interface-renderable.php index 0f177df96..fc40dbf6d 100644 --- a/src/interface-renderable.php +++ b/src/interface-renderable.php @@ -2,7 +2,7 @@ /** * File that holds the renderable interface. * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Core */ diff --git a/src/interface-service.php b/src/interface-service.php index 32e331e0f..0870498b3 100644 --- a/src/interface-service.php +++ b/src/interface-service.php @@ -2,7 +2,7 @@ /** * File that holds Has_Activation interface * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Core */ diff --git a/src/rest-routes/interface-field-callable.php b/src/rest-routes/interface-field-callable.php index 6f1162141..a2f782297 100644 --- a/src/rest-routes/interface-field-callable.php +++ b/src/rest-routes/interface-field-callable.php @@ -2,7 +2,7 @@ /** * File containing field callable interface * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Routes */ @@ -20,6 +20,7 @@ interface Field_Callable { * @param string $attr Rest field/attr string identifier from the second parameter of your register_rest_field() declaration. * @param object $request Full request payload – as a WP_REST_Request object. * @param string $object_type The object type which the field is registered against. Typically first parameter of your register_rest_field() declaration. + * * @return mixed If response generated an error, WP_Error, if response * is already an instance, WP_HTTP_Response, otherwise * returns a new WP_REST_Response instance. diff --git a/src/rest-routes/interface-field.php b/src/rest-routes/interface-field.php index 80955ad08..24d930ddd 100644 --- a/src/rest-routes/interface-field.php +++ b/src/rest-routes/interface-field.php @@ -2,7 +2,7 @@ /** * File containing type interface * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Routes */ diff --git a/src/rest-routes/interface-rest-callable.php b/src/rest-routes/interface-rest-callable.php index ce917eb22..95476bb52 100644 --- a/src/rest-routes/interface-rest-callable.php +++ b/src/rest-routes/interface-rest-callable.php @@ -2,7 +2,7 @@ /** * File containing rest callable interface * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Routes */ @@ -17,6 +17,7 @@ interface Rest_Callable { * Method that returns rest response * * @param \WP_REST_Request $request Data got from enpoint url. + * * @return WP_REST_Response|mixed If response generated an error, WP_Error, if response * is already an instance, WP_HTTP_Response, otherwise * returns a new WP_REST_Response instance. diff --git a/src/rest-routes/interface-route.php b/src/rest-routes/interface-route.php index 2e1d658d0..40f23fdb1 100644 --- a/src/rest-routes/interface-route.php +++ b/src/rest-routes/interface-route.php @@ -2,7 +2,7 @@ /** * File containing type interface * - * @since 1.0.0 + * @since 1.0.0 * @package Eightshift_Libs\Routes */ @@ -15,50 +15,50 @@ */ interface Route extends Service { - /** - * Alias for GET transport method. - * - * @var string - * - * @since 1.0.0 - */ - const READABLE = 'GET'; + /** + * Alias for GET transport method. + * + * @var string + * + * @since 1.0.0 + */ + const READABLE = 'GET'; - /** - * Alias for POST transport method. - * - * @var string - * - * @since 1.0.0 - */ - const CREATABLE = 'POST'; + /** + * Alias for POST transport method. + * + * @var string + * + * @since 1.0.0 + */ + const CREATABLE = 'POST'; /** - * Alias for PATCH transport method. - * - * @var string - * - * @since 1.0.0 - */ - const EDITABLE = 'PATCH'; + * Alias for PATCH transport method. + * + * @var string + * + * @since 1.0.0 + */ + const EDITABLE = 'PATCH'; - /** - * Alias for PUT transport method. - * - * @var string - * - * @since 1.0.0 - */ - const UPDATEABLE = 'PUT'; + /** + * Alias for PUT transport method. + * + * @var string + * + * @since 1.0.0 + */ + const UPDATEABLE = 'PUT'; - /** - * Alias for DELETE transport method. - * - * @var string - * - * @since 1.0.0 - */ - const DELETABLE = 'DELETE'; + /** + * Alias for DELETE transport method. + * + * @var string + * + * @since 1.0.0 + */ + const DELETABLE = 'DELETE'; /** * Method for adding custom routes From f2f413f6d884f638f2fef1c379a149d1a93e8223 Mon Sep 17 00:00:00 2001 From: Ivan Ruzevic Date: Mon, 8 Apr 2019 17:43:49 +0200 Subject: [PATCH 20/23] travis --- .travis.yml | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..ce1973f8c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,64 @@ +sudo: false + +dist: trusty + +language: php + +php: + - 7.0 + - 7.1 + - 7.2 + - 7.3 + +notifications: + email: + on_success: never + on_failure: change + +branches: + only: + - master + - development + +cache: + apt: true + directories: + - vendor + - node_modules + - composer + - $HOME/.composer/cache + +matrix: + fast_finish: true + include: + - php: 7.3 + env: WP_VERSION=latest WP_MULTISITE=0 + - php: 7.2 + env: WP_VERSION=latest WP_MULTISITE=0 + - php: 7.2 + env: WP_VERSION=latest WP_MULTISITE=1 + - php: 7.1 + env: WP_VERSION=latest WP_MULTISITE=0 + - php: 7.0 + env: WP_VERSION=latest WP_MULTISITE=1 + + allow_failures: + # Allow failures for unstable builds. + - php: nightly + +before_install: + # Speed up build time by disabling Xdebug. + # https://johnblackbourn.com/reducing-travis-ci-build-times-for-wordpress-projects/ + # https://twitter.com/kelunik/status/954242454676475904 + - phpenv config-rm xdebug.ini || echo 'No xdebug config.' + # Install PHP CodeSniffer. + - composer self-update + - composer clearcache + - composer install + - phpenv rehash + +script: + # Search for PHP syntax errors. + - find -L . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l + # Run PHPCS. + - composer check-cs . -- --runtime-set ignore_warnings_on_exit 1 From 6d72e05ff0cf929d0edec965305fb1f92c4ce7fc Mon Sep 17 00:00:00 2001 From: Ivan Ruzevic Date: Mon, 8 Apr 2019 17:52:46 +0200 Subject: [PATCH 21/23] linting --- examples/admin/register-post-type.php | 72 +++++++++++++++++++++++++ examples/admin/register-taxonomy.php | 76 +++++++++++++++++++++++++++ examples/blocks/heading/heading.php | 51 ++++++++++++++++++ examples/includes/main.php | 41 +++++++++++++++ 4 files changed, 240 insertions(+) create mode 100644 examples/admin/register-post-type.php create mode 100644 examples/admin/register-taxonomy.php create mode 100644 examples/blocks/heading/heading.php create mode 100644 examples/includes/main.php diff --git a/examples/admin/register-post-type.php b/examples/admin/register-post-type.php new file mode 100644 index 000000000..9323331ae --- /dev/null +++ b/examples/admin/register-post-type.php @@ -0,0 +1,72 @@ + esc_html_x( 'FAQ', 'post type upper case singular name', 'eightshift-libs' ), + Label_Generator::SINGULAR_NAME_LC => esc_html_x( 'faq', 'post type lower case singular name', 'eightshift-libs' ), + Label_Generator::PLURAL_NAME_UC => esc_html_x( 'FAQs', 'post type upper case plural name', 'eightshift-libs' ), + Label_Generator::PLURAL_NAME_LC => esc_html_x( 'faqs', 'post type lower case plural name', 'eightshift-libs' ), + ]; + + return [ + 'label' => $nouns[ Label_Generator::SINGULAR_NAME_UC ], + 'labels' => ( new Label_Generator() )->get_generated_labels( $nouns ), + 'public' => true, + 'menu_position' => 50, + 'menu_icon' => self::MENU_ICON, + 'supports' => array( 'title', 'revisions', 'editor' ), + 'has_archive' => false, + 'show_in_rest' => true, + 'publicly_queryable' => true, + 'capability_type' => 'page', + 'map_meta_cap' => true, + 'can_export' => true, + ]; + } +} diff --git a/examples/admin/register-taxonomy.php b/examples/admin/register-taxonomy.php new file mode 100644 index 000000000..e197daf67 --- /dev/null +++ b/examples/admin/register-taxonomy.php @@ -0,0 +1,76 @@ + esc_html_x( 'FAQ category', 'post type upper case singular name', 'eighshift-libs' ), + Label_Generator::SINGULAR_NAME_LC => esc_html_x( 'faq category', 'post type lower case singular name', 'eighshift-libs' ), + Label_Generator::PLURAL_NAME_UC => esc_html_x( 'FAQ categories', 'post type upper case plural name', 'eighshift-libs' ), + Label_Generator::PLURAL_NAME_LC => esc_html_x( 'faq categories', 'post type lower case plural name', 'eighshift-libs' ), + ]; + + return [ + 'label' => $nouns[ Label_Generator::SINGULAR_NAME_UC ], + 'labels' => ( new Label_Generator() )->get_generated_labels( $nouns ), + 'hierarchical' => true, + 'show_ui' => true, + 'show_admin_column' => true, + 'update_count_callback' => '_update_post_term_count', + 'query_var' => true, + ]; + } +} diff --git a/examples/blocks/heading/heading.php b/examples/blocks/heading/heading.php new file mode 100644 index 000000000..72494c787 --- /dev/null +++ b/examples/blocks/heading/heading.php @@ -0,0 +1,51 @@ + array( + 'type' => 'string', + ), + 'level' => array( + 'type' => 'int', + 'default' => '2', + ), + 'styleAlign' => array( + 'type' => 'string', + 'default' => 'center', + ), + 'styleSize' => array( + 'type' => 'string', + 'default' => 'huge', + ), + ); + } +} diff --git a/examples/includes/main.php b/examples/includes/main.php new file mode 100644 index 000000000..aabfb0037 --- /dev/null +++ b/examples/includes/main.php @@ -0,0 +1,41 @@ + Array of fully qualified class names. + */ + protected function get_service_classes() : array { + return [ + Admin\Admin::class, + ]; + } +} From 3898339789d6b3e94917e477123db5e97a6a3f54 Mon Sep 17 00:00:00 2001 From: Ivan Ruzevic Date: Tue, 9 Apr 2019 10:44:22 +0200 Subject: [PATCH 22/23] fixes --- README.md | 2 +- composer.json | 11 ++-- ...-type.php => class-register-post-type.php} | 6 +- ...xonomy.php => class-register-taxonomy.php} | 7 ++- .../{heading.php => class-heading.php} | 12 ++-- .../includes/{main.php => class-main.php} | 6 +- phpcs.xml.dist | 4 +- src/blocks/class-attribute-type-enums.php | 60 +++++++++++++++++++ src/blocks/class-base-block.php | 33 ++++------ src/blocks/interface-block.php | 14 +++++ src/class-main.php | 2 +- .../class-label-generator.php | 2 + src/exception/class-missing-block-name.php | 28 --------- ...block-view.php => class-missing-block.php} | 21 +++++-- src/interface-service.php | 18 ------ ...lable.php => interface-callable-field.php} | 2 +- ...llable.php => interface-callable-rest.php} | 2 +- 17 files changed, 132 insertions(+), 98 deletions(-) rename examples/admin/{register-post-type.php => class-register-post-type.php} (95%) rename examples/admin/{register-taxonomy.php => class-register-taxonomy.php} (95%) rename examples/blocks/heading/{heading.php => class-heading.php} (73%) rename examples/includes/{main.php => class-main.php} (88%) create mode 100644 src/blocks/class-attribute-type-enums.php delete mode 100644 src/exception/class-missing-block-name.php rename src/exception/{class-missing-block-view.php => class-missing-block.php} (52%) rename src/rest-routes/{interface-field-callable.php => interface-callable-field.php} (97%) rename src/rest-routes/{interface-rest-callable.php => interface-callable-rest.php} (96%) diff --git a/README.md b/README.md index a0af4f34f..ae733528e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # Eightshift Libs -This is a collection of Abstract classes and interfaces and some implementation methods used in WordPress boilerplate. This is and abstract implementations of WordPress methods that can be easily tested and reused. +TBD diff --git a/composer.json b/composer.json index 46b00002a..69f8be61a 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "infinum/eightshift-libs", - "description": "WordPress libs developed by Eightshift team to use in WordPress boilerplate.", + "description": "WordPress libs developed by Eightshift team to use in modern WordPress.", "keywords": [ "composer", "installer", "plugin" ], @@ -19,11 +19,10 @@ "source": "https://github.com/infinum/eightshift-libs" }, "require": { - "php": "^5.6|^7", - "composer-plugin-api": "^1.0" + "php": ">=7.0" }, "require-dev": { - "infinum/coding-standards-wp": "*", + "infinum/coding-standards-wp": "^0.4.1", "dealerdirect/phpcodesniffer-composer-installer": "^0.5" }, "autoload": { @@ -39,7 +38,7 @@ "process-timeout": 2000 }, "scripts": { - "check-cs": "@php ./vendor/bin/phpcs --extensions=php --ignore=/vendor/", - "fix-cs": "@php ./vendor/bin/phpcbf --extensions=php --ignore=/vendor/" + "check-cs": "@php ./vendor/bin/phpcs", + "fix-cs": "@php ./vendor/bin/phpcbf" } } diff --git a/examples/admin/register-post-type.php b/examples/admin/class-register-post-type.php similarity index 95% rename from examples/admin/register-post-type.php rename to examples/admin/class-register-post-type.php index 9323331ae..3affd0477 100644 --- a/examples/admin/register-post-type.php +++ b/examples/admin/class-register-post-type.php @@ -3,10 +3,10 @@ * File that holds faq custom post type registration details * * @since 1.0.0 - * @package Inf_Theme\Admin + * @package Custom_Namespace\Admin */ -namespace Inf_Theme\Admin; +namespace Custom_Namespace\Admin; use Eightshift_Libs\Custom_Post_Type\Base_Post_Type; use Eightshift_Libs\Custom_Post_Type\Label_Generator; @@ -23,7 +23,7 @@ final class Faq extends Base_Post_Type { * * @var string */ - const POST_TYPE_SLUG = 'faq-type'; + const POST_TYPE_SLUG = 'faq'; /** * The custom post type menu icon diff --git a/examples/admin/register-taxonomy.php b/examples/admin/class-register-taxonomy.php similarity index 95% rename from examples/admin/register-taxonomy.php rename to examples/admin/class-register-taxonomy.php index e197daf67..1c8c94924 100644 --- a/examples/admin/register-taxonomy.php +++ b/examples/admin/class-register-taxonomy.php @@ -3,14 +3,15 @@ * File that holds taxonomy class for fax taxonomy registration * * @since 1.0.0 - * @package Inf_Theme\Admin + * @package Custom_Namespace\Admin */ -namespace Inf_Theme\Admin; +namespace Custom_Namespace\Admin; use Eightshift_Libs\Custom_Taxonomy\Base_Taxonomy; use Eightshift_Libs\Custom_Post_Type\Label_Generator; -use Inf_Theme\Admin\Faq; + +use Custom_Namespace\Admin\Faq; /** * Class Faq_Taxonomy. diff --git a/examples/blocks/heading/heading.php b/examples/blocks/heading/class-heading.php similarity index 73% rename from examples/blocks/heading/heading.php rename to examples/blocks/heading/class-heading.php index 72494c787..c259d09e8 100644 --- a/examples/blocks/heading/heading.php +++ b/examples/blocks/heading/class-heading.php @@ -3,10 +3,10 @@ * All info regarding the Heading block * * @since 1.0.0 - * @package Inf_Theme\Blocks\Heading + * @package Custom_Namespace\Blocks\Heading */ -namespace Inf_Theme\Blocks\Heading; +namespace Custom_Namespace\Blocks\Heading; use Eightshift_Libs\Blocks\Base_Block; @@ -32,18 +32,18 @@ class Heading extends Base_Block { public function get_block_attributes() : array { return array( 'content' => array( - 'type' => 'string', + 'type' => parent::TYPE_STRING, ), 'level' => array( - 'type' => 'int', + 'type' => parent::TYPE_NUMBER, 'default' => '2', ), 'styleAlign' => array( - 'type' => 'string', + 'type' => parent::TYPE_STRING, 'default' => 'center', ), 'styleSize' => array( - 'type' => 'string', + 'type' => parent::TYPE_STRING, 'default' => 'huge', ), ); diff --git a/examples/includes/main.php b/examples/includes/class-main.php similarity index 88% rename from examples/includes/main.php rename to examples/includes/class-main.php index aabfb0037..771cf621b 100644 --- a/examples/includes/main.php +++ b/examples/includes/class-main.php @@ -6,14 +6,14 @@ * theme-facing side of the site and the admin area. * * @since 1.0.0 - * @package Inf_Theme\Includes + * @package Custom_Namespace\Includes */ -namespace Inf_Theme\Includes; +namespace Custom_Namespace\Includes; use Eightshift_Libs\Core\Main as LibMain; -use Inf_Theme\Admin; +use Custom_Namespace\Admin; /** * The main start class. diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 6ece537b3..81950c05b 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -1,6 +1,6 @@ - - Loader for the Infinum coding standards for WordPress. + + Eightshift Library uses extended WordPress coding standards with some minor corections. TBD diff --git a/src/blocks/class-attribute-type-enums.php b/src/blocks/class-attribute-type-enums.php new file mode 100644 index 000000000..7eb51a564 --- /dev/null +++ b/src/blocks/class-attribute-type-enums.php @@ -0,0 +1,60 @@ + array( - 'type' => self::BLOCK_DEFAULT_ATTRIBUTE_TYPE, + 'type' => parent::TYPE_STRING, 'default' => self::BLOCK_NAMESPACE . '/' . static::NAME, ), 'rootClass' => array( - 'type' => self::BLOCK_DEFAULT_ATTRIBUTE_TYPE, + 'type' => parent::TYPE_STRING, 'default' => 'block-' . static::NAME, ), 'jsClass' => array( - 'type' => self::BLOCK_DEFAULT_ATTRIBUTE_TYPE, + 'type' => parent::TYPE_STRING, 'default' => 'js-block-' . static::NAME, ), ]; @@ -138,20 +129,20 @@ public function get_attributes() : array { * * @since 1.0.0 */ - public function render( array $attributes, string $content ) : string { //phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed + public function render( array $attributes, string $content ) : string { - // Block must have a defined name to find it's template. + // Block must have a defined name to find its template. // Make sure the class (block) extending this class (abstract Base_Block) - // has defined it's own name. + // has defined its own name. if ( static::NAME === self::NAME ) { - throw Missing_Block_Name::message(); + throw Missing_Block::name_exception(); } $template_path = 'src/blocks/' . static::NAME . '/view/' . static::NAME . '.php'; $template = locate_template( $template_path ); if ( empty( $template ) ) { - throw Missing_Block_View::message( static::NAME, $template_path ); + throw Missing_Block::view_exception( static::NAME, $template_path ); } // If everything is ok, return the contents of the template (return, NOT echo). diff --git a/src/blocks/interface-block.php b/src/blocks/interface-block.php index 5cda47201..8fbc6ad91 100644 --- a/src/blocks/interface-block.php +++ b/src/blocks/interface-block.php @@ -13,6 +13,20 @@ */ interface Block { + /** + * Register the current registrable. + * + * A register method holds the plugin action and filter hooks. + * Following the single responsibility principle, every class + * holds a functionality for a certain part of the plugin. + * This is why every class should hold its own hooks. + * + * @return void + * + * @since 1.0.0 + */ + public function register() : void; + /** * Adds default attributes that are dynamically built for all blocks. * These are: diff --git a/src/class-main.php b/src/class-main.php index 8cd93f510..70a37b510 100644 --- a/src/class-main.php +++ b/src/class-main.php @@ -1,6 +1,6 @@ Date: Tue, 9 Apr 2019 10:48:52 +0200 Subject: [PATCH 23/23] fixes --- composer.lock | 4 ++-- phpcs.xml.dist | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.lock b/composer.lock index 89e4cfa14..50de2d975 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d55064de69258c66f6641394ff38aa85", + "content-hash": "fda87bcab613aa12bab5ea6cc1cf4ea0", "packages": [], "packages-dev": [ { @@ -383,7 +383,7 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^5.6|^7" + "php": ">=7.0" }, "platform-dev": [] } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 81950c05b..4441c7318 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -8,15 +8,15 @@ 0 - + 0 - + 0 - + 0