toArray(); } if (false === $field) { return static::$_config; } return (array_key_exists($field, static::$_config)) ? static::$_config[$field] : $default; } public static function getDocumentRoot() { if (null === self::$documentRoot) { throw new Exception('Document Root is not defined'); } return self::$documentRoot; } public static function setDocumentRoot($documentRoot) { if (!is_dir($documentRoot)) { throw new Exception('Invalid Document Root ' . $documentRoot); } self::$documentRoot = $documentRoot; } /** * Returns non quoted relative target file name * Example: userfiles/files/notes(18).pdf * * @static * @param $name * @return string */ protected static function _getFullName($name) { if (!empty($name)) { $dir = dirname($name); if ('.' === $dir) { $name = self::WEB_PATH . '/' . $name; } $fullName = self::getDocumentRoot() . '/' . $name; if (file_exists($fullName)) { return $name; } } return null; } public static function getFileFullName($name) { return self::getDocumentRoot() . '/' . ('.' === dirname($name) ? self::WEB_PATH . '/' : '') . $name; } /** * @static * @param string $fullName * @return string */ public static function quotePath($fullName) { $parts = explode('/', $fullName); return implode('/', array_map('rawurlencode', $parts)); } /** * Returns quoted full file name * Example: userfiles/notes(18).pdf * * @static * @param string $name * @return string */ public static function get($name) { $fullName = static::_getFullName($name); return static::quotePath($fullName); } public static function getFullPath($name) { $name = $name ? static::_getFullName($name) : null; return $name ? self::getDocumentRoot() . '/' . $name : null; } public static function getUrl($name) { $name = static::get($name); if ($name) { $name = BASE_URL_LANGUAGE . '/' . $name; } return $name; } /** * @param string $fullName * @return bool */ public static function delete($fullName) { return file_exists($fullName) && unlink($fullName); } public static function ensurePath($filename) { if ('.' !== ($dir = dirname($filename))) { mkdir($dir, 0777, true); } } public static function getMimeType($file) { if (class_exists('finfo', false)) { $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME; $zendMime = new Zend_Validate_File_MimeType(''); $mimeFile = $zendMime->getMagicFile(); if (!empty($mimeFile)) { $mime = new finfo($const, $mimeFile); } else { $mime = new finfo($const); } if ($mime !== false) { $type = $mime->file($file); } unset($mime); } if (empty($type) && (function_exists('mime_content_type') && ini_get('mime_magic.magicfile'))) { $type = mime_content_type($file); } return $type; } }