class ImageReplaceDatabaseStorage in Image Replace 8
Defines a class for image_replace database storage operations.
Hierarchy
- class \Drupal\image_replace\ImageReplaceDatabaseStorage implements ImageReplaceStorageInterface
Expanded class hierarchy of ImageReplaceDatabaseStorage
1 string reference to 'ImageReplaceDatabaseStorage'
1 service uses ImageReplaceDatabaseStorage
File
- src/
ImageReplaceDatabaseStorage.php, line 10
Namespace
Drupal\image_replaceView source
class ImageReplaceDatabaseStorage implements ImageReplaceStorageInterface {
/**
* Active database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* Constructs a ImageReplaceDatabaseStorage object.
*
* @param \Drupal\Core\Database\Connection $database
* The database connection to be used.
*/
public function __construct(Connection $database) {
$this->database = $database;
}
/**
* {@inheritdoc}
*/
public function get($target_style, $target_uri) {
$target_uri_hash = hash('sha256', $target_uri);
return $this->database
->select('image_replace')
->fields('image_replace', [
'replacement_uri',
])
->condition('target_style', $target_style)
->condition('target_uri_hash', $target_uri_hash)
->execute()
->fetchField();
}
/**
* {@inheritdoc}
*/
public function add($target_style, $target_uri, $replacement_uri) {
$target_uri_hash = hash('sha256', $target_uri);
return $this->database
->insert('image_replace')
->fields([
'target_style' => $target_style,
'target_uri_hash' => $target_uri_hash,
'replacement_uri' => $replacement_uri,
])
->execute();
}
/**
* {@inheritdoc}
*/
public function remove($target_style, $target_uri) {
$target_uri_hash = hash('sha256', $target_uri);
return $this->database
->delete('image_replace')
->condition('target_style', $target_style)
->condition('target_uri_hash', $target_uri_hash)
->execute();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ImageReplaceDatabaseStorage:: |
protected | property | Active database connection. | |
ImageReplaceDatabaseStorage:: |
public | function |
Add an image replacement mapping. Overrides ImageReplaceStorageInterface:: |
|
ImageReplaceDatabaseStorage:: |
public | function |
Determine replacement image uri for the given original filename. Overrides ImageReplaceStorageInterface:: |
|
ImageReplaceDatabaseStorage:: |
public | function |
Remove the given image replacement mapping if it exists. Overrides ImageReplaceStorageInterface:: |
|
ImageReplaceDatabaseStorage:: |
public | function | Constructs a ImageReplaceDatabaseStorage object. |