Exemplo n.º 1
0
 public function testClean()
 {
     // Initialize
     $aInput = ['key1' => 'value1', 'key2' => ' ', 'key3' => 'value3'];
     // Assert
     $this->assertEquals(2, count(ExtendedArray::clean($aInput)));
 }
Exemplo n.º 2
0
 public static function askBinaryPath(Event $oEvent, $sLabel, $sBinaryName, $sCheckCommand, $sDefault = null, $bGetRealDefaultValue = true, $bMandatory = false)
 {
     // Get real default value
     $aOutput = [];
     if ($bGetRealDefaultValue) {
         try {
             ExtendedShell::exec(sprintf('which %s', $sBinaryName), $aOutput);
         } catch (Exception $oException) {
             $aOutput = [];
         }
     }
     $sDefault = isset($aOutput[0]) ? trim($aOutput[0]) : $sDefault;
     // Return
     return self::ask($oEvent, self::formatQuestion($sLabel, $sDefault), $sDefault, $bMandatory, function ($sValue) use($sCheckCommand) {
         // Initialize
         $aOutput = [];
         // Update check command
         $sCheckCommand = sprintf($sCheckCommand, $sValue);
         // Exec
         try {
             ExtendedShell::exec($sCheckCommand, $aOutput);
         } catch (\Exception $oException) {
             throw new RuntimeException(sprintf("Invalid path %s with error %s", $sValue, implode(', ', ExtendedArray::clean($aOutput))));
         }
         // Return
         return $sValue;
     });
 }