本文整理汇总了PHP中CSSMin::isLocalUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP CSSMin::isLocalUrl方法的具体用法?PHP CSSMin::isLocalUrl怎么用?PHP CSSMin::isLocalUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSSMin
的用法示例。
在下文中一共展示了CSSMin::isLocalUrl方法的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;
}
示例2: testIsLocalUrl
/**
* @dataProvider provideIsLocalUrls
* @cover CSSMin::isLocalUrl
*/
public function testIsLocalUrl($expect, $url)
{
$this->assertEquals(CSSMin::isLocalUrl($url), $expect);
}
示例3: isLocalUrl
public static function isLocalUrl($maybeUrl)
{
return parent::isLocalUrl($maybeUrl);
}