3232 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3333 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3434 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35- *
35+ *
3636 * @author André Rothe <andre.rothe@phosco.info>
3737 * @copyright 2010-2014 Justin Swanhart and André Rothe
3838 * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
@@ -56,34 +56,42 @@ class PHPSQLParser {
5656 public $ parsed ;
5757
5858 /**
59- * Constructor. It simply calls the parse() function.
59+ * @var Options
60+ */
61+ private $ options ;
62+
63+ /**
64+ * Constructor. It simply calls the parse() function.
6065 * Use the public variable $parsed to get the output.
61- *
62- * @param String $sql The SQL statement.
63- * @param boolean $calcPositions True, if the output should contain [position], false otherwise.
66+ *
67+ * @param String|bool $sql The SQL statement.
68+ * @param bool $calcPositions True, if the output should contain [position], false otherwise.
69+ * @param array $options
6470 */
65- public function __construct ($ sql = false , $ calcPositions = false ) {
71+ public function __construct ($ sql = false , $ calcPositions = false , array $ options = []) {
72+ $ this ->options = new Options ($ options );
73+
6674 if ($ sql ) {
6775 $ this ->parse ($ sql , $ calcPositions );
6876 }
6977 }
7078
7179 /**
72- * It parses the given SQL statement and generates a detailled
73- * output array for every part of the statement. The method can
74- * also generate [position] fields within the output, which hold
75- * the character position for every statement part. The calculation
80+ * It parses the given SQL statement and generates a detailled
81+ * output array for every part of the statement. The method can
82+ * also generate [position] fields within the output, which hold
83+ * the character position for every statement part. The calculation
7684 * of the positions needs some time, if you don't need positions in
7785 * your application, set the parameter to false.
78- *
86+ *
7987 * @param String $sql The SQL statement.
8088 * @param boolean $calcPositions True, if the output should contain [position], false otherwise.
81- *
89+ *
8290 * @return array An associative array with all meta information about the SQL statement.
8391 */
8492 public function parse ($ sql , $ calcPositions = false ) {
8593
86- $ processor = new DefaultProcessor ();
94+ $ processor = new DefaultProcessor ($ this -> options );
8795 $ queries = $ processor ->process ($ sql );
8896
8997 // calc the positions of some important tokens
@@ -99,9 +107,9 @@ public function parse($sql, $calcPositions = false) {
99107
100108 /**
101109 * Add a custom function to the parser. no return value
102- *
110+ *
103111 * @param String $token The name of the function to add
104- *
112+ *
105113 * @return null
106114 */
107115 public function addCustomFunction ($ token ) {
@@ -110,9 +118,9 @@ public function addCustomFunction($token) {
110118
111119 /**
112120 * Remove a custom function from the parser. no return value
113- *
121+ *
114122 * @param String $token The name of the function to remove
115- *
123+ *
116124 * @return null
117125 */
118126 public function removeCustomFunction ($ token ) {
@@ -121,8 +129,8 @@ public function removeCustomFunction($token) {
121129
122130 /**
123131 * Returns the list of custom functions
124- *
125- * @return array Returns an array of all custom functions
132+ *
133+ * @return array Returns an array of all custom functions
126134 */
127135 public function getCustomFunctions () {
128136 return PHPSQLParserConstants::getInstance ()->getCustomFunctions ();
0 commit comments