HEX
Server: LiteSpeed
System: Linux premium221.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
User: madepabj (2566)
PHP: 8.3.26
Disabled: NONE
Upload Files
File: //home/madepabj/gharana.pk/wp-content/plugins/wp-smushit/core/media/class-attachment-url-cache.php
<?php

namespace Smush\Core\Media;

class Attachment_Url_Cache {
	private $cache = array();

	/**
	 * Static instance
	 *
	 * @var self
	 */
	private static $instance;
	private $fetch_in_advance = false;

	/**
	 * Static instance getter
	 */
	public static function get_instance() {
		if ( empty( self::$instance ) ) {
			self::$instance = new self();
		}

		return self::$instance;
	}

	public function has_cached( $url ) {
		return isset( $this->cache[ trim( $url ) ] );
	}

	public function get_id_for_url( $url, $fetch = false ) {
		if ( ! isset( $this->cache[ trim( $url ) ] ) ) {
			$attachment_id = 0;
			if ( $fetch ) {
				$attachment_id = attachment_url_to_postid( $url );
			}

			$this->set_id_for_url( $url, $attachment_id );
		}

		return $this->cache[ trim( $url ) ] ?? 0;
	}

	public function set_id_for_url( $url, $attachment_id ) {
		$this->cache[ trim( $url ) ] = $attachment_id;
	}

	public function reset() {
		$this->cache = array();
	}

	public function get_all() {
		return $this->cache;
	}

	public function set_fetch_in_advance( $fetch_in_advance ) {
		$this->fetch_in_advance = $fetch_in_advance;
	}

	public function fetch_in_advance() {
		return $this->fetch_in_advance;
	}
}