Skip to content

Commit 9913af9

Browse files
committed
Add Video property
1 parent 2800a8e commit 9913af9

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"admin": {
3+
"input_type": "charcoal/admin/property/input/video",
4+
"display_type": "charcoal/admin/property/display/video"
5+
}
6+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace Charcoal\Property;
4+
5+
// From 'charcoal-property'
6+
use Charcoal\Property\FileProperty;
7+
8+
/**
9+
* Video Property.
10+
*
11+
* The video property is a specialized file property that handles video file.
12+
*/
13+
class VideoProperty extends FileProperty
14+
{
15+
/**
16+
* @return string
17+
*/
18+
public function type()
19+
{
20+
return 'video';
21+
}
22+
23+
/**
24+
* Retrieves the default list of acceptable MIME types for uploaded files.
25+
*
26+
* This method should be overriden.
27+
*
28+
* @return string[]
29+
*/
30+
public function getDefaultAcceptedMimetypes()
31+
{
32+
return [
33+
'video/mp4',
34+
'video/webm',
35+
'video/ogg',
36+
'video/ogv',
37+
'video/x-matroska',
38+
];
39+
}
40+
41+
/**
42+
* Resolve the file extension from the given MIME type.
43+
*
44+
* @param string $type The MIME type to resolve.
45+
* @return string|null The extension based on the MIME type.
46+
*/
47+
protected function resolveExtensionFromMimeType($type)
48+
{
49+
switch ($type) {
50+
case 'video/mp4':
51+
return 'mp4';
52+
53+
case 'video/webm':
54+
return 'webm';
55+
56+
case 'video/ogg':
57+
case 'video/ogv':
58+
return 'ogv';
59+
60+
case 'video/x-matroska':
61+
return 'mkv';
62+
}
63+
64+
return null;
65+
}
66+
}

0 commit comments

Comments
 (0)