HEX
Server: LiteSpeed
System: Linux eko108.isimtescil.net 4.18.0-477.21.1.lve.1.el8.x86_64 #1 SMP Tue Sep 5 23:08:35 UTC 2023 x86_64
User: uyarreklamcomtr (11202)
PHP: 7.4.33
Disabled: opcache_get_status
Upload Files
File: /var/www/vhosts/uyarreklam.com.tr/httpdocs/BlockTemplateRegistry.tar
BlockTemplateRegistry.php000064400000003213151544716620011546 0ustar00<?php

namespace Automattic\WooCommerce\Internal\Admin\BlockTemplateRegistry;

use Automattic\WooCommerce\Admin\BlockTemplates\BlockTemplateInterface;

/**
 * Block template registry.
 */
final class BlockTemplateRegistry {

	/**
	 * Class instance.
	 *
	 * @var BlockTemplateRegistry|null
	 */
	private static $instance = null;

	/**
	 * Templates.
	 *
	 * @var array
	 */
	protected $templates = array();

	/**
	 * Get the instance of the class.
	 */
	public static function get_instance(): BlockTemplateRegistry {
		if ( null === self::$instance ) {
			self::$instance = new self();
		}

		return self::$instance;
	}

	/**
	 * Register a single template.
	 *
	 * @param BlockTemplateInterface $template Template to register.
	 *
	 * @throws \ValueError If a template with the same ID already exists.
	 */
	public function register( BlockTemplateInterface $template ) {
		$id = $template->get_id();

		if ( isset( $this->templates[ $id ] ) ) {
			throw new \ValueError( 'A template with the specified ID already exists in the registry.' );
		}

		/**
		 * Fires when a template is registered.
		 *
		 * @param BlockTemplateInterface $template Template that was registered.
		 *
		 * @since 8.2.0
		 */
		do_action( 'woocommerce_block_template_register', $template );

		$this->templates[ $id ] = $template;
	}

	/**
	 * Get the registered templates.
	 */
	public function get_all_registered(): array {
		return $this->templates;
	}

	/**
	 * Get a single registered template.
	 *
	 * @param string $id ID of the template.
	 */
	public function get_registered( $id ): BlockTemplateInterface {
		return isset( $this->templates[ $id ] ) ? $this->templates[ $id ] : null;
	}
}
BlockTemplatesController.php000064400000002675151544716620012257 0ustar00<?php

namespace Automattic\WooCommerce\Internal\Admin\BlockTemplateRegistry;

/**
 * Block template controller.
 */
class BlockTemplatesController {

    /**
     * Block template registry
     *
     * @var BlockTemplateRegistry
     */
    private $block_template_registry;

    /**
     * Block template transformer.
     *
     * @var TemplateTransformer
     */
    private $template_transformer;

    /**
     * Init.
     */
    public function init( $block_template_registry, $template_transformer ) {
        $this->block_template_registry = $block_template_registry;
        $this->template_transformer    = $template_transformer;
        add_action( 'rest_api_init', array( $this, 'register_templates' ) );
    }

    /**
     * Register templates in the blocks endpoint.
     */
    public function register_templates() {
        $templates = $this->block_template_registry->get_all_registered();

        foreach ( $templates as $template ) {
            add_filter( 'pre_get_block_templates', function( $query_result, $query, $template_type ) use( $template ) {
                if ( ! isset( $query['area'] ) || $query['area'] !== $template->get_area() ) {
                    return $query_result;
                }

                $wp_block_template = $this->template_transformer->transform( $template );
                $query_result[]    = $wp_block_template;
        
                return $query_result;
            }, 10, 3 );
        }
    }

}TemplateTransformer.php000064400000002575151544716620011277 0ustar00<?php

namespace Automattic\WooCommerce\Internal\Admin\BlockTemplateRegistry;

use Automattic\WooCommerce\Admin\BlockTemplates\BlockTemplateInterface;

/**
 * Template transformer.
 */
class TemplateTransformer {

    /**
	 * Transform the WooCommerceBlockTemplate to a WP_Block_Template.
	 *
	 * @param object $block_template The product template.
	 */
	public function transform( BlockTemplateInterface $block_template ): \WP_Block_Template {
		$template                 = new \WP_Block_Template();
		$template->id             = $block_template->get_id();
		$template->theme          = 'woocommerce/woocommerce';
		$template->content        = $block_template->get_formatted_template();
		$template->source         = 'plugin';
		$template->slug           = $block_template->get_id();
		$template->type           = 'wp_template';
		$template->title          = $block_template->get_title();
		$template->description    = $block_template->get_description();
		$template->status         = 'publish';
		$template->has_theme_file = true;
		$template->origin         = 'plugin';
		$template->is_custom      = false; // Templates loaded from the filesystem aren't custom, ones that have been edited and loaded from the DB are.
		$template->post_types     = array(); // Don't appear in any Edit Post template selector dropdown.
		$template->area           = $block_template->get_area();

		return $template;
	}

}