本文整理汇总了PHP中SplSubject::getCurrentTransactionParameters方法的典型用法代码示例。如果您正苦于以下问题:PHP SplSubject::getCurrentTransactionParameters方法的具体用法?PHP SplSubject::getCurrentTransactionParameters怎么用?PHP SplSubject::getCurrentTransactionParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplSubject
的用法示例。
在下文中一共展示了SplSubject::getCurrentTransactionParameters方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* (PHP 5 >= 5.1.0)<br/>
* Receive update from subject
* @link http://php.net/manual/en/splobserver.update.php
* @param SplSubject $subject <p>
* The <b>SplSubject</b> notifying the observer of an update.
* </p>
* @return void
*/
public function update(SplSubject $subject)
{
$position = $subject->getCurrentLine();
$params = $subject->getCurrentTransactionParameters();
$result = $subject->getCurrentTransactionResult();
if ($position == 0) {
$this->knownResultHeaders = array_keys($result);
$this->headers = array_unique(array_merge(array_keys($params), $this->knownResultHeaders));
sort($this->headers);
// Write headers
fputcsv($this->file, $this->headers, $subject->getDelimiter(), $subject->getEnclosure());
}
$newLine = array_merge($params, $result);
$this->inMemoryImage[] = $newLine;
// Search for new header keys
$newKeys = array_diff(array_keys($result), $this->knownResultHeaders);
// Search for missing header keys
$missingKeys = array_diff($this->knownResultHeaders, array_keys($result));
// Set to empty missing keys values so fputcsv will generate empty columns
foreach ($missingKeys as $missingKey) {
$newLine[$missingKey] = '';
}
// Rewrite full memory image and file
if ($newKeys) {
rewind($this->file);
// Add new headers
$this->headers = array_unique(array_merge($this->headers, $newKeys));
$this->knownResultHeaders = array_unique(array_merge($this->knownResultHeaders, $newKeys));
// Rewrite headers
sort($this->headers);
fputcsv($this->file, $this->headers, $subject->getDelimiter(), $subject->getEnclosure());
// Re -dump top file from in memory image
foreach ($this->inMemoryImage as $newLine) {
foreach ($this->knownResultHeaders as $header) {
// The new header was not present for this line
if (!isset($newLine[$header])) {
// Set to empty so fputcsv will generate empty columns
$newLine[$header] = '';
}
}
ksort($newLine);
fputcsv($this->file, $newLine, $subject->getDelimiter(), $subject->getEnclosure());
}
} else {
ksort($newLine);
fputcsv($this->file, $newLine, $subject->getDelimiter(), $subject->getEnclosure());
}
}
示例2: update
/**
* (PHP 5 >= 5.1.0)<br/>
* Receive update from subject
* @link http://php.net/manual/en/splobserver.update.php
* @param SplSubject $subject <p>
* The <b>SplSubject</b> notifying the observer of an update.
* </p>
* @return void
*/
public function update(SplSubject $subject)
{
$line = $subject->getCurrentLine() + 1;
$params = $subject->getCurrentTransactionParameters();
$result = $subject->getCurrentTransactionResult();
$output = "Line {$line}";
if (isset($params['ORDERID'])) {
$output .= " (ORDERID={$params['ORDERID']})";
}
$output .= ' :';
if (isset($result['EXECCODE'])) {
$output .= " EXECCODE={$result['EXECCODE']}";
}
if (isset($result['MESSAGE'])) {
$output .= " MESSAGE={$result['MESSAGE']}";
}
if (isset($result['TRANSACTIONID'])) {
$output .= " TRANSACTIONID={$result['TRANSACTIONID']}";
}
$output .= "\n";
echo $output;
}