1<?php
2
3namespace Drupal\Composer\Plugin\Scaffold\Operations;
4
5use Drupal\Composer\Plugin\Scaffold\ScaffoldFilePath;
6
7/**
8 * Provides default behaviors for operations.
9 *
10 * @internal
11 */
12abstract class AbstractOperation implements OperationInterface {
13
14  /**
15   * Cached contents of scaffold file to be written to disk.
16   *
17   * @var string
18   */
19  protected $contents;
20
21  /**
22   * {@inheritdoc}
23   */
24  final public function contents() {
25    if (!isset($this->contents)) {
26      $this->contents = $this->generateContents();
27    }
28    return $this->contents;
29  }
30
31  /**
32   * Load the scaffold contents or otherwise generate what is needed.
33   *
34   * @return string
35   *   The contents of the scaffold file.
36   */
37  abstract protected function generateContents();
38
39  /**
40   * {@inheritdoc}
41   */
42  public function scaffoldOverExistingTarget(OperationInterface $existing_target) {
43    return $this;
44  }
45
46  /**
47   * {@inheritdoc}
48   */
49  public function scaffoldAtNewLocation(ScaffoldFilePath $destination) {
50    return $this;
51  }
52
53}
54