You are here

class JavaService in Search File Attachments 8

Service class to define and check the java binary for the tika library.

Hierarchy

Expanded class hierarchy of JavaService

1 string reference to 'JavaService'
search_file_attachments.services.yml in ./search_file_attachments.services.yml
search_file_attachments.services.yml
1 service uses JavaService
search_file_attachments.java in ./search_file_attachments.services.yml
Drupal\search_file_attachments\JavaService

File

src/JavaService.php, line 8

Namespace

Drupal\search_file_attachments
View source
class JavaService {
  protected $javaPath;

  /**
   * Constructor.
   */
  public function __construct() {
    $this
      ->setJavaPath('java');
  }

  /**
   * Returns the java path.
   *
   * @return string
   *   The java path.
   */
  public function getJavaPath() {
    return $this->javaPath;
  }

  /**
   * Set the java path.
   *
   * @param string $path
   *   The path to the java binary.
   *
   * @return \Drupal\search_file_attachments\JavaService
   *   This class itself.
   */
  public function setJavaPath($path) {
    if (strpos(ini_get('extension_dir'), 'MAMP/')) {
      $path = 'export DYLD_LIBRARY_PATH=""; ' . $path;
    }
    $this->javaPath = $path;
    return $this;
  }

  /**
   * Checks the java path that the java binary can be executed.
   *
   * @return bool
   *   TRUE or FALSE if the java binary can be executed.
   */
  public function checkJava() {
    $path = $this
      ->getJavaPath();
    $temp = tempnam(file_directory_temp(), 'asa');
    exec($path . ' -version > ' . $temp . ' 2>&1');
    $stderror = file_get_contents($temp);
    $found = preg_match('/Runtime Environment/', $stderror);
    return $found ? TRUE : FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
JavaService::$javaPath protected property
JavaService::checkJava public function Checks the java path that the java binary can be executed.
JavaService::getJavaPath public function Returns the java path.
JavaService::setJavaPath public function Set the java path.
JavaService::__construct public function Constructor.