本文整理汇总了PHP中Symfony\CS\Tokenizer\Token::setContent方法的典型用法代码示例。如果您正苦于以下问题:PHP Token::setContent方法的具体用法?PHP Token::setContent怎么用?PHP Token::setContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\CS\Tokenizer\Token
的用法示例。
在下文中一共展示了Token::setContent方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fixWhitespace
private function fixWhitespace(Token $token)
{
$content = $token->getContent();
if (substr_count($content, "\n") > 1) {
$lines = Utils::splitLines($content);
$token->setContent("\n" . end($lines));
}
}
示例2: setContent
public function setContent($content)
{
$currentContent = $this->getContent();
parent::setContent($content);
if ($currentContent !== $content) {
$this->messages = array();
}
}
示例3: fixWhitespace
/**
* Cleanup a whitespace token.
*
* @param Token $token
*/
private function fixWhitespace(Token $token)
{
$content = $token->getContent();
// if there is more than one new line in the whitespace, then we need to fix it
if (substr_count($content, "\n") > 1) {
// the final bit of the whitespace must be the next statement's indentation
$lines = Utils::splitLines($content);
$token->setContent("\n" . end($lines));
}
}
示例4: process
/**
* {@inheritdoc}
*/
public function process(Tokens $tokens, Token $token, $index)
{
if (!$token->isComment()) {
return;
}
$content = $token->getContent();
$trimmedContent = rtrim($content);
// nothing trimmed, nothing to do
if ($content === $trimmedContent) {
return;
}
$whitespaces = substr($content, strlen($trimmedContent));
$token->setContent($trimmedContent);
if (isset($tokens[$index + 1]) && $tokens[$index + 1]->isGivenKind(T_WHITESPACE)) {
$tokens[$index + 1]->setContent($whitespaces . $tokens[$index + 1]->getContent());
} else {
$tokens->insertAt($index + 1, new Token(array(T_WHITESPACE, $whitespaces)));
}
}
示例5: fixWhitespace
private function fixWhitespace(Token $token)
{
if ($token->isWhitespace(array('whitespaces' => " \t"))) {
$token->setContent(' ');
}
}
示例6: testIsEmpty
public function testIsEmpty()
{
$braceToken = $this->getBraceToken();
$this->assertFalse($braceToken->isEmpty());
$braceToken->setContent('');
$this->assertTrue($braceToken->isEmpty());
$whitespaceToken = new Token(array(T_WHITESPACE, ' '));
$this->assertFalse($whitespaceToken->isEmpty());
$whitespaceToken->setContent('');
$this->assertTrue($whitespaceToken->isEmpty());
$whitespaceToken->override(array(null, ''));
$this->assertTrue($whitespaceToken->isEmpty());
$whitespaceToken = new Token(array(T_WHITESPACE, ' '));
$whitespaceToken->clear();
$this->assertTrue($whitespaceToken->isEmpty());
}
示例7: fixWhitespace
private function fixWhitespace(Token $token)
{
if ($token->isWhitespace() && !$token->isWhitespace(" \t")) {
$token->setContent(rtrim($token->getContent()) . ' ');
}
}
示例8: convertToNowdoc
/**
* Transforms the heredoc start token to nowdoc notation.
*
* @param Token $token
*/
private function convertToNowdoc(Token $token)
{
$token->setContent(preg_replace('/(?<=^<<<)"?(.*?)"?$/', '\'$1\'', $token->getContent()));
}
示例9: fixWhitespace
/**
* If given token is a single line whitespace then fix it to be a single space.
*
* @param Token $token
*/
private function fixWhitespace(Token $token)
{
if ($token->isWhitespace(" \t")) {
$token->setContent(' ');
}
}