Skip to content

Commit 78cea83

Browse files
authored
Merge pull request #11 from m4olivei/10-caption-descriptor
Issue #10 add support for caption descriptor.
2 parents 9752efa + 2d6a78f commit 78cea83

File tree

4 files changed

+83
-4
lines changed

4 files changed

+83
-4
lines changed

autoload.php

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ function autoload679875ef60343fd604aa0fa4d353e67e($class) {
6161
'chapterthree\\applenewsapi\\document\\components\\title' => '/src/Document/Components/Title.php',
6262
'chapterthree\\applenewsapi\\document\\components\\tweet' => '/src/Document/Components/Tweet.php',
6363
'chapterthree\\applenewsapi\\document\\components\\video' => '/src/Document/Components/Video.php',
64+
'chapterthree\\applenewsapi\\document\\captiondescriptor' => '/src/Document/CaptionDescriptor.php',
6465
'chapterthree\\applenewsapi\\document\\contentinset' => '/src/Document/ContentInset.php',
6566
'chapterthree\\applenewsapi\\document\\galleryitem' => '/src/Document/GalleryItem.php',
6667
'chapterthree\\applenewsapi\\document\\layouts\\advertisinglayout' => '/src/Document/Layouts/AdvertisingLayout.php',

src/Document/CaptionDescriptor.php

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Caption Descriptor referenced property.
6+
*/
7+
namespace ChapterThree\AppleNewsAPI\Document;
8+
9+
use ChapterThree\AppleNewsAPI\Document\Components\Text;
10+
11+
/**
12+
* An Apple News Document Caption Descriptor. Used with Galleries to support
13+
* HTML.
14+
*/
15+
class CaptionDescriptor extends Text {
16+
17+
protected $additions;
18+
19+
/**
20+
* CaptionDescriptor constructor.
21+
*
22+
* @param string $text
23+
* Contains the raw caption text that needs to be displayed.
24+
*/
25+
public function __construct($text) {
26+
$this->setText($text);
27+
}
28+
29+
/**
30+
* {@inheritdoc}
31+
*/
32+
protected function optional() {
33+
return array_merge(parent::optional(), array(
34+
// Note that CaptionDescriptor from Text components in that it is a
35+
// referenced property, not a component. Thus we mark role as optional.
36+
'role',
37+
'additions',
38+
));
39+
}
40+
41+
/**
42+
* @return mixed
43+
*/
44+
public function getAdditions() {
45+
return $this->additions;
46+
}
47+
48+
/**
49+
* @param mixed $additions
50+
*/
51+
public function setAdditions($additions) {
52+
$this->additions = $additions;
53+
}
54+
}

src/Document/Components/ScalableImage.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace ChapterThree\AppleNewsAPI\Document\Components;
99

10+
use ChapterThree\AppleNewsAPI\Document\CaptionDescriptor;
11+
1012
/**
1113
* An Apple News Document ScalableImage.
1214
*/
@@ -74,13 +76,24 @@ public function getCaption() {
7476
/**
7577
* Setter for caption.
7678
*
77-
* @param string $value
79+
* @param string|CaptionDescriptor $value
7880
* Caption.
7981
*
8082
* @return $this
8183
*/
8284
public function setCaption($value) {
83-
$this->caption = (string) $value;
85+
$class = CaptionDescriptor::class;
86+
if (is_object($value)) {
87+
if ($value instanceof $class) {
88+
$this->caption = $value;
89+
}
90+
else {
91+
$this->triggerError("Caption not of class ${class}.");
92+
}
93+
}
94+
else {
95+
$this->caption = (string) $value;
96+
}
8497
return $this;
8598
}
8699

src/Document/GalleryItem.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,24 @@ public function getCaption() {
6969
/**
7070
* Setter for caption.
7171
*
72-
* @param string $value
72+
* @param string|CaptionDescriptor $value
7373
* Caption.
7474
*
7575
* @return $this
7676
*/
7777
public function setCaption($value) {
78-
$this->caption = (string) $value;
78+
$class = CaptionDescriptor::class;
79+
if (is_object($value)) {
80+
if ($value instanceof $class) {
81+
$this->caption = $value;
82+
}
83+
else {
84+
$this->triggerError("Caption not of class ${class}.");
85+
}
86+
}
87+
else {
88+
$this->caption = (string) $value;
89+
}
7990
return $this;
8091
}
8192

0 commit comments

Comments
 (0)