本文整理汇总了PHP中Text_Template::render方法的典型用法代码示例。如果您正苦于以下问题:PHP Text_Template::render方法的具体用法?PHP Text_Template::render怎么用?PHP Text_Template::render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Text_Template
的用法示例。
在下文中一共展示了Text_Template::render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetchFrontendResponse
/**
* @param array $requestArguments
* @param bool $failOnFailure
* @return Response
*/
protected function fetchFrontendResponse(array $requestArguments, $failOnFailure = true)
{
if (!empty($requestArguments['url'])) {
$requestUrl = '/' . ltrim($requestArguments['url'], '/');
} else {
$requestUrl = '/?' . GeneralUtility::implodeArrayForUrl('', $requestArguments);
}
if (property_exists($this, 'instancePath')) {
$instancePath = $this->instancePath;
} else {
$instancePath = ORIGINAL_ROOT . 'typo3temp/functional-' . substr(sha1(get_class($this)), 0, 7);
}
$arguments = array('documentRoot' => $instancePath, 'requestUrl' => 'http://localhost' . $requestUrl);
$template = new \Text_Template(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/request.tpl');
$template->setVar(array('arguments' => var_export($arguments, true), 'originalRoot' => ORIGINAL_ROOT));
$php = \PHPUnit_Util_PHP::factory();
$response = $php->runJob($template->render());
$result = json_decode($response['stdout'], true);
if ($result === null) {
$this->fail('Frontend Response is empty');
}
if ($failOnFailure && $result['status'] === Response::STATUS_Failure) {
$this->fail('Frontend Response has failure:' . LF . $result['error']);
}
$response = new Response($result['status'], $result['content'], $result['error']);
return $response;
}
示例2: renderRelease
/**
* @param Release $release
* @param bool $latest
*
* @return string
*/
private function renderRelease(Release $release, $latest = false)
{
$item = new \Text_Template(__DIR__ . '/../templates/item.html');
$manifest = '';
if (!empty($release->manifest())) {
$manifest = sprintf(' class="phar" data-title="Manifest" data-content="<ul>%s</ul>" data-placement="bottom" data-html="true"', implode('', array_map(function ($item) {
return '<li>' . $item . '</li>';
}, $release->manifest())));
}
$item->setVar(['domain' => $this->domain(), 'package' => $release->package(), 'version' => $release->version(), 'date' => $release->date(), 'size' => $release->size(), 'sha256' => $release->sha256(), 'strongOpen' => $latest ? '<strong>' : '', 'strongClose' => $latest ? '</strong>' : '', 'manifest' => $manifest]);
return $item->render();
}
示例3: renderInvokers
/**
* @param Tombstone $tombstone
*
* @return string
*/
private function renderInvokers(Tombstone $tombstone)
{
$invokers = array();
foreach ($tombstone->getVampires() as $vampire) {
$invokers[] = $vampire->getInvoker();
}
$invokers = array_unique($invokers);
$invokersString = '';
foreach ($invokers as $invoker) {
$this->invokerTemplate->setVar(array('invoker' => $invoker ?: 'global scope'));
$invokersString .= $this->invokerTemplate->render();
}
return $invokersString;
}
示例4: render
/**
* @param ReleaseCollection $releases
*/
public function render(ReleaseCollection $releases)
{
$feedTemplate = new \Text_Template(__DIR__ . '/../templates/feed.xml');
$feedItemTemplate = new \Text_Template(__DIR__ . '/../templates/item.xml');
$rdfList = '';
$rdfItems = '';
foreach ($releases->latestReleasesSortedByDate() as $release) {
$rdfList .= sprintf(' <rdf:li rdf:resource="%s/%s-%s.phar"/>' . "\n", $this->domain(), $release->package(), $release->version());
$feedItemTemplate->setVar(['domain' => $this->domain(), 'package' => $release->package(), 'version' => $release->version(), 'date' => $release->date(), 'content' => '']);
$rdfItems .= $feedItemTemplate->render();
}
$feedTemplate->setVar(['items_list' => $rdfList, 'items' => $rdfItems, 'domain' => $this->domain(), 'email' => $this->email()]);
$feedTemplate->renderTo($this->target());
}
示例5: resultPrintAfter
/**
* @param PrintResultEvent $printResultEvent
* @throws \Codeception\Exception\ModuleRequireException
*/
public function resultPrintAfter(PrintResultEvent $printResultEvent)
{
if (count($this->failedIdentifiers) > 0) {
$items = '';
$itemTemplate = new \Text_Template($this->config['templateFolder'] . 'Item.html');
foreach ($this->failedIdentifiers as $vars) {
$itemTemplate->setVar($vars);
$items .= $itemTemplate->render();
}
$pageTemplate = new \Text_Template($this->config['templateFolder'] . 'Page.html');
$pageTemplate->setVar(array('items' => $items));
$reportPath = $this->fileSystemUtil->getFailImageDirectory() . 'index.html';
$pageTemplate->renderTo($reportPath);
$printResultEvent->getPrinter()->write('Report has been created: ' . $reportPath . "\n");
}
}
示例6: ReflectionExtension
$extension = new ReflectionExtension($extname);
$classes = array_keys($extension->getClasses());
$functions = array_keys($extension->getFunctions());
$constants = array_keys($extension->getConstants());
$classItems = array();
foreach ($classes as $classname) {
$classItems[] = " " . sprintf("%-40s", "'{$classname}'") . "=> array('{$defversion}', ''),";
}
$functionItems = array();
foreach ($functions as $fctname) {
$functionItems[] = " " . sprintf("%-40s", "'{$fctname}'") . "=> array('{$defversion}', ''),";
}
$constantItems = array();
foreach ($constants as $cstname) {
$constantItems[] = " " . sprintf("%-40s", "'{$cstname}'") . "=> array('{$defversion}', ''),";
}
$tplDir = dirname(__FILE__) . DIRECTORY_SEPARATOR;
try {
$skeleton = $tplDir . 'reference.skeleton.tpl';
$tpl = new Text_Template($skeleton);
/**
* Cannot use directly setFile() method, due to issue
* @link: https://github.com/sebastianbergmann/php-text-template/issues/7
*/
//$tpl->setFile($skeleton);
$vars = array('extname' => $extname, 'extversion' => $extversion, 'defversion' => $defversion, 'release' => '2.x.y', 'classes' => implode(PHP_EOL, $classItems), 'functions' => implode(PHP_EOL, $functionItems), 'constants' => implode(PHP_EOL, $constantItems));
$tpl->setVar($vars);
echo $tpl->render();
} catch (Exception $e) {
die($e->getMessage());
}
示例7: generateMockedMethodDefinition
/**
* @param string $templateDir
* @param string $className
* @param string $methodName
* @param bool $cloneArguments
* @param string $modifier
* @param string $arguments_decl
* @param string $arguments_call
* @param string $reference
* @param bool $callOriginalMethods
* @param bool $static
* @return string
*/
protected function generateMockedMethodDefinition($templateDir, $className, $methodName, $cloneArguments = true, $modifier = 'public', $arguments_decl = '', $arguments_call = '', $reference = '', $callOriginalMethods = false, $static = false)
{
if ($static) {
$templateFile = 'mocked_static_method.tpl';
} else {
$templateFile = sprintf('%s_method.tpl', $callOriginalMethods ? 'proxied' : 'mocked');
}
$template = new Text_Template($templateDir . $templateFile);
$template->setVar(array('arguments_decl' => $arguments_decl, 'arguments_call' => $arguments_call, 'arguments_count' => !empty($arguments_call) ? count(explode(',', $arguments_call)) : 0, 'class_name' => $className, 'method_name' => $methodName, 'modifier' => $modifier, 'reference' => $reference, 'clone_arguments' => $cloneArguments ? 'TRUE' : 'FALSE'));
return $template->render();
}
示例8: getFrontendResponse
/**
* @param int $pageId
* @param int $languageId
* @param int $backendUserId
* @param int $workspaceId
* @param bool $failOnFailure
* @return Response
*/
protected function getFrontendResponse($pageId, $languageId = 0, $backendUserId = 0, $workspaceId = 0, $failOnFailure = TRUE)
{
$pageId = (int) $pageId;
$languageId = (int) $languageId;
$additionalParameter = '';
if (!empty($backendUserId)) {
$additionalParameter .= '&backendUserId=' . (int) $backendUserId;
}
if (!empty($workspaceId)) {
$additionalParameter .= '&workspaceId=' . (int) $workspaceId;
}
$arguments = array('documentRoot' => $this->instancePath, 'requestUrl' => 'http://localhost/?id=' . $pageId . '&L=' . $languageId . $additionalParameter);
$template = new \Text_Template(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/request.tpl');
$template->setVar(array('arguments' => var_export($arguments, TRUE), 'originalRoot' => ORIGINAL_ROOT));
$php = \PHPUnit_Util_PHP::factory();
$response = $php->runJob($template->render());
$result = json_decode($response['stdout'], TRUE);
if ($result === FALSE) {
$this->fail('Frontend Response is empty');
}
if ($failOnFailure && $result['status'] === Response::STATUS_Failure) {
$this->fail('Frontend Response has failure:' . LF . $result['error']);
}
$response = new Response($result['status'], $result['content'], $result['error']);
return $response;
}
示例9: generateMessageBody
/**
* Generate mail body
*
* @return mixed
*/
protected function generateMessageBody()
{
$template = new Template($this->templateFile);
$template->setVar(['current_date' => date('d.m.Y H:i'), 'form_id' => $this->formId]);
foreach ($this->fields as $field => $rules) {
$value = $this->getValue($field);
$template->setVar([$field => $value]);
}
$template->setVar($this->templateData);
return $template->render();
}
示例10: render
/**
* Renders this node.
*
* @param string $target
* @param string $title
* @param string $charset
* @param integer $lowUpperBound
* @param integer $highLowerBound
* @param string $generator
*/
public function render($target, $title, $charset = 'UTF-8', $lowUpperBound = 35, $highLowerBound = 70, $generator = '')
{
if ($this->yui) {
$template = new Text_Template(PHP_CodeCoverage_Report_HTML::$templatePath . 'file.html');
$yuiTemplate = new Text_Template(PHP_CodeCoverage_Report_HTML::$templatePath . 'yui_item.js');
} else {
$template = new Text_Template(PHP_CodeCoverage_Report_HTML::$templatePath . 'file_no_yui.html');
}
$i = 1;
$lines = '';
foreach ($this->codeLines as $line) {
$css = '';
if (!isset($this->ignoredLines[$i]) && isset($this->executedLines[$i])) {
$count = '';
// Array: Line is executable and was executed.
// count(Array) = Number of tests that hit this line.
if (is_array($this->executedLines[$i])) {
$color = 'lineCov';
$numTests = count($this->executedLines[$i]);
$count = sprintf('%8d', $numTests);
if ($this->yui) {
$buffer = '';
$testCSS = '';
foreach ($this->executedLines[$i] as $test) {
switch ($test['status']) {
case 0:
$testCSS = ' class=\\"testPassed\\"';
break;
case 1:
case 2:
$testCSS = ' class=\\"testIncomplete\\"';
break;
case 3:
$testCSS = ' class=\\"testFailure\\"';
break;
case 4:
$testCSS = ' class=\\"testError\\"';
break;
default:
$testCSS = '';
}
$buffer .= sprintf('<li%s>%s</li>', $testCSS, addslashes(htmlspecialchars($test['id'])));
}
if ($numTests > 1) {
$header = $numTests . ' tests cover';
} else {
$header = '1 test covers';
}
$header .= ' line ' . $i;
$yuiTemplate->setVar(array('line' => $i, 'header' => $header, 'tests' => $buffer), FALSE);
$this->yuiPanelJS .= $yuiTemplate->render();
}
} else {
if ($this->executedLines[$i] == -1) {
$color = 'lineNoCov';
$count = sprintf('%8d', 0);
} else {
$color = 'lineDeadCode';
$count = ' ';
}
}
$css = sprintf('<span class="%s"> %s : ', $color, $count);
}
$fillup = array_shift($this->codeLinesFillup);
if ($fillup > 0) {
$line .= str_repeat(' ', $fillup);
}
$lines .= sprintf('<span class="lineNum" id="container%d"><a name="%d"></a>' . '<a href="#%d" id="line%d">%8d</a> </span>%s%s%s' . "\n", $i, $i, $i, $i, $i, !empty($css) ? $css : ' : ', !$this->highlight ? htmlspecialchars($line) : $line, !empty($css) ? '</span>' : '');
$i++;
}
$items = '';
foreach ($this->classes as $className => $classData) {
if ($classData['executedLines'] == $classData['executableLines']) {
$numTestedClasses = 1;
$testedClassesPercent = 100;
} else {
$numTestedClasses = 0;
$testedClassesPercent = 0;
}
$numMethods = 0;
$numTestedMethods = 0;
foreach ($classData['methods'] as $method) {
if ($method['executableLines'] > 0) {
$numMethods++;
if ($method['executedLines'] == $method['executableLines']) {
$numTestedMethods++;
}
}
}
$items .= $this->doRenderItem(array('name' => sprintf('<b><a href="#%d">%s</a></b>', $classData['startLine'], $className), 'numClasses' => 1, 'numTestedClasses' => $numTestedClasses, 'testedClassesPercent' => sprintf('%01.2f', $testedClassesPercent), 'numMethods' => $numMethods, 'numTestedMethods' => $numTestedMethods, 'testedMethodsPercent' => PHP_CodeCoverage_Util::percent($numTestedMethods, $numMethods, TRUE), 'numExecutableLines' => $classData['executableLines'], 'numExecutedLines' => $classData['executedLines'], 'executedLinesPercent' => PHP_CodeCoverage_Util::percent($classData['executedLines'], $classData['executableLines'], TRUE)), $lowUpperBound, $highLowerBound);
//.........这里部分代码省略.........
示例11: generate
//.........这里部分代码省略.........
dirname(__FILE__),
DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR,
$template
)
);
$origMethodName = $method->getName();
$methodName = ucfirst($origMethodName);
if (isset($this->methodNameCounter[$methodName])) {
$this->methodNameCounter[$methodName]++;
} else {
$this->methodNameCounter[$methodName] = 1;
}
if ($this->methodNameCounter[$methodName] > 1) {
$methodName .= $this->methodNameCounter[$methodName];
}
$methodTemplate->setVar(
array(
'annotation' => trim($annotation),
'arguments' => $matches[1],
'assertion' => isset($assertion) ? $assertion : '',
'expected' => $matches[3],
'origMethodName' => $origMethodName,
'className' => $this->inClassName['fullyQualifiedClassName'],
'methodName' => $methodName
)
);
$methods .= $methodTemplate->render();
$assertAnnotationFound = TRUE;
}
}
}
if (!$assertAnnotationFound) {
$methodTemplate = new Text_Template(
sprintf(
'%s%sTemplate%sIncompleteTestMethod.tpl',
dirname(__FILE__),
DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR
)
);
$methodTemplate->setVar(
array(
'methodName' => ucfirst($method->getName())
)
);
$incompleteMethods .= $methodTemplate->render();
}
}
}
$classTemplate = new Text_Template(
sprintf(
'%s%sTemplate%sTestClass.tpl',
示例12: renderSubsteps
/**
* @param $metaStep
* @param $substepsBuffer
* @return string
*/
protected function renderSubsteps(Meta $metaStep, $substepsBuffer)
{
$metaTemplate = new \Text_Template($this->templatePath . 'substeps.html');
$metaTemplate->setVar(['metaStep' => $metaStep, 'steps' => $substepsBuffer, 'id' => uniqid()]);
return $metaTemplate->render();
}
示例13: generateClassFromWsdl
/**
* @param string $wsdlFile
* @param string $className
* @param array $methods
* @param array $options
*
* @return string
* @throws PHPUnit_Framework_MockObject_RuntimeException
*/
public function generateClassFromWsdl($wsdlFile, $className, array $methods = array(), array $options = array())
{
if ($this->soapLoaded === null) {
$this->soapLoaded = extension_loaded('soap');
}
if ($this->soapLoaded) {
$options = array_merge($options, array('cache_wsdl' => WSDL_CACHE_NONE));
$client = new SoapClient($wsdlFile, $options);
$_methods = array_unique($client->__getFunctions());
unset($client);
sort($_methods);
$templateDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Generator' . DIRECTORY_SEPARATOR;
$methodTemplate = new Text_Template($templateDir . 'wsdl_method.tpl');
$methodsBuffer = '';
foreach ($_methods as $method) {
$nameStart = strpos($method, ' ') + 1;
$nameEnd = strpos($method, '(');
$name = substr($method, $nameStart, $nameEnd - $nameStart);
if (empty($methods) || in_array($name, $methods)) {
$args = explode(',', substr($method, $nameEnd + 1, strpos($method, ')') - $nameEnd - 1));
$numArgs = count($args);
for ($i = 0; $i < $numArgs; $i++) {
$args[$i] = substr($args[$i], strpos($args[$i], '$'));
}
$methodTemplate->setVar(array('method_name' => $name, 'arguments' => join(', ', $args)));
$methodsBuffer .= $methodTemplate->render();
}
}
$optionsBuffer = 'array(';
foreach ($options as $key => $value) {
$optionsBuffer .= $key . ' => ' . $value;
}
$optionsBuffer .= ')';
$classTemplate = new Text_Template($templateDir . 'wsdl_class.tpl');
$namespace = '';
if (strpos($className, '\\') !== false) {
$parts = explode('\\', $className);
$className = array_pop($parts);
$namespace = 'namespace ' . join('\\', $parts) . ';' . "\n\n";
}
$classTemplate->setVar(array('namespace' => $namespace, 'class_name' => $className, 'wsdl' => $wsdlFile, 'options' => $optionsBuffer, 'methods' => $methodsBuffer));
return $classTemplate->render();
} else {
throw new PHPUnit_Framework_MockObject_RuntimeException('The SOAP extension is required to generate a mock object ' . 'from WSDL.');
}
}
示例14: endRun
/**
* Handler for 'end run' event.
*
*/
protected function endRun()
{
$scenarioHeaderTemplate = new \Text_Template($this->templatePath . 'scenario_header.html');
$status = !$this->failed ? '<span style="color: green">OK</span>' : '<span style="color: red">FAILED</span>';
$scenarioHeaderTemplate->setVar(array('name' => 'Codeception Results', 'status' => $status, 'time' => round($this->timeTaken, 1)));
$header = $scenarioHeaderTemplate->render();
$scenariosTemplate = new \Text_Template($this->templatePath . 'scenarios.html');
$scenariosTemplate->setVar(array('header' => $header, 'scenarios' => $this->scenarios, 'successfulScenarios' => $this->successful, 'failedScenarios' => $this->failed, 'skippedScenarios' => $this->skipped, 'incompleteScenarios' => $this->incomplete));
$this->write($scenariosTemplate->render());
}
示例15: render
/**
* renders the test object to real PHP code
*
* @return string
*/
public function render()
{
$nsMappings = Configuration::getInstance()->getNamespaceMappings();
if ($this->getNamespace() !== null && $this->getNamespace() != "") {
$nsName = null;
if (isset($nsMappings[$this->getNamespace()])) {
$nsName = $nsMappings[$this->getNamespace()];
} else {
$nsOriginal = null;
$nsTester = null;
foreach ($nsMappings as $nsOrig => $nsTest) {
if (0 === strpos($this->getNamespace(), $nsOrig)) {
$nsOriginal = $nsOrig;
$nsTester = $nsTest;
break;
}
}
if ($nsOriginal !== null && $nsTester !== null) {
$nsName = str_replace($nsOriginal, $nsTester, $this->getNamespace());
}
}
if ($nsName !== null) {
$ns = "\nnamespace " . $nsName . ";";
$ns .= "\nuse " . $this->getNamespace() . ";";
} else {
$ns = "\nnamespace " . $this->getNamespace() . ";";
}
} else {
$ns = "";
}
$methods = "";
foreach ($this->getWriteableTestedMethods() as $testedMethodContent) {
$methods .= $testedMethodContent . "\n";
}
$tpl = new \Text_Template(\PhpUnitTestGenerator\Resource\Helper::getTemplateFileByName($this->getTestClassTemplate()));
$tpl->setVar(array('namespace' => $ns, 'testClassName' => $this->getClassname(), 'className' => '\\' . $this->getOriginalFullClassName(), 'baseTestClass' => $this->getBaseClass(), 'methods' => $methods, 'constructorArgs' => $this->getConstructorArgs()));
return $tpl->render();
}