| 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; |
| 11 |
|
| 12 |
/** |
| 13 |
* A node that represents a method declaration in classes and object literals. |
| 14 |
* |
| 15 |
* @author Marco Marchiò <[email protected]> |
| 16 |
*/ |
| 17 |
class MethodDefinition extends Node |
| 18 |
{ |
| 19 |
/** |
| 20 |
* Map of node properties |
| 21 |
* |
| 22 |
* @var array |
| 23 |
*/ |
| 24 |
protected $propertiesMap = array( |
| 25 |
"key" => true, |
| 26 |
"value" => true, |
| 27 |
"kind" => false, |
| 28 |
"computed" => false, |
| 29 |
"static" => false |
| 30 |
); |
| 31 |
|
| 32 |
//Kind constants |
| 33 |
/** |
| 34 |
* Constructor method |
| 35 |
*/ |
| 36 |
const KIND_CONSTRUCTOR = "constructor"; |
| 37 |
|
| 38 |
/** |
| 39 |
* Standard method |
| 40 |
*/ |
| 41 |
const KIND_METHOD = "method"; |
| 42 |
|
| 43 |
/** |
| 44 |
* Getter method |
| 45 |
*/ |
| 46 |
const KIND_GET = "get"; |
| 47 |
|
| 48 |
/** |
| 49 |
* Setter method |
| 50 |
*/ |
| 51 |
const KIND_SET = "set"; |
| 52 |
|
| 53 |
/** |
| 54 |
* Method's key |
| 55 |
* |
| 56 |
* @var Expression|PrivateIdentifier |
| 57 |
*/ |
| 58 |
protected $key; |
| 59 |
|
| 60 |
/** |
| 61 |
* Method's value |
| 62 |
* |
| 63 |
* @var FunctionExpression |
| 64 |
*/ |
| 65 |
protected $value; |
| 66 |
|
| 67 |
/** |
| 68 |
* Method's kind that is one of the kind constants |
| 69 |
* |
| 70 |
* @var string |
| 71 |
*/ |
| 72 |
protected $kind = self::KIND_METHOD; |
| 73 |
|
| 74 |
/** |
| 75 |
* Computed flag that is true if method's key is declared using square |
| 76 |
* brackets syntax |
| 77 |
* |
| 78 |
* @var bool |
| 79 |
*/ |
| 80 |
protected $computed = false; |
| 81 |
|
| 82 |
/** |
| 83 |
* Static flag that is true if the method is static |
| 84 |
* |
| 85 |
* @var bool |
| 86 |
*/ |
| 87 |
protected $static = false; |
| 88 |
|
| 89 |
/** |
| 90 |
* Returns the method's key |
| 91 |
* |
| 92 |
* @return Expression|PrivateIdentifier |
| 93 |
*/ |
| 94 |
public function getKey() |
| 95 |
{ |
| 96 |
return $this->key; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Sets the method's key |
| 101 |
* |
| 102 |
* @param Expression|PrivateIdentifier $key Method's key |
| 103 |
* |
| 104 |
* @return $this |
| 105 |
*/ |
| 106 |
public function setKey($key) |
| 107 |
{ |
| 108 |
$this->assertType($key, array("Expression", "PrivateIdentifier")); |
| 109 |
$this->key = $key; |
| 110 |
return $this; |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Returns the method's value |
| 115 |
* |
| 116 |
* @return FunctionExpression |
| 117 |
*/ |
| 118 |
public function getValue() |
| 119 |
{ |
| 120 |
return $this->value; |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Sets the method's value |
| 125 |
* |
| 126 |
* @param FunctionExpression $value Method's value |
| 127 |
* |
| 128 |
* @return $this |
| 129 |
*/ |
| 130 |
public function setValue(FunctionExpression $value) |
| 131 |
{ |
| 132 |
$this->value = $value; |
| 133 |
return $this; |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Returns the method's kind that is one of the kind constants |
| 138 |
* |
| 139 |
* @return string |
| 140 |
*/ |
| 141 |
public function getKind() |
| 142 |
{ |
| 143 |
return $this->kind; |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Sets the method's kind that is one of the kind constants |
| 148 |
* |
| 149 |
* @param string $kind Method's kind |
| 150 |
* |
| 151 |
* @return $this |
| 152 |
*/ |
| 153 |
public function setKind($kind) |
| 154 |
{ |
| 155 |
$this->kind = $kind; |
| 156 |
return $this; |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Returns the computed flag that is true if method's key is declared using |
| 161 |
* square brackets syntax |
| 162 |
* |
| 163 |
* @return bool |
| 164 |
*/ |
| 165 |
public function getComputed() |
| 166 |
{ |
| 167 |
return $this->computed; |
| 168 |
} |
| 169 |
|
| 170 |
/** |
| 171 |
* Sets the computed flag that is true if method's key is declared using |
| 172 |
* square brackets syntax |
| 173 |
* |
| 174 |
* @param bool $computed Computed flag |
| 175 |
* |
| 176 |
* @return $this |
| 177 |
*/ |
| 178 |
public function setComputed($computed) |
| 179 |
{ |
| 180 |
$this->computed = (bool) $computed; |
| 181 |
return $this; |
| 182 |
} |
| 183 |
|
| 184 |
/** |
| 185 |
* Returns the static flag that is true if the method is static |
| 186 |
* |
| 187 |
* @return bool |
| 188 |
*/ |
| 189 |
public function getStatic() |
| 190 |
{ |
| 191 |
return $this->{"static"}; |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Sets the static flag that is true if the method is static |
| 196 |
* |
| 197 |
* @param bool $static Static flag |
| 198 |
* |
| 199 |
* @return $this |
| 200 |
*/ |
| 201 |
public function setStatic($static) |
| 202 |
{ |
| 203 |
$this->{"static"} = (bool) $static; |
| 204 |
return $this; |
| 205 |
} |
| 206 |
} |