class Comment
Same name in this branch
- 11.1.x vendor/egulias/email-validator/src/Parser/Comment.php \Egulias\EmailValidator\Parser\Comment
- 11.1.x vendor/egulias/email-validator/src/Warning/Comment.php \Egulias\EmailValidator\Warning\Comment
- 11.1.x vendor/nikic/php-parser/lib/PhpParser/Comment.php \PhpParser\Comment
- 11.1.x vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/Comment.php \SlevomatCodingStandard\Helpers\Comment
- 11.1.x vendor/squizlabs/php_codesniffer/src/Tokenizers/Comment.php \PHP_CodeSniffer\Tokenizers\Comment
- 11.1.x core/modules/comment/src/Plugin/migrate/source/d6/Comment.php \Drupal\comment\Plugin\migrate\source\d6\Comment
- 11.1.x core/modules/comment/src/Plugin/migrate/source/d7/Comment.php \Drupal\comment\Plugin\migrate\source\d7\Comment
- 11.1.x core/modules/comment/src/Plugin/views/wizard/Comment.php \Drupal\comment\Plugin\views\wizard\Comment
- 11.1.x core/modules/comment/src/Entity/Comment.php \Drupal\comment\Entity\Comment
A node that represents a comment.
@author Marco Marchiò <marco.mm89@gmail.com>
Hierarchy
- class \Peast\Syntax\Node\Node implements \Peast\Syntax\Node\JSONSerializable
- class \Peast\Syntax\Node\Comment extends \Peast\Syntax\Node\Node
Expanded class hierarchy of Comment
1 file declares its use of Comment
- Renderer.php in vendor/
mck89/ peast/ lib/ Peast/ Renderer.php
115 string references to 'Comment'
- AuthorNameFormatter::isApplicable in core/
modules/ comment/ src/ Plugin/ Field/ FieldFormatter/ AuthorNameFormatter.php - Returns if the formatter can be used for the provided field.
- comment.info.yml in core/
modules/ comment/ comment.info.yml - core/modules/comment/comment.info.yml
- comment.migrate_drupal.yml in core/
modules/ comment/ migrations/ state/ comment.migrate_drupal.yml - core/modules/comment/migrations/state/comment.migrate_drupal.yml
- comment.routing.yml in core/
modules/ comment/ comment.routing.yml - core/modules/comment/comment.routing.yml
- comment.type.comment.yml in core/
profiles/ standard/ config/ install/ comment.type.comment.yml - core/profiles/standard/config/install/comment.type.comment.yml
File
-
vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Node/ Comment.php, line 17
Namespace
Peast\Syntax\NodeView source
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;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
Comment::$kind | protected | property | The comment kind | ||
Comment::$propertiesMap | protected | property | Map of node properties | Overrides Node::$propertiesMap | |
Comment::$text | protected | property | The comment text | ||
Comment::getKind | public | function | Returns the comment kind | ||
Comment::getRawText | public | function | Returns the comment raw text | ||
Comment::getText | public | function | Returns the comment text | ||
Comment::jsonSerialize | public | function | Returns a serializable version of the node | Overrides Node::jsonSerialize | |
Comment::KIND_HASHBANG | constant | Hashbang comment | |||
Comment::KIND_HTML_CLOSE | constant | Html close comment | |||
Comment::KIND_HTML_OPEN | constant | Html open comment | |||
Comment::KIND_INLINE | constant | Inline comment | |||
Comment::KIND_MULTILINE | constant | Multiline comment | |||
Comment::setKind | public | function | Sets the comment kind | ||
Comment::setLeadingComments | public | function | Sets leading comments array | Overrides Node::setLeadingComments | |
Comment::setRawText | public | function | Sets the comment raw text | ||
Comment::setText | public | function | Sets the comment text | ||
Comment::setTrailingComments | public | function | Sets trailing comments array | Overrides Node::setTrailingComments | |
Node::$leadingComments | protected | property | Leading comments array | ||
Node::$location | public | property | Node location in the source code | ||
Node::$trailingComments | protected | property | Trailing comments array | ||
Node::assertArrayOf | protected | function | Asserts that the given value is an array of defined type | ||
Node::assertType | protected | function | Asserts that the given value respects the defined type | ||
Node::getLeadingComments | public | function | Returns leading comments array | ||
Node::getLocation | public | function | Returns node location in the source code | ||
Node::getTrailingComments | public | function | Returns trailing comments array | ||
Node::getType | public | function | Returns node type | 2 | |
Node::render | public | function | Renders the current node | ||
Node::setEndPosition | public | function | Sets the end position of the node in the source code | ||
Node::setStartPosition | public | function | Sets the start position of the node in the source code | ||
Node::traverse | public | function | Traverses the current node and all its child nodes using the given function |
||
Node::typeError | protected | function | Throws an error if the defined type is not supported b | ||
Node::__construct | public | function | Class constructor |