当前位置: 首页>>代码示例>>PHP>>正文


PHP ApiMain::createPrinterByName方法代码示例

本文整理汇总了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');
     }
 }
开发者ID:ngertrudiz,项目名称:mediawiki,代码行数:34,代码来源:ApiFormatPhpTest.php

示例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;
     }
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:33,代码来源:ApiFormatTestBase.php

示例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;
}
开发者ID:akoehn,项目名称:wikireader,代码行数:21,代码来源:wr_parser_sa.php


注:本文中的ApiMain::createPrinterByName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。