Update namespaces to include Automattic prefix (https://github.com/woocommerce/woocommerce-blocks/pull/653)

* Update namespaces with Automattic prefix.

* Use static methods for stateless class
This commit is contained in:
Mike Jolley 2019-06-27 11:28:52 +01:00 committed by GitHub
parent 8bc02c3b0c
commit 51ece61df6
13 changed files with 32 additions and 80 deletions

View File

@ -52,11 +52,11 @@ class WGPB_Block_Library {
}
self::register_blocks();
self::register_assets();
\Automattic\WooCommerce\Blocks\RestApi::init();
add_action( 'admin_print_footer_scripts', array( 'WGPB_Block_Library', 'print_script_wc_settings' ), 1 );
add_action( 'admin_print_footer_scripts', array( 'WGPB_Block_Library', 'print_script_block_data' ), 1 );
add_action( 'wp_print_footer_scripts', array( 'WGPB_Block_Library', 'print_script_block_data' ), 1 );
add_action( 'body_class', array( 'WGPB_Block_Library', 'add_theme_body_class' ), 1 );
add_action( 'rest_api_init', array( WooCommerce\Blocks\RestApi::instance(), 'register_rest_routes' ), 10 );
}
/**

View File

@ -14,6 +14,16 @@
"phpunit/phpunit": "6.5.14",
"woocommerce/woocommerce-sniffs": "0.0.6"
},
"autoload": {
"psr-4": {
"Automattic\\WooCommerce\\Blocks\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Automattic\\WooCommerce\\Blocks\\Tests\\": "tests/php/"
}
},
"scripts": {
"phpcs": [
"phpcs --extensions=php -s -p"
@ -27,11 +37,5 @@
"phpcs": "Analyze code against the WordPress coding standards with PHP_CodeSniffer",
"phpcbf": "Fix coding standards warnings/errors automatically with PHP Code Beautifier"
}
},
"autoload": {
"psr-4": {
"WooCommerce\\Blocks\\": "src/",
"WooCommerce\\Blocks\\Tests\\": "tests/php/"
}
}
}

View File

@ -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": "07ebe4c4b31c087d205310291fd74763",
"content-hash": "8c78d4f23f27ee1c5764148b44b263ae",
"packages": [
{
"name": "composer/installers",
@ -1970,12 +1970,12 @@
"version": "1.2.1",
"source": {
"type": "git",
"url": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git",
"url": "https://github.com/WordPress/WordPress-Coding-Standards.git",
"reference": "f328bcafd97377e8e5e5d7b244d5ddbf301a3a5c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/f328bcafd97377e8e5e5d7b244d5ddbf301a3a5c",
"url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/f328bcafd97377e8e5e5d7b244d5ddbf301a3a5c",
"reference": "f328bcafd97377e8e5e5d7b244d5ddbf301a3a5c",
"shasum": ""
},

View File

@ -5,34 +5,31 @@
* @package WooCommerce/Blocks
*/
namespace WooCommerce\Blocks;
namespace Automattic\WooCommerce\Blocks;
defined( 'ABSPATH' ) || exit;
use WooCommerce\Blocks\Utilities\SingletonTrait;
/**
* RestApi class.
*/
class RestApi {
use SingletonTrait;
/**
* REST API controllers.
*
* @var array
* Initialize class features.
*/
protected $controllers = [];
public static function init() {
add_action( 'rest_api_init', array( __CLASS__, 'register_rest_routes' ), 10 );
}
/**
* Register REST API routes.
*/
public function register_rest_routes() {
$controllers = $this->get_controllers();
public static function register_rest_routes() {
$controllers = self::get_controllers();
foreach ( $controllers as $controller_name => $controller_class ) {
$this->controllers[ $controller_name ] = new $controller_class();
$this->controllers[ $controller_name ]->register_routes();
foreach ( $controllers as $name => $class ) {
$instance = new $class();
$instance->register_routes();
}
}

View File

@ -8,7 +8,7 @@
* @package WooCommerce/Blocks
*/
namespace WooCommerce\Blocks\RestApi\Controllers;
namespace Automattic\WooCommerce\Blocks\RestApi\Controllers;
defined( 'ABSPATH' ) || exit;

View File

@ -8,7 +8,7 @@
* @package WooCommerce/Blocks
*/
namespace WooCommerce\Blocks\RestApi\Controllers;
namespace Automattic\WooCommerce\Blocks\RestApi\Controllers;
defined( 'ABSPATH' ) || exit;

View File

@ -8,7 +8,7 @@
* @package WooCommerce/Blocks
*/
namespace WooCommerce\Blocks\RestApi\Controllers;
namespace Automattic\WooCommerce\Blocks\RestApi\Controllers;
defined( 'ABSPATH' ) || exit;

View File

@ -8,7 +8,7 @@
* @package WooCommerce/Blocks
*/
namespace WooCommerce\Blocks\RestApi\Controllers;
namespace Automattic\WooCommerce\Blocks\RestApi\Controllers;
defined( 'ABSPATH' ) || exit;

View File

@ -1,49 +0,0 @@
<?php
/**
* Abstract singleton class.
*
* @package WooCommerce/Blocks
*/
namespace WooCommerce\Blocks\Utilities;
/**
* Singleton trait.
*/
trait SingletonTrait {
/**
* The single instance of the class.
*
* @var object
*/
protected static $instance = null;
/**
* Constructor
*
* @return void
*/
protected function __construct() {}
/**
* Get class instance.
*
* @return object Instance.
*/
final public static function instance() {
if ( null === static::$instance ) {
static::$instance = new static();
}
return static::$instance;
}
/**
* Prevent cloning.
*/
private function __clone() {}
/**
* Prevent unserializing.
*/
private function __wakeup() {}
}

View File

@ -5,7 +5,7 @@
* @package WooCommerce\Blocks\Tests
*/
namespace WooCommerce\Blocks\Tests\RestApi\Controllers;
namespace Automattic\WooCommerce\Blocks\Tests\RestApi\Controllers;
use \WP_REST_Request;
use \WC_REST_Unit_Test_Case;

View File

@ -5,7 +5,7 @@
* @package WooCommerce\Blocks\Tests
*/
namespace WooCommerce\Blocks\Tests\RestApi\Controllers;
namespace Automattic\WooCommerce\Blocks\Tests\RestApi\Controllers;
use \WP_REST_Request;
use \WC_REST_Unit_Test_Case;

View File

@ -5,7 +5,7 @@
* @package WooCommerce\Blocks\Tests
*/
namespace WooCommerce\Blocks\Tests\RestApi\Controllers;
namespace Automattic\WooCommerce\Blocks\Tests\RestApi\Controllers;
use \WP_REST_Request;
use \WC_REST_Unit_Test_Case;

View File

@ -5,7 +5,7 @@
* @package WooCommerce\Blocks\Tests
*/
namespace WooCommerce\Blocks\Tests\RestApi\Controllers;
namespace Automattic\WooCommerce\Blocks\Tests\RestApi\Controllers;
use \WP_REST_Request;
use \WC_REST_Unit_Test_Case;