3 namespace Drupal\update;
5 use Drupal\Core\DrupalKernelInterface;
6 use Symfony\Component\HttpFoundation\RequestStack;
9 * Gets the root path used by the Update Manager to install or update projects.
11 class UpdateRootFactory {
16 * @var \Drupal\Core\DrupalKernelInterface
18 protected $drupalKernel;
23 * @var \Symfony\Component\HttpFoundation\RequestStack
25 protected $requestStack;
28 * Constructs an UpdateRootFactory instance.
30 * @param \Drupal\Core\DrupalKernelInterface $drupal_kernel
32 * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
35 public function __construct(DrupalKernelInterface $drupal_kernel, RequestStack $request_stack) {
36 $this->drupalKernel = $drupal_kernel;
37 $this->requestStack = $request_stack;
41 * Gets the root path under which projects are installed or updated.
43 * The Update Manager will ensure that project files can only be copied to
44 * specific subdirectories of this root path.
48 public function get() {
49 // Normally the Update Manager's root path is the same as the app root (the
50 // directory in which the Drupal site is installed).
51 $root_path = $this->drupalKernel->getAppRoot();
53 // When running in a test site, change the root path to be the testing site
54 // directory. This ensures that it will always be writable by the webserver
55 // (thereby allowing the actual extraction and installation of projects by
56 // the Update Manager to be tested) and also ensures that new project files
57 // added there won't be visible to the parent site and will be properly
58 // cleaned up once the test finishes running. This is done here (rather
59 // than having the tests enable a module which overrides the update root
60 // factory service) to ensure that the parent site is automatically kept
61 // clean without relying on test authors to take any explicit steps. See
62 // also \Drupal\update\Tests\UpdateTestBase::setUp().
63 if (DRUPAL_TEST_IN_CHILD_SITE) {
64 $kernel = $this->drupalKernel;
65 $request = $this->requestStack->getCurrentRequest();
66 $root_path .= '/' . $kernel::findSitePath($request);