本文整理汇总了PHP中Text_Template::setVar方法的典型用法代码示例。如果您正苦于以下问题:PHP Text_Template::setVar方法的具体用法?PHP Text_Template::setVar怎么用?PHP Text_Template::setVar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Text_Template
的用法示例。
在下文中一共展示了Text_Template::setVar方法的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: render
/**
* @param FileNode $node
* @param string $file
*/
public function render(FileNode $node, $file)
{
$template = new \Text_Template($this->templatePath . 'file.html', '{{', '}}');
$template->setVar(['items' => $this->renderItems($node), 'lines' => $this->renderSource($node)]);
$this->setCommonTemplateVariables($template, $node);
$template->renderTo($file);
}
示例3: render
/**
* @param PHP_CodeCoverage_Report_Node_File $node
* @param string $file
*/
public function render(PHP_CodeCoverage_Report_Node_File $node, $file)
{
$template = new Text_Template($this->templatePath . 'file.html', '{{', '}}');
$template->setVar(array('items' => $this->renderItems($node), 'lines' => $this->renderSource($node)));
$this->setCommonTemplateVariables($template, $node);
$template->renderTo($file);
}
示例4: 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();
}
示例5: 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;
}
示例6: 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());
}
示例7: 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");
}
}
示例8: prepareTemplate
/**
* Define constants after including files.
*/
function prepareTemplate(Text_Template $template)
{
$template->setVar(array('constants' => ''));
$template->setVar(array('wp_constants' => PHPUnit_Util_GlobalState::getConstantsAsString()));
parent::prepareTemplate($template);
}
示例9: renderDashboard
/**
* @param PHP_CodeCoverage_Report_HTML_Node_Directory $root
* @param string $file
* @param string $title
*/
protected function renderDashboard(PHP_CodeCoverage_Report_HTML_Node_Directory $root, $file, $title)
{
$classes = $this->classes($root);
$template = new Text_Template(PHP_CodeCoverage_Report_HTML::$templatePath . 'dashboard.html');
$template->setVar(array('title' => $title, 'charset' => $this->options['charset'], 'date' => date('D M j G:i:s T Y', $_SERVER['REQUEST_TIME']), 'version' => '@package_version@', 'php_version' => PHP_VERSION, 'generator' => $this->options['generator'], 'least_tested_methods' => $this->leastTestedMethods($classes), 'top_project_risks' => $this->topProjectRisks($classes), 'cc_values' => $this->classComplexity($classes), 'ccd_values' => $this->classCoverageDistribution($classes), 'backlink' => basename(str_replace('.dashboard', '', $file))));
$template->renderTo($file);
}
示例10: prepareTemplate
/**
* we need process isolation to prevent "headers already sent"
*
* but process isolation triggers another error, because phpunit tries to load all previously included files
* where throw_exception.php should not be called
*
* however disabled globalState prevents constants in bootstrap.php to be loaded
*
* that is why we need this ugly hack method
*
* @param \Text_Template $template
*/
protected function prepareTemplate(\Text_Template $template)
{
$template->setVar(array('iniSettings' => '', 'constants' => '', 'included_files' => '', 'globals' => '$GLOBALS[\'__PHPUNIT_BOOTSTRAP\'] = ' . var_export($GLOBALS['__PHPUNIT_BOOTSTRAP'], TRUE) . ";\n"));
}
示例11: 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);
//.........这里部分代码省略.........
示例12: getLine
/**
* Cleans and returns a line. Removes php tag added to make highlight-string
* work
*
* @param unknown_type $traceline
* @param unknown_type $relativePosition
* @param unknown_type $style
* @return Ambigous <string, mixed>
*/
protected function getLine($traceline, $relativePosition, $style = 'normal')
{
$line = new \Text_Template($this->templateDir() . '/Line.html.dist');
$code = str_replace(array('<span style="color: #0000BB"><?php </span>', '<code>', '</code>'), '', highlight_string('<?php ' . Backtrace::readLine($traceline['file'], $traceline['line'] + $relativePosition), true));
$code = preg_replace('/\\n/', '', $code);
$code = preg_replace('/<span style="color: #0000BB"><\\?php (.*)(<\\/span>+?)/', '$1', $code);
$line->setVar(array('line' => $traceline['line'] + $relativePosition, 'class' => $style, 'code' => ' ' . $code));
return $line->render();
}
示例13: run
/**
* Runs the test case and collects the results in a TestResult object.
* If no TestResult object is passed a new one will be created.
*
* @param PHPUnit_Framework_TestResult $result
* @return PHPUnit_Framework_TestResult
* @throws InvalidArgumentException
*/
public function run(PHPUnit_Framework_TestResult $result = NULL)
{
if ($result === NULL) {
$result = $this->createResult();
}
$this->setExpectedExceptionFromAnnotation();
$this->setUseErrorHandlerFromAnnotation();
$this->setUseOutputBufferingFromAnnotation();
if ($this->useErrorHandler !== NULL) {
$oldErrorHandlerSetting = $result->getConvertErrorsToExceptions();
$result->convertErrorsToExceptions($this->useErrorHandler);
}
$this->result = $result;
if (!empty($this->dependencies) && !$this->inIsolation) {
$className = get_class($this);
$passed = $this->result->passed();
$passedKeys = array_keys($passed);
$numKeys = count($passedKeys);
for ($i = 0; $i < $numKeys; $i++) {
$pos = strpos($passedKeys[$i], ' with data set');
if ($pos !== FALSE) {
$passedKeys[$i] = substr($passedKeys[$i], 0, $pos);
}
}
$passedKeys = array_flip(array_unique($passedKeys));
foreach ($this->dependencies as $dependency) {
if (strpos($dependency, '::') === FALSE) {
$dependency = $className . '::' . $dependency;
}
if (!isset($passedKeys[$dependency])) {
$result->addError($this, new PHPUnit_Framework_SkippedTestError(sprintf('This test depends on "%s" to pass.', $dependency)), 0);
return;
} else {
if (isset($passed[$dependency])) {
$this->dependencyInput[] = $passed[$dependency];
} else {
$this->dependencyInput[] = NULL;
}
}
}
}
if ($this->runTestInSeparateProcess === TRUE && $this->inIsolation !== TRUE && !$this instanceof PHPUnit_Extensions_SeleniumTestCase && !$this instanceof PHPUnit_Extensions_PhptTestCase) {
$class = new ReflectionClass($this);
$template = new Text_Template(sprintf('%s%sProcess%sTestCaseMethod.tpl', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
if ($this->preserveGlobalState) {
$constants = PHPUnit_Util_GlobalState::getConstantsAsString();
$globals = PHPUnit_Util_GlobalState::getGlobalsAsString();
$includedFiles = PHPUnit_Util_GlobalState::getIncludedFilesAsString();
} else {
$constants = '';
$globals = '';
$includedFiles = '';
}
if ($result->getCollectCodeCoverageInformation()) {
$coverage = 'TRUE';
} else {
$coverage = 'FALSE';
}
$data = addcslashes(serialize($this->data), "'");
$dependencyInput = addcslashes(serialize($this->dependencyInput), "'");
$includePath = addslashes(get_include_path());
$template->setVar(array('filename' => $class->getFileName(), 'className' => $class->getName(), 'methodName' => $this->name, 'collectCodeCoverageInformation' => $coverage, 'data' => $data, 'dataName' => $this->dataName, 'dependencyInput' => $dependencyInput, 'constants' => $constants, 'globals' => $globals, 'include_path' => $includePath, 'included_files' => $includedFiles));
$this->prepareTemplate($template);
PHPUnit_Util_PHP::runJob($template->render(), $this, $result);
} else {
$result->run($this);
}
if ($this->useErrorHandler !== NULL) {
$result->convertErrorsToExceptions($oldErrorHandlerSetting);
}
$this->result = NULL;
return $result;
}
示例14: generate
/**
* Generates the class' source.
*
* @return mixed
*/
public function generate()
{
$methods = '';
foreach ($this->findTestedMethods() as $method) {
$methodTemplate = new Text_Template(sprintf('%s%sTemplate%sMethod.tpl', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
$methodTemplate->setVar(array('methodName' => $method));
$methods .= $methodTemplate->render();
}
$classTemplate = new Text_Template(sprintf('%s%sTemplate%sClass.tpl', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
$classTemplate->setVar(array('className' => $this->outClassName['fullyQualifiedClassName'], 'methods' => $methods, 'date' => date('Y-m-d'), 'time' => date('H:i:s')));
return $classTemplate->render();
}
示例15: run
/**
* Runs the test case and collects the results in a TestResult object.
* If no TestResult object is passed a new one will be created.
*
* @param PHPUnit_Framework_TestResult $result
* @return PHPUnit_Framework_TestResult
* @throws PHPUnit_Framework_Exception
*/
public function run(PHPUnit_Framework_TestResult $result = NULL)
{
if ($result === NULL) {
$result = $this->createResult();
}
if (!$this instanceof PHPUnit_Framework_Warning) {
$this->setTestResultObject($result);
$this->setUseErrorHandlerFromAnnotation();
$this->setUseOutputBufferingFromAnnotation();
}
if ($this->useErrorHandler !== NULL) {
$oldErrorHandlerSetting = $result->getConvertErrorsToExceptions();
$result->convertErrorsToExceptions($this->useErrorHandler);
}
if (!$this->handleDependencies()) {
return;
}
if ($this->runTestInSeparateProcess === TRUE && $this->inIsolation !== TRUE && !$this instanceof PHPUnit_Extensions_SeleniumTestCase && !$this instanceof PHPUnit_Extensions_PhptTestCase) {
$class = new ReflectionClass($this);
$template = new Text_Template(sprintf('%s%sProcess%sTestCaseMethod.tpl', __DIR__, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
if ($this->preserveGlobalState) {
$constants = PHPUnit_Util_GlobalState::getConstantsAsString();
$globals = PHPUnit_Util_GlobalState::getGlobalsAsString();
$includedFiles = PHPUnit_Util_GlobalState::getIncludedFilesAsString();
} else {
$constants = '';
$globals = '';
$includedFiles = '';
}
if ($result->getCollectCodeCoverageInformation()) {
$coverage = 'TRUE';
} else {
$coverage = 'FALSE';
}
if ($result->isStrict()) {
$strict = 'TRUE';
} else {
$strict = 'FALSE';
}
$data = var_export(serialize($this->data), TRUE);
$dependencyInput = var_export(serialize($this->dependencyInput), TRUE);
$includePath = var_export(get_include_path(), TRUE);
// must do these fixes because TestCaseMethod.tpl has unserialize('{data}') in it, and we can't break BC
// the lines above used to use addcslashes() rather than var_export(), which breaks null byte escape sequences
$data = "'." . $data . ".'";
$dependencyInput = "'." . $dependencyInput . ".'";
$includePath = "'." . $includePath . ".'";
$template->setVar(array('filename' => $class->getFileName(), 'className' => $class->getName(), 'methodName' => $this->name, 'collectCodeCoverageInformation' => $coverage, 'data' => $data, 'dataName' => $this->dataName, 'dependencyInput' => $dependencyInput, 'constants' => $constants, 'globals' => $globals, 'include_path' => $includePath, 'included_files' => $includedFiles, 'strict' => $strict));
$this->prepareTemplate($template);
$php = PHPUnit_Util_PHP::factory();
$php->runJob($template->render(), $this, $result);
} else {
$result->run($this);
}
if ($this->useErrorHandler !== NULL) {
$result->convertErrorsToExceptions($oldErrorHandlerSetting);
}
$this->result = NULL;
return $result;
}