public function media($path, array $options = [])
{
$options += ['tag' => null, 'pathPrefix' => 'files/', 'text' => ''];
if (!empty($options['tag'])) {
$tag = $options['tag'];
} else {
$tag = null;
}
if (is_array($path)) {
$sourceTags = '';
foreach ($path as &$source) {
if (is_string($source)) {
$source = ['src' => $source];
}
if (!isset($source['type'])) {
$ext = pathinfo($source['src'], PATHINFO_EXTENSION);
$source['type'] = $this->response->getMimeType($ext);
}
$source['src'] = $this->Url->assetUrl($source['src'], $options);
$sourceTags .= $this->formatTemplate('tagselfclosing', ['tag' => 'source', 'attrs' => $this->templater()->formatAttributes($source)]);
}
unset($source);
$options['text'] = $sourceTags . $options['text'];
unset($options['fullBase']);
} else {
if (empty($path) && !empty($options['src'])) {
$path = $options['src'];
}
$options['src'] = $this->Url->assetUrl($path, $options);
}
if ($tag === null) {
if (is_array($path)) {
$mimeType = $path[0]['type'];
} else {
$mimeType = $this->response->getMimeType(pathinfo($path, PATHINFO_EXTENSION));
}
if (preg_match('#^video/#', $mimeType)) {
$tag = 'video';
} else {
$tag = 'audio';
}
}
if (isset($options['poster'])) {
$options['poster'] = $this->Url->assetUrl($options['poster'], ['pathPrefix' => Configure::read('App.imageBaseUrl')] + $options);
}
$text = $options['text'];
$options = array_diff_key($options, ['tag' => null, 'fullBase' => null, 'pathPrefix' => null, 'text' => null]);
return $this->tag($tag, $text, $options);
}