1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | <?php /** * File mime type strategy guessing the file extension * * @author Christopher Han <xiphux@gmail.com> * @copyright Copyright (c) 2012 Christopher Han * @package GitPHP * @subpackage Git\FileMimeType */ class GitPHP_FileMimeType_Extension implements GitPHP_FileMimeTypeStrategy_Interface { /** * Gets the mime type for a blob * * @param GitPHP_Blob $blob blob * @return string mime type */ public function GetMime($blob) { if (!$blob) return false; $file = $blob->GetName(); if (empty($file)) return ''; $dotpos = strrpos($file, '.'); if ($dotpos !== FALSE) $file = substr($file, $dotpos+1); switch ($file) { case 'jpg': case 'jpeg': case 'jpe': return 'image/jpeg'; break; case 'gif': return 'image/gif'; break; case 'png'; return 'image/png'; break; } return ''; } /** * Gets whether this mimetype strategy is valid * * @return bool true if valid */ public function Valid() { return true; } } |