MailPoet\EmailEditor\Engine\Renderer\ContentRenderer

Process_Manager{}WC 1.0

Class Process_Manager

No Hooks.

Usage

$Process_Manager = new Process_Manager();
// use class methods

Methods

  1. public __construct(
  2. public postprocess( string $html )
  3. public preprocess( array $parsed_blocks, array $layout, array $styles )
  4. public register_postprocessor( Postprocessor $postprocessor )
  5. public register_preprocessor( Preprocessor $preprocessor )

Process_Manager{} code WC 9.8.1

class Process_Manager {
	/**
	 * List of preprocessors
	 *
	 * @var Preprocessor[]
	 */
	private $preprocessors = array();

	/**
	 * List of postprocessors
	 *
	 * @var Postprocessor[]
	 */
	private $postprocessors = array();

	/**
	 * Process_Manager constructor.
	 *
	 * @param Cleanup_Preprocessor       $cleanup_preprocessor Cleanup preprocessor.
	 * @param Blocks_Width_Preprocessor  $blocks_width_preprocessor Blocks width preprocessor.
	 * @param Typography_Preprocessor    $typography_preprocessor Typography preprocessor.
	 * @param Spacing_Preprocessor       $spacing_preprocessor Spacing preprocessor.
	 * @param Highlighting_Postprocessor $highlighting_postprocessor Highlighting postprocessor.
	 * @param Variables_Postprocessor    $variables_postprocessor Variables postprocessor.
	 */
	public function __construct(
		Cleanup_Preprocessor $cleanup_preprocessor,
		Blocks_Width_Preprocessor $blocks_width_preprocessor,
		Typography_Preprocessor $typography_preprocessor,
		Spacing_Preprocessor $spacing_preprocessor,
		Highlighting_Postprocessor $highlighting_postprocessor,
		Variables_Postprocessor $variables_postprocessor
	) {
		$this->register_preprocessor( $cleanup_preprocessor );
		$this->register_preprocessor( $blocks_width_preprocessor );
		$this->register_preprocessor( $typography_preprocessor );
		$this->register_preprocessor( $spacing_preprocessor );
		$this->register_postprocessor( $highlighting_postprocessor );
		$this->register_postprocessor( $variables_postprocessor );
	}

	/**
	 * Method to preprocess blocks
	 *
	 * @param array                                                                                                             $parsed_blocks Parsed blocks.
	 * @param array{contentSize: string, wideSize?: string, allowEditing?: bool, allowCustomContentAndWideSize?: bool}          $layout Layout.
	 * @param array{spacing: array{padding: array{bottom: string, left: string, right: string, top: string}, blockGap: string}} $styles Styles.
	 * @return array
	 */
	public function preprocess( array $parsed_blocks, array $layout, array $styles ): array {
		foreach ( $this->preprocessors as $preprocessor ) {
			$parsed_blocks = $preprocessor->preprocess( $parsed_blocks, $layout, $styles );
		}
		return $parsed_blocks;
	}

	/**
	 * Method to postprocess the content
	 *
	 * @param string $html HTML content.
	 * @return string
	 */
	public function postprocess( string $html ): string {
		foreach ( $this->postprocessors as $postprocessor ) {
			$html = $postprocessor->postprocess( $html );
		}
		return $html;
	}

	/**
	 * Register preprocessor
	 *
	 * @param Preprocessor $preprocessor Preprocessor.
	 */
	public function register_preprocessor( Preprocessor $preprocessor ): void {
		$this->preprocessors[] = $preprocessor;
	}

	/**
	 * Register postprocessor
	 *
	 * @param Postprocessor $postprocessor Postprocessor.
	 */
	public function register_postprocessor( Postprocessor $postprocessor ): void {
		$this->postprocessors[] = $postprocessor;
	}
}