Commit f96b7fba authored by catch's avatar catch
Browse files

Issue #3232095 by daffie, dww, longwave, andypost, catch, larowlan: [Symfony...

Issue #3232095 by daffie, dww, longwave, andypost, catch, larowlan: [Symfony 6] Refactor the "update.root" service to return an object not a string
parent ea01173e
Loading
Loading
Loading
Loading
+24 −2
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@
/**
 * Gets the root path used by the Update Manager to install or update projects.
 */
class UpdateRootFactory {
class UpdateRoot {

  /**
   * The Drupal kernel.
@@ -24,6 +24,13 @@ class UpdateRootFactory {
   */
  protected $requestStack;

  /**
   * The update root.
   *
   * @var string
   */
  protected $updateRoot;

  /**
   * Constructs an UpdateRootFactory instance.
   *
@@ -37,6 +44,16 @@ public function __construct(DrupalKernelInterface $drupal_kernel, RequestStack $
    $this->requestStack = $request_stack;
  }

  /**
   * Sets the root path under which projects are installed or updated.
   *
   * @param string $update_root
   *   The update root.
   */
  public function set(string $update_root): void {
    $this->updateRoot = $update_root;
  }

  /**
   * Gets the root path under which projects are installed or updated.
   *
@@ -45,7 +62,12 @@ public function __construct(DrupalKernelInterface $drupal_kernel, RequestStack $
   *
   * @return string
   */
  public function get() {
  public function __toString(): string {
    // Return the $updateRoot when it is set.
    if (isset($this->updateRoot)) {
      return $this->updateRoot;
    }

    // Normally the Update Manager's root path is the same as the app root (the
    // directory in which the Drupal site is installed).
    $root_path = $this->drupalKernel->getAppRoot();
+1 −2
Original line number Diff line number Diff line
@@ -63,8 +63,7 @@ protected function setUp() {
    // test child site.
    $request = \Drupal::request();
    $update_root = $this->container->get('update.root') . '/' . DrupalKernel::findSitePath($request);
    $this->container->set('update.root', $update_root);
    \Drupal::setContainer($this->container);
    $this->container->get('update.root')->set($update_root);

    // Create the directories within the root path within which the Update
    // Manager will install projects.
+1 −7
Original line number Diff line number Diff line
@@ -14,11 +14,5 @@ services:
    class: Drupal\update\UpdateFetcher
    arguments: ['@config.factory', '@http_client', '@settings']
  update.root:
    class: SplString
    factory: ['@update.root.factory', 'get']
    tags:
      - { name: parameter_service }
  update.root.factory:
    class: Drupal\update\UpdateRootFactory
    class: Drupal\update\UpdateRoot
    arguments: ['@kernel', '@request_stack']
    public: false