File: /var/www/vhosts/uyarreklam.com.tr/httpdocs/Infrastructure.tar
Activateable.php 0000644 00000000733 15154557156 0007662 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure;
/**
* Something that can be activated.
*
* By implementing a class with this interface, the plugin will automatically hook
* it up to the WordPress activation hook. This means we don't have to worry about
* manually writing activation code.
*/
interface Activateable {
/**
* Activate the service.
*
* @return void
*/
public function activate(): void;
}
AdminConditional.php 0000644 00000000645 15154557156 0010514 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure;
/**
* Trait AdminConditional
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure
*/
trait AdminConditional {
/**
* Check whether this object is currently needed.
*
* @return bool Whether the object is needed.
*/
public static function is_needed(): bool {
return is_admin();
}
}
Conditional.php 0000644 00000001204 15154557156 0007533 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure;
/**
* Conditional interface.
*
* This interface allows objects to be instantiated only as needed. A static method is used to
* determine whether an object needs to be instantiated. This prevents needless instantiation of
* objects that won't be used in the current request.
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure
*/
interface Conditional {
/**
* Check whether this object is currently needed.
*
* @return bool Whether the object is needed.
*/
public static function is_needed(): bool;
}
Deactivateable.php 0000644 00000000747 15154557156 0010200 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure;
/**
* Something that can be deactivated.
*
* By implementing a class with this interface, the plugin will automatically hook
* it up to the WordPress deactivation hook. This means we don't have to worry about
* manually writing deactivation code.
*/
interface Deactivateable {
/**
* Deactivate the service.
*
* @return void
*/
public function deactivate(): void;
}
GoogleListingsAndAdsPlugin.php 0000644 00000007021 15154557156 0012456 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure;
use Automattic\WooCommerce\GoogleListingsAndAds\Jobs\JobInitializer;
use Automattic\WooCommerce\GoogleListingsAndAds\Internal\Requirements\PluginValidator;
use Automattic\WooCommerce\GoogleListingsAndAds\Options\OptionsInterface;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Psr\Container\ContainerInterface;
/**
* Class GoogleListingsAndAdsPlugin
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure
*/
final class GoogleListingsAndAdsPlugin implements Plugin {
/**
* The hook for registering our plugin's services.
*
* @var string
*/
private const SERVICE_REGISTRATION_HOOK = 'plugins_loaded';
/**
* @var ContainerInterface
*/
private $container;
/**
* @var Service[]
*/
private $registered_services;
/**
* GoogleListingsAndAdsPlugin constructor.
*
* @param ContainerInterface $container
*/
public function __construct( ContainerInterface $container ) {
$this->container = $container;
}
/**
* Activate the plugin.
*
* @return void
*/
public function activate(): void {
// Delay activation if a required plugin is missing or an incompatible plugin is active.
if ( ! PluginValidator::validate() ) {
// Using update_option because we cannot access the option service
// when the services have not been registered.
update_option( 'gla_' . OptionsInterface::DELAYED_ACTIVATE, true );
return;
}
$this->maybe_register_services();
foreach ( $this->registered_services as $service ) {
if ( $service instanceof Activateable ) {
$service->activate();
}
}
}
/**
* Deactivate the plugin.
*
* @return void
*/
public function deactivate(): void {
$this->maybe_register_services();
foreach ( $this->registered_services as $service ) {
if ( $service instanceof Deactivateable ) {
$service->deactivate();
}
}
}
/**
* Register the plugin with the WordPress system.
*
* @return void
*/
public function register(): void {
add_action(
self::SERVICE_REGISTRATION_HOOK,
function () {
$this->maybe_register_services();
},
20
);
add_action(
'init',
function () {
// Register the job initializer only if it is available, see JobInitializer::is_needed.
// Note: ActionScheduler must be loaded after the init hook, so we can't load JobInitializer like a regular Service.
if ( $this->container->has( JobInitializer::class ) ) {
$this->container->get( JobInitializer::class )->register();
}
// Check if activation is still pending.
if ( $this->container->get( OptionsInterface::class )->get( OptionsInterface::DELAYED_ACTIVATE ) ) {
$this->activate();
// Remove the DELAYED_ACTIVATE flag.
$this->container->get( OptionsInterface::class )->delete( OptionsInterface::DELAYED_ACTIVATE );
}
}
);
}
/**
* Register our services if dependency validation passes.
*/
protected function maybe_register_services(): void {
// Don't register anything if a required plugin is missing or an incompatible plugin is active.
if ( ! PluginValidator::validate() ) {
$this->registered_services = [];
return;
}
static $registered = false;
if ( $registered ) {
return;
}
/** @var Service[] $services */
$services = $this->container->get( Service::class );
foreach ( $services as $service ) {
if ( $service instanceof Registerable ) {
$service->register();
}
$this->registered_services[ get_class( $service ) ] = $service;
}
$registered = true;
}
}
Plugin.php 0000644 00000000426 15154557156 0006533 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure;
/**
* Interface Plugin
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure
*/
interface Plugin extends Activateable, Deactivateable, Registerable {}
Registerable.php 0000644 00000000561 15154557156 0007705 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure;
/**
* Registerable interface.
*
* Used to designate an object that can be registered.
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure
*/
interface Registerable {
/**
* Register a service.
*/
public function register(): void;
}
Renderable.php 0000644 00000001175 15154557156 0007342 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure;
defined( 'ABSPATH' ) || exit;
/**
* Interface Renderable
*
* Used to designate an object that can be rendered (e.g. views, blocks, shortcodes, etc.).
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure
*/
interface Renderable {
/**
* Render the renderable.
*
* @param array $context Optional. Contextual information to use while
* rendering. Defaults to an empty array.
*
* @return string Rendered result.
*/
public function render( array $context = [] ): string;
}
Service.php 0000644 00000000577 15154557156 0006704 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure;
/**
* Service interface.
*
* A services is one piece of functionality within the plugin as a whole. It aims to encapsulate
* a particular functionality within a single class.
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure
*/
interface Service {}
View.php 0000644 00000002766 15154557156 0006220 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure;
use Automattic\WooCommerce\GoogleListingsAndAds\View\ViewException;
defined( 'ABSPATH' ) || exit;
interface View extends Renderable {
/**
* Render the current view with a given context.
*
* @param array $context Context in which to render.
*
* @return string Rendered HTML.
*
* @throws ViewException If the view could not be loaded.
*/
public function render( array $context = [] ): string;
/**
* Render a partial view.
*
* This can be used from within a currently rendered view, to include
* nested partials.
*
* The passed-in context is optional, and will fall back to the parent's
* context if omitted.
*
* @param string $path Path of the partial to render.
* @param array|null $context Context in which to render the partial.
*
* @return string Rendered HTML.
*
* @throws ViewException If the view could not be loaded or provided path was not valid.
*/
public function render_partial( string $path, ?array $context = null ): string;
/**
* Return the raw value of a context property.
*
* By default, properties are automatically escaped when accessing them
* within the view. This method allows direct access to the raw value
* instead to bypass this automatic escaping.
*
* @param string $property Property for which to return the raw value.
*
* @return mixed Raw context property value.
*/
public function raw( string $property );
}
ViewFactory.php 0000644 00000000721 15154557156 0007535 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure;
defined( 'ABSPATH' ) || exit;
/**
* Interface ViewFactory
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure
*/
interface ViewFactory {
/**
* Create a new view object.
*
* @param string $path Path to the view file to render.
*
* @return View Instantiated view object.
*/
public function create( string $path ): View;
}