Skip to content

Commit 71a3a65

Browse files
committed
add missing music types
1 parent 55b1285 commit 71a3a65

File tree

5 files changed

+119
-1
lines changed

5 files changed

+119
-1
lines changed

src/Types/Music/Album.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Astrotomic\OpenGraph\Types\Music;
4+
5+
use Astrotomic\OpenGraph\Type;
6+
use DateTime;
7+
8+
class Album extends Type
9+
{
10+
protected const PREFIX = 'music';
11+
12+
protected string $type = 'music.album';
13+
14+
public function musician(string $url)
15+
{
16+
$this->addProperty(self::PREFIX, 'musician', $url);
17+
18+
return $this;
19+
}
20+
21+
public function song(string $url, ?int $disc = null, ?int $track = null)
22+
{
23+
$this->addProperty(self::PREFIX, 'song', $url);
24+
$this->when($disc > 0, fn() => $this->addProperty(self::PREFIX, 'song:disc', $disc));
25+
$this->when($track > 0, fn() => $this->addProperty(self::PREFIX, 'song:track', $track));
26+
27+
return $this;
28+
}
29+
30+
public function releasedAt(DateTime $releaseDate)
31+
{
32+
$this->setProperty(self::PREFIX, 'release_date', $releaseDate->format('Y-m-d'));
33+
34+
return $this;
35+
}
36+
}

src/Types/Music/Playlist.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Astrotomic\OpenGraph\Types\Music;
4+
5+
use Astrotomic\OpenGraph\Type;
6+
7+
class Playlist extends Type
8+
{
9+
protected const PREFIX = 'music';
10+
11+
protected string $type = 'music.playlist';
12+
13+
public function creator(string $url)
14+
{
15+
$this->setProperty(self::PREFIX, 'creator', $url);
16+
17+
return $this;
18+
}
19+
20+
public function song(string $url, ?int $disc = null, ?int $track = null)
21+
{
22+
$this->addProperty(self::PREFIX, 'song', $url);
23+
$this->when($disc > 0, fn() => $this->addProperty(self::PREFIX, 'song:disc', $disc));
24+
$this->when($track > 0, fn() => $this->addProperty(self::PREFIX, 'song:track', $track));
25+
26+
return $this;
27+
}
28+
}

src/Types/Music/RadioStation.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Astrotomic\OpenGraph\Types\Music;
4+
5+
use Astrotomic\OpenGraph\Type;
6+
7+
class RadioStation extends Type
8+
{
9+
protected const PREFIX = 'music';
10+
11+
protected string $type = 'music.radio_station';
12+
13+
public function creator(string $url)
14+
{
15+
$this->setProperty(self::PREFIX, 'creator', $url);
16+
17+
return $this;
18+
}
19+
}

src/Types/Music/Song.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Astrotomic\OpenGraph\Types\Music;
4+
5+
use Astrotomic\OpenGraph\Type;
6+
7+
class Song extends Type
8+
{
9+
protected const PREFIX = 'music';
10+
11+
protected string $type = 'music.song';
12+
13+
public function duration(int $seconds)
14+
{
15+
$this->setProperty(self::PREFIX, 'duration', $seconds);
16+
17+
return $this;
18+
}
19+
20+
public function musician(string $url)
21+
{
22+
$this->addProperty(self::PREFIX, 'musician', $url);
23+
24+
return $this;
25+
}
26+
27+
public function album(string $url, ?int $disc = null, ?int $track = null)
28+
{
29+
$this->addProperty(self::PREFIX, 'album', $url);
30+
$this->when($disc > 0, fn() => $this->addProperty(self::PREFIX, 'album:disc', $disc));
31+
$this->when($track > 0, fn() => $this->addProperty(self::PREFIX, 'album:track', $track));
32+
33+
return $this;
34+
}
35+
}

src/Types/Video/Movie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Movie extends Type
1414
public function actor(string $url, ?string $role = null)
1515
{
1616
$this->addProperty(self::PREFIX, 'actor', $url);
17-
$this->when($role, fn(Movie $movie) => $movie->addProperty(self::PREFIX, 'actor:role', $role));
17+
$this->when($role, fn() => $this->addProperty(self::PREFIX, 'actor:role', $role));
1818

1919
return $this;
2020
}

0 commit comments

Comments
 (0)