0 follower

Final Class Yiisoft\Yii\Debug\Storage\FileStorage

InheritanceYiisoft\Yii\Debug\Storage\FileStorage
ImplementsYiisoft\Yii\Debug\Storage\StorageInterface

Constants

Hide inherited constants

Constant Value Description Defined By
TYPE_DATA 'data' Yiisoft\Yii\Debug\Storage\StorageInterface
TYPE_OBJECTS 'objects' Yiisoft\Yii\Debug\Storage\StorageInterface
TYPE_SUMMARY 'summary' Yiisoft\Yii\Debug\Storage\StorageInterface

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string $path )
$path string

                public function __construct(
    private readonly string $path,
) {
}

            
clear() public method

public void clear ( )

                public function clear(): void
{
    FileHelper::removeDirectory($this->path);
}

            
read() public method

public array read ( string $type, string|null $id null )
$type string
$id string|null

                public function read(string $type, ?string $id = null): array
{
    clearstatcache();
    $dataFiles = $this->findFilesOrderedByModifiedTime(
        sprintf(
            '%s/**/%s/%s.json',
            $this->path,
            $id ?? '**',
            $type,
        )
    );
    $data = [];
    foreach ($dataFiles as $file) {
        $dir = dirname($file);
        $id = substr($dir, strlen(dirname($file, 2)) + 1);
        $content = file_get_contents($file);
        $data[$id] = $content === '' ? '' : json_decode($content, true, flags: JSON_THROW_ON_ERROR);
    }
    return $data;
}

            
setHistorySize() public method

public void setHistorySize ( integer $historySize )
$historySize integer

                public function setHistorySize(int $historySize): void
{
    $this->historySize = $historySize;
}

            
write() public method

public void write ( string $id, array $data, array $objectsMap, array $summary )
$id string
$data array
$objectsMap array
$summary array

                public function write(string $id, array $data, array $objectsMap, array $summary): void
{
    $basePath = $this->path . '/' . date('Y-m-d') . '/' . $id . '/';
    try {
        FileHelper::ensureDirectory($basePath);
        file_put_contents($basePath . self::TYPE_DATA . '.json', $this->encode($data));
        file_put_contents($basePath . self::TYPE_OBJECTS . '.json', $this->encode($objectsMap));
        file_put_contents($basePath . self::TYPE_SUMMARY . '.json', $this->encode($summary));
    } finally {
        $this->gc();
    }
}