本文整理汇总了PHP中sprinf函数的典型用法代码示例。如果您正苦于以下问题:PHP sprinf函数的具体用法?PHP sprinf怎么用?PHP sprinf使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sprinf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Class Constructor
*
* @access public
* @return void
*
*/
public function __construct(Connection $dbal, $sequenceTableName)
{
$this->dbal = $dbal;
if (empty($sequenceTableName)) {
throw new LedgerException(sprinf("The sequence table name is empty string"));
}
$this->sequenceTableName = $sequenceTableName;
}
示例2: getConfig
/**
* Verifies and returns the configuration.
*
* @return array
*
* @throws \RuntimeException
*/
protected function getConfig()
{
if (false === isset($this->config['pike']['datatable'])) {
throw new \RuntimeException('No [pike][datatable] section configured');
}
if (false === isset($this->config['pike']['datatable'][$this->getName()])) {
throw new \RuntimeException(sprinf('No datatable configuration found for %s', $this->getName()));
}
return $this->config['pike']['datatable'][$this->getName()];
}
示例3: before
public function before(Request $request, Application $app)
{
if (!$request->headers->get('X-Authentication-Token')) {
$app->abort(401, 'Not authenticated. Header X-Authentication-Token missing.');
}
$token = $request->headers->get('X-Authentication-Token');
if (!$this->isAuthorized($token, $app)) {
$msg = sprinf('Not authenticated. X-Authentication-Token %s is not authorized.', $token);
$app->abort(401, $msg);
}
}
示例4: set
public function set(Base $record, $name, $value)
{
if ($value !== null && !$value instanceof Base) {
if (is_object($value)) {
$message = sprintf("Must pass instance of Rails\\ActiveRecord\\Base as value, instance of %s passed", get_class($value));
} else {
$message = sprintf("Must pass either null or instance of Rails\\ActiveRecord\\Base as value, %s passed", gettype($value));
}
throw new Exception\InvalidArgumentException($message);
}
$options = $record->getAssociations()->get($name);
switch ($options['type']) {
case 'belongsTo':
if ($value) {
$this->matchClass($value, $options['className']);
$value = $value->id();
}
$record->setAttribute($options['foreignKey'], $value);
break;
case 'hasOne':
$foreignKey = $options['foreignKey'];
if ($value) {
$this->matchClass($value, $options['className']);
$value->setAttribute($foreignKey, $record->id());
}
if ($record->isNewRecord()) {
return;
}
$oldValue = $record->getAssociation($name);
if ($value && $oldValue && $value->getAttribute($foreignKey) == $oldValue->getAttribute($foreignKey)) {
return;
}
if ($oldValue) {
$oldValue->setAttribute($foreignKey, null);
}
if (!static::transaction(function () use($name, $value, $oldValue) {
if ($value) {
if (!$value->save()) {
return false;
}
}
if ($oldValue) {
if (!$oldValue->save()) {
return false;
}
}
})) {
throw new RecordNotSavedException(sprinf("Failed to save new associated %s", strtolower($record::getService('inflector')->underscore($name)->humanize())));
}
break;
}
return true;
}
示例5: subclassDeleteAction
public function subclassDeleteAction(Request $request)
{
/** @var $em EntityManager */
$em = $this->get('doctrine.orm.entity_manager');
$subclass = $em->getRepository('WealthbotAdminBundle:Subclass')->find($request->get('id'));
if (!$subclass) {
throw $this->createNotFoundException(sprinf('Subclass with ID %s does not exist.', $request->get('id')));
}
$em->remove($subclass);
$em->flush();
return $this->getJsonResponse(array('status' => 'success'));
}
示例6: watched_episode
public function watched_episode()
{
if (!isset($_POST['episode_id'])) {
wp_send_json_error(__('No episode ID provided.', 'life-control'));
}
$episode = get_post($_POST['episode_id']);
if (!$episode || 'episode' != $episode->post_type) {
wp_send_json_error(__("Provided ID isn't a episode.", 'life-control'));
}
$watched = get_post_meta($episode->ID, 'user_' . get_current_user_id() . '_watched', true);
if ($watched) {
wp_send_json_error(sprinf(__('You already watched %s', 'life-control'), $episode->post_title));
}
update_post_meta($episode->ID, 'user_' . get_current_user_id() . '_watched', time());
wp_send_json_success(__('You mark this episode as watched.', 'life-control'));
}
示例7: _get_notify_url
/**
* Gets the URL that the user should generally be sent back to after payment completion offiste
* Adds the reg_url_link in order to remember which session we were in the middle of processing
* @param EE_Registration or int, current registration we want to link back to in the return url.
* @param boolean $urlencode whether or not to url-encode the url (if true, you probably intend to pass
* this string as a URL parameter itself, or maybe a post parameter)
* @return string URL on the current site of the thank_you page, with parameters added on to know which registration was just
* processed in order to correctly display the payment status. And it gets URL-encoded by default
*/
protected function _get_notify_url($registration, $urlencode = false)
{
//if $registration is an ID instead of an EE_Registration, make it an EE_Registration
if (!$registration instanceof EE_Registration) {
$registration = $this->_REG->get_one_by_ID($registration);
}
if (empty($registration)) {
$msg[0] = __("Cannot get Notify URL for gateway. Invalid registration", 'event_espresso');
$msg[1] = sprinf(__("Registration being used is %s.", 'event_espresso'), print_r($registration, true));
EE_Error::add_error(implode("||", $msg), __FILE__, __FUNCTION__, __LINE__);
return '';
}
//get a registration that's currently getting processed
/*@var $registration EE_Registration */
$url = add_query_arg(array('e_reg_url_link' => $registration->reg_url_link(), 'ee_gateway' => $this->_gateway_name), get_permalink(EE_Registry::instance()->CFG->core->txn_page_id));
if ($urlencode) {
$url = urlencode($url);
}
return $url;
}
示例8: number_to_human_size
public static function number_to_human_size($size, $precision = 1)
{
$size = float($size);
$return = null;
if ($size == 1) {
$return = "1 Byte";
} elseif ($size < 1024) {
$return = sprintf("%d Bytes", $size);
} elseif ($size < 1024 * 1024) {
$return = sprintf("%.{$precision}f KB", $size / (1024 * 1024));
} elseif ($size < 1024 * 1024 * 1024) {
$return = sprinf("%.{$precision}f MB", $size / (1024 * 1024 * 1024));
} elseif ($size < 1024 * 1024 * 1024 * 1024) {
$return = sprinf("%.{$precision}f GB", $size / (1024 * 1024 * 1024 * 1024));
} else {
$return = sprintf("%.{$precision}f TB", $size / (1024 * 1024 * 1024 * 1024 * 1024));
}
return str_replace(".0", "", $return);
}
示例9: submitTranslationsMails
/**
* This method is used to wright translation for mails.
* This wrights subject translation files
* (in root/mails/lang_choosen/lang.php or root/_PS_THEMES_DIR_/mails/lang_choosen/lang.php)
* and mails files.
*/
protected function submitTranslationsMails()
{
$arr_mail_content = array();
$arr_mail_path = array();
if (Tools::getValue('core_mail')) {
$arr_mail_content['core_mail'] = Tools::getValue('core_mail');
// Get path of directory for find a good path of translation file
if ($this->theme_selected != self::DEFAULT_THEME_NAME) {
$arr_mail_path['core_mail'] = $this->translations_informations[$this->type_selected]['override']['dir'];
} else {
$arr_mail_path['core_mail'] = $this->translations_informations[$this->type_selected]['dir'];
}
}
if (Tools::getValue('module_mail')) {
$arr_mail_content['module_mail'] = Tools::getValue('module_mail');
// Get path of directory for find a good path of translation file
if ($this->theme_selected != self::DEFAULT_THEME_NAME) {
$arr_mail_path['module_mail'] = $this->translations_informations['modules']['override']['dir'] . '{module}/mails/' . $this->lang_selected->iso_code . '/';
} else {
$arr_mail_path['module_mail'] = $this->translations_informations['modules']['dir'] . '{module}/mails/' . $this->lang_selected->iso_code . '/';
}
}
// Save each mail content
foreach ($arr_mail_content as $group_name => $all_content) {
foreach ($all_content as $type_content => $mails) {
foreach ($mails as $mail_name => $content) {
$module_name = false;
$module_name_pipe_pos = stripos($mail_name, '|');
if ($module_name_pipe_pos) {
$module_name = substr($mail_name, 0, $module_name_pipe_pos);
if (!Validate::isModuleName($module_name)) {
throw new PrestaShopException(sprinf(Tools::displayError('Invalid module name "%s"'), $module_name));
}
$mail_name = substr($mail_name, $module_name_pipe_pos + 1);
if (!Validate::isTplName($mail_name)) {
throw new PrestaShopException(sprintf(Tools::displayError('Invalid mail name "%s"'), $mail_name));
}
}
if ($type_content == 'html') {
$content = Tools::htmlentitiesUTF8($content);
$content = htmlspecialchars_decode($content);
// replace correct end of line
$content = str_replace("\r\n", PHP_EOL, $content);
$title = '';
if (Tools::getValue('title_' . $group_name . '_' . $mail_name)) {
$title = Tools::getValue('title_' . $group_name . '_' . $mail_name);
}
$string_mail = $this->getMailPattern();
$content = str_replace(array('#title', '#content'), array($title, $content), $string_mail);
// Magic Quotes shall... not.. PASS!
if (_PS_MAGIC_QUOTES_GPC_) {
$content = stripslashes($content);
}
}
if (Validate::isCleanHTML($content)) {
$path = $arr_mail_path[$group_name];
if ($module_name) {
$path = str_replace('{module}', $module_name, $path);
}
file_put_contents($path . $mail_name . '.' . $type_content, $content);
} else {
throw new PrestaShopException(Tools::displayError('HTML e-mail templates cannot contain JavaScript code.'));
}
}
}
}
// Update subjects
$array_subjects = array();
if (($subjects = Tools::getValue('subject')) && is_array($subjects)) {
$array_subjects['core_and_modules'] = array('translations' => array(), 'path' => $arr_mail_path['core_mail'] . 'lang.php');
foreach ($subjects as $subject_translation) {
$array_subjects['core_and_modules']['translations'] = array_merge($array_subjects['core_and_modules']['translations'], $subject_translation);
}
}
if (!empty($array_subjects)) {
foreach ($array_subjects as $infos) {
$this->writeSubjectTranslationFile($infos['translations'], $infos['path']);
}
}
if (Tools::isSubmit('submitTranslationsMailsAndStay')) {
$this->redirect(true);
} else {
$this->redirect();
}
}
示例10: rotateTable
//.........这里部分代码省略.........
addslashes($stopSQL)
);
if ($this->CDRdb->query($query)) {
$this->CDRdb->next_record();
$rowsSourceTable=$this->CDRdb->f('c');
$log=sprintf ("Source table %s has %d records in month %s\n",$sourceTable,$rowsSourceTable,$month);
syslog(LOG_NOTICE,$log);
print $log;
if (!$rowsSourceTable) return 1;
} else {
$log=sprintf ("Error: %s (%s)\n",$this->table,$this->CDRdb->Error);
syslog(LOG_NOTICE,$log);
print $log;
return 0;
}
$query=sprintf("select count(*) as c from %s\n", addslashes($destinationTable));
if ($this->CDRdb->query($query)) {
$this->CDRdb->next_record();
$rowsDestinationTable = $this->CDRdb->f('c');
$log=sprintf ("Destination table %s has %d records\n",$destinationTable,$rowsDestinationTable);
syslog(LOG_NOTICE,$log);
print $log;
if ($rowsDestinationTable != $rowsSourceTable) {
$log=sprintf ("Error: source table has %d records and destination table has %d records\n",$rowsSourceTable,$rowsDestinationTable);
syslog(LOG_NOTICE,$log);
print $log;
} else {
$log=sprintf ("Tables are in sync\n");
syslog(LOG_NOTICE,$log);
print $log;
}
} else {
$log=sprintf ("%s (%s)\n",$this->CDRdb->Error,$this->CDRdb->Errno);
syslog(LOG_NOTICE,$log);
print $log;
if ($this->CDRdb->Errno==1146) {
$destinationTableTmp=$destinationTable."_tmp";
$query=sprintf("drop table if exists %s",addslashes($destinationTableTmp));
print($query);
$this->CDRdb->query($query);
if ($query=file_get_contents($createTableFile)) {
$query=preg_replace("/CREATE TABLE.*/","CREATE TABLE $destinationTableTmp (",$query);
if (!$this->CDRdb->query($query)) {
$log=sprintf ("Error creating table %s: %s, %s\n",$destinationTableTmp,$this->CDRdb->Error,$query);
syslog(LOG_NOTICE,$log);
print $log;
return 0;
}
} else {
$log=sprintf ("Cannot read file %s\n",$createTableFile);
syslog(LOG_NOTICE,$log);
print $log;
return 0;
}
// if we reached this point we start to copy records
$query=sprintf("insert into %s select * from %s where %s >='%s' and %s < '%s'",
addslashes($destinationTableTmp),
addslashes($sourceTable),
addslashes($this->CDRFields['startTime']),
addslashes($startSQL),
addslashes($this->CDRFields['startTime']),
addslashes($stopSQL)
);
return ;
if ($this->CDRdb->query($query)) {
$e=time();
$d=$e-$b;
$rps=0;
if ($this->CDRdb->affected_rows() && $d) $rps=$this->CDRdb->affected_rows()/$d;
$log=printf ("Copied %d CDRs into table %s in %d s @ %.0f rps\n",$this->CDRdb->affected_rows(),$destinationTableTmp,$d,$rps);
syslog(LOG_NOTICE,$log);
print $log;
$query=sprinf("rename table %s to %s", addslashes($destinationTableTmp),addslashes($destinationTableTmp));
if (!$this->CDRdb->query($query)) {
printf ("Error renaming table %s to %s: %s\n",$destinationTableTmp,$destinationTable,$this->CDRdb->Error);
return 0;
}
} else {
printf ("Error copying records in table %s: %s\n",$destinationTable,$this->CDRdb->Error);
return 0;
}
}
}
}
示例11: ui_create_icon
/**
* Create a jquery.ui icon
* @param string $icon the icon ID. Ex: ('lightbulb, plusthick, ...')
* @param string $properties Html properties
*/
function ui_create_icon($icon = 'notice', $properties = '')
{
if (is_array($properties)) {
$class = sprinf(' ui-icon ui-icon-%s ', $icon);
$properties['class'] = isset($properties['class']) ? $class . $properties['class'] : $class;
$properties = arrayToString($properties);
$pattern = '<span %s></span>';
} else {
$properties = $properties === '' ? 'style="z-index:2000"' : $properties;
$pattern = '<span class="ui-icon ui-icon-%s ui-datepicker-prev" %s></span>';
}
return sprintf($pattern, $icon, $properties);
}
示例12: _show_generator
/**
*
* @param mixed $handler_id The ID of the handler.
* @param array &$data The local request data.
*/
public function _show_generator($handler_id, array &$data)
{
// Builtin style prefix
if (preg_match('/^builtin:(.+)/', $this->_request_data['query_data']['style'], $matches)) {
$bpr = '-' . $matches[1];
debug_add('Recognized builtin report, style prefix: ' . $bpr);
} else {
debug_add("'{$this->_request_data['query_data']['style']}' not recognized as builtin style");
$bpr = '';
}
//Mangling if report wants to do it (done here to have style context, otherwise MidCOM will not like us.
debug_print_r("query data before mangle:", $this->_request_data['query_data']);
debug_add("calling midcom_show_style('report{$bpr}-mangle-query') to mangle the query data as necessary");
midcom_show_style("projects_report{$bpr}-mangle-query");
debug_print_r("query data after mangle:", $this->_request_data['query_data']);
//Handle grouping
debug_add('checking grouping');
if (array_key_exists('grouping', $this->_request_data['query_data']) && !empty($this->_request_data['query_data']['grouping'])) {
debug_add("checking validity of grouping value '{$this->_request_data['query_data']['grouping']}'");
if (array_key_exists($this->_request_data['query_data']['grouping'], $this->_valid_groupings)) {
debug_add('Setting grouping to: ' . $this->_request_data['query_data']['grouping']);
$this->_grouping =& $this->_request_data['query_data']['grouping'];
} else {
debug_add(sprinf("\"%s\" is not a valid grouping, keeping default", $this->_request_data['query_data']['grouping']), MIDCOM_LOG_WARN);
}
}
// Put grouping to request data
$this->_request_data['grouping'] =& $this->_grouping;
//Get our results
$results_hr = $this->_get_hour_reports();
//For debugging and sensible passing of data
$this->_request_data['raw_results'] = array();
$this->_request_data['raw_results']['hr'] = $results_hr;
//TODO: Mileages, expenses
$this->_request_data['report'] = array();
$this->_request_data['report']['rows'] = array();
$this->_request_data['report']['total_hours'] = 0;
$this->_analyze_raw_hours();
$this->_sort_rows_recursive($this->_request_data['report']['rows']);
//TODO: add other report types when supported
if (!is_array($this->_request_data['raw_results']['hr']) || count($this->_request_data['raw_results']['hr']) == 0) {
midcom_show_style("projects_report{$bpr}-noresults");
return;
}
//Start actual display
//Indented to make style flow clearer
midcom_show_style("projects_report{$bpr}-start");
midcom_show_style("projects_report{$bpr}-header");
$this->_show_generator_group($this->_request_data['report']['rows'], $bpr);
midcom_show_style("projects_report{$bpr}-totals");
midcom_show_style("projects_report{$bpr}-footer");
midcom_show_style("projects_report{$bpr}-end");
}
示例13: setMode
/**
* Sets the Processing Mode
*
* @access public
* @return void
*
*/
public function setMode($mode)
{
if ($mode !== self::PROCESS_MODE_COMPLETE || $mode !== self::PROCESS_MODE_DELAYED || $mode !== self::PROCESS_MODE_PROCESS) {
throw new LedgerException(sprinf('Mode set to %s is not a valid option', $mode));
}
$this->mode = $mode;
}
示例14: set
public function set(DocumentInterface $record, $name, $value)
{
if ($value !== null && !is_array($value) && !$value instanceof DocumentInterface) {
if (is_object($value)) {
$message = sprintf("Must pass instance of Rails\\ActiveRecord\\Mongo\\Base as value, instance of %s passed", get_class($value));
} else {
$message = sprintf("Must pass either null, array or instance of Rails\\ActiveRecord\\Mongo\\Base as value, %s passed", gettype($value));
}
throw new Exception\InvalidArgumentException($message);
}
$options = $record->getAssociations()->get($name);
switch ($options['type']) {
case 'belongsTo':
if ($value) {
if (is_object($value)) {
$this->matchClass($value, $options['className']);
$dbref = MongoDBRef::create($value->collectionName(), $value->id(), $value->connection()->databaseName());
} elseif (is_array($value)) {
if (!MongoDBRef::isRef($value)) {
throw new Exception\InvalidArgumentException(sprintf("Array passed to %s::%s association is not a reference", get_class($record), $name));
}
$dbref = $value;
} else {
throw new Exception\InvalidArgumentException(sprintf("Value passed to %s::%s association must be either object or array, %s passed", gettype($value)));
}
} else {
$dbref = null;
}
$record->setAttribute($options['reference'], $dbref);
break;
case 'hasOne':
$refAttr = $options['reference'];
if ($value) {
$this->matchClass($value, $options['className']);
$dbref = MongoDBRef::create($record->collectionName(), $record->id(), $record->connection()->databaseName());
$value->setAttribute($refAttr, $dbref);
}
if ($record->isNewRecord()) {
return;
}
$oldValue = $record->getAssociation($name);
if ($value && $oldValue && (string) $value->getAttribute($refAttr) == (string) $oldValue->getAttribute($refAttr)) {
return;
}
if ($oldValue) {
$oldValue->setAttribute($refAttr, null);
}
if ($value && $oldValue) {
$saved = $value->isValid() && $oldValue->isValid();
} else {
$saved = true;
}
if ($saved && $value) {
if (!$value->save()) {
$saved = false;
}
}
if ($saved && $oldValue) {
if (!$oldValue->save()) {
$saved = false;
}
}
if (!$saved) {
throw new RecordNotSavedException(sprinf("Failed to save new associated %s", strtolower($record::getService('inflector')->underscore($name)->humanize())));
}
break;
case 'hasMany':
if ($value instanceof Collection) {
$value = $value->toArray();
} elseif (!is_array($value)) {
throw new Exception\InvalidArgumentException(sprintf("HasMany association accepts either array or instance of Mongo\\Collection, %s passed", gettype($value)));
}
if (!empty($options['embedded'])) {
$record->{$name}()->set($value);
break;
}
break;
default:
throw new Exception\InvalidArgumentException(sprintf("Can't set unsupported association type %s", $options['type']));
}
return true;
}
示例15: output_dialog_markup
/**
* Output the HTML markup for the dialog box.
* @access public
* @since 5.5.6
* @return void
*/
public function output_dialog_markup()
{
$woo_framework_url = $this->framework_url();
$woo_framework_version = get_option('woo_framework_version');
$MIN_VERSION = '2.9';
$meetsMinVersion = version_compare($woo_framework_version, $MIN_VERSION) >= 0;
$isWooTheme = true;
?>
<div id="woo-dialog" style="display: none;">
<?php
if ($meetsMinVersion && $isWooTheme) {
?>
<div id="woo-options-buttons" class="clear">
<div class="alignleft">
<input type="button" id="woo-btn-cancel" class="button" name="cancel" value="Cancel" accesskey="C" />
</div>
<div class="alignright">
<input type="button" id="woo-btn-insert" class="button-primary" name="insert" value="Insert" accesskey="I" />
</div>
<div class="clear"></div><!--/.clear-->
</div><!--/#woo-options-buttons .clear-->
<div id="woo-options" class="alignleft">
<h3><?php
echo __('Customize the Shortcode', 'woothemes');
?>
</h3>
<table id="woo-options-table">
</table>
</div>
<div class="clear"></div>
<script type="text/javascript" src="<?php
echo esc_url($woo_framework_url . 'js/shortcode-generator/js/column-control.js');
?>
"></script>
<script type="text/javascript" src="<?php
echo esc_url($woo_framework_url . 'js/shortcode-generator/js/tab-control.js');
?>
"></script>
<?php
} else {
?>
<div id="woo-options-error">
<h3><?php
echo __('Ninja Trouble', 'woothemes');
?>
</h3>
<?php
if ($isWooTheme && !$meetsMinVersion) {
?>
<p><?php
echo sprinf(__('Your version of the WooFramework (%s) does not yet support shortcodes. Shortcodes were introduced with version %s of the framework.', 'woothemes'), $woo_framework_version, $MIN_VERSION);
?>
</p>
<h4><?php
echo __('What to do now?', 'woothemes');
?>
</h4>
<p><?php
echo __('Upgrading your theme, or rather the WooFramework portion of it, will do the trick.', 'woothemes');
?>
</p>
<p><?php
echo sprintf(__('The framework is a collection of functionality that all WooThemes have in common. In most cases you can update the framework even if you have modified your theme, because the framework resides in a separate location (under %s).', 'woothemes'), '<code>/functions/</code>');
?>
</p>
<p><?php
echo sprintf(__('There\'s a tutorial on how to do this on WooThemes.com: %sHow to upgradeyour theme%s.', 'woothemes'), '<a title="WooThemes Tutorial" target="_blank" href="http://www.woothemes.com/2009/08/how-to-upgrade-your-theme/">', '</a>');
?>
</p>
<p><?php
echo __('<strong>Remember:</strong> Every Ninja has a backup plan. Safe or not, always backup your theme before you update it or make changes to it.', 'woothemes');
?>
</p>
<?php
} else {
?>
//.........这里部分代码省略.........