AbstractOperation.php

Same filename and directory in other branches
  1. 8.9.x composer/Plugin/Scaffold/Operations/AbstractOperation.php
  2. 10 composer/Plugin/Scaffold/Operations/AbstractOperation.php
  3. 11.x composer/Plugin/Scaffold/Operations/AbstractOperation.php

Namespace

Drupal\Composer\Plugin\Scaffold\Operations

File

composer/Plugin/Scaffold/Operations/AbstractOperation.php

View source
<?php

namespace Drupal\Composer\Plugin\Scaffold\Operations;

use Drupal\Composer\Plugin\Scaffold\ScaffoldFilePath;

/**
 * Provides default behaviors for operations.
 *
 * @internal
 */
abstract class AbstractOperation implements OperationInterface {
    
    /**
     * Cached contents of scaffold file to be written to disk.
     *
     * @var string
     */
    protected $contents;
    
    /**
     * {@inheritdoc}
     */
    public final function contents() {
        if (!isset($this->contents)) {
            $this->contents = $this->generateContents();
        }
        return $this->contents;
    }
    
    /**
     * Load the scaffold contents or otherwise generate what is needed.
     *
     * @return string
     *   The contents of the scaffold file.
     */
    protected abstract function generateContents();
    
    /**
     * {@inheritdoc}
     */
    public function scaffoldOverExistingTarget(OperationInterface $existing_target) {
        return $this;
    }
    
    /**
     * {@inheritdoc}
     */
    public function scaffoldAtNewLocation(ScaffoldFilePath $destination) {
        return $this;
    }

}

Classes

Title Deprecated Summary
AbstractOperation Provides default behaviors for operations.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.