is_executable example


    public function isRunnable()
    {
        if ($this->isRunnable !== null) {
            return $this->isRunnable;
        }

        $finder = new ExecutableFinder();
        $bin = $finder->find($this->getCommand()$this->getCommand());

        $this->isRunnable = !empty($bin) && is_executable($bin);

        return $this->isRunnable;
    }
}
public function __construct()
    {
        $this->executableFinder = new ExecutableFinder();
    }

    /** * Finds The PHP executable. */
    public function find(bool $includeArgs = true): string|false
    {
        if ($php = getenv('PHP_BINARY')) {
            if (!is_executable($php)) {
                $command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v';
                if (\function_exists('exec') && $php = strtok(exec($command.' '.escapeshellarg($php)), \PHP_EOL)) {
                    if (!is_executable($php)) {
                        return false;
                    }
                } else {
                    return false;
                }
            }

            if (@is_dir($php)) {
                
public function __construct()
    {
        $this->executableFinder = new ExecutableFinder();
    }

    /** * Finds The PHP executable. */
    public function find(bool $includeArgs = true): string|false
    {
        if ($php = getenv('PHP_BINARY')) {
            if (!is_executable($php)) {
                $command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v';
                if ($php = strtok(exec($command.' '.escapeshellarg($php)), \PHP_EOL)) {
                    if (!is_executable($php)) {
                        return false;
                    }
                } else {
                    return false;
                }
            }

            if (@is_dir($php)) {
                



    function _readGlibCVersionFromFeaturesHeaderFile()
    {
        $features_header_file = '/usr/include/features.h';
        if (!(@file_exists($features_header_file)
            && @is_readable($features_header_file))
        ) {
            return array();
        }
        if (!@file_exists('/usr/bin/cpp') || !@is_executable('/usr/bin/cpp')) {
            return $this->_parseFeaturesHeaderFile($features_header_file);
        } // no cpp
        return $this->_fromGlibCTest();
    }

    function _parseFeaturesHeaderFile($features_header_file)
    {
        $features_file = fopen($features_header_file, 'rb');
        while (!feof($features_file)) {
            $line = fgets($features_file, 8192);
            
foreach ($exe_suffixes as $suff) {
            foreach ($path_elements as $dir) {
                $file = $dir . DIRECTORY_SEPARATOR . $program . $suff;
                // It's possible to run a .bat on Windows that is_executable                 // would return false for. The is_executable check is meaningless...                 if (OS_WINDOWS) {
                    if (file_exists($file)) {
                        return $file;
                    }
                } else {
                    if (is_executable($file)) {
                        return $file;
                    }
                }
            }
        }
        return $fallback;
    }

    /** * The "find" command * * Usage: * * System::find($dir); * System::find("$dir -type d"); * System::find("$dir -type f"); * System::find("$dir -name *.php"); * System::find("$dir -name *.php -name *.htm*"); * System::find("$dir -maxdepth 1"); * * Params implemented: * $dir -> Start the search at this directory * -type d -> return only directories * -type f -> return only files * -maxdepth <n> -> max depth of recursion * -name <pattern> -> search pattern (bash style). Multiple -name param allowed * * @param mixed Either array or string with the command line * @return array Array of found files */
/** * Ensures that a given directory is world readable. * * @param \Drupal\Core\FileTransfer\FileTransfer $filetransfer * Object which is a child of FileTransfer. * @param string $path * The file path to make world readable. * @param bool $recursive * If the chmod should be applied recursively. */
  public function makeWorldReadable(&$filetransfer$path$recursive = TRUE) {
    if (!is_executable($path)) {
      // Set it to read + execute.       $new_perms = fileperms($path) & 0777 | 0005;
      $filetransfer->chmod($path$new_perms$recursive);
    }
  }

  /** * Performs a backup. * * @param \Drupal\Core\FileTransfer\FileTransfer $filetransfer * Object which is a child of FileTransfer. * @param string $from * The file path to copy from. * @param string $to * The file path to copy to. * * @todo Not implemented: https://www.drupal.org/node/2474355 */

    public function find(string $name, string $default = null, array $extraDirs = []): ?string
    {
        if (\ini_get('open_basedir')) {
            $searchPath = array_merge(explode(\PATH_SEPARATOR, \ini_get('open_basedir'))$extraDirs);
            $dirs = [];
            foreach ($searchPath as $path) {
                // Silencing against https://bugs.php.net/69240                 if (@is_dir($path)) {
                    $dirs[] = $path;
                } else {
                    if (basename($path) == $name && @is_executable($path)) {
                        return $path;
                    }
                }
            }
        } else {
            $dirs = array_merge(
                explode(\PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),
                $extraDirs
            );
        }

        

                else
                {
                    return false;
                }
                return true;
                break;
            case "https":
                if(!$this->curl_path)
                    return false;
                if(function_exists("is_executable"))
                    if (!is_executable($this->curl_path))
                        return false;
                $this->host = $URI_PARTS["host"];
                if(!empty($URI_PARTS["port"]))
                    $this->port = $URI_PARTS["port"];
                if($this->_isproxy)
                {
                    // using proxy, send entire URI                     $this->_httpsrequest($URI,$URI,$this->_httpmethod);
                }
                else
                {
                    
break;

                case 'readable':
                    $fileInfo['readable'] = is_readable($file);
                    break;

                case 'writable':
                    $fileInfo['writable'] = is_writable($file);
                    break;

                case 'executable':
                    $fileInfo['executable'] = is_executable($file);
                    break;

                case 'fileperms':
                    $fileInfo['fileperms'] = fileperms($file);
                    break;
            }
        }

        return $fileInfo;
    }
}
explode(\PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),
            $extraDirs
        );

        $suffixes = [''];
        if ('\\' === \DIRECTORY_SEPARATOR) {
            $pathExt = getenv('PATHEXT');
            $suffixes = array_merge($pathExt ? explode(\PATH_SEPARATOR, $pathExt) : $this->suffixes, $suffixes);
        }
        foreach ($suffixes as $suffix) {
            foreach ($dirs as $dir) {
                if (@is_file($file = $dir.\DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === \DIRECTORY_SEPARATOR || @is_executable($file))) {
                    return $file;
                }

                if (!@is_dir($dir) && basename($dir) === $name.$suffix && @is_executable($dir)) {
                    return $dir;
                }
            }
        }

        $command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v';
        if (\function_exists('exec') && ($executablePath = strtok(@exec($command.' '.escapeshellarg($name)), \PHP_EOL)) && is_executable($executablePath)) {
            
break;

                case 'readable':
                    $fileInfo['readable'] = is_readable($file);
                    break;

                case 'writable':
                    $fileInfo['writable'] = is_really_writable($file);
                    break;

                case 'executable':
                    $fileInfo['executable'] = is_executable($file);
                    break;

                case 'fileperms':
                    $fileInfo['fileperms'] = fileperms($file);
                    break;
            }
        }

        return $fileInfo;
    }
}

public function testFindWithExecutableDirectory()
    {
        if ('\\' === \DIRECTORY_SEPARATOR) {
            $this->markTestSkipped('Directories are not executable on Windows');
        }

        $originalPhpBinary = getenv('PHP_BINARY');

        try {
            $executableDirectoryPath = sys_get_temp_dir().'/PhpExecutableFinderTest_testFindWithExecutableDirectory';
            @mkdir($executableDirectoryPath);
            $this->assertTrue(is_executable($executableDirectoryPath));
            putenv('PHP_BINARY='.$executableDirectoryPath);

            $this->assertFalse((new PhpExecutableFinder())->find());
        } finally {
            putenv('PHP_BINARY='.$originalPhpBinary);
        }
    }
}
$this->markTestSkipped('Cannot test when open_basedir is set');
        }
        if ('\\' !== \DIRECTORY_SEPARATOR) {
            $this->markTestSkipped('Can be only tested on windows');
        }

        $target = tempnam(sys_get_temp_dir(), 'example-windows-executable');

        touch($target);
        touch($target.'.BAT');

        $this->assertFalse(is_executable($target));

        putenv('PATH='.sys_get_temp_dir());

        $finder = new ExecutableFinder();
        $result = $finder->find(basename($target), false);

        unlink($target);
        unlink($target.'.BAT');

        $this->assertSamePath($target.'.BAT', $result);
    }

    
Home | Imprint | This part of the site doesn't use cookies.