Debian Codegraph @

vendor/mck89/peast/lib/Peast/Syntax/Node/Program.php

raw
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 use Peast\Query;
13 use Peast\Selector;
14
15 /**
16 * Root node for scripts and modules.
17 *
18 * @author Marco Marchiò <[email protected]>
19 */
20 class Program extends Node
21 {
22 /**
23 * Map of node properties
24 *
25 * @var array
26 */
27 protected $propertiesMap = array(
28 "body" => true,
29 "sourceType" => false
30 );
31
32 /**
33 * Source type that is one of the source type constants in the Peast class
34 *
35 * @var string
36 */
37 protected $sourceType = \Peast\Peast::SOURCE_TYPE_SCRIPT;
38
39 /**
40 * Program's body
41 *
42 * @var Statement[]|ModuleDeclaration[]
43 */
44 protected $body = array();
45
46 /**
47 * Returns the source type that is one of the source type constants in the
48 * Peast class
49 *
50 * @return string
51 */
52 public function getSourceType()
53 {
54 return $this->sourceType;
55 }
56
57 /**
58 * Sets the source type that is one of the source type constants in the
59 * Peast class
60 *
61 * @param string $sourceType Source type
62 *
63 * @return $this
64 */
65 public function setSourceType($sourceType)
66 {
67 $this->sourceType = $sourceType;
68 return $this;
69 }
70
71 /**
72 * Returns the program's body
73 *
74 * @return Statement[]|ModuleDeclaration[]
75 */
76 public function getBody()
77 {
78 return $this->body;
79 }
80
81 /**
82 * Sets the program's body
83 *
84 * @param Statement[]|ModuleDeclaration[] $body Program's body
85 *
86 * @return $this
87 */
88 public function setBody($body)
89 {
90 $this->assertArrayOf($body, array("Statement", "ModuleDeclaration"));
91 $this->body = $body;
92 return $this;
93 }
94
95 /**
96 * Finds nodes matching the given selector.
97 *
98 * @param string $selector Selector
99 * @param array $options Options array. See Query class
100 * documentation for available options
101 *
102 * @return Query
103 *
104 * @throws Selector\Exception
105 */
106 public function query($selector, $options = array())
107 {
108 $query = new Query($this, $options);
109 return $query->find($selector);
110 }
111 }