eZ\Publish\Core\MVC\Symfony\Cache\Http\LocationAwareStore::getPath PHP Method

getPath() public method

Will detect if $key is eZ Publish specific.
public getPath ( string $key ) : string
$key string
return string
    public function getPath($key)
    {
        if (strpos($key, static::LOCATION_CACHE_DIR) === false) {
            return parent::getPath($key);
        }
        $prefix = '';
        if (($pos = strrpos($key, DIRECTORY_SEPARATOR)) !== false) {
            $prefix = substr($key, 0, $pos) . DIRECTORY_SEPARATOR;
            $key = substr($key, $pos + 1);
            list($locationCacheDir, $locationId) = explode(DIRECTORY_SEPARATOR, $prefix);
            unset($locationCacheDir);
            // If cache purge is in progress, serve stale cache instead of regular cache.
            // We first check for a global cache purge, then for the current location.
            foreach (array($this->getLocationCacheLockName(), $this->getLocationCacheLockName($locationId)) as $cacheLockFile) {
                if (is_file($cacheLockFile)) {
                    if (function_exists('posix_kill')) {
                        // Check if purge process is still running. If not, remove the lock file to unblock future cache purge
                        if (!posix_kill(file_get_contents($cacheLockFile), 0)) {
                            $fs = $this->getFilesystem();
                            $fs->remove(array($cacheLockFile, $this->getLocationCacheDir($locationId)));
                            goto returnCachePath;
                        }
                    }
                    $prefix = str_replace(static::LOCATION_CACHE_DIR, static::LOCATION_STALE_CACHE_DIR, $prefix);
                }
            }
        }
        returnCachePath:
        return $this->root . DIRECTORY_SEPARATOR . $prefix . substr($key, 0, 2) . DIRECTORY_SEPARATOR . substr($key, 2, 2) . DIRECTORY_SEPARATOR . substr($key, 4, 2) . DIRECTORY_SEPARATOR . substr($key, 6);
    }

Usage Example

 public function testGetPathDeadProcess()
 {
     if (!function_exists('posix_kill')) {
         self::markTestSkipped('posix_kill() function is needed for this test');
     }
     $locationId = 123;
     $prefix = LocationAwareStore::LOCATION_CACHE_DIR . "/{$locationId}";
     $lockFile = $this->store->getLocationCacheLockName($locationId);
     file_put_contents($lockFile, '99999999999999999');
     $path = $this->store->getPath("{$prefix}/en" . sha1('someContent'));
     $this->assertTrue(strpos($path, __DIR__ . "/{$prefix}") === 0);
     $this->assertFalse(file_exists($lockFile));
 }