Completed
Pull Request — master (#129)
by jelmer
03:24
created

AbstractImage::getFallbackImage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace SumoCoders\FrameworkCoreBundle\ValueObject;
4
5
use Doctrine\ORM\Mapping as ORM;
6
7
/**
8
 * The following things are mandatory to use this class.
9
 *
10
 * You need to implement the method getUploadDir.
11
 * When using this class in an entity certain life cycle callbacks should be called
12
 * prepareToUpload for @ORM\PrePersist() and @ORM\PreUpdate()
13
 * upload for @ORM\PostPersist() and @ORM\PostUpdate()
14
 * remove for @ORM\PostRemove()
15
 *
16
 * The following things are optional
17
 * A fallback image can be set by setting the full path of the image to the FALLBACK_IMAGE constant
18
 * By default we will use the fork way for image sizes (source, 100X100 etc)
19
 * if you don't want it set GENERATE_THUMBNAILS to false
20
 */
21
abstract class AbstractImage extends AbstractFile
22
{
23
    /**
24
     * @var string|null
25
     */
26
    const FALLBACK_IMAGE = null;
27
28
    /**
29
     * @return string
30
     */
31
    public function getWebPath()
32
    {
33
        $webPath = parent::getWebPath();
34
35
        if (empty($webPath)) {
36
            return static::FALLBACK_IMAGE;
37
        }
38
39
        return $webPath;
40
    }
41
42
    /**
43
     * @return null|string
44
     */
45
    public function getFallbackImage()
46
    {
47
        return static::FALLBACK_IMAGE;
48
    }
49
}
50