public function didTranslateString($raw_pattern, $translated_pattern, array $args, $result_text)
 {
     return phutil_utf8_strtoupper($result_text);
 }
Exemplo n.º 2
0
 private function sign(array $params)
 {
     ksort($params);
     $pstr = array();
     foreach ($params as $key => $value) {
         $pstr[] = rawurlencode($key) . '=' . rawurlencode($value);
     }
     $pstr = implode('&', $pstr);
     $sign_uri = clone $this->uri;
     $sign_uri->setFragment('');
     $sign_uri->setQueryParams(array());
     $sign_uri->setProtocol(phutil_utf8_strtolower($sign_uri->getProtocol()));
     $protocol = $sign_uri->getProtocol();
     switch ($protocol) {
         case 'http':
             if ($sign_uri->getPort() == 80) {
                 $sign_uri->setPort(null);
             }
             break;
         case 'https':
             if ($sign_uri->getPort() == 443) {
                 $sign_uri->setPort(null);
             }
             break;
     }
     $method = rawurlencode(phutil_utf8_strtoupper($this->method));
     $sign_uri = rawurlencode((string) $sign_uri);
     $pstr = rawurlencode($pstr);
     $sign_input = "{$method}&{$sign_uri}&{$pstr}";
     return $this->signString($sign_input);
 }
 private function loadObjectFromMail(PhabricatorMetaMTAReceivedMail $mail, PhabricatorUser $sender)
 {
     $parts = $this->matchObjectAddressInMail($mail);
     return $this->loadObject(phutil_utf8_strtoupper($parts['pattern']), $sender);
 }
 private function getFrequency($value)
 {
     // NOTE: This is normalizing three generations of these transactions
     // to use RRULE constants. It would be vaguely nice to migrate them
     // for consistency.
     if (is_array($value)) {
         $value = idx($value, 'rule');
     } else {
         $value = $value;
     }
     return phutil_utf8_strtoupper($value);
 }
<?php

$table = new PhabricatorCalendarEvent();
$conn = $table->establishConnection('w');
$table_name = 'calendar_event';
foreach (new LiskRawMigrationIterator($conn, $table_name) as $row) {
    $parameters = phutil_json_decode($row['parameters']);
    if (isset($parameters['recurrenceRule'])) {
        // This event has already been migrated.
        continue;
    }
    if (!$row['isRecurring']) {
        continue;
    }
    $old_rule = $row['recurrenceFrequency'];
    if (!$old_rule) {
        continue;
    }
    try {
        $frequency = phutil_json_decode($old_rule);
        if ($frequency) {
            $frequency_rule = $frequency['rule'];
            $frequency_rule = phutil_utf8_strtoupper($frequency_rule);
            $rrule = id(new PhutilCalendarRecurrenceRule())->setFrequency($frequency_rule);
        }
    } catch (Exception $ex) {
        continue;
    }
    $parameters['recurrenceRule'] = $rrule->toDictionary();
    queryfx($conn, 'UPDATE %T SET parameters = %s WHERE id = %d', $table_name, phutil_json_encode($parameters), $row['id']);
}
 /**
  * Check if a diff has a running or failed buildable, and prompt the user
  * before landing if it does.
  */
 private function checkForBuildables($diff_phid)
 {
     // NOTE: Since Harbormaster is still beta and this stuff all got added
     // recently, just bail if we can't find a buildable. This is just an
     // advisory check intended to prevent human error.
     try {
         $buildables = $this->getConduit()->callMethodSynchronous('harbormaster.querybuildables', array('buildablePHIDs' => array($diff_phid), 'manualBuildables' => false));
     } catch (ConduitClientException $ex) {
         return;
     }
     if (!$buildables['data']) {
         // If there's no corresponding buildable, we're done.
         return;
     }
     $console = PhutilConsole::getConsole();
     $buildable = head($buildables['data']);
     if ($buildable['buildableStatus'] == 'passed') {
         $console->writeOut("**<bg:green> %s </bg>** %s\n", pht('BUILDS PASSED'), pht('Harbormaster builds for the active diff completed successfully.'));
         return;
     }
     switch ($buildable['buildableStatus']) {
         case 'building':
             $message = pht('Harbormaster is still building the active diff for this revision:');
             $prompt = pht('Land revision anyway, despite ongoing build?');
             break;
         case 'failed':
             $message = pht('Harbormaster failed to build the active diff for this revision. ' . 'Build failures:');
             $prompt = pht('Land revision anyway, despite build failures?');
             break;
         default:
             // If we don't recognize the status, just bail.
             return;
     }
     $builds = $this->getConduit()->callMethodSynchronous('harbormaster.querybuilds', array('buildablePHIDs' => array($buildable['phid'])));
     $console->writeOut($message . "\n\n");
     foreach ($builds['data'] as $build) {
         switch ($build['buildStatus']) {
             case 'failed':
                 $color = 'red';
                 break;
             default:
                 $color = 'yellow';
                 break;
         }
         $console->writeOut("    **<bg:" . $color . "> %s </bg>** %s: %s\n", phutil_utf8_strtoupper($build['buildStatusName']), pht('Build %d', $build['id']), $build['name']);
     }
     $console->writeOut("\n%s\n\n    **%s**: __%s__", pht('You can review build details here:'), pht('Harbormaster URI'), $buildable['uri']);
     if (!$console->confirm($prompt)) {
         throw new ArcanistUserAbortException();
     }
 }
 public function testUTF8strtoupper()
 {
     $tests = array('' => '', 'a' => 'A', 'A' => 'A', '!' => '!', 'Cats have 9 lives.' => 'CATS HAVE 9 LIVES.', "☃" => "☃");
     foreach ($tests as $input => $expect) {
         $this->assertEqual($expect, phutil_utf8_strtoupper($input), 'phutil_utf8_strtoupper("' . $input . '")');
     }
 }
Exemplo n.º 8
0
/**
 * Convert a string to title case in a UTF8-aware way. This function doesn't
 * necessarily do a great job, but the builtin implementation of `ucwords()` can
 * completely destroy inputs, so it just has to be better than that. Similar to
 * @{function:ucwords}.
 *
 * @param   string  UTF-8 input string.
 * @return  string  Input, in some semblance of title case.
 */
function phutil_utf8_ucwords($str)
{
    // NOTE: mb_convert_case() discards uppercase letters in words when converting
    // to title case. For example, it will convert "AAA" into "Aaa", which is
    // undesirable.
    $v = phutil_utf8v($str);
    $result = '';
    $last = null;
    $ord_a = ord('a');
    $ord_z = ord('z');
    foreach ($v as $c) {
        $convert = false;
        if ($last === null || $last === ' ') {
            $o = ord($c[0]);
            if ($o >= $ord_a && $o <= $ord_z) {
                $convert = true;
            }
        }
        if ($convert) {
            $result .= phutil_utf8_strtoupper($c);
        } else {
            $result .= $c;
        }
        $last = $c;
    }
    return $result;
}