本文整理汇总了PHP中Util类的典型用法代码示例。如果您正苦于以下问题:PHP Util类的具体用法?PHP Util怎么用?PHP Util使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Util类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createApp
function createApp($appName, $orgName)
{
Util::throwExceptionIfNullOrBlank($appName, "App Name");
Util::throwExceptionIfNullOrBlank($orgName, "orgName");
$objUtil = new Util($this->apiKey, $this->secretKey);
try {
$params = array();
$params['apiKey'] = $this->apiKey;
$params['version'] = $this->version;
date_default_timezone_set('UTC');
$params['timeStamp'] = date("Y-m-d\\TG:i:s") . substr((string) microtime(), 1, 4) . "Z";
$params['App Name'] = $appName;
$params['orgName'] = $orgName;
$signature = urlencode($objUtil->sign($params));
//die();
$body = null;
$body = '{"app42":{"app":}}';
$params['body'] = $body;
$params['signature'] = $signature;
$contentType = $this->content_type;
$accept = $this->accept;
$this->url = $this->url;
$response = RestClient::post($this->url, $params, null, null, $contentType, $accept, $body);
} catch (App42Exception $e) {
throw $e;
} catch (Exception $e) {
throw new App42Exception($e);
}
return $response;
}
示例2: emailExists
/**
* A method to check if an email exists
*
* @param {String} [$email] - must be valid email
*
* @return boolean
*/
public function emailExists($email)
{
$u = new Util();
$db = new DB($u->getDBConfig());
$stmt = $db->getDb()->prepare("SELECT * FROM users WHERE email = :email");
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$stmt->execute();
if ($stmt->rowCount() > 0) {
return false;
}
return true;
}
示例3: commitFile
/**
* 向网站提交数据
*/
public function commitFile()
{
$starttime = date('Y-m-d H:i:s');
$util = new \Util();
$res = $util->commitData();
// var_dump($res);
$endtime = date('Y-m-d H:i:s');
$this->assign('starttime', $starttime);
$this->assign('endtime', $endtime);
$this->assign('list', $res);
$this->assign('count', count($res));
$this->display();
}
示例4: cadastrarAction
public function cadastrarAction()
{
$ct = new Categoria();
$ut = new Util();
$user = My_Auth::getInstance('Painel')->getStorage()->read();
$request = $this->getRequest();
if ($request->isPost()) {
$pt = new Postagem();
$erro = false;
$msg = '';
$now = $ut->nowDateSql();
$pt->setTitulo($request->getPost('titulo'));
$pt->setPostagem($request->getPost('postagem'));
$pt->setCagegoriaId($request->getPost('categoria_id'));
$pt->setUsuarioId($user->id);
$pt->setPostadoem($now);
$pt->setTags($request->getPost('tags'));
$pt->setAlteradoem($now);
$data = array('titulo' => $pt->getTitulo(), 'postagem' => $pt->getPostagem(), 'categoria_id' => $pt->getCagegoriaId(), 'usuario_id' => $pt->getUsuarioId(), 'postadoem' => $pt->getPostadoem(), 'tags' => $pt->getTags(), 'alteradoem' => $pt->getAlteradoem());
if ($postagem_id = $pt->savePostagem($data)) {
if ($request->getPost('image_data')) {
$imageName = time() . '_saved.jpg';
//$imagem = json_decode($request->getPost('image_data'));
$base64 = base64_decode(preg_replace('#^data:image/[^;]+;base64,#', '', $request->getPost('image_data')));
//base64_decode(preg_replace('#^data:image/[^;]+;base64,#', '', $_POST['imagem']));
// create image
$source = imagecreatefromstring($base64);
if (!file_exists(ROOT_DIR . DS . 'site' . DS . 'images' . DS . 'blog' . DS . $postagem_id)) {
mkdir(ROOT_DIR . DS . 'site' . DS . 'images' . DS . 'blog' . DS . $postagem_id, 0777, true);
}
$url = ROOT_DIR . DS . 'site' . DS . 'images' . DS . 'blog' . DS . $postagem_id . DS . $imageName;
imagejpeg($source, $url, 100);
$pt->setImagem($imageName);
$data = array('imagem' => $pt->getImagem());
if (!$pt->savePostagem($data, $postagem_id)) {
$erro = true;
}
}
} else {
$erro = true;
}
if ($erro) {
$msg = 'Ocorreu um erro, tente novamente';
$this->view->msg = $msg;
} else {
$this->_helper->redirector('listar', 'postagens');
}
}
$this->view->categorias = $ct->getAllCategoria();
$this->render();
}
示例5: HistorySpec
function HistorySpec($query)
{
$util = new Util();
$myDateToday = $util->dateTodaySQL();
$queryMYSQL = new QueryMYSQL();
//cherche le dernier groupe
$queryMaxGroup = "select max(GROUPE) `maxGROUPE` from HISTORIQUE";
echo $queryMaxGroup . "<br/>";
$arrayMax = $queryMYSQL->select_n($queryMaxGroup);
$groupe = $arrayMax[0]["maxGROUPE"];
$groupe = $groupe + 1;
$queryHistory = "insert into HISTORIQUE (GROUPE,VARIABLE,login,date_modif) values ({$groupe},\"{$query}\",'" . $_SESSION['login'] . "','{$myDateToday}')";
//echo $queryHistory."<br/>";
$queryMYSQL->query($queryHistory);
}
示例6: buildHttpQuery
/**
* @param $params
*
* @return string
*/
public static function buildHttpQuery($params)
{
if (!$params) {
return '';
}
// Urlencode both keys and values
$keys = Util::urlencodeRfc3986(array_keys($params));
$values = Util::urlencodeRfc3986(array_values($params));
$params = array_combine($keys, $values);
// Parameters are sorted by name, using lexicographical byte value ordering.
// Ref: Spec: 9.1.1 (1)
uksort($params, 'strcmp');
$pairs = array();
foreach ($params as $parameter => $value) {
if (is_array($value)) {
// If two or more parameters share the same name, they are sorted by their value
// Ref: Spec: 9.1.1 (1)
// June 12th, 2010 - changed to sort because of issue 164 by hidetaka
sort($value, SORT_STRING);
foreach ($value as $duplicateValue) {
$pairs[] = $parameter . '=' . $duplicateValue;
}
} else {
$pairs[] = $parameter . '=' . $value;
}
}
// For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
// Each name-value pair is separated by an '&' character (ASCII code 38)
return implode('&', $pairs);
}
示例7: get_unresolved_alarms
function get_unresolved_alarms($conn)
{
$alarms = intval(Alarm::get_count($conn, '', '', 1, TRUE));
$alarms_prev = intval($_SESSION['_unresolved_alarms']);
if ($alarms != $alarms_prev && $alarms_prev > 0) {
$new_alarms = $alarms - $alarms_prev;
} else {
$new_alarms = 0;
}
$_SESSION['_unresolved_alarms'] = $alarms;
$data['alarms'] = $alarms;
$data['new_alarms'] = $new_alarms;
$data['new_alarms_desc'] = '';
if ($new_alarms > 0) {
$criteria = array('src_ip' => '', 'dst_ip' => '', 'hide_closed' => 1, 'order' => 'ORDER BY a.timestamp DESC', 'inf' => 0, 'sup' => $new_alarms, 'date_from' => '', 'date_to' => '', 'query' => '', 'directive_id' => '', 'intent' => 0, 'sensor' => '', 'tag' => '', 'num_events' => '', 'num_events_op' => 0, 'plugin_id' => '', 'plugin_sid' => '', 'ctx' => '', 'host' => '', 'net' => '', 'host_group' => '');
list($alarm_list, $count) = Alarm::get_list($conn, $criteria);
$alarm_string = '';
foreach ($alarm_list as $alarm) {
$desc_alarm = Util::translate_alarm($conn, $alarm->get_sid_name(), $alarm);
$desc_alarm = html_entity_decode(str_replace("'", "\\'", $desc_alarm));
$desc_alarm = str_replace('"', """, $desc_alarm);
$desc_alarm = str_replace('—', "-", $desc_alarm);
$desc_alarm = Util::js_entities($desc_alarm);
if ($alarm_string != '') {
$alarm_string .= '|';
}
$alarm_string .= $desc_alarm;
}
$data['new_alarms_desc'] = $alarm_string;
}
$return['error'] = FALSE;
$return['output'] = $data;
return $return;
}
示例8: actionBuyApi
public function actionBuyApi($item_id, $num)
{
$itemList = Util::loadConfig('items');
$item = $itemList[$item_id];
if (isset($item)) {
$user = User::model()->findByPk($this->usr_id);
if ($user->gold - $item['price'] * $num < 0) {
throw new PException('余额不足');
} else {
$transaction = Yii::app()->db->beginTransaction();
try {
$user->gold -= $item['price'] * $num;
$items = unserialize($user->items);
if (isset($items[$item_id])) {
$items[$item_id] += $num;
} else {
$items[$item_id] = $num;
}
$user->items = serialize($items);
$user->saveAttributes(array('gold', 'items'));
$transaction->commit();
} catch (Exception $e) {
$transaction->rollback();
throw $e;
}
$this->echoJsonData(array('user_gold' => $user->gold));
}
} else {
throw new PException('商品不存在');
}
}
示例9: getAngebote
public function getAngebote($data)
{
if (!$this->loggedIn) {
return "TIMEOUT";
}
$html = "";
$T = new HTMLTable(2);
#, "Bitte wählen Sie einen Lieferschein");
$T->setTableStyle("width:100%;margin-top:10px;");
$T->setColWidth(1, 130);
$T->useForSelection(false);
$T->maxHeight(400);
$AC = anyC::get("GRLBM", "isA", "1");
$AC->addJoinV3("Auftrag", "AuftragID", "=", "AuftragID");
$AC->addAssocV3("UserID", "=", Session::currentUser()->getID());
$AC->addAssocV3("status", "=", "open");
#$AC->addOrderV3("datum", "DESC");
$AC->addOrderV3("nummer", "DESC");
#$AC->setLimitV3(100);
#$AC->addJoinV3("Adresse", "t2.AdresseID", "=", "AdresseID");
$i = 0;
while ($B = $AC->n()) {
$Adresse = new Adresse($B->A("AdresseID"));
$T->addRow(array("<span style=\"font-size:20px;font-weight:bold;\">" . $B->A("prefix") . $B->A("nummer") . "</span><br><span style=\"color:grey;\">" . Util::CLDateParser($B->A("datum")) . "</span>", $Adresse->getHTMLFormattedAddress()));
$T->addCellStyle(1, "vertical-align:top;");
$T->addRowStyle("cursor:pointer;border-bottom:1px solid #ccc;");
#if($i % 2 == 1)
# $T->addRowStyle ("background-color:#eee;");
$T->addRowEvent("click", "\n\t\t\t\t\$(this).addClass('selected');\n\t\t\t\t\n\t\t\t\tCustomerPage.rme('getAuftrag', {GRLBMID: " . $B->getID() . "}, function(transport){ \n\t\t\t\t\t\tif(transport == 'TIMEOUT') { document.location.reload(); return; } \n\t\t\t\t\t\t\$('#contentLeft').html(transport); \n\t\t\t\t\t}, \n\t\t\t\t\tfunction(){},\n\t\t\t\t\t'POST');\n\t\t\t\t\t\n\t\t\t\tCustomerPage.rme('getArtikel', {GRLBMID: " . $B->getID() . ", query : '', KategorieID: ''}, function(transport){ \n\t\t\t\t\t\tif(transport == 'TIMEOUT') { document.location.reload(); return; } \n\t\t\t\t\t\t\$('#contentRight').html(transport); \n\t\t\t\t\t\t\$('.selected').removeClass('selected');\n\t\t\t\t\t\t\$('#frameSelect').hide(); \$('#frameEdit').show();\n\t\t\t\t\t}, \n\t\t\t\t\tfunction(){},\n\t\t\t\t\t'POST');");
$i++;
}
$html .= $T;
return $html;
}
示例10: alert
/**
* Método para generar un mensaje de alerta, párametros que puede recibir: "icon: icono", "title: ", "subtext: ", "name: ", "autoOpen: "
* @param type $text
* @param type $params
* @return type
*/
public static function alert($text, $params = '')
{
//Extraigo los parametros
$params = Util::getParams(func_get_args());
$icon = isset($params['icon']) ? $params['icon'] : 'icon-exclamation-sign';
$title = isset($params['title']) ? '<i class="' . $icon . '" style="padding-right:5px; margin-top:5px;"></i>' . $params['title'] : null;
$subtext = isset($params['subtext']) ? "<p style='margin-top: 10px'>{$params['subtext']}</p>" : null;
$name = isset($params['name']) ? trim($params['name'], '()') : "dwModal" . rand(10, 5000);
$autoOpen = isset($params['autoOpen']) ? true : false;
$modal = '<div class="modal hide" id="' . $name . '">';
$modal .= '<div class="modal-header">';
$modal .= '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>';
$modal .= $title ? "<h3>{$title}</h3>" : '';
$modal .= '</div>';
$modal .= "<div class=\"modal-body\">{$text} {$subtext}</div>";
$modal .= '<div class="modal-footer">';
$modal .= '<button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Aceptar</button>';
$modal .= '</div>';
$modal .= '</div>';
$modal .= '<script type="text/javascript">';
$modal .= "function {$name}() { \$('#{$name}').modal('show'); }; ";
if ($autoOpen) {
$modal .= '$(function(){ ' . $name . '(); });';
}
$modal .= "\$('#{$name}').on('shown', function () { \$('.btn-primary', '#{$name}').focus(); });";
$modal .= '</script>';
return $modal . PHP_EOL;
}
示例11: process
public static function process()
{
global $neardConfig, $neardApps, $neardTools;
$result = '[git]' . PHP_EOL;
$result .= 'client = \'' . $neardTools->getGit()->getExe() . '\'' . PHP_EOL;
$foundRepos = $neardTools->getGit()->findRepos(true);
if (!empty($foundRepos)) {
// Repositories
$refactorRepos = array();
foreach ($foundRepos as $repo) {
/*$repo = dirname($repo);
if (!in_array($repo, $refactorRepos)) {
$refactorRepos[] = $repo;*/
$result .= 'repositories[] = \'' . Util::formatUnixPath($repo) . '\'' . PHP_EOL;
//}
}
} else {
$result .= 'repositories[] = \'\'' . PHP_EOL;
}
// App
$result .= PHP_EOL . '[app]' . PHP_EOL;
$result .= 'debug = false' . PHP_EOL;
$result .= 'cache = false' . PHP_EOL . PHP_EOL;
// Filetypes
$result .= '[filetypes]' . PHP_EOL;
$result .= '; extension = type' . PHP_EOL;
$result .= '; dist = xml' . PHP_EOL . PHP_EOL;
// Binary filetypes
$result .= '[binary_filetypes]' . PHP_EOL;
$result .= '; extension = true' . PHP_EOL;
$result .= '; svh = false' . PHP_EOL;
$result .= '; map = true' . PHP_EOL . PHP_EOL;
file_put_contents($neardApps->getGitlist()->getConf(), $result);
}
示例12: assertThat
/**
* Make an assertion and throw {@link Hamcrest\AssertionError} if it fails.
*
* The first parameter may optionally be a string identifying the assertion
* to be included in the failure message.
*
* If the third parameter is not a matcher it is passed to
* {@link Hamcrest\Core\IsEqual#equalTo} to create one.
*
* Example:
* <pre>
* // With an identifier
* assertThat("apple flavour", $apple->flavour(), equalTo("tasty"));
* // Without an identifier
* assertThat($apple->flavour(), equalTo("tasty"));
* // Evaluating a boolean expression
* assertThat("some error", $a > $b);
* assertThat($a > $b);
* </pre>
*/
public static function assertThat()
{
$args = func_get_args();
switch (count($args)) {
case 1:
self::$_count++;
if (!$args[0]) {
throw new AssertionError();
}
break;
case 2:
self::$_count++;
if ($args[1] instanceof Matcher) {
self::doAssert('', $args[0], $args[1]);
} elseif (!$args[1]) {
throw new AssertionError($args[0]);
}
break;
case 3:
self::$_count++;
self::doAssert($args[0], $args[1], Util::wrapValueWithIsEqual($args[2]));
break;
default:
throw new \InvalidArgumentException('assertThat() requires one to three arguments');
}
}
示例13: __construct
public function __construct($args)
{
global $neardBs, $neardConfig, $neardLang, $neardBins, $neardWinbinder;
if (isset($args[0]) && !empty($args[0])) {
$filePath = $neardBs->getAliasPath() . '/' . $args[0] . '.conf';
$fileContent = file_get_contents($filePath);
if (preg_match('/^Alias \\/' . $args[0] . ' "(.+)"/', $fileContent, $match)) {
$this->initName = $args[0];
$initDest = Util::formatWindowsPath($match[1]);
$apachePortUri = $neardBins->getApache()->getPort() != 80 ? ':' . $neardBins->getApache()->getPort() : '';
$neardWinbinder->reset();
$this->wbWindow = $neardWinbinder->createAppWindow(sprintf($neardLang->getValue(Lang::EDIT_ALIAS_TITLE), $this->initName), 490, 200, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP);
$this->wbLabelName = $neardWinbinder->createLabel($this->wbWindow, $neardLang->getValue(Lang::ALIAS_NAME_LABEL) . ' :', 15, 15, 85, null, WBC_RIGHT);
$this->wbInputName = $neardWinbinder->createInputText($this->wbWindow, $this->initName, 105, 13, 150, null, 20);
$this->wbLabelDest = $neardWinbinder->createLabel($this->wbWindow, $neardLang->getValue(Lang::ALIAS_DEST_LABEL) . ' :', 15, 45, 85, null, WBC_RIGHT);
$this->wbInputDest = $neardWinbinder->createInputText($this->wbWindow, $initDest, 105, 43, 190, null, 20, WBC_READONLY);
$this->wbBtnDest = $neardWinbinder->createButton($this->wbWindow, $neardLang->getValue(Lang::BUTTON_BROWSE), 300, 43, 110);
$this->wbLabelExp = $neardWinbinder->createLabel($this->wbWindow, sprintf($neardLang->getValue(Lang::ALIAS_EXP_LABEL), $apachePortUri, $this->initName, $initDest), 15, 80, 470, 50);
$this->wbProgressBar = $neardWinbinder->createProgressBar($this->wbWindow, self::GAUGE_SAVE + 1, 15, 137, 190);
$this->wbBtnSave = $neardWinbinder->createButton($this->wbWindow, $neardLang->getValue(Lang::BUTTON_SAVE), 215, 132);
$this->wbBtnDelete = $neardWinbinder->createButton($this->wbWindow, $neardLang->getValue(Lang::BUTTON_DELETE), 300, 132);
$this->wbBtnCancel = $neardWinbinder->createButton($this->wbWindow, $neardLang->getValue(Lang::BUTTON_CANCEL), 385, 132);
$neardWinbinder->setHandler($this->wbWindow, $this, 'processWindow');
$neardWinbinder->mainLoop();
$neardWinbinder->reset();
}
}
}
示例14: GetGenerator
public function GetGenerator($bytearray = false)
{
if ($bytearray) {
return Util::toByteArray($this->Generator);
}
return $this->Generator->toString();
}
示例15: stripMarkup
/**
* Strip markup to show plaintext
* Attention the following code block is an adaption
* of the Active Abstract MediaWiki Plugin
* created by Brion Vibber et. al.
* It is not Public Domain, but has the same license as the MediaWiki
* @param string $text
* @return string
* @access private
*/
public static function stripMarkup($text, $image = 'image', $category = 'Category', $language = 'en')
{
$category = Util::getMediaWikiCategoryNamespace($language);
$image = preg_quote($image, '#');
// $image = preg_quote( $wgContLang->getNsText( NS_IMAGE ), '#' );
$text = preg_replace('/(<ref>.+?<\\/ref>)/s', "", $text);
// remove ref
$text = str_replace("'''", "", $text);
$text = str_replace("''", "", $text);
$text = preg_replace('#<!--.*?-->#s', '', $text);
// HTML-style comments
$text = preg_replace('#</?[a-z0-9]+.*?>#s', '', $text);
// HTML-style tags
$text = preg_replace('#\\[[a-z]+:.*? (.*?)\\]#s', '$1', $text);
// URL links
$text = preg_replace('#\\{\\{\\{.*?\\}\\}\\}#s', '', $text);
// template parameters
//$text = preg_replace( '#\\{\\{.*?\\}\\}#s', '', $text ); // template calls
$text = preg_replace('/\\{{2}((?>[^\\{\\}]+)|(?R))*\\}{2}/x', '', $text);
// search {{....}}
$text = preg_replace('#\\{\\|.*?\\|\\}#s', '', $text);
// tables
$text = preg_replace("#\r\n\t\t\t\\[\\[\r\n\t\t\t\t:?{$image}\\s*:\r\n\t\t\t\t\t(\r\n\t\t\t\t\t\t[^][]*\r\n\t\t\t\t\t\t\\[\\[\r\n\t\t\t\t\t\t[^][]*\r\n\t\t\t\t\t\t\\]\\]\r\n\t\t\t\t\t)*\r\n\t\t\t\t[^][]*\r\n\t\t\t\\]\\]#six", '', $text);
// images
$text = preg_replace('#\\[\\[(' . $category . ':.*)\\]\\]#s', '', $text);
// Category Links
$text = preg_replace('#\\[\\[([^|\\]]*\\|)?(.*?)\\]\\]#s', '$2', $text);
// links
$text = preg_replace('#^:.*$#m', '', $text);
// indented lines near start are usually disambigs or notices
//TODO $text = Sanitizer::decodeCharReferences( $text );
return trim($text);
}