|
1
|
|
|
<?php |
|
2
|
|
|
namespace Wambo\Catalog\Model; |
|
3
|
|
|
|
|
4
|
|
|
use Wambo\Catalog\Error\ContentException; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Class Content contains the product summary and description text |
|
8
|
|
|
* |
|
9
|
|
|
* @package Wambo\Catalog\Model |
|
10
|
|
|
*/ |
|
11
|
|
|
class Content |
|
12
|
|
|
{ |
|
13
|
|
|
const SUMMARY_MIN_LENGTH = 5; |
|
14
|
|
|
const SUMMARY_MAX_LENGTH = 140; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
private $summaryText; |
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
private $productDescription; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Creates a new instance of the product Content model. |
|
27
|
|
|
* |
|
28
|
|
|
* @param string $summaryText A short description text of the product (e.g. "The first edition of our fancy |
|
29
|
|
|
* T-Shirt with a unicorn pooping ice cream on the front"; optional) |
|
30
|
|
|
* @param string $productDescription A full product description text (optional) |
|
31
|
|
|
* |
|
32
|
|
|
* @throws ContentException If the summary text is too short |
|
33
|
|
|
* @throws ContentException If the summary text is too long |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(string $summaryText = "", string $productDescription = "") |
|
36
|
|
|
{ |
|
37
|
|
|
// trim the summary |
|
38
|
|
|
$summaryText = trim($summaryText); |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
if (strlen($summaryText) < self::SUMMARY_MIN_LENGTH) { |
|
41
|
|
|
throw new ContentException(sprintf("The summary text should not be shorter than %s characters", self::SUMMARY_MIN_LENGTH)); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if (strlen($summaryText) > self::SUMMARY_MAX_LENGTH) { |
|
45
|
|
|
throw new ContentException(sprintf("The summary text should not be longer than %s characters", self::SUMMARY_MAX_LENGTH)); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$this->summaryText = trim($summaryText); |
|
49
|
|
|
$this->productDescription = $productDescription; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get a short description text of the product (e.g. "The first edition of our fancy T-Shirt with a unicorn pooping |
|
54
|
|
|
* ice cream on the front") |
|
55
|
|
|
* |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getSummaryText() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->summaryText; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get a full product description text |
|
65
|
|
|
* |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getProductDescription() |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->productDescription; |
|
71
|
|
|
} |
|
72
|
|
|
} |