Final Class Yiisoft\Proxy\ClassCache
| Inheritance | Yiisoft\Proxy\ClassCache |
|---|
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Proxy\ClassCache | |
| get() | Reads proxy class contents. | Yiisoft\Proxy\ClassCache |
| getClassPath() | Gets full path to a class. For example: /tmp/Yiisoft/Tests/Stub/GraphInterface.MyProxy.php or
/tmp/Yiisoft/Tests/Stub/Graph.MyProxy.php. Additionally, checks and prepares (if needed) {@see $cachePath} for
usage (@see FileHelper::ensureDirectory()}. |
Yiisoft\Proxy\ClassCache |
| set() | Writes proxy class contents to a file in {@see getClassPath()}. | Yiisoft\Proxy\ClassCache |
Method Details
| public mixed __construct ( string $cachePath ) | ||
| $cachePath | string | |
public function __construct(
/**
* @var string Base directory for working with cache. It will be created automatically if it does not exist
* ({@see getClassPath()}).
*/
private string $cachePath
) {
}
Reads proxy class contents.
| public string|null get ( string $className, string $baseProxyClassName ) | ||
| $className | string |
The full name of user class or interface (with namespace). For example: |
| $baseProxyClassName | string |
The full name of {@see \Yiisoft\Proxy\ObjectProxy} implementation (with namespace) which will
be the base class for proxy. For example: |
| return | string|null |
In case of presence data in cache the whole class contents (including PHP opening tag)
returned as a string. In case of its absence or other errors - |
|---|---|---|
| throws | Exception |
When unable to write to a file in {@see \Yiisoft\Proxy\getClassPath()}. |
public function get(string $className, string $baseProxyClassName): ?string
{
$classPath = $this->getClassPath($className, $baseProxyClassName);
if (!file_exists($classPath)) {
return null;
}
$content = file_get_contents($classPath);
return $content === false ? null : $content;
}
Gets full path to a class. For example: /tmp/Yiisoft/Tests/Stub/GraphInterface.MyProxy.php or
/tmp/Yiisoft/Tests/Stub/Graph.MyProxy.php. Additionally, checks and prepares (if needed) {@see $cachePath} for
usage (@see FileHelper::ensureDirectory()}.
| public string getClassPath ( string $className, string $baseProxyClassName ) | ||
| $className | string |
The full name of user class or interface (with namespace). For example: |
| $baseProxyClassName | string |
The full name of {@see \Yiisoft\Proxy\ObjectProxy} implementation (with namespace) which will
be the base class for proxy. For example: |
| throws | RuntimeException |
In case when it's impossible to use or create {@see $cachePath}. |
|---|---|---|
public function getClassPath(string $className, string $baseProxyClassName): string
{
[$classFileName, $classFilePath] = $this->getClassFileNameAndPath($className, $baseProxyClassName);
try {
FileHelper::ensureDirectory($classFilePath, 0777);
} catch (RuntimeException) {
throw new RuntimeException("Directory \"$classFilePath\" was not created.");
}
return $classFilePath . DIRECTORY_SEPARATOR . $classFileName;
}
Writes proxy class contents to a file in {@see getClassPath()}.
| public void set ( string $className, string $baseProxyClassName, string $classContents ) | ||
| $className | string |
The full name of user class or interface (with namespace). For example:
|
| $baseProxyClassName | string |
The full name of {@see \Yiisoft\Proxy\ObjectProxy} implementation (with namespace) which will
be the base class for proxy. For example: |
| $classContents | string |
The whole class contents without opening PHP tag (it's prepended automatically). |
public function set(string $className, string $baseProxyClassName, string $classContents): void
{
file_put_contents($this->getClassPath($className, $baseProxyClassName), "<?php\n\n" . $classContents, LOCK_EX);
}
Signup or Login in order to comment.