Skip to content

Commit 16738f4

Browse files
committed
add missing audio and video structured properties
1 parent 90f6d2d commit 16738f4

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

src/StructuredProperties/Audio.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Astrotomic\OpenGraph\StructuredProperties;
4+
5+
use Astrotomic\OpenGraph\BaseObject;
6+
7+
class Audio extends BaseObject
8+
{
9+
protected const PREFIX = 'og:video';
10+
11+
public function __construct(string $url)
12+
{
13+
$this->setProperty(self::PREFIX, 'url', $url);
14+
}
15+
16+
public static function make(string $url)
17+
{
18+
return new static($url);
19+
}
20+
21+
public function secureUrl(string $url)
22+
{
23+
$this->setProperty(self::PREFIX, 'secure_url', $url);
24+
25+
return $this;
26+
}
27+
28+
public function mimeType(string $mimeType)
29+
{
30+
$this->setProperty(self::PREFIX, 'type', $mimeType);
31+
32+
return $this;
33+
}
34+
}

src/StructuredProperties/Video.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace Astrotomic\OpenGraph\StructuredProperties;
4+
5+
use Astrotomic\OpenGraph\BaseObject;
6+
7+
class Video extends BaseObject
8+
{
9+
protected const PREFIX = 'og:video';
10+
11+
public function __construct(string $url)
12+
{
13+
$this->setProperty(self::PREFIX, 'url', $url);
14+
}
15+
16+
public static function make(string $url)
17+
{
18+
return new static($url);
19+
}
20+
21+
public function secureUrl(string $url)
22+
{
23+
$this->setProperty(self::PREFIX, 'secure_url', $url);
24+
25+
return $this;
26+
}
27+
28+
public function mimeType(string $mimeType)
29+
{
30+
$this->setProperty(self::PREFIX, 'type', $mimeType);
31+
32+
return $this;
33+
}
34+
35+
public function width(int $width)
36+
{
37+
$this->setProperty(self::PREFIX, 'width', $width);
38+
39+
return $this;
40+
}
41+
42+
public function height(int $height)
43+
{
44+
$this->setProperty(self::PREFIX, 'height', $height);
45+
46+
return $this;
47+
}
48+
49+
public function alt(string $alt)
50+
{
51+
$this->setProperty(self::PREFIX, 'alt', $alt);
52+
53+
return $this;
54+
}
55+
}

src/Type.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Astrotomic\OpenGraph;
44

5+
use Astrotomic\OpenGraph\StructuredProperties\Audio;
56
use Astrotomic\OpenGraph\StructuredProperties\Image;
7+
use Astrotomic\OpenGraph\StructuredProperties\Video;
68

79
abstract class Type extends BaseObject
810
{
@@ -71,6 +73,11 @@ public function alternateLocale(string $locale)
7173
return $this;
7274
}
7375

76+
/**
77+
* @param Image|string $image
78+
*
79+
* @return $this
80+
*/
7481
public function image($image)
7582
{
7683
$this->addStructuredProperty(
@@ -82,6 +89,36 @@ public function image($image)
8289
return $this;
8390
}
8491

92+
/**
93+
* @param Video|string $video
94+
* @return $this
95+
*/
96+
public function video($video)
97+
{
98+
$this->addStructuredProperty(
99+
is_string($video)
100+
? Image::make($video)
101+
: $video
102+
);
103+
104+
return $this;
105+
}
106+
107+
/**
108+
* @param Audio|string $audio
109+
* @return $this
110+
*/
111+
public function audio($audio)
112+
{
113+
$this->addStructuredProperty(
114+
is_string($audio)
115+
? Image::make($audio)
116+
: $audio
117+
);
118+
119+
return $this;
120+
}
121+
85122
protected function addStructuredProperty(BaseObject $property)
86123
{
87124
$this->tags[] = $property;

0 commit comments

Comments
 (0)