/** * @test */ public function readLockCanBeAcquiredTwice() { $lock1 = new Lock('testLock', false); $lock2 = new Lock('testLock', false); $this->assertTrue($lock1->release(), 'Lock 1 could not be released'); $this->assertTrue($lock2->release(), 'Lock 2 could not be released'); }
/** * Writes the cache data into the given cache file, using locking. * * @param string $cacheEntryPathAndFilename * @param string $data * @return boolean|integer Return value of file_put_contents */ protected function writeCacheFile($cacheEntryPathAndFilename, $data) { $lock = new Lock($cacheEntryPathAndFilename); $result = file_put_contents($cacheEntryPathAndFilename, $data); $lock->release(); return $result; }
/** * Initializes the Configuration Manager, the Flow settings and the Environment service * * @param Bootstrap $bootstrap * @return void * @throws FlowException */ public static function initializeConfiguration(Bootstrap $bootstrap) { $context = $bootstrap->getContext(); $environment = new Environment($context); $environment->setTemporaryDirectoryBase(FLOW_PATH_TEMPORARY_BASE); $bootstrap->setEarlyInstance(Environment::class, $environment); $packageManager = $bootstrap->getEarlyInstance(PackageManagerInterface::class); $configurationManager = new ConfigurationManager($context); $configurationManager->setTemporaryDirectoryPath($environment->getPathToTemporaryDirectory()); $configurationManager->injectConfigurationSource(new YamlSource()); $configurationManager->setPackages($packageManager->getActivePackages()); $configurationManager->loadConfigurationCache(); $settings = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.Flow'); $lockManager = new LockManager($settings['utility']['lockStrategyClassName'], ['lockDirectory' => Files::concatenatePaths([$environment->getPathToTemporaryDirectory(), 'Lock'])]); Lock::setLockManager($lockManager); $packageManager->injectSettings($settings); $bootstrap->getSignalSlotDispatcher()->dispatch(ConfigurationManager::class, 'configurationManagerReady', [$configurationManager]); $bootstrap->setEarlyInstance(ConfigurationManager::class, $configurationManager); }
/** * Internal get method, allows to nest locks by using the $acquireLock flag * * @param string $entryIdentifier * @param boolean $acquireLock * @return bool|string * @throws \InvalidArgumentException */ protected function internalGet($entryIdentifier, $acquireLock = true) { if ($entryIdentifier !== basename($entryIdentifier)) { throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1282073033); } $pathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension; if ($this->frozen === true) { if ($acquireLock) { $lock = new Lock($pathAndFilename, false); } $result = isset($this->cacheEntryIdentifiers[$entryIdentifier]) ? file_get_contents($this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension) : false; if ($acquireLock) { $lock->release(); } return $result; } if ($this->isCacheFileExpired($pathAndFilename, $acquireLock)) { return false; } if ($acquireLock) { $lock = new Lock($pathAndFilename, false); } $cacheData = file_get_contents($pathAndFilename); if ($acquireLock) { $lock->release(); } $dataSize = (int) substr($cacheData, -self::DATASIZE_DIGITS); return substr($cacheData, 0, $dataSize); }
/** * Initializes the Configuration Manager, the Flow settings and the Environment service * * @param Bootstrap $bootstrap * @return void * @throws FlowException */ public static function initializeConfiguration(Bootstrap $bootstrap) { $context = $bootstrap->getContext(); $packageManager = $bootstrap->getEarlyInstance(PackageManagerInterface::class); $configurationManager = new ConfigurationManager($context); $configurationManager->injectConfigurationSource(new YamlSource()); $configurationManager->loadConfigurationCache(); $configurationManager->setPackages($packageManager->getActivePackages()); $settings = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.Flow'); $environment = new Environment($context); if (isset($settings['utility']['environment']['temporaryDirectoryBase'])) { $defaultTemporaryDirectoryBase = FLOW_PATH_DATA . '/Temporary'; if (FLOW_PATH_TEMPORARY_BASE !== $defaultTemporaryDirectoryBase) { throw new FlowException(sprintf('It seems like the PHP default temporary base path has been changed from "%s" to "%s" via the FLOW_PATH_TEMPORARY_BASE environment variable. If that variable is present, the Neos.Flow.utility.environment.temporaryDirectoryBase setting must not be specified!', $defaultTemporaryDirectoryBase, FLOW_PATH_TEMPORARY_BASE), 1447707261); } $environment->setTemporaryDirectoryBase($settings['utility']['environment']['temporaryDirectoryBase']); } else { $environment->setTemporaryDirectoryBase(FLOW_PATH_TEMPORARY_BASE); } $configurationManager->setTemporaryDirectoryPath($environment->getPathToTemporaryDirectory()); $lockManager = new LockManager($settings['utility']['lockStrategyClassName'], ['lockDirectory' => Files::concatenatePaths([$environment->getPathToTemporaryDirectory(), 'Lock'])]); Lock::setLockManager($lockManager); $packageManager->injectSettings($settings); $bootstrap->getSignalSlotDispatcher()->dispatch(ConfigurationManager::class, 'configurationManagerReady', [$configurationManager]); $bootstrap->setEarlyInstance(ConfigurationManager::class, $configurationManager); $bootstrap->setEarlyInstance(Environment::class, $environment); }