This commit is contained in:
Varun 2020-10-21 13:27:49 +05:30
parent 976cc40b9b
commit 89005b2617
No known key found for this signature in database
GPG key ID: 93FB46DCF16E0D6F
3 changed files with 43 additions and 4 deletions

View file

@ -56,6 +56,7 @@ GH_LOG::Log( 'This Text Will Be [blink]', 'normal', false, 'blink' );
GH_LOG::Log( 'This Text Will Be [reverse]', 'normal', false, 'reverse' );
GH_LOG::Log( 'This Text Will Be [hidden]', 'normal', false, 'hidden' );
gh_log( "Input Value For VALUE2" );
gh_log( print_r( $_ENV ) );
print_r( gh_validate_input( 'VALUE1' ) );
print_r( gh_validate_input( 'VALUE2' ) );
print_r( gh_validate_input( 'VALUE3' ) );
print_r( gh_validate_input( 'VALUE32', 'Important Input Variable Not Found !' ) );

View file

@ -1,4 +1,5 @@
<?php
require_once __DIR__ . '/php/logger.php';
require_once __DIR__ . '/php/log-functions.php';
require_once __DIR__ . '/php/log-functions.php';
require_once __DIR__ . '/php/inputvar.php';

37
toolkit/php/inputvar.php Normal file
View file

@ -0,0 +1,37 @@
<?php
/**
* Checks Input Variable's Value
*
* @param $key
* @param null $default
*
* @return mixed|null
*/
function gh_input( $key, $default = null ) {
$key = sprintf( 'INPUT_%s', $key );
if ( isset( $_ENV[ $key ] ) ) {
return $_ENV[ $key ];
}
return $default;
}
/**
* Validates Input Value.
*
* @param $key
* @param bool $custom_message
*
* @return mixed|null
*/
function gh_validate_input( $key, $custom_message = false ) {
if ( null === gh_input( $key ) ) {
$custom_message = ( false === $custom_message ) ? '%s Not Found. Please Set The Input Value using WITH in workflow file' : $custom_message;
$custom_message = sprintf( '%s', $key );
$custom_message = '🚨 ' . $custom_message;
gh_log_red( $custom_message );
die();
}
return gh_input( $key );
}