| Server IP : 172.67.134.116 / Your IP : 216.73.216.40 Web Server : Apache System : Linux server.rehabsharif.com 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64 User : nobi37te ( 1003) PHP Version : 8.2.33 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/nobi37te/public_html/wp-content/themes/pro/framework/classes/Util/ |
Upload File : |
<?php
namespace Themeco\Theme\Util;
class IocContainer {
protected $container = [];
protected $registrationHandler;
public function register($class, $instance) {
$this->container[$class] = $instance;
}
public function setRegistrationHandler($cb) {
$this->registrationHandler = $cb;
}
public function resolve() {
$args = func_get_args();
$class = array_shift($args);
if (isset( $this->container[$class] ) ) return $this->container[$class];
if (!class_exists($class)) {
throw new \Exception("Class $class not found");
}
$reflector = new \ReflectionClass($class);
$interfaces = $reflector->getInterfaces();
$constructor = $reflector->getConstructor();
$plugin_class = get_class();
if ( $constructor ) {
$param_map = function($param) use ($args, $plugin_class ){
if (!$param->hasType()) {
return array_shift($args);
}
$type = $param->getType();
if ($type->isBuiltin()) {
return array_shift($args);
}
$className = null;
if (PHP_VERSION_ID > 71000) {
$className = (string) $type;
} else {
$className = $type->getName();
}
return $className === $plugin_class ? $this : $this->resolve($className);
};
$param_map->bindTo($this);
$parameters = array_map($param_map, $constructor->getParameters());
$instance = $reflector->newInstanceArgs($parameters);
} else {
$instance = $reflector->newInstance();
}
$cb = $this->registrationHandler;
if (is_callable($cb)) {
$cb($class, $instance, $interfaces,$reflector);
}
return $instance;
}
}