Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 40... Línea 40...
40
    /**
40
    /**
41
     * @var string Path of the temporary file whose contents is currently stored in memory
41
     * @var string Path of the temporary file whose contents is currently stored in memory
42
     *
42
     *
43
     * @see CachingStrategyFactory::MAX_NUM_STRINGS_PER_TEMP_FILE
43
     * @see CachingStrategyFactory::MAX_NUM_STRINGS_PER_TEMP_FILE
44
     */
44
     */
-
 
45
    private string $readMemoryTempFilePath = '';
-
 
46
 
-
 
47
    /** @var string Path of the temporary file whose contents is currently being written to */
45
    private string $inMemoryTempFilePath = '';
48
    private string $writeMemoryTempFilePath = '';
Línea 46... Línea 49...
46
 
49
 
47
    /**
50
    /**
48
     * @see CachingStrategyFactory::MAX_NUM_STRINGS_PER_TEMP_FILE
51
     * @see CachingStrategyFactory::MAX_NUM_STRINGS_PER_TEMP_FILE
49
     *
52
     *
Línea 71... Línea 74...
71
     */
74
     */
72
    public function addStringForIndex(string $sharedString, int $sharedStringIndex): void
75
    public function addStringForIndex(string $sharedString, int $sharedStringIndex): void
73
    {
76
    {
74
        $tempFilePath = $this->getSharedStringTempFilePath($sharedStringIndex);
77
        $tempFilePath = $this->getSharedStringTempFilePath($sharedStringIndex);
Línea 75... Línea 78...
75
 
78
 
76
        if (!file_exists($tempFilePath)) {
79
        if ($this->writeMemoryTempFilePath !== $tempFilePath) {
77
            if (null !== $this->tempFilePointer) {
80
            if (null !== $this->tempFilePointer) {
78
                fclose($this->tempFilePointer);
81
                fclose($this->tempFilePointer);
79
            }
82
            }
80
            $resource = fopen($tempFilePath, 'w');
83
            $resource = fopen($tempFilePath, 'w');
81
            \assert(false !== $resource);
84
            \assert(false !== $resource);
-
 
85
            $this->tempFilePointer = $resource;
82
            $this->tempFilePointer = $resource;
86
            $this->writeMemoryTempFilePath = $tempFilePath;
Línea 83... Línea 87...
83
        }
87
        }
84
 
88
 
85
        // The shared string retrieval logic expects each cell data to be on one line only
89
        // The shared string retrieval logic expects each cell data to be on one line only
Línea 95... Línea 99...
95
     */
99
     */
96
    public function closeCache(): void
100
    public function closeCache(): void
97
    {
101
    {
98
        // close pointer to the last temp file that was written
102
        // close pointer to the last temp file that was written
99
        if (null !== $this->tempFilePointer) {
103
        if (null !== $this->tempFilePointer) {
-
 
104
            $this->writeMemoryTempFilePath = '';
100
            fclose($this->tempFilePointer);
105
            fclose($this->tempFilePointer);
101
        }
106
        }
102
    }
107
    }
Línea 103... Línea 108...
103
 
108
 
Línea 113... Línea 118...
113
    public function getStringAtIndex(int $sharedStringIndex): string
118
    public function getStringAtIndex(int $sharedStringIndex): string
114
    {
119
    {
115
        $tempFilePath = $this->getSharedStringTempFilePath($sharedStringIndex);
120
        $tempFilePath = $this->getSharedStringTempFilePath($sharedStringIndex);
116
        $indexInFile = $sharedStringIndex % $this->maxNumStringsPerTempFile;
121
        $indexInFile = $sharedStringIndex % $this->maxNumStringsPerTempFile;
Línea 117... Línea -...
117
 
-
 
118
        if (!file_exists($tempFilePath)) {
-
 
119
            throw new SharedStringNotFoundException("Shared string temp file not found: {$tempFilePath} ; for index: {$sharedStringIndex}");
-
 
120
        }
-
 
121
 
122
 
122
        if ($this->inMemoryTempFilePath !== $tempFilePath) {
123
        if ($this->readMemoryTempFilePath !== $tempFilePath) {
123
            $tempFilePath = realpath($tempFilePath);
124
            $contents = @file_get_contents($tempFilePath);
124
            \assert(false !== $tempFilePath);
125
            if (false === $contents) {
125
            $contents = file_get_contents($tempFilePath);
126
                throw new SharedStringNotFoundException("Shared string temp file could not be read: {$tempFilePath} ; for index: {$sharedStringIndex}");
126
            \assert(false !== $contents);
127
            }
127
            $this->inMemoryTempFileContents = explode(PHP_EOL, $contents);
128
            $this->inMemoryTempFileContents = explode(PHP_EOL, $contents);
128
            $this->inMemoryTempFilePath = $tempFilePath;
129
            $this->readMemoryTempFilePath = $tempFilePath;
Línea 129... Línea 130...
129
        }
130
        }
Línea 130... Línea 131...
130
 
131