App\Libraries\Str::isNullOrEmptyString PHP Method

isNullOrEmptyString() public static method

Modification from: http://stackoverflow.com/a/381275 Author: Michael Haren (http://stackoverflow.com/users/29/michael-haren)
public static isNullOrEmptyString ( $question ) : boolean
$question
return boolean
    public static function isNullOrEmptyString($question)
    {
        $isSet = isset($question);
        $isNull = is_null($question);
        $isString = is_string($question);
        if ($isSet && !$isNull && $isString) {
            $question = trim($question);
        }
        $isEmpty = empty($question);
        if (!$isSet || $isNull || $isEmpty) {
            return true;
        } else {
            return false;
        }
    }

Usage Example

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     try {
         if ($key = $this->argument('key')) {
             $message = "";
             $value = $this->argument('value');
             $encrypt = $this->option('encrypt');
             if (Str::isNullOrEmptyString($value)) {
                 if ($encrypt) {
                     $value = $this->secret('Enter secret value:');
                     $message = "Setting [{$key}] set to encrypted value.";
                 } else {
                     $value = $this->ask('Enter value:');
                     $message = "Setting [{$key}] set to [{$value}].";
                 }
             }
             Setting::set($key, $value, $encrypt);
             Setting::save();
             $this->info($message);
         } else {
             $this->error("Missing 'key' argument.");
         }
     } catch (\Exception $ex) {
         $this->error("Exception: " . $ex->getMessage());
         $this->error("Stack trace: " . $ex->getTraceAsString());
     }
 }
All Usage Examples Of App\Libraries\Str::isNullOrEmptyString