/** * Advances the current position to the next match of a given matcher. * * @param $matcher The matcher * @return The index of the tag which has been found, or false if the end of the souce has been reached */ public function find(Matcher $matcher) { $oldPos = $this->pos; $result = $matcher->match($this->source, $this->pos); if ($this->pos !== $oldPos) { $this->line += substr_count($this->source, "\n", $oldPos, $this->pos - $oldPos); } return $result; }
/** * {@inheritdoc} */ public function match($patternOrPatterns, $route = null, $priority = 5) { if (is_array($patternOrPatterns)) { foreach ($patternOrPatterns as $pattern => $route) { $this->match($pattern, $route); } return null; } return $this->parent->match($this->prefix . '/' . $patternOrPatterns, $route, $priority); }
/** * Performs the actual assertion logic. * * If <code>$matcher</code> doesn't match <code>$actual</code>, * throws a {@link Hamcrest\AssertionError} with a description * of the failure along with the optional <code>$identifier</code>. * * @param string $identifier added to the message upon failure * @param mixed $actual value to compare against <code>$matcher</code> * @param \Hamcrest\Matcher $matcher applied to <code>$actual</code> * @throws AssertionError */ private static function doAssert($identifier, $actual, Matcher $matcher) { if (!$matcher->matches($actual)) { $description = new StringDescription(); if (!empty($identifier)) { $description->appendText($identifier . PHP_EOL); } $description->appendText('Expected: ')->appendDescriptionOf($matcher)->appendText(PHP_EOL . ' but: '); $matcher->describeMismatch($actual, $description); throw new AssertionError((string) $description); } }
public static function jsonStringMatchJsonString($expected, $actual) { $expected = json_decode($expected, true); $actual = json_decode($actual, true); if (is_array($expected)) { Matcher::matchArrays($expected, $actual); } else { Matcher::matchPrimitives($expected, $actual); } }
/** * * @param FixtureData $data * @throws FixtureException */ public function persist(FixtureData $data) { $object = $data->getObject(); $class = get_class($object); foreach ($this->mapping as $mapping) { if (!Matcher::match($class, $mapping['pattern'])) { continue; } return $mapping['persister']->persist($data); } throw new FixtureException(sprintf('not matching for class "%s"', $class)); }
public function update(array $search, array $update) { $filter = Matcher::factory($search); $this->jsonData = array_map(function ($item) use($filter, $update) { if ($filter->match($item)) { //item matches the filter foreach ($update as $updateKey => $updateValue) { $item[$updateKey] = $updateValue; } } return $item; }, $this->jsonData); }
public function testCompareMultiple() { $comparator = new Matcher(['id' => '1', 'category' => 'bar']); $this->assertFalse($comparator->match([])); $this->assertFalse($comparator->match(['id' => '1'])); $this->assertFalse($comparator->match(['id' => '1', 'category' => 'bat'])); $this->assertFalse($comparator->match(['category' => 'bar'])); $this->assertTrue($comparator->match(['id' => '1', 'category' => 'bar'])); }
?> /item/detail?id=<?php echo $itemId; ?> "> <section class="status<?php echo $item['grade']; ?> "> <img class="pic" src="<?php echo $goods['img']; ?> "/> <h2>【<?php echo Matcher::matchOrigin($goods['origin']); ?> 】<?php echo $goods['title']; ?> </h2> <div>总价:<span class="price"> <?php echo sprintf('%.2f', $item['gross']); ?> </span>元</div> <div>筹集方式:<span class="collect"><?php echo $item['title']; ?> </span></div> </section>
private function matchesEmergencyNumberHelper($number, $regionCode, $allowPrefixMatch) { $number = PhoneNumberUtil::extractPossibleNumber($number); $matcher = new Matcher(PhoneNumberUtil::$PLUS_CHARS_PATTERN, $number); if ($matcher->lookingAt()) { // Returns false if the number starts with a plus sign. WE don't believe dialling the country // code before emergency numbers (e.g. +1911) works, but later, if that proves to work, we can // add additional logic here to handle it. return false; } $metadata = $this->getMetadataForRegion($regionCode); if ($metadata === null || !$metadata->hasEmergency()) { return false; } $emergencyNumberPattern = $metadata->getEmergency()->getNationalNumberPattern(); $normalizedNumber = PhoneNumberUtil::normalizeDigitsOnly($number); $emergencyMatcher = new Matcher($emergencyNumberPattern, $normalizedNumber); return !$allowPrefixMatch || in_array($regionCode, self::$regionsWhereEmergencyNumbersMustBeExact) ? $emergencyMatcher->matches() : $emergencyMatcher->lookingAt(); }
public function formatNsnUsingPattern($nationalNumber, NumberFormat $formattingPattern, $numberFormat, $carrierCode = NULL) { $numberFormatRule = $formattingPattern->getFormat(); $m = new Matcher($formattingPattern->getPattern(), $nationalNumber); if ($numberFormat == PhoneNumberFormat::NATIONAL && $carrierCode !== NULL && strlen($carrierCode) > 0 && strlen($formattingPattern->getDomesticCarrierCodeFormattingRule()) > 0) { // Replace the $CC in the formatting rule with the desired carrier code. $carrierCodeFormattingRule = $formattingPattern->getDomesticCarrierCodeFormattingRule(); $ccPatternMatcher = new Matcher(self::CC_PATTERN, $carrierCodeFormattingRule); $carrierCodeFormattingRule = $ccPatternMatcher->replaceFirst($carrierCode); // Now replace the $FG in the formatting rule with the first group and the carrier code // combined in the appropriate way. $firstGroupMatcher = new Matcher(self::FIRST_GROUP_PATTERN, $numberFormatRule); $numberFormatRule = $firstGroupMatcher->replaceFirst($carrierCodeFormattingRule); $formattedNationalNumber = $m->replaceAll($numberFormatRule); } else { // Use the national prefix formatting rule instead. $nationalPrefixFormattingRule = $formattingPattern->getNationalPrefixFormattingRule(); if ($numberFormat == PhoneNumberFormat::NATIONAL && $nationalPrefixFormattingRule !== NULL && strlen($nationalPrefixFormattingRule) > 0) { $firstGroupMatcher = new Matcher(self::FIRST_GROUP_PATTERN, $numberFormatRule); $formattedNationalNumber = $m->replaceAll($firstGroupMatcher->replaceFirst($nationalPrefixFormattingRule)); } else { $formattedNationalNumber = $m->replaceAll($numberFormatRule); } } if ($numberFormat == PhoneNumberFormat::RFC3966) { // Strip any leading punctuation. $matcher = new Matcher(self::$SEPARATOR_PATTERN, $formattedNationalNumber); if ($matcher->lookingAt()) { $formattedNationalNumber = $matcher->replaceFirst(""); } // Replace the rest with a dash between each number group. $formattedNationalNumber = $matcher->reset($formattedNationalNumber)->replaceAll("-"); } return $formattedNationalNumber; }
<?php use Lead\Jit\Spec\Fixture\Parser; class NoNamespace { public function hello() { return "Hello World!"; } } function test() { return "It's a test"; } if (true) { echo "Hello World!"; } Matcher::register('toBe', 'Kahlan\\Matcher\\ToBe'); Box::share('kahlan.suite', function () { return new Suite(); }); ?> Outside PHP Tags <?php for ($i = 0; $i < 10; $i++) { echo "Success"; }
/** * Returns whether the given national number (a string containing only decimal digits) matches * the possible number pattern defined in the given {@code PhoneNumberDesc} message. * * @param string $nationalNumber * @param PhoneNumberDesc $numberDesc * @return boolean */ public function matchesPossibleNumber($nationalNumber, PhoneNumberDesc $numberDesc) { $possibleNumberPatternMatcher = new Matcher($numberDesc->getPossibleNumberPattern(), $nationalNumber); return $possibleNumberPatternMatcher->matches(); }
/** * Retrieve files match by user pattern * * @return FileInfo[] */ public function getFiles() { return $this->matcher->match($this->rootDirectory); }
function __construct($text, $ner_vocabs) { parent::__construct($text, $ner_vocabs); }
/** * Returns whether the given national number (a string containing only decimal digits) matches * the national number pattern defined in the given {@code PhoneNumberDesc} message. * * @param string $nationalNumber * @param PhoneNumberDesc $numberDesc * @param boolean $allowPrefixMatch * @return boolean */ public function matchesNationalNumber($nationalNumber, PhoneNumberDesc $numberDesc, $allowPrefixMatch) { $nationalNumberPatternMatcher = new Matcher($numberDesc->getNationalNumberPattern(), $nationalNumber); return $nationalNumberPatternMatcher->matches() || $allowPrefixMatch && $nationalNumberPatternMatcher->lookingAt(); }
/** * Formats a phone number in the specified format using client-defined formatting rules. Note that * if the phone number has a country calling code of zero or an otherwise invalid country calling * code, we cannot work out things like whether there should be a national prefix applied, or how * to format extensions, so we return the national significant number with no formatting applied. * * @param PhoneNumber $number the phone number to be formatted * @param int $numberFormat the format the phone number should be formatted into * @param array $userDefinedFormats formatting rules specified by clients * @return String the formatted phone number */ public function formatByPattern(PhoneNumber $number, $numberFormat, array $userDefinedFormats) { $countryCallingCode = $number->getCountryCode(); $nationalSignificantNumber = $this->getNationalSignificantNumber($number); if (!$this->hasValidCountryCallingCode($countryCallingCode)) { return $nationalSignificantNumber; } // Note getRegionCodeForCountryCode() is used because formatting information for regions which // share a country calling code is contained by only one region for performance reasons. For // example, for NANPA regions it will be contained in the metadata for US. $regionCode = $this->getRegionCodeForCountryCode($countryCallingCode); // Metadata cannot be null because the country calling code is valid $metadata = $this->getMetadataForRegionOrCallingCode($countryCallingCode, $regionCode); $formattedNumber = ""; $formattingPattern = $this->chooseFormattingPatternForNumber($userDefinedFormats, $nationalSignificantNumber); if ($formattingPattern === null) { // If no pattern above is matched, we format the number as a whole. $formattedNumber .= $nationalSignificantNumber; } else { $numFormatCopy = new NumberFormat(); // Before we do a replacement of the national prefix pattern $NP with the national prefix, we // need to copy the rule so that subsequent replacements for different numbers have the // appropriate national prefix. $numFormatCopy->mergeFrom($formattingPattern); $nationalPrefixFormattingRule = $formattingPattern->getNationalPrefixFormattingRule(); if (mb_strlen($nationalPrefixFormattingRule) > 0) { $nationalPrefix = $metadata->getNationalPrefix(); if (mb_strlen($nationalPrefix) > 0) { // Replace $NP with national prefix and $FG with the first group ($1). $npPatternMatcher = new Matcher(self::NP_PATTERN, $nationalPrefixFormattingRule); $nationalPrefixFormattingRule = $npPatternMatcher->replaceFirst($nationalPrefix); $fgPatternMatcher = new Matcher(self::FG_PATTERN, $nationalPrefixFormattingRule); $nationalPrefixFormattingRule = $fgPatternMatcher->replaceFirst("\\\$1"); $numFormatCopy->setNationalPrefixFormattingRule($nationalPrefixFormattingRule); } else { // We don't want to have a rule for how to format the national prefix if there isn't one. $numFormatCopy->clearNationalPrefixFormattingRule(); } } $formattedNumber .= $this->formatNsnUsingPattern($nationalSignificantNumber, $numFormatCopy, $numberFormat); } $this->maybeAppendFormattedExtension($number, $metadata, $numberFormat, $formattedNumber); $this->prefixNumberWithCountryCallingCode($countryCallingCode, $numberFormat, $formattedNumber); return $formattedNumber; }
/** Performs matching on paths specified by arrays or objects. * @internal **/ private static function _extractPaths($node, $paths, $context) { $return = array(); foreach ($paths as $key => $val) { if (is_int($key)) { // merge into current level $x = Matcher::_evalPath($node, $val, $context); if (is_scalar($x) || $x === null) { throw new \Exception("Cannot merge scalar value" . (is_string($val) ? " produced by path `{$val}`" : "") . " Expected array or object."); } if (is_object($x)) { $x = (array) $x; } $return = array_merge($return, $x); } else { $return[$key] = Matcher::_evalPath($node, $val, $context); } } return is_object($paths) ? (object) $return : $return; }