Skip to content

Commit

Permalink
Refactor logic out of view
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera committed Mar 24, 2019
1 parent 67496be commit 551a46d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
48 changes: 40 additions & 8 deletions src/SettingsGeneralService.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ public function __construct( ViewFactory $view_factory ) {
* @return void
*/
public function register(): void {
if ( ! isset( $_SERVER[ ASMP::VERSION ] ) ) {
// TODO return;
if ( ! $this->has_asmp() ) {
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' );
\add_action( 'admin_init', function () {
\add_settings_field(
'asmp',
esc_html__( 'PHP Versions', 'asmp' ),
[ $this, 'render' ],
'general'
);
} );
}

Expand All @@ -56,7 +58,37 @@ public function register(): void {
*/
public function render(): void {
echo $this->view_factory->create( 'views/setting' )
->render();
->render( [ 'options' => $this->retrieve_php_version_options() ] );
}

/**
* Check whether ASMP is available.
*
* @return bool Whether ASMP is available.
*/
private function has_asmp(): bool {
return true;
// return isset( $_SERVER[ ASMP::VERSION ] );
}

/**
* Get the ASMP endpoint to communimcate with.
*
* @return string ASMP endpoint.
*/
private function get_endpoint(): string {
return '';
// return $_SERVER[ ASMP::ENDPOINT ];
}

/**
* Retrieve the available options for the PHP version.
*
* @return array
*/
private function retrieve_php_version_options() {
// TODO
return [ '5.6', '7.0', '7.2' ];
}
}

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

0 comments on commit 551a46d

Please sign in to comment.