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/ProductForm.tar
Component.php000064400000005547151547771400007245 0ustar00<?php
/**
 * Abstract class for product form components.
 */

namespace Automattic\WooCommerce\Internal\Admin\ProductForm;

/**
 * Component class.
 */
abstract class Component {
	/**
	 * Product Component traits.
	 */
	use ComponentTrait;

	/**
	 * Component additional arguments.
	 *
	 * @var array
	 */
	protected $additional_args;

	/**
	 * Constructor
	 *
	 * @param string $id Component id.
	 * @param string $plugin_id Plugin id.
	 * @param array  $additional_args Array containing additional arguments.
	 */
	public function __construct( $id, $plugin_id, $additional_args ) {
		$this->id              = $id;
		$this->plugin_id       = $plugin_id;
		$this->additional_args = $additional_args;
	}

	/**
	 * Component arguments.
	 *
	 * @return array
	 */
	public function get_additional_args() {
		return $this->additional_args;
	}

	/**
	 * Component arguments.
	 *
	 * @param string $key key of argument.
	 * @return mixed
	 */
	public function get_additional_argument( $key ) {
		return self::get_argument_from_path( $this->additional_args, $key );
	}

	/**
	 * Get the component as JSON.
	 *
	 * @return array
	 */
	public function get_json() {
		return array_merge(
			array(
				'id'        => $this->get_id(),
				'plugin_id' => $this->get_plugin_id(),
			),
			$this->get_additional_args()
		);
	}

	/**
	 * Sorting function for product form component.
	 *
	 * @param Component $a Component a.
	 * @param Component $b Component b.
	 * @param array     $sort_by key and order to sort by.
	 * @return int
	 */
	public static function sort( $a, $b, $sort_by = array() ) {
		$key   = $sort_by['key'];
		$a_val = $a->get_additional_argument( $key );
		$b_val = $b->get_additional_argument( $key );
		if ( 'asc' === $sort_by['order'] ) {
			return $a_val <=> $b_val;
		} else {
			return $b_val <=> $a_val;
		}
	}

	/**
	 * Gets argument by dot notation path.
	 *
	 * @param array  $arguments Arguments array.
	 * @param string $path Path for argument key.
	 * @param string $delimiter Path delimiter, default: '.'.
	 * @return mixed|null
	 */
	public static function get_argument_from_path( $arguments, $path, $delimiter = '.' ) {
		$path_keys = explode( $delimiter, $path );
		$num_keys  = count( $path_keys );

		$val = $arguments;
		for ( $i = 0; $i < $num_keys; $i++ ) {
			$key = $path_keys[ $i ];
			if ( array_key_exists( $key, $val ) ) {
				$val = $val[ $key ];
			} else {
				$val = null;
				break;
			}
		}
		return $val;
	}

	/**
	 * Array of required arguments.
	 *
	 * @var array
	 */
	protected $required_arguments = array();

	/**
	 * Get missing arguments of args array.
	 *
	 * @param array $args field arguments.
	 * @return array
	 */
	public function get_missing_arguments( $args ) {
		return array_values(
			array_filter(
				$this->required_arguments,
				function( $arg_key ) use ( $args ) {
					return null === self::get_argument_from_path( $args, $arg_key );
				}
			)
		);
	}
}
ComponentTrait.php000064400000001315151547771400010236 0ustar00<?php
/**
 * Product Form Traits
 */

namespace Automattic\WooCommerce\Internal\Admin\ProductForm;

defined( 'ABSPATH' ) || exit;

/**
 * ComponentTrait class.
 */
trait ComponentTrait {
	/**
	 * Component ID.
	 *
	 * @var string
	 */
	protected $id;

	/**
	 * Plugin ID.
	 *
	 * @var string
	 */
	protected $plugin_id;

	/**
	 * Product form component location.
	 *
	 * @var string
	 */
	protected $location;

	/**
	 * Product form component order.
	 *
	 * @var number
	 */
	protected $order;

	/**
	 * Return id.
	 *
	 * @return string
	 */
	public function get_id() {
		return $this->id;
	}

	/**
	 * Return plugin id.
	 *
	 * @return string
	 */
	public function get_plugin_id() {
		return $this->plugin_id;
	}
}
Field.php000064400000002422151547771400006313 0ustar00<?php
/**
 * Handles product form field related methods.
 */

namespace Automattic\WooCommerce\Internal\Admin\ProductForm;

/**
 * Field class.
 */
class Field extends Component {

	/**
	 * Constructor
	 *
	 * @param string $id Field id.
	 * @param string $plugin_id Plugin id.
	 * @param array  $additional_args Array containing the necessary arguments.
	 *     $args = array(
	 *       'type'            => (string) Field type. Required.
	 *       'section'         => (string) Field location. Required.
	 *       'order'           => (int) Field order.
	 *       'properties'      => (array) Field properties.
	 *     ).
	 * @throws \Exception If there are missing arguments.
	 */
	public function __construct( $id, $plugin_id, $additional_args ) {
		parent::__construct( $id, $plugin_id, $additional_args );
		$this->required_arguments = array(
			'type',
			'section',
			'properties.name',
			'properties.label',
		);

		$missing_arguments = self::get_missing_arguments( $additional_args );
		if ( count( $missing_arguments ) > 0 ) {
			throw new \Exception(
				sprintf(
				/* translators: 1: Missing arguments list. */
					esc_html__( 'You are missing required arguments of WooCommerce ProductForm Field: %1$s', 'woocommerce' ),
					join( ', ', $missing_arguments )
				)
			);
		}
	}
}
FormFactory.php000064400000016476151547771400007541 0ustar00<?php
/**
 * WooCommerce Product Form Factory
 *
 * @package Woocommerce ProductForm
 */

namespace Automattic\WooCommerce\Internal\Admin\ProductForm;

use WP_Error;

/**
 * Factory that contains logic for the WooCommerce Product Form.
 */
class FormFactory {
	/**
	 * Class instance.
	 *
	 * @var Form instance
	 */
	protected static $instance = null;

	/**
	 * Store form fields.
	 *
	 * @var array
	 */
	protected static $form_fields = array();

	/**
	 * Store form cards.
	 *
	 * @var array
	 */
	protected static $form_subsections = array();

	/**
	 * Store form sections.
	 *
	 * @var array
	 */
	protected static $form_sections = array();

	/**
	 * Store form tabs.
	 *
	 * @var array
	 */
	protected static $form_tabs = array();

	/**
	 * Get class instance.
	 */
	final public static function instance() {
		if ( ! static::$instance ) {
			static::$instance = new static();
		}
		return static::$instance;
	}

	/**
	 * Init.
	 */
	public function init() {    }

	/**
	 * Adds a field to the product form.
	 *
	 * @param string $id Field id.
	 * @param string $plugin_id Plugin id.
	 * @param array  $args Array containing the necessary arguments.
	 *     $args = array(
	 *       'type'            => (string) Field type. Required.
	 *       'section'         => (string) Field location. Required.
	 *       'order'           => (int) Field order.
	 *       'properties'      => (array) Field properties.
	 *       'name'            => (string) Field name.
	 *     ).
	 * @return Field|WP_Error New field or WP_Error.
	 */
	public static function add_field( $id, $plugin_id, $args ) {
		$new_field = self::create_item( 'field', 'Field', $id, $plugin_id, $args );
		if ( is_wp_error( $new_field ) ) {
			return $new_field;
		}
		self::$form_fields[ $id ] = $new_field;
		return $new_field;
	}

	/**
	 * Adds a Subsection to the product form.
	 *
	 * @param string $id Subsection id.
	 * @param string $plugin_id Plugin id.
	 * @param array  $args Array containing the necessary arguments.
	 * @return Subsection|WP_Error New subsection or WP_Error.
	 */
	public static function add_subsection( $id, $plugin_id, $args = array() ) {
		$new_subsection = self::create_item( 'subsection', 'Subsection', $id, $plugin_id, $args );
		if ( is_wp_error( $new_subsection ) ) {
			return $new_subsection;
		}
		self::$form_subsections[ $id ] = $new_subsection;
		return $new_subsection;
	}

	/**
	 * Adds a section to the product form.
	 *
	 * @param string $id Card id.
	 * @param string $plugin_id Plugin id.
	 * @param array  $args Array containing the necessary arguments.
	 * @return Section|WP_Error New section or WP_Error.
	 */
	public static function add_section( $id, $plugin_id, $args ) {
		$new_section = self::create_item( 'section', 'Section', $id, $plugin_id, $args );
		if ( is_wp_error( $new_section ) ) {
			return $new_section;
		}
		self::$form_sections[ $id ] = $new_section;
		return $new_section;
	}

	/**
	 * Adds a tab to the product form.
	 *
	 * @param string $id Card id.
	 * @param string $plugin_id Plugin id.
	 * @param array  $args Array containing the necessary arguments.
	 * @return Tab|WP_Error New section or WP_Error.
	 */
	public static function add_tab( $id, $plugin_id, $args ) {
		$new_tab = self::create_item( 'tab', 'Tab', $id, $plugin_id, $args );
		if ( is_wp_error( $new_tab ) ) {
			return $new_tab;
		}
		self::$form_tabs[ $id ] = $new_tab;
		return $new_tab;
	}

	/**
	 * Returns list of registered fields.
	 *
	 * @param array $sort_by key and order to sort by.
	 * @return array list of registered fields.
	 */
	public static function get_fields( $sort_by = array(
		'key'   => 'order',
		'order' => 'asc',
	) ) {
		return self::get_items( 'field', 'Field', $sort_by );
	}

	/**
	 * Returns list of registered cards.
	 *
	 * @param array $sort_by key and order to sort by.
	 * @return array list of registered cards.
	 */
	public static function get_subsections( $sort_by = array(
		'key'   => 'order',
		'order' => 'asc',
	) ) {
		return self::get_items( 'subsection', 'Subsection', $sort_by );
	}

	/**
	 * Returns list of registered sections.
	 *
	 * @param array $sort_by key and order to sort by.
	 * @return array list of registered sections.
	 */
	public static function get_sections( $sort_by = array(
		'key'   => 'order',
		'order' => 'asc',
	) ) {
		return self::get_items( 'section', 'Section', $sort_by );
	}

	/**
	 * Returns list of registered tabs.
	 *
	 * @param array $sort_by key and order to sort by.
	 * @return array list of registered tabs.
	 */
	public static function get_tabs( $sort_by = array(
		'key'   => 'order',
		'order' => 'asc',
	) ) {
		return self::get_items( 'tab', 'Tab', $sort_by );
	}

	/**
	 * Returns list of registered items.
	 *
	 * @param string $type Form component type.
	 * @return array List of registered items.
	 */
	private static function get_item_list( $type ) {
		$mapping = array(
			'field'      => self::$form_fields,
			'subsection' => self::$form_subsections,
			'section'    => self::$form_sections,
			'tab'        => self::$form_tabs,
		);
		if ( array_key_exists( $type, $mapping ) ) {
			return $mapping[ $type ];
		}
		return array();
	}

	/**
	 * Returns list of registered items.
	 *
	 * @param string       $type Form component type.
	 * @param class-string $class_name Class of component type.
	 * @param array        $sort_by key and order to sort by.
	 * @return array       list of registered items.
	 */
	private static function get_items( $type, $class_name, $sort_by = array(
		'key'   => 'order',
		'order' => 'asc',
	) ) {
		$item_list = self::get_item_list( $type );
		$class     = 'Automattic\\WooCommerce\\Internal\\Admin\\ProductForm\\' . $class_name;
		$items     = array_values( $item_list );
		if ( class_exists( $class ) && method_exists( $class, 'sort' ) ) {
			usort(
				$items,
				function ( $a, $b ) use ( $sort_by, $class ) {
					return $class::sort( $a, $b, $sort_by );
				}
			);
		}
		return $items;
	}

	/**
	 * Creates a new item.
	 *
	 * @param string       $type Form component type.
	 * @param class-string $class_name Class of component type.
	 * @param string       $id Item id.
	 * @param string       $plugin_id Plugin id.
	 * @param array        $args additional arguments for item.
	 * @return Field|Card|Section|Tab|WP_Error New product form item or WP_Error.
	 */
	private static function create_item( $type, $class_name, $id, $plugin_id, $args ) {
		$item_list = self::get_item_list( $type );
		$class     = 'Automattic\\WooCommerce\\Internal\\Admin\\ProductForm\\' . $class_name;
		if ( ! class_exists( $class ) ) {
			return new WP_Error(
				'wc_product_form_' . $type . '_missing_form_class',
				sprintf(
				/* translators: 1: missing class name. */
					esc_html__( '%1$s class does not exist.', 'woocommerce' ),
					$class
				)
			);
		}
		if ( isset( $item_list[ $id ] ) ) {
			return new WP_Error(
				'wc_product_form_' . $type . '_duplicate_field_id',
				sprintf(
				/* translators: 1: Item type 2: Duplicate registered item id. */
					esc_html__( 'You have attempted to register a duplicate form %1$s with WooCommerce Form: %2$s', 'woocommerce' ),
					$type,
					'`' . $id . '`'
				)
			);
		}

		$defaults = array(
			'order' => 20,
		);

		$item_arguments = wp_parse_args( $args, $defaults );

		try {
			return new $class( $id, $plugin_id, $item_arguments );
		} catch ( \Exception $e ) {
			return new WP_Error(
				'wc_product_form_' . $type . '_class_creation',
				$e->getMessage()
			);
		}
	}
}

Section.php000064400000002234151547771400006675 0ustar00<?php
/**
 * Handles product form section related methods.
 */

namespace Automattic\WooCommerce\Internal\Admin\ProductForm;

/**
 * Section class.
 */
class Section extends Component {

	/**
	 * Constructor
	 *
	 * @param string $id Section id.
	 * @param string $plugin_id Plugin id.
	 * @param array  $additional_args Array containing additional arguments.
	 *     $args = array(
	 *       'order'       => (int) Section order.
	 *       'title'       => (string) Section description.
	 *       'description' => (string) Section description.
	 *     ).
	 * @throws \Exception If there are missing arguments.
	 */
	public function __construct( $id, $plugin_id, $additional_args ) {
		parent::__construct( $id, $plugin_id, $additional_args );
		$this->required_arguments = array(
			'title',
		);
		$missing_arguments        = self::get_missing_arguments( $additional_args );
		if ( count( $missing_arguments ) > 0 ) {
			throw new \Exception(
				sprintf(
				/* translators: 1: Missing arguments list. */
					esc_html__( 'You are missing required arguments of WooCommerce ProductForm Section: %1$s', 'woocommerce' ),
					join( ', ', $missing_arguments )
				)
			);
		}
	}
}
Subsection.php000064400000000304151547771400007403 0ustar00<?php
/**
 * Handles product form SubSection related methods.
 */

namespace Automattic\WooCommerce\Internal\Admin\ProductForm;

/**
 * SubSection class.
 */
class Subsection extends Component {}
Tab.php000064400000002322151547771400005775 0ustar00<?php
/**
 * Handles product form tab related methods.
 */

namespace Automattic\WooCommerce\Internal\Admin\ProductForm;

/**
 * Field class.
 */
class Tab extends Component {

	/**
	 * Constructor
	 *
	 * @param string $id Field id.
	 * @param string $plugin_id Plugin id.
	 * @param array  $additional_args Array containing the necessary arguments.
	 *     $args = array(
	 *       'name'            => (string) Tab name. Required.
	 *       'title'         => (string) Tab title. Required.
	 *       'order'           => (int) Tab order.
	 *       'properties'      => (array) Tab properties.
	 *     ).
	 * @throws \Exception If there are missing arguments.
	 */
	public function __construct( $id, $plugin_id, $additional_args ) {
		parent::__construct( $id, $plugin_id, $additional_args );

		$this->required_arguments = array(
			'name',
			'title',
		);

		$missing_arguments = self::get_missing_arguments( $additional_args );
		if ( count( $missing_arguments ) > 0 ) {
			throw new \Exception(
				sprintf(
				/* translators: 1: Missing arguments list. */
					esc_html__( 'You are missing required arguments of WooCommerce ProductForm Tab: %1$s', 'woocommerce' ),
					join( ', ', $missing_arguments )
				)
			);
		}
	}

}