Imbo\EventManager\EventInterface::getDatabase PHP Метод

getDatabase() публичный Метод

Get the database adapter
public getDatabase ( ) : Imbo\Database\DatabaseInterface
Результат Imbo\Database\DatabaseInterface
    function getDatabase();

Usage Example

Пример #1
0
 /**
  * Using the configured image identifier generator, attempt to generate a unique image
  * identifier for the given image until we either have found a unique ID or we hit the maximum
  * allowed attempts.
  *
  * @param EventInterface $event The current event
  * @param Image $image The event to generate the image identifier for
  * @return string
  * @throws ImageException
  */
 private function generateImageIdentifier(EventInterface $event, Image $image)
 {
     $database = $event->getDatabase();
     $config = $event->getConfig();
     $user = $event->getRequest()->getUser();
     $imageIdentifierGenerator = $config['imageIdentifierGenerator'];
     if (is_callable($imageIdentifierGenerator) && !$imageIdentifierGenerator instanceof GeneratorInterface) {
         $imageIdentifierGenerator = $imageIdentifierGenerator();
     }
     if ($imageIdentifierGenerator->isDeterministic()) {
         return $imageIdentifierGenerator->generate($image);
     }
     // Continue generating image identifiers until we get one that does not already exist
     $maxAttempts = 100;
     $attempts = 0;
     do {
         $imageIdentifier = $imageIdentifierGenerator->generate($image);
         $attempts++;
     } while ($attempts < $maxAttempts && $database->imageExists($user, $imageIdentifier));
     // Did we reach our max attempts limit?
     if ($attempts === $maxAttempts) {
         $e = new ImageException('Failed to generate unique image identifier', 503);
         $e->setImboErrorCode(Exception::IMAGE_IDENTIFIER_GENERATION_FAILED);
         // Tell the client it's OK to retry later
         $event->getResponse()->headers->set('Retry-After', 1);
         throw $e;
     }
     return $imageIdentifier;
 }
All Usage Examples Of Imbo\EventManager\EventInterface::getDatabase