HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /var/www/html/ielts-store/wp-content/plugins/woocommerce-zapier/src/WooCommerceResource/Manager.php
<?php

namespace OM4\WooCommerceZapier\WooCommerceResource;

use OM4\WooCommerceZapier\ContainerService;
use OM4\WooCommerceZapier\WooCommerceResource\Coupon\CouponResource;
use OM4\WooCommerceZapier\WooCommerceResource\Customer\CustomerResource;
use OM4\WooCommerceZapier\WooCommerceResource\Definition;
use OM4\WooCommerceZapier\WooCommerceResource\Order\OrderResource;
use OM4\WooCommerceZapier\WooCommerceResource\Product\ProductResource;
use ReflectionClass;

defined( 'ABSPATH' ) || exit;

/**
 * Resource Manager.
 *
 * Responsible for loading and accessing WooCommerce Zapier Resource Type definitions.
 *
 * @since 2.0.0
 */
class Manager {

	/**
	 * List of resource definitions (including enabled and disabled resources).
	 *
	 * @var Definition[]
	 */
	protected $resources = array();

	/**
	 * ContainerService instance.
	 *
	 * @var ContainerService
	 */
	protected $container;

	/**
	 * Constructor.
	 *
	 * @param ContainerService $container ContainerService instance.
	 */
	public function __construct( ContainerService $container ) {
		$this->container = $container;
	}

	/**
	 * Register all resources.
	 *
	 * @return void
	 */
	public function initialise() {
		$this->resources[] = $this->container->get( CustomerResource::class );
		$this->resources[] = $this->container->get( CouponResource::class );
		$this->resources[] = $this->container->get( OrderResource::class );
		$this->resources[] = $this->container->get( ProductResource::class );

		/**
		 * Extend the default list of supported resources.
		 *
		 * Any classes added using this filter must implement `OM4\WooCommerceZapier\WooCommerceResource\Definition`
		 *
		 * @internal
		 * @since 2.0.0
		 *
		 * @param class-string[] $additional_resources Array of class names (FQN).
		 */
		$additional_resources = apply_filters( 'wc_zapier_additional_resource_classes', array() );
		foreach ( $additional_resources as $resource_class_name ) {
			$class = new ReflectionClass( $resource_class_name );
			if ( $class->implementsInterface( Definition::class ) ) {
				$resource          = $this->container->get( $resource_class_name );
				$this->resources[] = $resource;
			}
		}
	}

	/**
	 * Get all active/enabled resource types.
	 *
	 * @return Definition[]
	 */
	public function get_enabled() {
		$enabled = array();
		foreach ( $this->get_all() as $resource ) {
			if ( $resource->is_enabled() ) {
				$enabled[] = $resource;
			}
		}
		return $enabled;
	}

	/**
	 * Get all registered resource types (including those that aren't enabled).
	 *
	 * @return Definition[]
	 */
	public function get_all() {
		if ( empty( $this->resources ) ) {
			// Not registered. Initialise.
			$this->initialise();
		}
		return $this->resources;
	}

	/**
	 * Get the Resource Definition object for the specified resource name.
	 *
	 * @param string $resource_type Resource key/type (coupon, customer, order, etc).
	 *
	 * @return Definition|false Resource definition, or false if resource definition doesn't exist.
	 */
	public function get_resource( $resource_type ) {
		foreach ( $this->get_all() as $resource ) {
			if ( $resource_type === $resource->get_key() ) {
				return $resource;
			}
		}
		return false;
	}

	/**
	 * Get a list of enabled/active resources.
	 *
	 * The array keys are plural resource keys (eg orders, customers) not singular.
	 *
	 * @return array
	 */
	public function get_enabled_resources_list() {
		$resources = array();
		foreach ( $this->get_enabled() as $resource ) {
			$resources[ $resource->get_key() . 's' ] = $resource->get_name();
		}
		return $resources;
	}

}