本文整理汇总了PHP中ApiMain::createPrinterByName方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiMain::createPrinterByName方法的具体用法?PHP ApiMain::createPrinterByName怎么用?PHP ApiMain::createPrinterByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiMain
的用法示例。
在下文中一共展示了ApiMain::createPrinterByName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCrossDomainMangling
public function testCrossDomainMangling()
{
$config = new HashConfig(array('MangleFlashPolicy' => false));
$context = new RequestContext();
$context->setConfig(new MultiConfig(array($config, $context->getConfig())));
$main = new ApiMain($context);
$main->getResult()->addValue(null, null, '< Cross-Domain-Policy >');
if (!function_exists('wfOutputHandler')) {
function wfOutputHandler($s)
{
return $s;
}
}
$printer = $main->createPrinterByName('php');
ob_start('wfOutputHandler');
$printer->initPrinter();
$printer->execute();
$printer->closePrinter();
$ret = ob_get_clean();
$this->assertSame('a:1:{i:0;s:23:"< Cross-Domain-Policy >";}', $ret);
$config->set('MangleFlashPolicy', true);
$printer = $main->createPrinterByName('php');
ob_start('wfOutputHandler');
try {
$printer->initPrinter();
$printer->execute();
$printer->closePrinter();
ob_end_clean();
$this->fail('Expected exception not thrown');
} catch (UsageException $ex) {
ob_end_clean();
$this->assertSame('This response cannot be represented using format=php. See https://phabricator.wikimedia.org/T68776', $ex->getMessage(), 'Expected exception');
}
}
示例2: encodeData
/**
* Get the formatter output for the given input data
* @param array $params Query parameters
* @param array $data Data to encode
* @param string $class Printer class to use instead of the normal one
* @return string
* @throws Exception
*/
protected function encodeData(array $params, array $data, $class = null)
{
$context = new RequestContext();
$context->setRequest(new FauxRequest($params, true));
$main = new ApiMain($context);
if ($class !== null) {
$main->getModuleManager()->addModule($this->printerName, 'format', $class);
}
$result = $main->getResult();
$result->addArrayType(null, 'default');
foreach ($data as $k => $v) {
$result->addValue(null, $k, $v);
}
$printer = $main->createPrinterByName($this->printerName);
$printer->initPrinter();
$printer->execute();
ob_start();
try {
$printer->closePrinter();
return ob_get_clean();
} catch (Exception $ex) {
ob_end_clean();
throw $ex;
}
}
示例3: wfParseText
function wfParseText($text, $action = 'parse', $format = 'xml')
{
# Initialise faux request
$cliRequest = new FauxRequest(array('action' => &$action, 'text' => &$text, 'format' => &$format));
# Initialise api and execute
$processor = new ApiMain($cliRequest);
$processor->execute();
# generate result and print the result
$printer = $processor->createPrinterByName($format);
$result = $processor->getResult();
if ($printer->getNeedsRawData()) {
$result->setRawMode();
}
$result->cleanUpUTF8();
#$printer->profileIn();
$printer->initPrinter(false);
$printer->execute();
$printer->closePrinter();
#$printer->profileOut();
return true;
}