annotate vendor/nikic/php-parser/lib/PhpParser/Internal/PrintableNewAnonClassNode.php @ 13:5fb285c0d0e3

Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've been lucky to get away with this so far, as we don't support self-registration which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5 was vulnerable to.
author Chris Cannam
date Mon, 23 Apr 2018 09:33:26 +0100
parents
children 129ea1e6d783
rev   line source
Chris@13 1 <?php declare(strict_types=1);
Chris@13 2
Chris@13 3 namespace PhpParser\Internal;
Chris@13 4
Chris@13 5 use PhpParser\Node;
Chris@13 6 use PhpParser\Node\Expr;
Chris@13 7
Chris@13 8 /**
Chris@13 9 * This node is used internally by the format-preserving pretty printer to print anonymous classes.
Chris@13 10 *
Chris@13 11 * The normal anonymous class structure violates assumptions about the order of token offsets.
Chris@13 12 * Namely, the constructor arguments are part of the Expr\New_ node and follow the class node, even
Chris@13 13 * though they are actually interleaved with them. This special node type is used temporarily to
Chris@13 14 * restore a sane token offset order.
Chris@13 15 *
Chris@13 16 * @internal
Chris@13 17 */
Chris@13 18 class PrintableNewAnonClassNode extends Expr
Chris@13 19 {
Chris@13 20 /** @var Node\Arg[] Arguments */
Chris@13 21 public $args;
Chris@13 22 /** @var null|Node\Name Name of extended class */
Chris@13 23 public $extends;
Chris@13 24 /** @var Node\Name[] Names of implemented interfaces */
Chris@13 25 public $implements;
Chris@13 26 /** @var Node\Stmt[] Statements */
Chris@13 27 public $stmts;
Chris@13 28
Chris@13 29 public function __construct(
Chris@13 30 array $args, Node\Name $extends = null, array $implements, array $stmts, array $attributes
Chris@13 31 ) {
Chris@13 32 parent::__construct($attributes);
Chris@13 33 $this->args = $args;
Chris@13 34 $this->extends = $extends;
Chris@13 35 $this->implements = $implements;
Chris@13 36 $this->stmts = $stmts;
Chris@13 37 }
Chris@13 38
Chris@13 39 public static function fromNewNode(Expr\New_ $newNode) {
Chris@13 40 $class = $newNode->class;
Chris@13 41 assert($class instanceof Node\Stmt\Class_);
Chris@13 42 assert($class->name === null);
Chris@13 43 return new self(
Chris@13 44 $newNode->args, $class->extends, $class->implements,
Chris@13 45 $class->stmts, $newNode->getAttributes()
Chris@13 46 );
Chris@13 47 }
Chris@13 48
Chris@13 49 public function getType() : string {
Chris@13 50 return 'Expr_PrintableNewAnonClass';
Chris@13 51 }
Chris@13 52
Chris@13 53 public function getSubNodeNames() : array {
Chris@13 54 return ['args', 'extends', 'implements', 'stmts'];
Chris@13 55 }
Chris@13 56 }