/** * @dataProvider isValidForProvider * @param string $pattern * @param string $name * @param bool $expectedResult */ public function testIsValidFor($pattern, $name, $expectedResult) { $this->regex->setEventRegex($pattern); $eventMock = $this->getMock('Magento\\Framework\\Event', [], [], '', false); $eventMock->expects($this->any())->method('getName')->will($this->returnValue($name)); $this->assertEquals($expectedResult, $this->regex->isValidFor($eventMock)); }
/** * Test a match where we can get the parameters (from the regex) */ public function testValidMatchParamaters() { $config = array('route' => '/foo/bar/:id'); $regex = new Regex($config); $this->assertTrue($regex->evaluate('/foo/bar/baz')); $params = $regex->getParams(); $this->assertEquals($params, array('id' => 'baz')); }
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 ''; }); }
public function ajaxSendEmailAction() { $email = Request::getPOST('email'); $verify = Request::getPOST('verify'); if (empty($verify)) { $this->renderAjax(1, '请输入图片验证码!'); } if (empty($email)) { $this->renderAjax(1, '请填写邮箱!'); } // 校验验证码 $imgCode = Session::get('check_code'); if (strtolower($verify) != $imgCode) { $this->renderAjax(2, '图片验证码错误!'); } if (!Regex::match($email, RegexVars::EMAIL)) { $this->renderAjax(1, '邮箱格式错误!'); } // 是否存在 $userInfo = UcUserInterface::getByLoginName(array('login_name' => $email)); if (empty($userInfo)) { $this->renderAjax(1, '用户邮箱不存在!'); } $code = UcAuthInterface::sendEmailCode(array('email' => $email, 'repeat_at' => time() + 60)); if (false === $code) { $this->renderAjax(1, '服务器繁忙,请1分钟后重试!'); } $this->renderAjax(0); }
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); } }
function internalRouteURI(string $requestUri = '') : string { $config = Config::get('Services', 'route'); if ($config['openPage']) { $internalDir = NULL; if (defined('_CURRENT_PROJECT')) { $configAppdir = PROJECTS_CONFIG['directory']['others']; if (is_array($configAppdir)) { $internalDir = !empty($configAppdir[$requestUri]) ? $requestUri : _CURRENT_PROJECT; } else { $internalDir = _CURRENT_PROJECT; } } if ($requestUri === DIRECTORY_INDEX || $requestUri === getLang() || $requestUri === $internalDir || empty($requestUri)) { $requestUri = $config['openPage']; } } $uriChange = $config['changeUri']; $patternType = $config['patternType']; if (!empty($uriChange)) { foreach ($uriChange as $key => $val) { if ($patternType === 'classic') { $requestUri = preg_replace(presuffix($key) . 'xi', $val, $requestUri); } else { $requestUri = Regex::replace($key, $val, $requestUri, 'xi'); } } } return $requestUri; }
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; }
public function ajaxSubmitAction() { $username = Request::getPOST('username'); $password = Request::getPOST('password'); $verify = Request::getPOST('verify'); if (!Regex::match($username, RegexVars::USERNAME)) { $this->renderAjax(1, '用户名格式不正确!'); } // 校验密码格式 if (!Regex::match($password, RegexVars::PASSWORD)) { $this->renderAjax(1, '密码长度为6-20位!'); } // 校验验证码 $code = Session::get('check_code'); if (strtolower($verify) != $code) { $this->renderAjax(1, '验证码错误,请重试!'); } // 过滤用户名 if (false !== strpos(strtolower($username), 'admin')) { $this->renderAjax(1, '用户已经存在!'); } // 校验用户是否存在 $userInfo = UcUserInterface::getByLoginName(array('login_name' => $username)); if (!empty($userInfo)) { $this->renderAjax(1, '用户名已经被占用!'); } // 保存 $data = array('username' => $username, 'password' => $password, 'reg_ip' => Http::getClientIp()); UcUserInterface::save($data); $this->renderAjax(0); }
public function ncEncode($string = '', $badWords = '', $changeChar = '[badchars]') { if (!is_string($string)) { return Error::set(lang('Error', 'stringParameter', 'string')); } // 2. Parametre boş ise varsayılan olarak Config/Security.php dosya ayarlarını kullan. if (empty($badWords)) { $secnc = $this->config['ncEncode']; $badWords = $secnc['bad_chars']; $changeChar = $secnc['change_bad_chars']; } if (!is_array($badWords)) { return $string = Regex::replace($badWords, $changeChar, $string, 'xi'); } $ch = ''; $i = 0; foreach ($badWords as $value) { if (!is_array($changeChar)) { $ch = $changeChar; } else { if (isset($changeChar[$i])) { $ch = $changeChar[$i]; $i++; } } $string = Regex::replace($value, $ch, $string, 'xi'); } return $string; }
public function word($string = '', $badWords = '', $changeChar = '[badwords]') { if (!isValue($string)) { return Error::set(lang('Error', 'valueParameter', 'string')); } if (!is_array($badWords)) { if (empty($badWords)) { return $string; } return $string = Regex::replace($badWords, $changeChar, $string, 'xi'); } $ch = ''; $i = 0; if (!empty($badWords)) { foreach ($badWords as $value) { if (!is_array($changeChar)) { $ch = $changeChar; } else { if (isset($changeChar[$i])) { $ch = $changeChar[$i]; $i++; } } $string = Regex::replace($value, $ch, $string, 'xi'); } } return $string; }
public static function process($directory = "", $defaults, $config = array()) { PipelineHooks::beforeProcessingFilesIn($directory, $defaults, $config); // Hook for before this directory is processed $configPath = $directory . "config.json"; if (file_exists($configPath)) { CL::printDebug("Config File at: " . $configPath, 1); } $config = Secretary::getJSON($configPath, $config); if (array_key_exists("Content", $config)) { CL::println("WARNING: You've declared field \"Content\" in JSON file: " . $directory . "config.json", 0, Colour::Red); CL::println("The \"Content\" keyword is reserved for storing the file contents in.", 0, Colour::Red); CL::println("The value for \"Content\" stored in the JSON file will be ignored.", 0, Colour::Red); } $files = array(); $markdowns = glob($directory . "*.md"); foreach ($markdowns as $markdown) { CL::printDebug("Processing: " . $markdown); $file = new File($markdown); // Set up our @data $data = array_merge($config, $file->data); // Renaming to make more semantic sense as we're now working with the "data" $data["Content"] = $file->contents; // Pass in our file contents $raw = $data; // Store raw data before processing // Process our data through data extensions if (array_key_exists("DataExtensions", $defaults)) { $data = DataProcessor::process($data, $defaults["DataExtensions"]); // Process our data to be filled in CL::printDebug("Processed data", 1, Colour::Green); } else { CL::printDebug("No data extensions declared", 1); } $data["Content"] = Regex::process($data["Content"]); // Now regex it all CL::printDebug("Processed Regex", 1, Colour::Green); $templateFile = Templater::process($data["Template"]); // Generate our template CL::printDebug("Processed template: " . $data["Template"], 1, Colour::Green); $processedFile = LTM::process($templateFile, $data, $raw); // Fill in any conditions and optionals CL::printDebug("Processed LTM", 1, Colour::Green); $file->contents = $processedFile; // Store the complete processed file back into the file object array_push($files, $file); // Add it to the array ready to be exported! } PipelineHooks::afterProcessing($files, $directory, $defaults, $config); // Hook for after this directory is processed - and lets pass some files! $directories = glob($directory . "*", GLOB_ONLYDIR); foreach ($directories as $directory) { $newFiles = self::process($directory . "/", $defaults, $config); foreach ($newFiles as $newFile) { array_push($files, $newFile); } } return $files; }
/** * @param string $expr */ public function __construct($expr) { try { $this->value = Regex::create($expr); } catch (\InvalidArgumentException $e) { $this->value = new Glob($expr); } }
public function __construct($useLocale = false) { $pattern = '^y(eah?|ep|es)?$'; if ($useLocale && defined('YESEXPR')) { $pattern = nl_langinfo(YESEXPR); } parent::__construct('/' . $pattern . '/i'); }
public function __construct($useLocale = false) { $pattern = '^n(o(t|pe)?|ix|ay)?$'; if ($useLocale && defined('NOEXPR')) { $pattern = nl_langinfo(NOEXPR); } parent::__construct('/' . $pattern . '/i'); }
private static function getController($location) { $location = strtolower($location); $pattern = '/controller/'; $match = Regex::match($pattern, $location); if ($match > 0) { $location = Regex::replace($pattern, '', $location); } return $location; }
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; }
/** * @Invocable */ protected function find() { if ($this->request->hasKey('friend')) { $name = Regex::replace('/[^A-Za-z0-9]/', '', $this->request->valueOf('friend')); Navigator::redirectTo($this->url->getParametersPath($name)); } $name = $this->url->getParameter(0); if ($name == null) { return; } $this->getUsers($name); }
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); } } }
public function ajaxUpdatePasswordAction() { // 获取参数 $oldPassword = Request::getPOST('old-password'); $password = trim(Request::getPOST('password')); if (!Regex::match($password, RegexVars::PASSWORD)) { $this->renderError('新密码限制为6-20位!'); } $encryptPassword = UserCommonInterface::encryptPassword(array('password' => $oldPassword)); if ($encryptPassword != $this->loginUserInfo['password']) { $this->renderError('旧密码不正确!'); } $data = array('id' => $this->loginUserInfo['id'], 'password' => $password); UserCommonInterface::save($data); UserCommonInterface::logout(); $this->renderAjax(0); }
/** * 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); } }
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'); } } }
public function ajaxSendEmailAction() { $email = Request::getPOST('email'); if (empty($email)) { $this->renderError('请填写邮箱!'); } if (!Regex::match($email, RegexVars::EMAIL)) { $this->renderError('邮箱格式错误!'); } // 是否已经被绑定 $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $email)); if (!empty($userInfo)) { $this->renderError('该邮箱已经被绑定!'); } $code = AuthCommonInterface::sendEmailCode(array('email' => $email, 'repeat_at' => time() + 60)); if (false === $code) { $this->renderError('服务器繁忙,请1分钟后重试!'); } $this->renderAjax(0); }
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; }
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); } } }
public function ParseTextMessage(TextMessage $Message) { if (!empty($Message->Text)) { if ($Message->Text[0] === '!') { return $this->ParseCommandMessage($Message); } else { # Text Event $Module = $this->ModuleManager->GetModule('Event', 'text'); if ($Module instanceof Module) { $this->SendResponse($Message, $Module->Execute($Message)); } elseif ($Module !== Module::NOT_LOADED) { $this->SendResponse($Message, $Module); } } } foreach (Regex::MatchAll(Regex::URL, $Message->Text) as $URL) { $this->ParseURLMessage($Message, $URL); } /* Parser * Send help if is pv * AI? */ }
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; } }
/** * @expectedException Respect\Validation\Exceptions\RegexException */ public function testRegexNot() { $v = new Regex('/^w+$/'); $this->assertFalse($v->validate('w poiur')); $this->assertFalse($v->assert('w poiur')); }
/** * Retourne un tableau contenant les informations des releases * @return array */ public function getReleaseTable() { //Création du tableau $aResponse = array(); $aRegex = Regex::getAllRegex(); $aTrackers = Tracker::getTrackers(); while ($aResult = $this->oResults->fetch_assoc()) { $row = array(); if ($aResult['id_links'] != NULL) { $aTags = explode(';', $aResult['tags']); $row['tags'] = array(); foreach ($aTags as $iTagId) { if ($iTagId != NULL) { $row['tags'][$iTagId] = $aRegex[$iTagId]->getName(); } } $row['categorie'] = $aResult['id_categorie']; $row['fiche'] = $aResult['id_fiche']; $row["release"] = $aResult['name']; $row["release_id"] = $aResult['id']; //Récupération des éléments $aTrackersId = explode(';', $aResult['trackers']); $aLinks = explode(';', $aResult['id_links']); $aDates = explode(';', $aResult['dates']); $aTorrentsId = explode(';', $aResult['id_torrents']); //Récupération du premier up $iFirstPost = 0; $iKeyFirst = 0; foreach ($aDates as $iKey => $sDate) { if ($iFirstPost == 0 || strtotime($sDate) < $iFirstPost) { $iFirstPost = strtotime($sDate); $iKeyFirst = $iKey; } } $row["first_tracker"] = $aTrackersId[$iKeyFirst]; //Affichage des liens $sBottom = ''; foreach ($aTrackersId as $iKey => $iTrackerId) { $aTorrent = array(); $aTorrent['tracker'] = $iTrackerId; //Calcul du pretime $sDate = $aDates[$iKey]; if ($aResult['pretime'] != "0000-00-00 00:00:00") { $iDelay = strtotime($sDate) - strtotime($aResult['pretime']); $sBottom = 'PRE Time : ' . $aResult['pretime']; $row['origin'] = 'Scene'; } else { $iDelay = strtotime($sDate) - $iFirstPost; $sBottom = 'Premier torrent : ' . date("Y-m-j G:i:s", $iFirstPost); $row['origin'] = 'P2P'; } if ($iDelay == 0) { $sDelay = "-"; } else { // Traitement pour affichage $iDelayJ = floor($iDelay / 86400); $iDelayH = floor(($iDelay - $iDelayJ * 86400) / 3600); $iDelayM = floor(($iDelay - $iDelayJ * 86400 - $iDelayH * 3600) / 60); $iDelayS = ($iDelay - $iDelayJ * 86400 - $iDelayH * 3600) % 60; $sDelay = ($iDelayJ != 0 ? $iDelayJ . 'j ' : '') . ($iDelayH != 0 ? $iDelayH . 'h ' : '') . ($iDelayM != 0 ? $iDelayM . 'm ' : '') . ($iDelayS != 0 ? $iDelayS . 's ' : ''); } $aTorrent['delay'] = $sDelay; //Affichage des liens $sFicheLink = $this->oCurrentUser->getLinkWithPasskey($iTrackerId, $aTrackers[$iTrackerId]->getLink()); if ($sFicheLink != false) { $sFicheLink = str_replace('{IDTORRENT}', $aLinks[$iKey], $sFicheLink); $aTorrent['fichelink'] = $sFicheLink; } $sDirectLink = $this->oCurrentUser->getLinkWithPasskey($iTrackerId, $aTrackers[$iTrackerId]->getDirectLink()); if ($sDirectLink != false) { $sDirectLink = str_replace('{IDTORRENT}', $aLinks[$iKey], $sDirectLink); $aTorrent['directlink'] = $sDirectLink; $aTorrent['torrentid'] = $aTorrentsId[$iKey]; } $row["torrents"][] = $aTorrent; } $row['first'] = $sBottom; $aResponse[$aResult['id']] = $row; } } return $aResponse; }
function validate($value, $valueIdentifier = null) { parent::validate($value, $valueIdentifier); $this->success = !$this->success; return $this->success; }
public static function parseAliasesFile($file) { if (!($tree = Util::parseIni($file, true))) { return false; } $regex = Regex::$patt; // Some alias groups need further parsing to unpack useful information into the tree. foreach ($tree as $section => $items) { if ($section === 'declarations') { $store = array(); foreach ($items as $prop_val => $aliases) { list($prop, $value) = array_map('trim', explode(':', $prop_val)); foreach ($aliases as &$alias) { list($p, $v) = explode(':', $alias); $vendor = null; // Try to detect the vendor from property and value in turn. if (preg_match($regex->vendorPrefix, $p, $m) || preg_match($regex->vendorPrefix, $v, $m)) { $vendor = $m[1]; } $alias = array($p, $v, $vendor); } $store[$prop][$value] = $aliases; } $tree['declarations'] = $store; } elseif (strpos($section, 'functions.') === 0) { $group = substr($section, strlen('functions')); $vendor_grouped_aliases = array(); foreach ($items as $func_name => $aliases) { // Assign group name to the aliasable function. $tree['functions'][$func_name] = $group; foreach ($aliases as $alias_func) { // Only supporting vendor prefixed aliases, for now. if (preg_match($regex->vendorPrefix, $alias_func, $m)) { // We'll cache the function matching regex here. $vendor_grouped_aliases[$m[1]]['find'][] = Regex::make("~{{ LB }}{$func_name}(?=\\()~iS"); $vendor_grouped_aliases[$m[1]]['replace'][] = $alias_func; } } } $tree['function_groups'][$group] = $vendor_grouped_aliases; unset($tree[$section]); } } $tree += self::$config->bareAliases; // Persisting dummy aliases for testing purposes. $tree['properties']['foo'] = $tree['at-rules']['foo'] = $tree['functions']['foo'] = array('-webkit-foo', '-moz-foo', '-ms-foo'); return $tree; }