Skip to content

Commit

Permalink
Add basic client access
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera committed Mar 25, 2019
1 parent dad0b56 commit c46f7fd
Show file tree
Hide file tree
Showing 37 changed files with 78 additions and 125 deletions.
81 changes: 3 additions & 78 deletions asmp-wordpress-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
*
* -----------------------------------------------------------------------------
* -- 1. Provide the plugin meta information that WordPress needs --
* -----------------------------------------------------------------------------
* @link https://www.asmprotocol.org/
*
* @wordpress-plugin
* Plugin Name: ASMP WordPress Integration Plugin
* Plugin URI: https://www.alainschlesser.com/asmp
* Plugin URI: https://www.asmprotocol.org/
* Description: WordPress Integration Plugin for ASMP.
* Version: 0.1.0
* Requires PHP: 7.2
Expand All @@ -24,86 +20,19 @@

namespace ASMP\WordPressIntegration;

/*
* This is the plugin's bootstrap file. It serves three main purposes:
* 1. Provide the plugin meta information that WordPress needs;
* 2. Prepare the environment so that it is ready to execute our OOP code;
* 3. Instantiate and kick off our "composition root" (our 'Plugin' class).
*
* The bootstrap file should not do anything else, so that we have a clean
* separation between a.) code that needs to be run sequentially and produces
* side-effects and b.) declarations that can be taken out of contexts for
* testing and reuse and have no side-effects.
*
* Anything past this bootstrap file should be autoloadable classes, interfaces
* or traits without any side-effects.
*/

/*
* As this is the only PHP file having side effects, we need to provide a
* safeguard, so we want to make sure this file is only run from within
* WordPress and cannot be directly called through a web request.
*/
if ( ! defined( 'ABSPATH' ) ) {
die();
}



/*
* -----------------------------------------------------------------------------
* -- 2. Prepare the environment so that it is ready to execute our OOP code --
* -----------------------------------------------------------------------------
*/

/*
* We try to load the Composer if it exists.
* If it doesn't exist, we fall back to a basic bundled autoloader
* implementation. This allows us to just use the plugin as-is without requirin
* the 'composer install' step.
* Note: If you use Composer not only for autoloading, but also including
* dependencies needed in production, the 'composer install' becomes mandatory
* and the fallback autoloader should probably be removed.
*/
$composer_autoloader = __DIR__ . '/vendor/autoload.php';

if ( is_readable ( $composer_autoloader ) ) {
require $composer_autoloader;
}

if ( ! class_exists( __NAMESPACE__ . '\\PluginFactory' ) ) {
// Composer autoloader apparently was not found, so fall back to our bundled
// autoloader.
require_once __DIR__ . '/src/Infrastructure/Autoloader.php';

( new Infrastructure\Autoloader() )
->add_namespace( __NAMESPACE__, __DIR__ . '/src' )
->register();
}



/*
* -----------------------------------------------------------------------------
* -- 3. Instantiate and kick off our "composition root" (our 'Plugin' class) --
* -----------------------------------------------------------------------------
*/

/*
* We use a factory to instantiate the actual plugin.
* The factory keeps the object as a shared instance, so that you can also
* get outside access to that same plugin instance through the factory.
* This is similar to a Singleton, but without all the drawbacks the Singleton
* anti-pattern brings along.
* For more information on why to avoid a Singleton, read:
* https://www.alainschlesser.com/singletons-shared-instances/
*/
$plugin = PluginFactory::create();

/*
* We register activation and deactivation hooks by using closures, as these
* need static access to work correctly.
*/

\register_activation_hook( __FILE__, function () use ( $plugin ) {
$plugin->activate();
} );
Expand All @@ -112,8 +41,4 @@
$plugin->deactivate();
} );

/*
* Finally, we run the plugin's register method to Hook the plugin into the
* WordPress request lifecycle.
*/
$plugin->register();
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "wordpress-plugin",
"license": "MIT",
"require": {
"application-server-management-protocol/php-client": "*"
"asmprotocol/php-client": "*"
},
"require-dev": {
"phpunit/phpunit": "^6"
Expand Down
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/ASMP.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
* @link https://www.asmprotocol.org/
*/

namespace ASMP\WordPressIntegration;
Expand Down
36 changes: 32 additions & 4 deletions src/Console/AsmpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,34 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
* @link https://www.asmprotocol.org/
*/

namespace ASMP\WordPressIntegration\Console;

use ASMP\Client\Api\ChangeApi;
use ASMP\Client\Api\CheckApi;
use ASMP\Client\Api\RollbackApi;
use ASMP\Client\Configuration;
use ASMP\Client\Model\ChangeRequest;
use ASMP\Client\Model\CheckRequest;
use ASMP\Client\Model\RollbackRequest;
use ASMP\WordPressIntegration\ASMP;
use GuzzleHttp\Client;
use WP_CLI;

final class AsmpCommand {

/** @var Configuration */
private $config;

/**
* Instantiate a AsmpCommand object.
*/
public function __construct() {
$this->config = Configuration::getDefaultConfiguration();
}

/**
* Run a check against ASMP.
*
Expand All @@ -23,7 +41,9 @@ final class AsmpCommand {
public function check( array $args, array $assoc_args ): void {
$this->ensure_asmp_is_available();

WP_CLI::error( 'Not implemented yet' );
$apiInstance = new CheckApi( new Client(), $this->config );
$body = new CheckRequest();
var_dump( $body );
}

/**
Expand All @@ -35,7 +55,9 @@ public function check( array $args, array $assoc_args ): void {
public function change( array $args = [], array $assoc_args = [] ): void {
$this->ensure_asmp_is_available();

WP_CLI::error( 'Not implemented yet' );
$apiInstance = new ChangeApi( new Client(), $this->config );
$body = new ChangeRequest();
var_dump( $body );
}

/**
Expand All @@ -47,7 +69,9 @@ public function change( array $args = [], array $assoc_args = [] ): void {
public function rollback( array $args = [], array $assoc_args = [] ): void {
$this->ensure_asmp_is_available();

WP_CLI::error( 'Not implemented yet' );
$apiInstance = new RollbackApi( new Client(), $this->config );
$body = new RollbackRequest();
var_dump( $body );
}

/**
Expand All @@ -62,6 +86,10 @@ public function rollback( array $args = [], array $assoc_args = [] ): void {
* @param array $assoc_args Optional. Array of associative arguments.
*/
public function status( array $args = [], array $assoc_args = [] ): void {
$this->ensure_asmp_is_available();

list( $id ) = $args;

WP_CLI::error( 'Not implemented yet' );
}

Expand Down
2 changes: 1 addition & 1 deletion src/ConsoleIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
* @link https://www.asmprotocol.org/
*/

namespace ASMP\WordPressIntegration;
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/FailedToLoadView.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
* @link https://www.asmprotocol.org/
*/

namespace ASMP\WordPressIntegration\Exception;
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/FailedToMakeInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
* @link https://www.asmprotocol.org/
*/

namespace ASMP\WordPressIntegration\Exception;
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/InvalidPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
* @link https://www.asmprotocol.org/
*/

namespace ASMP\WordPressIntegration\Exception;
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/InvalidService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
* @link https://www.asmprotocol.org/
*/

namespace ASMP\WordPressIntegration\Exception;
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/WordPressIntegrationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
* @link https://www.asmprotocol.org/
*/

namespace ASMP\WordPressIntegration\Exception;
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Activateable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
* @link https://www.asmprotocol.org/
*/

namespace ASMP\WordPressIntegration\Infrastructure;
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
* @link https://www.asmprotocol.org/
*/

namespace ASMP\WordPressIntegration\Infrastructure;
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Deactivateable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
* @link https://www.asmprotocol.org/
*/

namespace ASMP\WordPressIntegration\Infrastructure;
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Injector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
* @link https://www.asmprotocol.org/
*/

namespace ASMP\WordPressIntegration\Infrastructure;
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Injector/InjectionChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
* @link https://www.asmprotocol.org/
*/

namespace ASMP\WordPressIntegration\Infrastructure\Injector;
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Injector/SimpleInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
* @link https://www.asmprotocol.org/
*/

namespace ASMP\WordPressIntegration\Infrastructure\Injector;
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Instantiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
* @link https://www.asmprotocol.org/
*/

namespace ASMP\WordPressIntegration\Infrastructure;
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Registerable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
* @link https://www.asmprotocol.org/
*/

namespace ASMP\WordPressIntegration\Infrastructure;
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Renderable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
* @link https://www.asmprotocol.org/
*/

namespace ASMP\WordPressIntegration\Infrastructure;
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
* @link https://www.asmprotocol.org/
*/

namespace ASMP\WordPressIntegration\Infrastructure;
Expand Down
Loading

0 comments on commit c46f7fd

Please sign in to comment.