Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor support for values in file properties #13

Merged
merged 1 commit into from Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -19,14 +19,14 @@
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "0.10.x-dev"
"dev-master": "0.11.x-dev"
}
},
"require": {
"php": ">=5.6.0 || >=7.0",
"ext-fileinfo": "*",
"ext-PDO": "*",
"ext-SimpleXML": "*",
"ext-pdo": "*",
"ext-simplexml": "*",
"psr/log": "^1.0",
"psr/cache": "^1.0",
"locomotivemtl/charcoal-config": "~0.9",
Expand Down
39 changes: 20 additions & 19 deletions src/Charcoal/Property/AudioProperty.php
Expand Up @@ -85,51 +85,52 @@ public function getMaxLength()
}

/**
* Retrieves the default list of acceptable MIME types for uploaded files.
*
* This method should be overriden.
*
* @return string[]
*/
public function getAcceptedMimetypes()
public function getDefaultAcceptedMimetypes()
{
return [
'audio/mp3',
'audio/mpeg',
'audio/ogg',
'audio/webm',
'audio/wav',
'audio/wave',
'audio/x-wav',
'audio/x-pn-wav',
];
}

/**
* Generate the file extension from the property's value.
* Resolve the file extension from the given MIME type.
*
* @param string $file The file to parse.
* @return string The extension based on the MIME type.
* @param string $type The MIME type to resolve.
* @return string|null The extension based on the MIME type.
*/
public function generateExtension($file = null)
protected function resolveExtensionFromMimeType($type)
{
if (is_string($file)) {
if (in_array($file, $this->getAcceptedMimetypes())) {
$mime = $file;
} else {
$mime = $this->getMimetypeFor($file);
}
} else {
$mime = $this->getMimetype();
}

switch ($mime) {
switch ($type) {
case 'audio/mp3':
case 'audio/mpeg':
return 'mp3';

case 'audio/ogg':
return 'ogg';

case 'audio/webm':
return 'webm';

case 'audio/wav':
case 'audio/wave':
case 'audio/x-wav':
case 'audio/x-pn-wav':
return 'wav';

default:
return '';
}

return null;
}
}