N98\Util\OperatingSystem::isProgramInstalled PHP Method

isProgramInstalled() public static method

public static isProgramInstalled ( string $program ) : boolean
$program string
return boolean
    public static function isProgramInstalled($program)
    {
        if (self::isWindows()) {
            return WindowsSystem::isProgramInstalled($program);
        }
        $out = null;
        $return = null;
        @exec('which ' . $program, $out, $return);
        return $return === 0;
    }

Usage Example

コード例 #1
0
 /**
  * @return void
  *
  * @throws \Exception
  */
 public function execute()
 {
     if (OperatingSystem::isProgramInstalled('composer.phar')) {
         $composerBin = 'composer.phar';
     } elseif (OperatingSystem::isProgramInstalled('composer')) {
         $composerBin = 'composer';
     } elseif (OperatingSystem::isProgramInstalled('composer.bat')) {
         $composerBin = 'composer';
     }
     if (empty($composerBin)) {
         $composerBin = $this->downloadComposer();
     }
     if (empty($composerBin)) {
         throw new \Exception('Cannot find or install composer. Please try it manually. https://getcomposer.org/');
     }
     $this->output->writeln('<info>Found executable <comment>' . $composerBin . '</comment></info>');
     $this->config['composer_bin'] = $composerBin;
 }
All Usage Examples Of N98\Util\OperatingSystem::isProgramInstalled