class PathLocator in Automatic Updates 8.2
Computes file system paths that are needed for automatic updates.
Hierarchy
- class \Drupal\automatic_updates\PathLocator
Expanded class hierarchy of PathLocator
6 files declare their use of PathLocator
- Cleaner.php in src/
ComposerStager/ Cleaner.php - CoreComposerValidatorTest.php in tests/
src/ Kernel/ ReadinessValidation/ CoreComposerValidatorTest.php - DiskSpaceValidator.php in src/
Validator/ DiskSpaceValidator.php - FileSystemOperationsTest.php in tests/
src/ Functional/ FileSystemOperationsTest.php - ReadinessValidationManager.php in src/
Validation/ ReadinessValidationManager.php
1 string reference to 'PathLocator'
1 service uses PathLocator
File
- src/
PathLocator.php, line 12
Namespace
Drupal\automatic_updatesView source
class PathLocator {
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The absolute path of the running Drupal code base.
*
* @var string
*/
protected $appRoot;
/**
* Constructs a PathLocator object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
* @param string $app_root
* The absolute path of the running Drupal code base.
*/
public function __construct(ConfigFactoryInterface $config_factory, string $app_root) {
$this->configFactory = $config_factory;
$this->appRoot = $app_root;
}
/**
* Returns the path of the active directory, which should be updated.
*
* @return string
* The absolute path which should be updated.
*/
public function getActiveDirectory() : string {
return $this
->getProjectRoot();
}
/**
* Returns the path of the directory where updates should be staged.
*
* This directory may be made world-writeable for clean-up, so it should be
* somewhere that doesn't put the Drupal installation at risk.
*
* @return string
* The absolute path of the directory where updates should be staged.
*
* @see \Drupal\automatic_updates\ComposerStager\Cleaner::clean()
*/
public function getStageDirectory() : string {
// Append the site ID to the directory in order to support parallel test
// runs, or multiple sites hosted on the same server.
$site_id = $this->configFactory
->get('system.site')
->get('uuid');
return FileSystem::getOsTemporaryDirectory() . DIRECTORY_SEPARATOR . '.automatic_updates_stage_' . $site_id;
}
/**
* Returns the absolute path of the project root.
*
* This is where the project-level composer.json should normally be found, and
* may or may not be the same path as the Drupal code base.
*
* @return string
* The absolute path of the project root.
*/
public function getProjectRoot() : string {
// Assume that the vendor directory is immediately below the project root.
return realpath($this
->getVendorDirectory() . DIRECTORY_SEPARATOR . '..');
}
/**
* Returns the absolute path of the vendor directory.
*
* @return string
* The absolute path of the vendor directory.
*/
public function getVendorDirectory() : string {
$reflector = new \ReflectionClass(ClassLoader::class);
return dirname($reflector
->getFileName(), 2);
}
/**
* Returns the path of the Drupal installation, relative to the project root.
*
* @return string
* The path of the Drupal installation, relative to the project root and
* without leading or trailing slashes. Will return an empty string if the
* project root and Drupal root are the same.
*/
public function getWebRoot() : string {
$web_root = str_replace($this
->getProjectRoot(), NULL, $this->appRoot);
return trim($web_root, DIRECTORY_SEPARATOR);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PathLocator:: |
protected | property | The absolute path of the running Drupal code base. | |
PathLocator:: |
protected | property | The config factory service. | |
PathLocator:: |
public | function | Returns the path of the active directory, which should be updated. | |
PathLocator:: |
public | function | Returns the absolute path of the project root. | |
PathLocator:: |
public | function | Returns the path of the directory where updates should be staged. | |
PathLocator:: |
public | function | Returns the absolute path of the vendor directory. | |
PathLocator:: |
public | function | Returns the path of the Drupal installation, relative to the project root. | |
PathLocator:: |
public | function | Constructs a PathLocator object. |