You are here

abstract class Filesystem in Automatic Updates 8

Base class for filesystem checkers.

Hierarchy

Expanded class hierarchy of Filesystem

File

src/ReadinessChecker/Filesystem.php, line 10

Namespace

Drupal\automatic_updates\ReadinessChecker
View source
abstract class Filesystem implements ReadinessCheckerInterface {
  use StringTranslationTrait;

  /**
   * The root file path.
   *
   * @var string
   */
  protected $rootPath;

  /**
   * The vendor file path.
   *
   * @var string
   */
  protected $vendorPath;

  /**
   * Filesystem constructor.
   *
   * @param string $app_root
   *   The app root.
   */
  public function __construct($app_root) {
    $this->rootPath = (string) $app_root;
  }

  /**
   * {@inheritdoc}
   */
  public function run() {
    if (!file_exists($this
      ->getRootPath() . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, [
      'core',
      'core.api.php',
    ]))) {
      return [
        $this
          ->t('The web root could not be located.'),
      ];
    }
    return $this
      ->doCheck();
  }

  /**
   * Perform checks.
   *
   * @return array
   *   An array of translatable strings if any checks fail.
   */
  protected abstract function doCheck();

  /**
   * Get the root file path.
   *
   * @return string
   *   The root file path.
   */
  protected function getRootPath() {
    if (!$this->rootPath) {
      $this->rootPath = (string) \Drupal::root();
    }
    return $this->rootPath;
  }

  /**
   * Get the vendor file path.
   *
   * @return string
   *   The vendor file path.
   */
  protected function getVendorPath() {
    if (!$this->vendorPath) {
      $this->vendorPath = $this
        ->getRootPath() . DIRECTORY_SEPARATOR . 'vendor';
    }
    return $this->vendorPath;
  }

  /**
   * Determine if the root and vendor file system are the same logical disk.
   *
   * @param string $root
   *   Root file path.
   * @param string $vendor
   *   Vendor file path.
   *
   * @return bool
   *   TRUE if same file system, FALSE otherwise.
   */
  protected function areSameLogicalDisk($root, $vendor) {
    $root_statistics = stat($root);
    $vendor_statistics = stat($vendor);
    return $root_statistics && $vendor_statistics && $root_statistics['dev'] === $vendor_statistics['dev'];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Filesystem::$rootPath protected property The root file path.
Filesystem::$vendorPath protected property The vendor file path.
Filesystem::areSameLogicalDisk protected function Determine if the root and vendor file system are the same logical disk. 2
Filesystem::doCheck abstract protected function Perform checks. 4
Filesystem::getRootPath protected function Get the root file path.
Filesystem::getVendorPath protected function Get the vendor file path.
Filesystem::run public function Run check. Overrides ReadinessCheckerInterface::run
Filesystem::__construct public function Filesystem constructor. 1
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.