Comment.php
Same filename in this branch
- 11.1.x vendor/egulias/email-validator/src/Parser/Comment.php
- 11.1.x vendor/egulias/email-validator/src/Warning/Comment.php
- 11.1.x vendor/nikic/php-parser/lib/PhpParser/Comment.php
- 11.1.x vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/Comment.php
- 11.1.x vendor/squizlabs/php_codesniffer/src/Tokenizers/Comment.php
- 11.1.x core/modules/comment/src/Plugin/migrate/source/d6/Comment.php
- 11.1.x core/modules/comment/src/Plugin/migrate/source/d7/Comment.php
- 11.1.x core/modules/comment/src/Plugin/views/wizard/Comment.php
- 11.1.x core/modules/comment/src/Entity/Comment.php
Namespace
Peast\Syntax\NodeFile
-
vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Node/ Comment.php
View source
<?php
/**
* This file is part of the Peast package
*
* (c) Marco Marchiò <marco.mm89@gmail.com>
*
* For the full copyright and license information refer to the LICENSE file
* distributed with this source code
*/
namespace Peast\Syntax\Node;
/**
* A node that represents a comment.
*
* @author Marco Marchiò <marco.mm89@gmail.com>
*/
class Comment extends Node {
//Comment kind constants
/**
* Inline comment
*/
const KIND_INLINE = "inline";
/**
* Multiline comment
*/
const KIND_MULTILINE = "multiline";
/**
* Html open comment
*/
const KIND_HTML_OPEN = "html-open";
/**
* Html close comment
*/
const KIND_HTML_CLOSE = "html-close";
/**
* Hashbang comment
*/
const KIND_HASHBANG = "hashbang";
/**
* Map of node properties
*
* @var array
*/
protected $propertiesMap = array(
"kind" => false,
"text" => false,
);
/**
* The comment kind
*
* @var string
*/
protected $kind;
/**
* The comment text
*
* @var string
*/
protected $text;
/**
* Returns the comment kind
*
* @return string
*/
public function getKind() {
return $this->kind;
}
/**
* Sets the comment kind
*
* @param string $kind Comment kind
*
* @return $this
*/
public function setKind($kind) {
$this->kind = $kind;
return $this;
}
/**
* Returns the comment text
*
* @return string
*/
public function getText() {
return $this->text;
}
/**
* Sets the comment text
*
* @param string $text Comment text
*
* @return $this
*/
public function setText($text) {
$this->text = $text;
return $this;
}
/**
* Returns the comment raw text
*
* @return string
*/
public function getRawText() {
$text = $this->getText();
$kind = $this->getKind();
if ($kind === self::KIND_MULTILINE) {
$sanitize = "*/";
}
else {
$sanitize = array(
"\n",
"\r",
);
}
$text = str_replace($sanitize, "", $text);
if ($kind === self::KIND_INLINE) {
return "//" . $text;
}
elseif ($kind === self::KIND_HASHBANG) {
return "#!" . $text;
}
elseif ($kind === self::KIND_HTML_OPEN) {
return "<!--" . $text;
}
elseif ($kind === self::KIND_HTML_CLOSE) {
return "-->" . $text;
}
else {
return "/*" . $text . "*/";
}
}
/**
* Sets the comment raw text
*
* @param string $rawText Comment raw text
*
* @return $this
*/
public function setRawText($rawText) {
$start = substr($rawText, 0, 2);
if ($start === "//") {
$kind = self::KIND_INLINE;
$text = substr($rawText, 2);
}
elseif ($start === "/*" && substr($rawText, -2) === "*/") {
$kind = self::KIND_MULTILINE;
$text = substr($rawText, 2, -2);
}
elseif ($start === "#!") {
$kind = self::KIND_HASHBANG;
$text = substr($rawText, 2);
}
elseif ($start === "<!" && substr($rawText, 2, 2) === "--") {
$kind = self::KIND_HTML_OPEN;
$text = substr($rawText, 4);
}
elseif ($start === "--" && substr($rawText, 2, 1) === ">") {
$kind = self::KIND_HTML_CLOSE;
$text = substr($rawText, 3);
}
else {
throw new \Exception("Invalid comment");
}
return $this->setKind($kind)
->setText($text);
}
/**
* Sets leading comments array
*
* @param Comment[] $comments Comments array
*
* @return $this
*/
public function setLeadingComments($comments) {
//Comments cannot be attached to other comments
return $this;
}
/**
* Sets trailing comments array
*
* @param Comment[] $comments Comments array
*
* @return $this
*/
public function setTrailingComments($comments) {
//Comments cannot be attached to other comments
return $this;
}
/**
* Returns a serializable version of the node
*
* @return array
*/
public function jsonSerialize() {
$ret = parent::jsonSerialize();
unset($ret["leadingComments"]);
unset($ret["trailingComments"]);
return $ret;
}
}
Classes
Title | Deprecated | Summary |
---|---|---|
Comment | A node that represents a comment. |