PhpBrew\Utils::findBinByPrefix PHP Метод

findBinByPrefix() публичный статический Метод

Find bin from prefix list.
public static findBinByPrefix ( string $bin ) : string | null
$bin string
Результат string | null
    public static function findBinByPrefix($bin)
    {
        $prefixes = self::getLookupPrefixes();
        foreach ($prefixes as $prefix) {
            $binPath = $prefix . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . $bin;
            if (file_exists($binPath)) {
                return $binPath;
            }
            $binPath = $prefix . DIRECTORY_SEPARATOR . 'sbin' . DIRECTORY_SEPARATOR . $bin;
            if (file_exists($binPath)) {
                return $binPath;
            }
        }
        return;
    }

Usage Example

Пример #1
0
 public function __construct()
 {
     // init variant builders
     $this->variants['all'] = '--enable-all';
     $this->variants['dba'] = '--enable-dba';
     $this->variants['ipv6'] = '--enable-ipv6';
     $this->variants['dom'] = '--enable-dom';
     $this->variants['calendar'] = '--enable-calendar';
     $this->variants['wddx'] = '--enable-wddx';
     $this->variants['static'] = '--enable-static';
     $this->variants['inifile'] = '--enable-inifile';
     $this->variants['inline'] = '--enable-inline-optimization';
     $this->variants['cli'] = '--enable-cli';
     $this->variants['fpm'] = '--enable-fpm';
     $this->variants['ftp'] = '--enable-ftp';
     $this->variants['filter'] = '--enable-filter';
     $this->variants['gcov'] = '--enable-gcov';
     $this->variants['zts'] = '--enable-maintainer-zts';
     $this->variants['json'] = '--enable-json';
     $this->variants['hash'] = '--enable-hash';
     $this->variants['exif'] = '--enable-exif';
     $this->variants['mbstring'] = '--enable-mbstring';
     $this->variants['mbregex'] = '--enable-mbregex';
     $this->variants['libgcc'] = '--enable-libgcc';
     // $this->variants['gd-jis'] = '--enable-gd-jis-conv';
     $this->variants['pdo'] = '--enable-pdo';
     $this->variants['posix'] = '--enable-posix';
     $this->variants['embed'] = '--enable-embed';
     $this->variants['sockets'] = '--enable-sockets';
     $this->variants['debug'] = '--enable-debug';
     $this->variants['phpdbg'] = '--enable-phpdbg';
     $this->variants['zip'] = '--enable-zip';
     $this->variants['bcmath'] = '--enable-bcmath';
     $this->variants['fileinfo'] = '--enable-fileinfo';
     $this->variants['ctype'] = '--enable-ctype';
     $this->variants['cgi'] = '--enable-cgi';
     $this->variants['soap'] = '--enable-soap';
     $this->variants['gcov'] = '--enable-gcov';
     $this->variants['pcntl'] = '--enable-pcntl';
     /*
             --enable-intl 
     
     To build the extension you need to install the » ICU library, version 
     4.0.0 or newer is required.
     This extension is bundled with PHP as of PHP version 5.3.0. 
     Alternatively, the PECL version of this extension may be used with all 
     PHP versions greater than 5.2.0 (5.2.4+ recommended).
     
     This requires --with-icu-dir=/....
     */
     $this->variants['intl'] = '--enable-intl';
     $this->variants['phar'] = '--enable-phar';
     $this->variants['session'] = '--enable-session';
     $this->variants['tokenizer'] = '--enable-tokenizer';
     // PHP 5.5 only variants
     $this->variants['opcache'] = '--enable-opcache';
     $this->variants['imap'] = '--with-imap-ssl';
     $this->variants['tidy'] = '--with-tidy';
     $this->variants['kerberos'] = '--with-kerberos';
     $this->variants['xmlrpc'] = '--with-xmlrpc';
     $this->variants['pcre'] = function (Build $build, $prefix = null) {
         if ($prefix) {
             return array("--with-pcre-regex", "--with-pcre-dir={$prefix}");
         }
         if ($prefix = Utils::findIncludePrefix('pcre.h')) {
             return array("--with-pcre-regex", "--with-pcre-dir={$prefix}");
         }
         return array("--with-pcre-regex");
     };
     $this->variants['mhash'] = function (Build $build, $prefix = null) {
         if ($prefix) {
             return "--with-mhash={$prefix}";
         }
         if ($prefix = Utils::findIncludePrefix('mhash.h')) {
             return "--with-mhash={$prefix}";
         }
         return "--with-mhash";
         // let autotool to find it.
     };
     $this->variants['mcrypt'] = function (Build $build, $prefix = null) {
         if ($prefix) {
             return "--with-mcrypt={$prefix}";
         }
         if ($prefix = Utils::findIncludePrefix('mcrypt.h')) {
             return "--with-mcrypt={$prefix}";
         }
         return "--with-mcrypt";
         // let autotool to find it.
     };
     $this->variants['zlib'] = function (Build $build) {
         if ($prefix = Utils::findIncludePrefix('zlib.h')) {
             return '--with-zlib=' . $prefix;
         }
         return null;
     };
     $this->variants['curl'] = function (Build $build, $prefix = null) {
         if ($prefix) {
             return "--with-curl={$prefix}";
         }
         if ($prefix = Utils::findIncludePrefix('curl/curl.h')) {
             return "--with-curl={$prefix}";
         }
         if ($prefix = Utils::getPkgConfigPrefix('libcurl')) {
             return "--with-curl={$prefix}";
         }
         return null;
     };
     $this->variants['readline'] = function (Build $build, $prefix = null) {
         if ($prefix = Utils::findIncludePrefix('readline' . DIRECTORY_SEPARATOR . 'readline.h')) {
             $opts = array();
             $opts[] = '--with-readline=' . $prefix;
             if ($prefix = Utils::findIncludePrefix('editline' . DIRECTORY_SEPARATOR . 'readline.h')) {
                 $opts[] = '--with-libedit=' . $prefix;
             }
             return $opts;
         }
         return '--with-readline';
     };
     $this->variants['gd'] = function (Build $build, $prefix = null) {
         $opts = array();
         // it looks like gd won't be compiled without "shared"
         // suggested options is +gd=shared,/usr
         if ($prefix) {
             $opts[] = "--with-gd={$prefix}";
         } elseif ($prefix = Utils::findIncludePrefix('gd.h')) {
             $opts[] = "--with-gd=shared,{$prefix}";
         }
         $opts[] = '--enable-gd-native-ttf';
         if ($prefix = Utils::findIncludePrefix('jpeglib.h')) {
             $opts[] = "--with-jpeg-dir={$prefix}";
         }
         if ($prefix = Utils::findIncludePrefix('png.h', 'libpng12/pngconf.h')) {
             $opts[] = "--with-png-dir={$prefix}";
         }
         // the freetype-dir option does not take prefix as its value,
         // it takes the freetype.h directory as its value.
         //
         // from configure:
         //   for path in $i/include/freetype2/freetype/freetype.h
         if ($prefix = Utils::findIncludePrefix('freetype2/freetype.h')) {
             $opts[] = "--with-freetype-dir={$prefix}";
         } elseif ($prefix = Utils::findIncludePrefix("freetype2/freetype/freetype.h")) {
             $opts[] = "--with-freetype-dir={$prefix}";
         }
         return $opts;
     };
     /**
      * with icu
      */
     $this->variants['icu'] = function (Build $build, $val = null) {
         if ($val) {
             return '--with-icu-dir=' . $val;
         }
         // the last one path is for Ubuntu
         if ($prefix = Utils::findLibPrefix('icu/pkgdata.inc', 'icu/Makefile.inc')) {
             return '--with-icu-dir=' . $prefix;
         }
         // For macports
         if ($prefix = Utils::getPkgConfigPrefix('icu-i18n')) {
             return '--with-icu-dir=' . $prefix;
         }
         throw new RuntimeException("libicu not found, please install libicu-dev or libicu library/development files.");
     };
     /**
      * --with-openssl option
      *
      * --with-openssh=shared
      * --with-openssl=[dir]
      *
      * On ubuntu you need to install libssl-dev
      */
     $this->variants['openssl'] = function (Build $build, $val = null) {
         if ($val) {
             return "--with-openssl={$val}";
         }
         if ($prefix = Utils::findIncludePrefix('openssl/opensslv.h')) {
             return "--with-openssl={$prefix}";
         }
         if ($prefix = Utils::getPkgConfigPrefix('openssl')) {
             return "--with-openssl={$prefix}";
         }
         // This will create openssl.so file for dynamic loading.
         echo "Compiling with openssl=shared, please install libssl-dev or openssl header files if you need";
         return "--with-openssl";
     };
     /*
     --with-mysql[=DIR]      Include MySQL support.  DIR is the MySQL base
                             directory.  If mysqlnd is passed as DIR,
                             the MySQL native driver will be used [/usr/local]
     --with-mysqli[=FILE]    Include MySQLi support.  FILE is the path
                             to mysql_config.  If mysqlnd is passed as FILE,
                             the MySQL native driver will be used [mysql_config]
     --with-pdo-mysql[=DIR]    PDO: MySQL support. DIR is the MySQL base directoy
                             If mysqlnd is passed as DIR, the MySQL native
                             native driver will be used [/usr/local]
     
     --with-mysql         // deprecated
     */
     $this->variants['mysql'] = function (Build $build, $prefix = 'mysqlnd') {
         $opts = array("--with-mysql={$prefix}", "--with-mysqli={$prefix}");
         if ($build->hasVariant('pdo')) {
             $opts[] = "--with-pdo-mysql={$prefix}";
         }
         return $opts;
     };
     $this->variants['sqlite'] = function (Build $build, $prefix = null) {
         $opts = array('--with-sqlite3' . ($prefix ? "={$prefix}" : ''));
         if ($build->hasVariant('pdo')) {
             $opts[] = '--with-pdo-sqlite';
         }
         return $opts;
     };
     $this->variants['pgsql'] = function (Build $build, $prefix = null) {
         $opts = array();
         $possibleNames = array('psql90', 'psql91', 'psql92', 'psql93', 'psql');
         while (!$prefix && !empty($possibleNames)) {
             $prefix = Utils::findBin(array_pop($possibleNames));
         }
         $opts[] = $prefix ? "--with-pgsql={$prefix}" : "--with-pgsql";
         if ($build->hasVariant('pdo')) {
             $opts[] = $prefix ? "--with-pdo-pgsql={$prefix}" : '--with-pdo-pgsql';
         }
         return $opts;
     };
     $this->variants['xml'] = function (Build $build) {
         $options = array('--enable-dom', '--enable-libxml', '--enable-simplexml', '--enable-xml', '--enable-xmlreader', '--enable-xmlwriter', '--with-xsl');
         if ($prefix = Utils::getPkgConfigPrefix('libxml')) {
             $options[] = "--with-libxml-dir={$prefix}";
         } elseif ($prefix = Utils::findIncludePrefix('libxml2/libxml/globals.h')) {
             $options[] = "--with-libxml-dir={$prefix}";
         } elseif ($prefix = Utils::findLibPrefix('libxml2.a')) {
             $options[] = "--with-libxml-dir={$prefix}";
         }
         return $options;
     };
     $this->variants['xml_all'] = $this->variants['xml'];
     $this->variants['apxs2'] = function (Build $build, $prefix = null) {
         $a = '--with-apxs2';
         if ($prefix) {
             return '--with-apxs2=' . $prefix;
         }
         if ($bin = Utils::findBinByPrefix('apxs2')) {
             return '--with-apxs2=' . $bin;
         }
         if ($bin = Utils::findBinByPrefix('apxs')) {
             return '--with-apxs2=' . $bin;
         }
         return $a;
     };
     $this->variants['gettext'] = function (Build $build, $prefix = null) {
         if ($prefix) {
             return '--with-gettext=' . $prefix;
         }
         if ($prefix = Utils::findIncludePrefix('libintl.h')) {
             return '--with-gettext=' . $prefix;
         }
         return '--with-gettext';
     };
     $this->variants['iconv'] = function (Build $build, $prefix = null) {
         if ($prefix) {
             return "--with-iconv={$prefix}";
         }
         /*
          * php can't be compile with --with-iconv=/usr because it uses giconv
          *
          * https://bugs.php.net/bug.php?id=48451
          *
         // detect include path for iconv.h
         if ( $prefix = Utils::find_include_prefix('giconv.h', 'iconv.h') ) {
             return "--with-iconv=$prefix";
         }
         */
         return "--with-iconv";
     };
     $this->variants['bz2'] = function ($build, $prefix = null) {
         if ($prefix) {
             return "--with-bz2={$prefix}";
         }
         if ($prefix = Utils::findIncludePrefix('bzlib.h')) {
             return "--with-bz2={$prefix}";
         }
         return '--with-bz2';
     };
     $this->variants['ipc'] = function (Build $build) {
         return array('--enable-shmop', '--enable-sysvsem', '--enable-sysvshm', '--enable-sysvmsg');
     };
     $this->variants['gmp'] = function (Build $build, $prefix = null) {
         if ($prefix) {
             return "--with-gmp={$prefix}";
         }
         if ($prefix = Utils::findIncludePrefix('gmp.h')) {
             return "--with-gmp={$prefix}";
         }
         return "--with-gmp";
         // let autotool to find it.
     };
     // merge virtual variants with config file
     $customVirtualVariants = Config::getConfigParam('variants');
     $customVirtualVariantsToAdd = array();
     if (!empty($customVirtualVariants)) {
         foreach ($customVirtualVariants as $key => $extension) {
             $customVirtualVariantsToAdd[$key] = array_keys($extension);
         }
     }
     $this->virtualVariants = array_merge($customVirtualVariantsToAdd, $this->virtualVariants);
     // create +everything variant
     $this->virtualVariants['everything'] = array_diff(array_keys($this->variants), array('apxs2', 'all'));
 }
All Usage Examples Of PhpBrew\Utils::findBinByPrefix