| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,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_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.5/wp-content/plugins/woocommerce/packages/email-editor/src/ |
Upload File : |
<?php
/**
* This file is part of the WooCommerce Email Editor package
*
* @package Automattic\WooCommerce\EmailEditor
*/
declare( strict_types = 1 );
namespace Automattic\WooCommerce\EmailEditor;
/**
* Class Container is a simple dependency injection container.
*
* @package Automattic\WooCommerce\EmailEditor
*/
class Container {
/**
* A list of registered services
*
* @var array<string, callable> $services
*/
protected array $services = array();
/**
* A list of created instances
*
* @var array<string, object> $instances
*/
protected array $instances = array();
/**
* Prevents deserialization of this class to avoid callback replacement attacks.
*
* @param array $data The serialized data.
* @return void
* @throws \Exception Always throws an exception to prevent deserialization.
*/
public function __unserialize( array $data ): void {
throw new \Exception( 'Deserialization of Container is not allowed for security reasons.' );
}
/**
* The method for registering a new service.
*
* @param string $name The name of the service.
* @param callable $callback The callable that will be used to create the service.
* @return void
* @phpstan-template T of object
* @phpstan-param class-string<T> $name
*/
public function set( string $name, callable $callback ): void {
$this->services[ $name ] = $callback;
}
/**
* Method for getting a registered service.
*
* @param string $name The name of the service.
* @return object The service instance.
* @throws \Exception If the service is not found.
* @phpstan-template T of object
* @phpstan-param class-string<T> $name
* @phpstan-return T
*/
public function get( string $name ): object {
// Check if the service is already instantiated.
if ( isset( $this->instances[ $name ] ) ) {
/**
* Instance.
*
* @var T $instance Instance of requested service.
*/
$instance = $this->instances[ $name ];
return $instance;
}
// Check if the service is registered.
if ( ! isset( $this->services[ $name ] ) ) {
throw new \Exception( esc_html( "Service not found: $name" ) );
}
/**
* Instance.
*
* @var T $instance Instance of requested service.
*/
$instance = $this->services[ $name ]( $this );
$this->instances[ $name ] = $instance;
return $instance;
}
}