Exemplo n.º 1
0
 /**
  * Builds a configured data backend.
  *
  * If configured this method would automatically install the backend. I.e. a first
  * call will take some amount of time.
  *
  * @return DataBackend
  * @throws DataBackendException
  */
 private function buildDataBackend()
 {
     $configuration = ConfigurationRegistry::getConfiguration();
     $backend = $this->makeDataBackend();
     // Installation
     if ($configuration->isAutomaticInstallation() && !$backend->isInstalled()) {
         $lock = new Lock(self::INSTALL_LOCK);
         $lock->executeOnce(function () use($backend) {
             $backend->install();
         });
     }
     // Update hook
     register_shutdown_function(array($this, "applyUpdatePlan"), $backend);
     return $backend;
 }
Exemplo n.º 2
0
 /**
  * Tests executeOnce().
  * 
  * @see Lock::executeOnce()
  */
 public function testExecuteOnce()
 {
     $name = __FUNCTION__;
     $isExecuted = false;
     $isExecutedCheck = false;
     $lock = new Lock($name);
     $lock->executeOnce(function () use(&$isExecuted, &$isExecutedCheck, $name) {
         $isExecuted = true;
         $checkLock = new Lock($name);
         $checkLock->nonblockingExecuteOnce(function () use(&$isExecutedCheck) {
             $isExecutedCheck = true;
         });
     });
     $this->assertTrue($isExecuted);
     $this->assertFalse($isExecutedCheck);
 }