本文整理汇总了PHP中Formatter类的典型用法代码示例。如果您正苦于以下问题:PHP Formatter类的具体用法?PHP Formatter怎么用?PHP Formatter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Formatter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
* generate
*
*/
public function generate()
{
$this->out('Generate .cake ...');
$d = new Dotcake(APP, App::paths(), CAKE_CORE_INCLUDE_PATH);
$contents = json_encode($d->generate());
if (array_key_exists('format', $this->params)) {
$format = $this->params['format'];
switch ($format) {
case 'tab':
$formatter = new Formatter();
$contents = $formatter->reformat($contents);
break;
case 'ws':
// no break
// no break
case 'whitespace':
// can use JSON_PRETTY_PRINT option since PHP5.4
$formatter = new Formatter(' ');
// 4 spaces
$contents = $formatter->reformat($contents);
break;
default:
$this->out(__d('cake_console', "'{$format}' is invalid format option. You can use 'tab', 'ws' or 'whitespace' as option value."));
exit(0);
}
}
$this->createFile(APP . '.cake', $contents);
}
示例2: convertDate
/**
* Convert a date (number) to a database date representation (string).
*
* @param long dateTime The date (number)
* @param boolean whether the returned string should be surrounted by quotes.
* @return string
*/
public static function convertDate($dateTime, $timeZone = 'GMT', $withQuotes = true)
{
if ($dateTime == null) {
return $withQuotes ? "null" : null;
}
$format = new Formatter($timeZone);
$sDate = $format->dateFormat($dateTime, "Y-m-d H:i:s");
return $withQuotes ? "'{$sDate}'" : $sDate;
}
示例3: processor_folding
function processor_folding($formatter, $value = "", $options = array())
{
// unique id of the folding area
$id = isset($GLOBALS['_folding_id_']) ? $GLOBALS['_folding_id_'] : 0;
$id++;
$GLOBALS['_folding_id_'] = $id;
if ($value[0] == '#' and $value[1] == '!') {
list($line, $value) = explode("\n", $value, 2);
}
$init_state = 'none';
$title = _("More");
$class = '';
$opened = '';
// parse args
if (isset($line[0]) and ($p = strpos($line, ' ')) !== false) {
$tag = substr($line, 0, $p);
$args = substr($line, $p + 1);
if (preg_match("/^(?:(open|\\+))?(?(1)[ ]*,[ ]*)?((?:(?:[a-zA-Z][a-z0-9_-]+)[ ]*)*)?(?(2)[ ]*,[ ]*)?/", $args, $matches)) {
$class = isset($matches[2][0]) ? ' ' . $matches[2] : '';
$tmp = substr($args, strlen($matches[0]));
if (isset($tmp[0])) {
$title = $tmp;
}
if ($matches[1] == 'open' or $matches[1] == '+') {
$init_state = 'block';
$opened = ' class="opened"';
}
}
}
// FIXME footnote prefix
$fn_prefix = 'fn' . substr(md5(substr($value, 0, 32)), 0, 3);
// allow wiki syntax in folding content
ob_start();
$params = array('notoc' => 1);
$params['nosisters'] = 1;
$f = new Formatter($formatter->page, $params);
$f->foot_prefix = $fn_prefix;
$f->get_javascripts();
// trash default javascripts
$f->pi['#linenum'] = 0;
// do not use linenum
$f->send_page($value, $params);
$out = ob_get_contents();
ob_end_clean();
$onclick = " onclick=\"var f=document.getElementById('folding_{$id}');var s=f.style.display=='block';" . "f.style.display=s?'none':'block';this.className=s?'':'opened';\"";
return <<<HERE
<div class="folding-area{$class}">
<dl class="folding">
<dt{$onclick}{$opened}>{$title}</dt>
<dd id="folding_{$id}" style="display:{$init_state};">{$out}</dd>
</dl>
</div>
HERE;
}
示例4: macro_WantedPages
function macro_WantedPages($formatter, $value = '')
{
global $DBInfo;
$pages = $DBInfo->getPageLists();
$pagelinks = $formatter->pagelinks;
// save
$save = $formatter->sister_on;
$formatter->sister_on = 0;
$cache = new Cache_text("pagelinks");
foreach ($pages as $page) {
$dum = '';
$p = new WikiPage($page);
$f = new Formatter($p);
$pi = $f->page->get_instructions($dum);
if (in_array($pi['#format'], array('wiki', 'monimarkup'))) {
continue;
}
$links = $f->get_pagelinks();
if ($links) {
$lns =& $links;
foreach ($lns as $link) {
if (!$link or $DBInfo->hasPage($link)) {
continue;
}
if ($link and !$wants[$link]) {
$wants[$link] = "[\"{$page}\"]";
} else {
$wants[$link] .= " [\"" . $page . "\"]";
}
}
}
}
$formatter->pagelinks = $pagelinks;
// save
$formatter->sister_on = $save;
if (!count($wants)) {
return '';
}
$pagelinks = $formatter->pagelinks;
// save
$formatter->sister_on = 0;
asort($wants);
$out = "<ul>\n";
while (list($name, $owns) = each($wants)) {
$owns = str_replace('<', '<', $owns);
$nowns = preg_replace_callback("/(" . $formatter->wordrule . ")/", array(&$formatter, 'link_repl'), $owns);
$out .= "<li>" . $formatter->link_repl($name, htmlspecialchars($name)) . ": {$nowns}</li>";
}
$out .= "</ul>\n";
$formatter->sister_on = $save;
$formatter->pagelinks = $pagelinks;
// save
return $out;
}
示例5: test_names
public function test_names()
{
$tests = array('smith' => 'Smith', 'sMith' => 'Smith', 'SMITH' => 'Smith', 'mr extra space' => 'Mr Extra Space', 'p smith' => 'P Smith', 'mr p smith' => 'Mr P Smith', 'mr. p. smith' => 'Mr. P. Smith', 'john smith' => 'John Smith', 'mcdonald' => 'McDonald', 'joy macdonald' => 'Joy Macdonald', 'robert MacDonald' => 'Robert MacDonald', 'Macon' => 'Macon', 'mcdoNald-SMYTHE' => 'McDonald-Smythe', 'smythe-Mcdonald' => 'Smythe-McDonald', 'von MacDonald iii' => 'von MacDonald III', "o'grady" => "O'Grady", "van o'grady" => "van O'Grady", "van o'grady jr." => "van O'Grady Jr.", 'de la rue' => 'de la Rue', 'de la rue 1st.' => 'de la Rue 1st.', 'ap DAVIs' => 'ap Davis', 'john ap davis' => 'John ap Davis', 'smythington-twistle' => 'Smythington-Twistle', 'smythington-twistle-de-groot' => 'Smythington-Twistle-De-Groot', 'mary-jo von syMington-mcDonald-twistle 3RD' => 'Mary-Jo von Symington-McDonald-Twistle 3rd', 'st john' => 'St John', 'st. john iV' => 'St. John IV');
foreach ($tests as $input => $expected) {
$this->assertEquals($expected, Formatter::name($input));
}
}
示例6: getList
protected function getList()
{
$this->document->addBreadcrumbs(array('text' => Language::getVar('SUMO_ADMIN_SETTINGS_DASHBOARD'), 'href' => $this->url->link('settings/dashboard')));
$this->document->addBreadcrumbs(array('text' => Language::getVar('SUMO_ADMIN_USERS_OVERVIEW')));
// Initiate pagination
if (isset($this->request->get['page'])) {
$page = $this->request->get['page'];
} else {
$page = 1;
}
$data = array('start' => ($page - 1) * 25, 'limit' => 25);
$user_total = $this->model_user_user->getTotalUsers();
foreach ($this->model_user_user->getUsers($data) as $result) {
$this->data['users'][] = array_merge($result, array('status' => $result['status'] ? Language::getVar('SUMO_NOUN_ENABLED') : Language::getVar('SUMO_NOUN_DISABLED'), 'date_added' => Formatter::date($result['date_added']), 'date_last_seen' => $result['date_last_seen'] != '0000-00-00 00:00:00' ? Formatter::date($result['date_last_seen']) : '—', 'edit' => $this->url->link('user/user/update', 'token=' . $this->session->data['token'] . '&user_id=' . $result['user_id'], 'SSL')));
}
$pagination = new Pagination();
$pagination->total = $user_total;
$pagination->page = $page;
$pagination->limit = 25;
$pagination->text = '';
$pagination->url = $this->url->link('sale/return', 'token=' . $this->session->data['token'] . '&page={page}', 'SSL');
$this->data = array_merge($this->data, array('pagination' => $pagination->renderAdmin(), 'insert' => $this->url->link('user/user/insert', 'token=' . $this->session->data['token'], 'SSL'), 'delete' => $this->url->link('user/user/delete', 'token=' . $this->session->data['token'], 'SSL'), 'u_users' => $this->url->link('user/user', 'token=' . $this->session->data['token'], 'SSL'), 'u_permissions' => $this->url->link('user/user_permission', 'token=' . $this->session->data['token'], 'SSL')));
$this->template = 'user/user_list.tpl';
$this->children = array('common/header', 'common/footer');
$this->response->setOutput($this->render());
}
示例7: getPmaMatches
/**
* Parses result of preg_match_all
*
* @return array
*/
public function getPmaMatches()
{
$result['count'] = $this->pmaCount;
$result['expr'] = Formatter::arrayToTree($this->pmaMatches[0]);
$result['mtch'] = Formatter::arrayToTree($this->pmaMatches[1]);
return $result;
}
示例8: updateInvoice
public function updateInvoice($invoiceID, $data)
{
// Delete invoice-lines and add 'em later again
$this->query('DELETE FROM PREFIX_invoice_line WHERE invoice_id = :invoiceID', array('invoiceID' => $invoiceID));
$this->query('DELETE FROM PREFIX_invoice_total WHERE invoice_id = :invoiceID', array('invoiceID' => $invoiceID));
$totalTax = $total = 0;
foreach ($data['amount'] as $line => $amount) {
// Recalculate tax-amount based on the tax-percentage
if ($data['tax_percentage'][$line] > 0) {
$data['tax'][$line] = round($data['amount'][$line] * $data['quantity'][$line] * ($data['tax_percentage'][$line] / 100), 4);
$totalTax += $data['tax'][$line];
} else {
$data['tax'][$line] = 0;
}
$total += $amount * $data['quantity'][$line];
$this->query('INSERT INTO PREFIX_invoice_line (invoice_id, product_id, product, quantity, amount, tax_percentage, description) VALUES (
:invoiceID,
:productID,
:product,
:quantity,
:amount,
:taxPercentage,
:description)', array('invoiceID' => $invoiceID, 'productID' => $data['product_id'][$line], 'product' => $data['product'][$line], 'quantity' => $data['quantity'][$line], 'amount' => $data['amount'][$line], 'taxPercentage' => $data['tax_percentage'][$line], 'description' => $data['description'][$line]));
}
foreach ($data['totals'] as $sortOrder => $productTotal) {
$labelInject = isset($productTotal['label_inject']) ? $productTotal['label_inject'] : '';
$this->query("INSERT INTO PREFIX_invoice_total\n SET invoice_id = :id,\n sort_order = :sortOrder,\n label = :label,\n label_inject = :labelInject,\n value = :value,\n value_hr = :valueHR", array('id' => $invoiceID, 'sortOrder' => $sortOrder, 'label' => $productTotal['label'], 'labelInject' => $labelInject, 'value' => $productTotal['value'], 'valueHR' => Formatter::currency($productTotal['value'])));
}
// Totalamount is always the last line.
$total = $productTotal['value'];
$invoicePrefix = $this->config->get('invoice_prefix');
// Customer country numeric? Change to plain text
if (preg_match("/^\\d+\$/", $data['customer_country'])) {
$countryData = $this->query("SELECT name FROM PREFIX_country WHERE country_id = :countryID", array('countryID' => $data['customer_country']))->fetch();
$data['customer_country'] = !empty($countryData) ? $countryData['name'] : '-';
}
$this->query('UPDATE PREFIX_invoice SET
invoice_no = :invoiceNO,
customer_id = :customerID,
customer_no = :customerNo,
customer_name = :customerName,
customer_address = :customerAddress,
customer_postcode = :customerPostcode,
customer_city = :customerCity,
customer_country = :customerCountry,
customer_email = :customerEmail,
payment_amount = :paymentAmount,
payment_tax_percentage = :paymentTax,
shipping_amount = :shippingAmount,
shipping_tax_percentage = :shippingTax,
discount = :discount,
total_amount = :amount,
sent_date = :sentDate,
notes = :notes,
template = :template,
term = :term,
auto = :auto,
reference = :reference
WHERE invoice_id = :invoiceID', array('invoiceNO' => $invoicePrefix . str_pad($invoiceID, 5, 0, STR_PAD_LEFT), 'customerNo' => $customerNo, 'customerID' => $data['customer_id'], 'customerName' => $data['customer_name'], 'customerAddress' => $data['customer_address'], 'customerPostcode' => $data['customer_postcode'], 'customerCity' => $data['customer_city'], 'customerCountry' => $data['customer_country'], 'customerEmail' => $data['customer_email'], 'paymentAmount' => $data['payment_amount'], 'paymentTax' => $data['payment_tax'], 'shippingAmount' => $data['shipping_amount'], 'shippingTax' => $data['shipping_tax'], 'discount' => json_encode($data['discount']), 'amount' => $total, 'sentDate' => Formatter::dateReverse($data['sent_date']), 'notes' => $data['notes'], 'template' => $data['template'], 'term' => $data['term'], 'auto' => $data['auto'], 'reference' => $data['reference'], 'invoiceID' => $invoiceID));
}
示例9: getReturns
public function getReturns($data = array())
{
$values = array('language' => $this->config->get('language_id'));
$sql = "SELECT *, CONCAT(r.firstname, ' ', r.lastname) AS customer, (\n SELECT rs.name\n FROM PREFIX_return_status AS rs\n WHERE rs.return_status_id = r.return_status_id AND rs.language_id = :language\n ) AS status\n FROM PREFIX_return AS r";
$implode = array();
if (!empty($data['filter_return_id'])) {
$implode[] = "r.return_id = :filter_return_id";
$values['filter_return_id'] = $data['filter_return_id'];
}
if (!empty($data['filter_order_id'])) {
$implode[] = "r.order_id = :filter_order_id";
$values['filter_order_id'] = $data['filter_order_id'];
}
if (!empty($data['filter_customer'])) {
$implode[] = "CONCAT(r.firstname, ' ', r.lastname) LIKE :filter_customer";
$values['filter_customer'] = $data['filter_customer'] . '%';
}
if (!empty($data['filter_product'])) {
$implode[] = "r.product = :filter_product";
$values['filter_product'] = $data['filter_product'];
}
if (!empty($data['filter_model'])) {
$implode[] = "r.model = :filter_model";
$values['filter_model'] = $data['filter_model'];
}
if (!empty($data['filter_return_status_id'])) {
$implode[] = "r.return_status_id = :filter_return_status_id";
$values['filter_return_status_id'] = $data['filter_return_status_id'];
}
if (!empty($data['filter_date_added'])) {
$implode[] = "DATE(r.date_added) = DATE('" . Formatter::dateRevers($data['filter_date_added']) . "')";
}
if (!empty($data['filter_date_modified'])) {
$implode[] = "DATE(r.date_modified) = DATE('" . Formatter::dateRevers($data['filter_date_modified']) . "')";
}
if ($implode) {
$sql .= " WHERE " . implode(" AND ", $implode);
}
$sort_data = array('r.return_id', 'r.order_id', 'customer', 'r.product', 'r.model', 'status', 'r.date_added', 'r.date_modified');
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
$sql .= " ORDER BY " . $data['sort'];
} else {
$sql .= " ORDER BY r.return_id";
}
if (isset($data['order']) && $data['order'] == 'DESC') {
$sql .= " DESC";
} else {
$sql .= " ASC";
}
if (isset($data['start']) || isset($data['limit'])) {
if ($data['start'] < 0) {
$data['start'] = 0;
}
if ($data['limit'] < 1) {
$data['limit'] = 20;
}
$sql .= " LIMIT " . (int) $data['start'] . "," . (int) $data['limit'];
}
return $this->fetchAll($sql, $values);
}
示例10: removeDir
/**
* Recursively remove given directory
*
* @param string $dir
* @return boolean
*/
public static function removeDir($dir)
{
if (!Formatter::endsWith($dir, DIRECTORY_SEPARATOR) && !Formatter::endsWith($dir, self::DIR_SEPARATOR)) {
$dir .= self::DIR_SEPARATOR;
}
if (!is_dir($dir)) {
return false;
}
if ($handle = opendir($dir)) {
$dirsToVisit = array();
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($dir . $file)) {
$dirsToVisit[] = $dir . $file;
} else {
if (is_file($dir . $file)) {
unlink($dir . $file);
}
}
}
}
closedir($handle);
foreach ($dirsToVisit as $i => $w) {
self::removeDirectory($w);
}
}
rmdir($dir);
return true;
}
示例11: testYiiDateFormatToJQueryDateFormat
/**
* Ensure that yiiDateFormatToJQueryDateFormat correctly translates between format languages
*/
public function testYiiDateFormatToJQueryDateFormat()
{
$formats = array('d MMM y' => 'd M yy', 'd/MMM/y' => 'd/M/yy', 'd/MM/y' => 'd/mm/yy', 'd/MM M/y' => 'd/mm m/yy', 'd/MM M/y MMM' => 'd/mm m/yy M');
foreach ($formats as $fmt => $expected) {
$newFormat = Formatter::yiiDateFormatToJQueryDateFormat($fmt);
$this->assertEquals($expected, $newFormat);
}
}
示例12: doValidate
public function doValidate($ctx)
{
$formattedValue = $ctx->getRequest()->getString($this->getName(), null);
// Validate only if there is a value
if ($formattedValue === null || $formattedValue === '') {
return true;
}
$format = new Formatter($ctx->getUser()->getTimezone(), $ctx->getUser()->getLocale());
$value = $format->getNumber($formattedValue);
if ($value === false) {
$msg = sprintf(Application::getTranslator()->_('The field %1$s must be a valid number'), $this->getLabel());
$this->addFieldError($ctx, $this->getName(), $msg);
return false;
}
if ($this->minValue) {
if ($this->minValue->isExclusive()) {
if ($value <= $this->minValue->getValue()) {
$msg = sprintf(Application::getTranslator()->_('The value of the %1$s field must be greater than %2$s'), $this->getLabel(), $this->minValue->getValue());
$this->addFieldError($ctx, $this->getName(), $msg);
return false;
}
} else {
if ($value < $this->minValue->getValue()) {
$msg = sprintf(Application::getTranslator()->_('The value of the %1$s field must be greater or equal to %2$s'), $this->getLabel(), $this->minValue->getValue());
$this->addFieldError($ctx, $this->getName(), $msg);
return false;
}
}
}
if ($this->maxValue) {
if ($this->maxValue->isExclusive()) {
if ($value >= $this->maxValue->getValue()) {
$msg = sprintf(Application::getTranslator()->_('The value of the %1$s field must be smaller than %2$s'), $this->getLabel(), $this->maxValue->getValue());
$this->addFieldError($ctx, $this->getName(), $msg);
return false;
}
} else {
if ($value > $this->maxValue->getValue()) {
$msg = sprintf(Application::getTranslator()->_('The value of the %1$s field must be smaller or equal to %2$s'), $this->getLabel(), $this->maxValue->getValue());
$this->addFieldError($ctx, $this->getName(), $msg);
return false;
}
}
}
return true;
}
示例13: searchCustom
public function searchCustom($keyword, $pagesize = 10, $option = array())
{
$keyword = Formatter::clean($keyword);
//$keyword = Apache_Solr_Service::phrase($keyword);
$solr = $this->_getSolr();
$params = array('group' => 'true', 'group.limit' => $pagesize, 'group.field' => 'type');
$params['sort'] = "score desc, played_count desc";
$rs = $solr->search($keyword, 0, $pagesize, $params);
return $rs;
}
示例14: actionIndex
/**
* Lists all models.
*/
public function actionIndex()
{
$model = new AdminGUserModel();
$userInfo = null;
if (isset($_GET['AdminGUserModel'])) {
$model->attributes = $_GET['AdminGUserModel'];
$user_phone = Formatter::formatPhone($_GET['AdminGUserModel']['user_phone']);
$userInfo = GUserModel::model()->findByAttributes(array('user_phone' => $user_phone));
}
$this->render('index', array('model' => $model, 'userInfo' => $userInfo));
}
示例15: arrayToTree
/**
* Convert and array to a string representation in tree format
*
* @param string $array
* @return string
*/
public static function arrayToTree($array)
{
$tree = "";
foreach ($array as $key => $item) {
if (is_array($item)) {
$item = Formatter::arrayToTree($item);
}
$tree .= "[" . $key . "] " . self::sanitize($item) . PHP_EOL;
}
return $tree;
}