| 1 |
<?php |
| 2 |
/** |
| 3 |
* This file is part of the Peast package |
| 4 |
* |
| 5 |
* (c) Marco Marchiò <[email protected]> |
| 6 |
* |
| 7 |
* For the full copyright and license information refer to the LICENSE file |
| 8 |
* distributed with this source code |
| 9 |
*/ |
| 10 |
namespace Peast\Syntax\Node\JSX; |
| 11 |
|
| 12 |
use Peast\Syntax\Node\Node; |
| 13 |
use Peast\Syntax\Node\Expression; |
| 14 |
|
| 15 |
/** |
| 16 |
* A node that represents a JSX element. |
| 17 |
* |
| 18 |
* @author Marco Marchiò <[email protected]> |
| 19 |
*/ |
| 20 |
class JSXElement extends Node implements Expression |
| 21 |
{ |
| 22 |
/** |
| 23 |
* Map of node properties |
| 24 |
* |
| 25 |
* @var array |
| 26 |
*/ |
| 27 |
protected $propertiesMap = array( |
| 28 |
"openingElement" => true, |
| 29 |
"children" => true, |
| 30 |
"closingElement" => true |
| 31 |
); |
| 32 |
|
| 33 |
/** |
| 34 |
* Opening element node |
| 35 |
* |
| 36 |
* @var JSXOpeningElement |
| 37 |
*/ |
| 38 |
protected $openingElement; |
| 39 |
|
| 40 |
/** |
| 41 |
* Children nodes array |
| 42 |
* |
| 43 |
* @var Node[] |
| 44 |
*/ |
| 45 |
protected $children = array(); |
| 46 |
|
| 47 |
/** |
| 48 |
* Closing element node |
| 49 |
* |
| 50 |
* @var JSXClosingElement|null |
| 51 |
*/ |
| 52 |
protected $closingElement; |
| 53 |
|
| 54 |
/** |
| 55 |
* Returns the opening element node |
| 56 |
* |
| 57 |
* @return JSXOpeningElement |
| 58 |
*/ |
| 59 |
public function getOpeningElement() |
| 60 |
{ |
| 61 |
return $this->openingElement; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Sets the opening element node |
| 66 |
* |
| 67 |
* @param JSXOpeningElement $openingElement Opening element node |
| 68 |
* |
| 69 |
* @return $this |
| 70 |
*/ |
| 71 |
public function setOpeningElement(JSXOpeningElement $openingElement) |
| 72 |
{ |
| 73 |
$this->openingElement = $openingElement; |
| 74 |
return $this; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Returns the children nodes array |
| 79 |
* |
| 80 |
* @return Node[] |
| 81 |
*/ |
| 82 |
public function getChildren() |
| 83 |
{ |
| 84 |
return $this->children; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Sets the children nodes array |
| 89 |
* |
| 90 |
* @param Node[] $children Children nodes array |
| 91 |
* |
| 92 |
* @return $this |
| 93 |
*/ |
| 94 |
public function setChildren($children) |
| 95 |
{ |
| 96 |
$this->assertArrayOf($children, array( |
| 97 |
"JSX\\JSXText", "JSX\\JSXExpressionContainer", "JSX\\JSXSpreadChild", |
| 98 |
"JSX\\JSXElement", "JSX\\JSXFragment" |
| 99 |
)); |
| 100 |
$this->children = $children; |
| 101 |
return $this; |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Returns the closing element node |
| 106 |
* |
| 107 |
* @return JSXClosingElement|null |
| 108 |
*/ |
| 109 |
public function getClosingElement() |
| 110 |
{ |
| 111 |
return $this->closingElement; |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Sets the closing element node |
| 116 |
* |
| 117 |
* @param JSXClosingElement|null $closingElement Closing element node |
| 118 |
* |
| 119 |
* @return $this |
| 120 |
*/ |
| 121 |
public function setClosingElement($closingElement) |
| 122 |
{ |
| 123 |
$this->assertType($closingElement, "JSX\\JSXClosingElement", true); |
| 124 |
$this->closingElement = $closingElement; |
| 125 |
return $this; |
| 126 |
} |
| 127 |
} |