当前位置: 首页>>代码示例>>PHP>>正文


PHP CSSMin::getMimeType方法代码示例

本文整理汇总了PHP中CSSMin::getMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP CSSMin::getMimeType方法的具体用法?PHP CSSMin::getMimeType怎么用?PHP CSSMin::getMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CSSMin的用法示例。


在下文中一共展示了CSSMin::getMimeType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: embeddable

 /**
  * Check if an image file reference is suitable for embedding.
  * An image is embeddable if it (a) exists, (b) has a suitable MIME-type,
  * (c) does not exceed IE<9 size limit of 32kb. This is a LESS predicate
  * function; it returns a LESS boolean value and can thus be used as a
  * mixin guard.
  *
  * @par Example:
  * @code
  *   .background-image(@url) when(embeddable(@url)) {
  *       background-image: url(@url) !ie;
  *   }
  * @endcode
  * @param array $frame
  * @param lessc $less
  */
 public static function embeddable($frame, $less)
 {
     $base = pathinfo($less->parser->sourceName, PATHINFO_DIRNAME);
     $url = trim($less->compileValue($frame), '"\'');
     $file = realpath($base . '/' . $url);
     return $less->toBool($file && strpos($url, '//') === false && filesize($file) < CSSMin::EMBED_SIZE_LIMIT && CSSMin::getMimeType($file) !== false);
 }
开发者ID:Habatchii,项目名称:wikibase-for-mediawiki,代码行数:23,代码来源:ResourceLoaderLESSFunctions.php

示例2: remap

 /**
  * Remaps CSS URL paths and automatically embeds data URIs for CSS rules
  * or url() values preceded by an / * @embed * / comment.
  *
  * @param string $source CSS data to remap
  * @param string $local File path where the source was read from
  * @param string $remote URL path to the file
  * @param bool $embedData If false, never do any data URI embedding,
  *   even if / * @embed * / is found.
  * @return string Remapped CSS data
  */
 public static function remap($source, $local, $remote, $embedData = true)
 {
     // High-level overview:
     // * For each CSS rule in $source that includes at least one url() value:
     //   * Check for an @embed comment at the start indicating that all URIs should be embedded
     //   * For each url() value:
     //     * Check for an @embed comment directly preceding the value
     //     * If either @embed comment exists:
     //       * Embedding the URL as data: URI, if it's possible / allowed
     //       * Otherwise remap the URL to work in generated stylesheets
     // Guard against trailing slashes, because "some/remote/../foo.png"
     // resolves to "some/remote/foo.png" on (some?) clients (bug 27052).
     if (substr($remote, -1) == '/') {
         $remote = substr($remote, 0, -1);
     }
     // Disallow U+007F DELETE, which is illegal anyway, and which
     // we use for comment placeholders.
     $source = str_replace("", "?", $source);
     // Replace all comments by a placeholder so they will not interfere with the remapping.
     // Warning: This will also catch on anything looking like the start of a comment between
     // quotation marks (e.g. "foo /* bar").
     $comments = array();
     $pattern = '/(?!' . CSSMin::EMBED_REGEX . ')(' . CSSMin::COMMENT_REGEX . ')/s';
     $source = preg_replace_callback($pattern, function ($match) use(&$comments) {
         $comments[] = $match[0];
         return CSSMin::PLACEHOLDER . (count($comments) - 1) . 'x';
     }, $source);
     // Note: This will not correctly handle cases where ';', '{' or '}'
     // appears in the rule itself, e.g. in a quoted string. You are advised
     // not to use such characters in file names. We also match start/end of
     // the string to be consistent in edge-cases ('@import url(…)').
     $pattern = '/(?:^|[;{])\\K[^;{}]*' . CSSMin::URL_REGEX . '[^;}]*(?=[;}]|$)/';
     $source = preg_replace_callback($pattern, function ($matchOuter) use($local, $remote, $embedData) {
         $rule = $matchOuter[0];
         // Check for global @embed comment and remove it. Allow other comments to be present
         // before @embed (they have been replaced with placeholders at this point).
         $embedAll = false;
         $rule = preg_replace('/^((?:\\s+|' . CSSMin::PLACEHOLDER . '(\\d+)x)*)' . CSSMin::EMBED_REGEX . '\\s*/', '$1', $rule, 1, $embedAll);
         // Build two versions of current rule: with remapped URLs
         // and with embedded data: URIs (where possible).
         $pattern = '/(?P<embed>' . CSSMin::EMBED_REGEX . '\\s*|)' . CSSMin::URL_REGEX . '/';
         $ruleWithRemapped = preg_replace_callback($pattern, function ($match) use($local, $remote) {
             $remapped = CSSMin::remapOne($match['file'], $match['query'], $local, $remote, false);
             return CSSMin::buildUrlValue($remapped);
         }, $rule);
         if ($embedData) {
             // Remember the occurring MIME types to avoid fallbacks when embedding some files.
             $mimeTypes = array();
             $ruleWithEmbedded = preg_replace_callback($pattern, function ($match) use($embedAll, $local, $remote, &$mimeTypes) {
                 $embed = $embedAll || $match['embed'];
                 $embedded = CSSMin::remapOne($match['file'], $match['query'], $local, $remote, $embed);
                 $url = $match['file'] . $match['query'];
                 $file = $local . $match['file'];
                 if (!CSSMin::isRemoteUrl($url) && !CSSMin::isLocalUrl($url) && file_exists($file)) {
                     $mimeTypes[CSSMin::getMimeType($file)] = true;
                 }
                 return CSSMin::buildUrlValue($embedded);
             }, $rule);
             // Are all referenced images SVGs?
             $needsEmbedFallback = $mimeTypes !== array('image/svg+xml' => true);
         }
         if (!$embedData || $ruleWithEmbedded === $ruleWithRemapped) {
             // We're not embedding anything, or we tried to but the file is not embeddable
             return $ruleWithRemapped;
         } elseif ($embedData && $needsEmbedFallback) {
             // Build 2 CSS properties; one which uses a data URI in place of the @embed comment, and
             // the other with a remapped and versioned URL with an Internet Explorer 6 and 7 hack
             // making it ignored in all browsers that support data URIs
             return "{$ruleWithEmbedded};{$ruleWithRemapped}!ie";
         } else {
             // Look ma, no fallbacks! This is for files which IE 6 and 7 don't support anyway: SVG.
             return $ruleWithEmbedded;
         }
     }, $source);
     // Re-insert comments
     $pattern = '/' . CSSMin::PLACEHOLDER . '(\\d+)x/';
     $source = preg_replace_callback($pattern, function ($match) use(&$comments) {
         return $comments[$match[1]];
     }, $source);
     return $source;
 }
开发者ID:natebrunette,项目名称:sphericalcow,代码行数:92,代码来源:CSSMin.php


注:本文中的CSSMin::getMimeType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。