0 follower

Final Class Yiisoft\Proxy\ProxyManager

InheritanceYiisoft\Proxy\ProxyManager

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Proxy\ProxyManager
createObjectProxy() Creates object proxy based on an interface / a class and parent proxy class. Yiisoft\Proxy\ProxyManager

Constants

Hide inherited constants

Constant Value Description Defined By
PROXY_SUFFIX 'Proxy' A suffix appended to proxy class names / files. Yiisoft\Proxy\ProxyManager

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string|null $cachePath null )
$cachePath string|null

Cache path, optional, {@see \Yiisoft\Proxy\ClassCache::$cachePath}.

                public function __construct(?string $cachePath = null)
{
    $this->classCache = $cachePath !== null ? new ClassCache($cachePath) : null;
    $this->classRenderer = new ClassRenderer();
    $this->classConfigFactory = new ClassConfigFactory();
}

            
createObjectProxy() public method

Creates object proxy based on an interface / a class and parent proxy class.

public Yiisoft\Proxy\ObjectProxy createObjectProxy ( string $baseStructure, string $parentProxyClass, array $proxyConstructorArguments )
$baseStructure string

Either or an interface or a class for proxying method calls.

$parentProxyClass string

A base proxy class which acts like a parent for dynamically created proxy. {@see \Yiisoft\Proxy\ObjectProxy} or a class extended from it must be used.

$proxyConstructorArguments array

A list of arguments passed to proxy constructor ({@see \Yiisoft\Proxy\ObjectProxy::__construct}).

return Yiisoft\Proxy\ObjectProxy

A subclass of {@see \Yiisoft\Proxy\ObjectProxy}.

throws Exception

In case of error during creation or working with cache / requiring PHP code.

                public function createObjectProxy(
    string $baseStructure,
    string $parentProxyClass,
    array $proxyConstructorArguments
): ObjectProxy {
    $className = $baseStructure . self::PROXY_SUFFIX;
    /** @psalm-var class-string $shortClassName */
    $shortClassName = self::getProxyClassName($className);
    if (class_exists($shortClassName)) {
        /**
         * @var ObjectProxy
         * @psalm-suppress MixedMethodCall
         */
        return new $shortClassName(...$proxyConstructorArguments);
    }
    $classDeclaration = $this->classCache?->get($className, $parentProxyClass);
    if ($classDeclaration === null) {
        $classConfig = $this->classConfigFactory->getClassConfig($baseStructure);
        $classConfig = $this->generateProxyClassConfig($classConfig, $parentProxyClass);
        $classDeclaration = $this->classRenderer->render($classConfig);
        $this->classCache?->set($baseStructure, $parentProxyClass, $classDeclaration);
    }
    if (!$this->classCache) {
        /** @psalm-suppress UnusedFunctionCall Bug https://github.com/vimeo/psalm/issues/8406 */
        eval(str_replace('<?php', '', $classDeclaration));
    } else {
        $path = $this->classCache->getClassPath($baseStructure, $parentProxyClass);
        /** @psalm-suppress UnresolvableInclude */
        require $path;
    }
    /**
     * @var ObjectProxy
     * @psalm-var class-string $shortClassName
     * @psalm-suppress MixedMethodCall
     */
    return new $shortClassName(...$proxyConstructorArguments);
}