Custom storage driversΒΆ

If you wish to implement your own storage driver you are free to do so. The only requirement is that you implement the Imbo\Storage\StorageInterface interface that comes with Imbo. Below is the complete interface with comments:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
 * This file is part of the Imbo package
 *
 * (c) Christer Edvartsen <cogo@starzinger.net>
 *
 * For the full copyright and license information, please view the LICENSE file that was
 * distributed with this source code.
 */

namespace Imbo\Storage;

use Imbo\Model\Image,
    Imbo\Exception\StorageException;

/**
 * Storage driver interface
 *
 * This is an interface for different storage drivers for Imbo.
 *
 * @author Christer Edvartsen <cogo@starzinger.net>
 * @package Storage
 */
interface StorageInterface {
    /**
     * Store an image
     *
     * This method will receive the binary data of the image and store it somewhere suited for the
     * actual storage driver. If an error occurs the driver should throw an
     * Imbo\Exception\StorageException exception.
     *
     * If the image already exists, simply overwrite it.
     *
     * @param string $publicKey The public key of the user
     * @param string $imageIdentifier The image identifier
     * @param string $imageData The image data to store
     * @return boolean Returns true on success or false on failure
     * @throws StorageException
     */
    function store($publicKey, $imageIdentifier, $imageData);

    /**
     * Delete an image
     *
     * This method will delete the file associated with $imageIdentifier from the storage medium
     *
     * @param string $publicKey The public key of the user
     * @param string $imageIdentifier Image identifier
     * @return boolean Returns true on success or false on failure
     * @throws StorageException
     */
    function delete($publicKey, $imageIdentifier);

    /**
     * Get image content
     *
     * @param string $publicKey The public key of the user
     * @param string $imageIdentifier Image identifier
     * @return string The binary content of the image
     * @throws StorageException
     */
    function getImage($publicKey, $imageIdentifier);

    /**
     * Get the last modified timestamp
     *
     * @param string $publicKey The public key of the user
     * @param string $imageIdentifier Image identifier
     * @return DateTime Returns an instance of DateTime
     * @throws StorageException
     */
    function getLastModified($publicKey, $imageIdentifier);

    /**
     * Get the current status of the storage
     *
     * This method is used with the status resource.
     *
     * @return boolean
     */
    function getStatus();

    /**
     * See if the image already exists
     *
     * @param string $publicKey The public key of the user
     * @param string $imageIdentifier Image identifier
     * @return DateTime Returns an instance of DateTime
     * @throws StorageException
     */
    function imageExists($publicKey, $imageIdentifier);
}

Have a look at the existing implementations of this interface for more details. If you implement a driver that you think should be a part of Imbo feel free to send a pull request to the project over at GitHub.