Skip to content

Commit

Permalink
Add setting
Browse files Browse the repository at this point in the history
  • Loading branch information
obenland committed Mar 24, 2019
1 parent 1417643 commit 67496be
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/ASMP.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare( strict_types=1 );

/**
* ASMP WordPress Integration Plugin.
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
*/

namespace ASMP\WordPressIntegration;

interface ASMP {
public const VERSION = 'ASMP_DISCOVERY_VERSION';
public const ENDPOINT = 'ASMP_DISCOVERY_ENDPOINT';
}
1 change: 1 addition & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ private function get_service_classes(): array {
// Add services as FQCNs here.
ViewFactory::class,
SampleService::class,
SettingsGeneralService::class,
] );
}
}
62 changes: 62 additions & 0 deletions src/SettingsGeneralService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* ASMP WordPress Integration Plugin.
*
* @package ASMP\WordPressIntegration
* @license MIT
* @link https://www.alainschlesser.com/asmp
*/

namespace ASMP\WordPressIntegration;

use ASMP\WordPressIntegration\Infrastructure\Registerable;
use ASMP\WordPressIntegration\Infrastructure\Service;
use ASMP\WordPressIntegration\Infrastructure\ViewFactory;

/**
*
*/
final class SettingsGeneralService implements Service, Registerable {

/** @var ViewFactory */
private $view_factory;

/**
* Instantiate a SampleService object.
*
* @param ViewFactory $view_factory View factory to use for instantiating
* the views.
*/
public function __construct( ViewFactory $view_factory ) {
$this->view_factory = $view_factory;
}

/**
* Register the service.
*
* @return void
*/
public function register(): void {
if ( ! isset( $_SERVER[ ASMP::VERSION ] ) ) {
// TODO return;
}

// TODO
$_SERVER[ ASMP::ENDPOINT ] = [ '5.6', '7.0', '7.2' ];

add_action( 'admin_init', function() {
\add_settings_field( 'asmp', esc_html__( 'PHP Versions', 'asmp' ), [ $this, 'render' ], 'general' );
} );
}

/**
* Render the admin notice.
*
* @return void
*/
public function render(): void {
echo $this->view_factory->create( 'views/setting' )
->render();
}
}

7 changes: 7 additions & 0 deletions views/setting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<select id="php_version" name="php_version">
<?php
foreach ( $_SERVER[ ASMP\WordPressIntegration\ASMP::ENDPOINT ] as $version ) :
printf( '<option value="%1$s">%1$s</option>', $version );
endforeach;
?>
</select>

0 comments on commit 67496be

Please sign in to comment.