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/JobRepository.php.tar
uyarreklam.com.tr/httpdocs/wp-content/plugins/google-listings-and-ads/src/Jobs/JobRepository.php000064400000003020151550250160032030 0ustar00var/www/vhosts<?php
declare( strict_types=1 );

namespace Automattic\WooCommerce\GoogleListingsAndAds\Jobs;

use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Service;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\ContainerAwareTrait;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\Interfaces\ContainerAwareInterface;
use Exception;

defined( 'ABSPATH' ) || exit;

/**
 * Class JobRepository
 *
 * ContainerAware used for:
 * - JobInterface
 *
 * @package Automattic\WooCommerce\GoogleListingsAndAds\Jobs
 */
class JobRepository implements ContainerAwareInterface, Service {

	use ContainerAwareTrait;

	/**
	 * @var JobInterface[] indexed by class name.
	 */
	protected $jobs = [];

	/**
	 * Fetch all jobs from Container.
	 *
	 * @return JobInterface[]
	 */
	public function list(): array {
		foreach ( $this->container->get( JobInterface::class ) as $job ) {
			$this->jobs[ get_class( $job ) ] = $job;
		}

		return $this->jobs;
	}

	/**
	 * Fetch job from Container (or cache if previously fetched).
	 *
	 * @param string $classname Job class name.
	 *
	 * @return JobInterface
	 *
	 * @throws JobException If the job is not found.
	 */
	public function get( string $classname ): JobInterface {
		if ( ! isset( $this->jobs[ $classname ] ) ) {
			try {
				$job = $this->container->get( $classname );
			} catch ( Exception $e ) {
				throw JobException::job_does_not_exist( $classname );
			}

			$classname                = get_class( $job );
			$this->jobs[ $classname ] = $job;
		}

		return $this->jobs[ $classname ];
	}
}