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


PHP CSSMin::isRemoteUrl方法代码示例

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


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

示例1: 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

示例2: testIsRemoteUrl

 /**
  * @dataProvider provideIsRemoteUrl
  * @cover CSSMin::isRemoteUrl
  */
 public function testIsRemoteUrl($expect, $url)
 {
     $this->assertEquals(CSSMin::isRemoteUrl($url), $expect);
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:8,代码来源:CSSMinTest.php

示例3: isRemoteUrl

 public static function isRemoteUrl($maybeUrl)
 {
     return parent::isRemoteUrl($maybeUrl);
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:4,代码来源:CSSMinTest.php


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