本文整理汇总了PHP中Regex::make方法的典型用法代码示例。如果您正苦于以下问题:PHP Regex::make方法的具体用法?PHP Regex::make怎么用?PHP Regex::make使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Regex
的用法示例。
在下文中一共展示了Regex::make方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loop_resolve_list
function loop_resolve_list($list_text)
{
// Resolve the list of items for iteration.
// Either a generator function or a plain list.
$items = array();
$list_text = Crush::$process->functions->apply($list_text);
$generator_func_patt = Regex::make('~(?<func>range|color-range) {{parens}}~ix');
if (preg_match($generator_func_patt, $list_text, $m)) {
$func = strtolower($m['func']);
$args = Functions::parseArgs($m['parens_content']);
switch ($func) {
case 'range':
$items = call_user_func_array('range', $args);
break;
default:
$func = str_replace('-', '_', $func);
if (function_exists("CssCrush\\loop_{$func}")) {
$items = call_user_func_array("CssCrush\\loop_{$func}", $args);
}
}
} else {
$items = Util::splitDelimList($list_text);
}
return $items;
}
示例2: __invoke
public function __invoke($args)
{
$handler = $this->handler;
$tokens = Crush::$process->tokens;
$splat_arg_patt = Regex::make('~#\\((?<fallback>{{ ident }})?\\)~');
switch ($this->type) {
case 'alias':
return $handler($args);
case 'callback':
$template = new Template($handler($args));
return $template($args);
case 'splat':
$handler = $tokens->restore($handler, 's');
if ($args) {
$list = array();
foreach ($args as $arg) {
$list[] = SelectorAlias::wrap($tokens->capture(preg_replace($splat_arg_patt, $arg, $handler), 's'));
}
$handler = implode(',', $list);
} else {
$handler = $tokens->capture(preg_replace_callback($splat_arg_patt, function ($m) {
return $m['fallback'];
}, $handler), 's');
}
return SelectorAlias::wrap($handler);
}
}
示例3: svg_capture
function svg_capture($process)
{
$process->string->pregReplaceCallback(Regex::make('~@svg\\s+(?<name>{{ ident }})\\s*{{ block }}~iS'), function ($m) {
Crush::$process->misc->svg_defs[strtolower($m['name'])] = new Template($m['block_content']);
return '';
});
}
示例4: expand
public function expand()
{
static $grouping_patt, $expand, $expandSelector;
if (!$grouping_patt) {
$grouping_patt = Regex::make('~\\:any{{ parens }}~iS');
$expand = function ($selector_string) use($grouping_patt) {
if (preg_match($grouping_patt, $selector_string, $m, PREG_OFFSET_CAPTURE)) {
list($full_match, $full_match_offset) = $m[0];
$before = substr($selector_string, 0, $full_match_offset);
$after = substr($selector_string, strlen($full_match) + $full_match_offset);
$selectors = array();
// Allowing empty strings for more expansion possibilities.
foreach (Util::splitDelimList($m['parens_content'][0], array('allow_empty_strings' => true)) as $segment) {
if ($selector = trim("{$before}{$segment}{$after}")) {
$selectors[$selector] = true;
}
}
return $selectors;
}
return false;
};
$expandSelector = function ($selector_string) use($expand) {
if ($running_stack = $expand($selector_string)) {
$flattened_stack = array();
do {
$loop_stack = array();
foreach ($running_stack as $selector => $bool) {
$selectors = $expand($selector);
if (!$selectors) {
$flattened_stack += array($selector => true);
} else {
$loop_stack += $selectors;
}
}
$running_stack = $loop_stack;
} while ($loop_stack);
return $flattened_stack;
}
return array($selector_string => true);
};
}
$expanded_set = array();
foreach ($this->store as $original_selector) {
if (stripos($original_selector->value, ':any(') !== false) {
foreach ($expandSelector($original_selector->value) as $selector_string => $bool) {
$new = new Selector($selector_string);
$expanded_set[$new->readableValue] = $new;
}
} else {
$expanded_set[$original_selector->readableValue] = $original_selector;
}
}
$this->store = $expanded_set;
}
示例5: hsl2hex
function hsl2hex(Rule $rule)
{
$hsl_patt = Regex::make('~{{ LB }}hsl({{ parens }})~i');
foreach ($rule->declarations->filter(array('skip' => false)) as $declaration) {
if (isset($declaration->functions['hsl'])) {
$declaration->value = preg_replace_callback($hsl_patt, function ($m) {
$color = new Color($m[0]);
return $color->getHex();
}, $declaration->value);
}
}
}
示例6: postalias_fix_radial_gradients
/**
* Remove the 'at' keyword from -x-radial-gradient() for legacy implementations.
*/
function postalias_fix_radial_gradients($declaration_copies)
{
// Create new paren tokens based on the first prefixed declaration.
// Replace the new syntax with the legacy syntax.
static $fn_patt;
if (!$fn_patt) {
$fn_patt = Regex::make('~{{ LB }}{{ vendor }}(?:repeating-)?radial-gradient{{ parens }}~iS');
}
$original_parens = array();
$replacement_parens = array();
foreach (Regex::matchAll($fn_patt, $declaration_copies[0]->value) as $m) {
$original_parens[] = $m['parens'][0];
$replacement_parens[] = preg_replace('~\\bat +(top|left|bottom|right|center)\\b~i', '$1', $m['parens'][0]);
}
foreach ($declaration_copies as $prefixed_copy) {
$prefixed_copy->value = str_replace($original_parens, $replacement_parens, $prefixed_copy->value);
}
}
示例7: color_capture
function color_capture($process)
{
$captured_keywords = $process->string->captureDirectives('color', array('singles' => true));
if ($captured_keywords) {
$native_keywords = Color::getKeywords();
$custom_keywords = array();
$process->colorKeywords = $native_keywords;
foreach ($captured_keywords as $key => $value) {
$value = $process->functions->apply($value);
if (!isset($native_keywords[$key]) && ($rgba = Color::parse($value))) {
$custom_keywords[] = $key;
$process->stat['colors'][$key] = new Color($rgba);
$process->colorKeywords[$key] = $rgba;
}
}
if ($custom_keywords) {
$GLOBALS['CSSCRUSH_COLOR_PATT'] = Regex::make('~{{ LB }}(?<color_keyword>' . implode('|', $custom_keywords) . '){{ RB }}~iS');
}
}
}
示例8: captureUrls
public function captureUrls($str, $add_padding = false)
{
$count = preg_match_all(Regex::make('~@import \\s+ (?<import>{{s_token}}) | {{LB}} (?<func>url|data-uri) {{parens}}~ixS'), $str, $m, PREG_OFFSET_CAPTURE);
while ($count--) {
list($full_text, $full_offset) = $m[0][$count];
list($import_text, $import_offset) = $m['import'][$count];
// @import directive.
if ($import_offset !== -1) {
$label = $this->add(new Url(trim($import_text)));
$str = str_replace($import_text, $add_padding ? str_pad($label, strlen($import_text)) : $label, $str);
} else {
$func_name = strtolower($m['func'][$count][0]);
$url = new Url(trim($m['parens_content'][$count][0]));
$url->convertToData = 'data-uri' === $func_name;
$label = $this->add($url);
$str = substr_replace($str, $add_padding ? Tokens::pad($label, $full_text) : $label, $full_offset, strlen($full_text));
}
}
return $str;
}
示例9: ease
function ease(Rule $rule)
{
static $find, $replace, $easing_properties;
if (!$find) {
$easings = array('ease-in-out-back' => 'cubic-bezier(.680,-0.550,.265,1.550)', 'ease-in-out-circ' => 'cubic-bezier(.785,.135,.150,.860)', 'ease-in-out-expo' => 'cubic-bezier(1,0,0,1)', 'ease-in-out-sine' => 'cubic-bezier(.445,.050,.550,.950)', 'ease-in-out-quint' => 'cubic-bezier(.860,0,.070,1)', 'ease-in-out-quart' => 'cubic-bezier(.770,0,.175,1)', 'ease-in-out-cubic' => 'cubic-bezier(.645,.045,.355,1)', 'ease-in-out-quad' => 'cubic-bezier(.455,.030,.515,.955)', 'ease-out-back' => 'cubic-bezier(.175,.885,.320,1.275)', 'ease-out-circ' => 'cubic-bezier(.075,.820,.165,1)', 'ease-out-expo' => 'cubic-bezier(.190,1,.220,1)', 'ease-out-sine' => 'cubic-bezier(.390,.575,.565,1)', 'ease-out-quint' => 'cubic-bezier(.230,1,.320,1)', 'ease-out-quart' => 'cubic-bezier(.165,.840,.440,1)', 'ease-out-cubic' => 'cubic-bezier(.215,.610,.355,1)', 'ease-out-quad' => 'cubic-bezier(.250,.460,.450,.940)', 'ease-in-back' => 'cubic-bezier(.600,-0.280,.735,.045)', 'ease-in-circ' => 'cubic-bezier(.600,.040,.980,.335)', 'ease-in-expo' => 'cubic-bezier(.950,.050,.795,.035)', 'ease-in-sine' => 'cubic-bezier(.470,0,.745,.715)', 'ease-in-quint' => 'cubic-bezier(.755,.050,.855,.060)', 'ease-in-quart' => 'cubic-bezier(.895,.030,.685,.220)', 'ease-in-cubic' => 'cubic-bezier(.550,.055,.675,.190)', 'ease-in-quad' => 'cubic-bezier(.550,.085,.680,.530)');
$easing_properties = array('transition' => true, 'transition-timing-function' => true);
foreach ($easings as $property => $value) {
$patt = Regex::make("~{{ LB }}{$property}{{ RB }}~i");
$find[] = $patt;
$replace[] = $value;
}
}
if (!array_intersect_key($rule->declarations->canonicalProperties, $easing_properties)) {
return;
}
foreach ($rule->declarations->filter(array('skip' => false)) as $declaration) {
if (isset($easing_properties[$declaration->canonicalProperty])) {
$declaration->value = preg_replace($find, $replace, $declaration->value);
}
}
}
示例10: call
public static function call($message, $context = null)
{
$process = Crush::$process;
$mixable = null;
$message = trim($message);
// Test for mixin or abstract rule. e.g:
// named-mixin( 50px, rgba(0,0,0,0), left 100% )
// abstract-rule
if (preg_match(Regex::make('~^(?<name>{{ident}}) {{parens}}?~xS'), $message, $message_match)) {
$name = $message_match['name'];
if (isset($process->mixins[$name])) {
$mixable = $process->mixins[$name];
} elseif (isset($process->references[$name])) {
$mixable = $process->references[$name];
}
}
// If no mixin or abstract rule matched, look for matching selector
if (!$mixable) {
$selector_test = Selector::makeReadable($message);
if (isset($process->references[$selector_test])) {
$mixable = $process->references[$selector_test];
}
}
// Avoid infinite recursion.
if (!$mixable || $mixable === $context) {
return false;
} elseif ($mixable instanceof Mixin) {
$args = array();
$raw_args = isset($message_match['parens_content']) ? trim($message_match['parens_content']) : null;
if ($raw_args) {
$args = Util::splitDelimList($raw_args);
}
return DeclarationList::parse($mixable->template->__invoke($args), array('flatten' => true, 'context' => $mixable));
} elseif ($mixable instanceof Rule) {
return $mixable->declarations->store;
}
}
示例11: colorSplit
public static function colorSplit($str)
{
if ($test = Color::test($str)) {
$color = $test['value'];
$type = $test['type'];
} else {
return false;
}
// If non-alpha color return early.
if (!in_array($type, array('hsla', 'rgba'))) {
return array($color, 1);
}
// Strip all whitespace.
$color = preg_replace('~\\s+~', '', $color);
// Extract alpha component if one is matched.
$opacity = 1;
if (preg_match(Regex::make('~^(rgb|hsl)a\\(({{number}}%?,{{number}}%?,{{number}}%?),({{number}})\\)$~i'), $color, $m)) {
$opacity = floatval($m[3]);
$color = "{$m['1']}({$m['2']})";
}
// Return color value and alpha component seperated.
return array($color, $opacity);
}
示例12: makePattern
public static function makePattern($functionNames)
{
$idents = array();
$nonIdents = array();
foreach ($functionNames as $functionName) {
if (preg_match(Regex::$patt->ident, $functionName[0])) {
$idents[] = preg_quote($functionName);
} else {
$nonIdents[] = preg_quote($functionName);
}
}
if ($idents) {
$idents = '{{ LB }}-?(?<function>' . implode('|', $idents) . ')';
}
if ($nonIdents) {
$nonIdents = '(?<simple_function>' . implode('|', $nonIdents) . ')';
}
if ($idents && $nonIdents) {
$patt = "(?:{$idents}|{$nonIdents})";
} elseif ($idents) {
$patt = $idents;
} elseif ($nonIdents) {
$patt = $nonIdents;
}
return Regex::make("~{$patt}\\(~iS");
}
示例13: rem
function rem(Rule $rule)
{
static $rem_patt, $px_patt, $font_props, $modes;
if (!$modes) {
$rem_patt = Regex::make('~{{LB}}({{number}})rem{{RB}}~iS');
$px_patt = Regex::make('~{{LB}}({{number}})px{{RB}}~iS');
$font_props = array('font' => true, 'font-size' => true, 'line-height' => true);
$modes = array('rem-fallback', 'px-fallback', 'convert');
}
// Determine which properties are touched; all, or just font related.
$just_font_props = !Crush::$process->settings->get('rem-all', false);
if ($just_font_props && !array_intersect_key($rule->declarations->canonicalProperties, $font_props)) {
return;
}
// Determine what conversion mode we're using.
$mode = Crush::$process->settings->get('rem-mode', $modes[0]);
// Determine the default base em-size, to my knowledge always 16px.
$base = Crush::$process->settings->get('rem-base', 16);
// Select the length match pattern depending on mode.
$length_patt = $mode === 'rem-fallback' ? $rem_patt : $px_patt;
$new_set = array();
$rule_updated = false;
foreach ($rule->declarations as $declaration) {
if ($declaration->skip || $just_font_props && !isset($font_props[$declaration->canonicalProperty]) || !preg_match_all($length_patt, $declaration->value, $m)) {
$new_set[] = $declaration;
continue;
}
// Value has matching length components.
$find = $m[0];
$replace = array();
$numbers = $m[1];
switch ($mode) {
// Converting a rem value to px.
case 'rem-fallback':
foreach ($numbers as $num) {
$replace[] = round(floatval($num) * $base, 5) . 'px';
}
break;
// Converting a px value to rem.
// Converting a px value to rem.
case 'convert':
case 'px-fallback':
foreach ($numbers as $num) {
$replace[] = round(floatval($num) / $base, 5) . 'rem';
}
break;
}
$converted_value = str_replace($find, $replace, $declaration->value);
if ($mode === 'convert') {
$declaration->value = $converted_value;
$new_set[] = $declaration;
} else {
$clone = clone $declaration;
$clone->value = $converted_value;
$rule_updated = true;
if ($mode === 'px-fallback') {
$new_set[] = $declaration;
$new_set[] = $clone;
} else {
$new_set[] = $clone;
$new_set[] = $declaration;
}
}
}
if ($rule_updated) {
$rule->declarations->reset($new_set);
}
}
示例14: minifyColors
protected function minifyColors()
{
static $keywords_patt, $functions_patt;
$minified_keywords = Color::getMinifyableKeywords();
if (!$keywords_patt) {
$keywords_patt = '~(?<![\\w-\\.#])(' . implode('|', array_keys($minified_keywords)) . ')(?![\\w-\\.#\\]])~iS';
$functions_patt = Regex::make('~{{ LB }}(rgb|hsl)\\(([^\\)]{5,})\\)~iS');
}
$this->string->pregReplaceCallback($keywords_patt, function ($m) use($minified_keywords) {
return $minified_keywords[strtolower($m[0])];
});
$this->string->pregReplaceCallback($functions_patt, function ($m) {
$args = Functions::parseArgs(trim($m[2]));
if (stripos($m[1], 'hsl') === 0) {
$args = Color::cssHslToRgb($args);
}
return Color::rgbToHex($args);
});
}
示例15: addMarkers
protected function addMarkers(&$str)
{
$process = $this->process;
$currentFileIndex = count($process->sources) - 1;
static $patt;
if (!$patt) {
$patt = Regex::make('~
(?:^|(?<=[;{}]))
(?<before>
(?: \\s | {{c_token}} )*
)
(?<selector>
(?:
# Some @-rules are treated like standard rule blocks.
@(?: (?i)page|abstract|font-face(?-i) ) {{RB}} [^{]*
|
[^@;{}]+
)
)
\\{
~xS');
}
$count = preg_match_all($patt, $str, $matches, PREG_OFFSET_CAPTURE);
while ($count--) {
$selectorOffset = $matches['selector'][$count][1];
$line = 0;
$before = substr($str, 0, $selectorOffset);
if ($selectorOffset) {
$line = substr_count($before, "\n");
}
$pointData = array($currentFileIndex, $line);
// Source maps require column index too.
if ($process->generateMap) {
$pointData[] = strlen($before) - strrpos($before, "\n") - 1;
}
// Splice in marker token (packing point_data into string is more memory efficient).
$str = substr_replace($str, $process->tokens->add(implode(',', $pointData), 't'), $selectorOffset, 0);
}
}