11<?php
22
33use Contentstack \Support \Utility ;
4+ use Contentstack \Error \ErrorMessages ;
45
56if (!function_exists ('contentstackGetFunctionName ' )) {
67 /*
@@ -40,7 +41,7 @@ function contentstackCreateError($msg = '') {
4041 * */
4142 function contentstackSearch ($ operator = '' , $ query = array (), $ value = '' ) {
4243 if (!(!Utility::isEmpty ($ value ) && is_string ($ value )))
43- throw contentstackCreateError (' Invalid input for " ' . contentstackGetFunctionName (). ' ". String value expected. ' );
44+ throw contentstackCreateError (ErrorMessages:: formatMessage (ErrorMessages:: INVALID_STRING_INPUT , contentstackGetFunctionName ()) );
4445 $ query [$ operator ] = $ value ;
4546 return $ query ;
4647 }
@@ -57,7 +58,7 @@ function contentstackSearch($operator = '', $query = array(), $value = '') {
5758 * */
5859 function contentstackReferences ($ operator = '' , $ query = array (), $ value = array ()) {
5960 if (!is_array ($ value ))
60- throw contentstackCreateError (' Invalid input for includeReferences. Array expected. ' );
61+ throw contentstackCreateError (ErrorMessages:: INVALID_INCLUDE_REFERENCES );
6162 $ query [$ operator ] = $ value ;
6263 return $ query ;
6364 }
@@ -77,7 +78,7 @@ function contentstackProjection($operator = '', $query = array(), $level = 'BASE
7778 $ value = $ level ;
7879 $ level = 'BASE ' ;
7980 }
80- if (!(!Utility::isEmpty ($ level ) && is_string ($ level ) && is_array ($ value ))) throw contentstackCreateError (' Invalid Input ' );
81+ if (!(!Utility::isEmpty ($ level ) && is_string ($ level ) && is_array ($ value ))) throw contentstackCreateError (ErrorMessages:: INVALID_INPUT_TYPE );
8182 if (!Utility::isKeySet ($ query , $ operator )) $ query [$ operator ] = array ();
8283 if (!Utility::isKeySet ($ query [$ operator ], $ level )) $ query [$ operator ][$ level ] = array ();
8384 $ query [$ operator ][$ level ] = array_merge ($ query [$ operator ][$ level ], $ value );
@@ -100,16 +101,16 @@ function contentstackProjection($operator = '', $query = array(), $level = 'BASE
100101 function contentstackRegexp ($ operator = '' , $ query = array (), $ values = array ()) {
101102 if (count ($ values ) === 2 || count ($ values ) === 3 ) {
102103 if (Utility::isEmpty ($ values [0 ]) && Utility::isEmpty ($ values [1 ]) && is_string ($ values [0 ]) && is_string ($ values [1 ]))
103- throw contentstackCreateError (' Invalid input for regex.Key must be string and value must be valid RegularExpression ' );
104+ throw contentstackCreateError (ErrorMessages:: INVALID_REGEX_KEY_VALUE );
104105 if (isset ($ values [2 ]) && !(is_string ($ values [2 ]) && strlen ($ values [2 ]) > 0 )) {
105- throw contentstackCreateError (' Invalid options for regex. Please provide the valid options ' );
106+ throw contentstackCreateError (ErrorMessages:: INVALID_REGEX_OPTIONS );
106107 }
107108 $ query [$ values [0 ]] = array ($ operator => $ values [1 ]);
108109 if (isset ($ values [2 ]))
109110 $ query [$ values [0 ]]['$options ' ] = $ values [2 ];
110111 return $ query ;
111112 } else {
112- throw contentstackCreateError (' Invalid input for regex. At least 2 or maximum 3 arguments are required. ' );
113+ throw contentstackCreateError (ErrorMessages:: INVALID_REGEX_ARGS );
113114 }
114115 }
115116}
@@ -126,7 +127,7 @@ function contentstackRegexp($operator = '', $query = array(), $values = array())
126127 * */
127128 function contentstackTags ($ operator = '' , $ query = array (), $ value = '' ) {
128129 if (!(is_array ($ value ) && count ($ value ) > 0 ))
129- throw contentstackCreateError (' Invalid input for tags.Value must be valid array of tags ' );
130+ throw contentstackCreateError (ErrorMessages:: INVALID_TAGS_INPUT );
130131 $ query [$ operator ] = $ value ;
131132 return $ query ;
132133 }
@@ -146,7 +147,7 @@ function contentstackTags($operator = '', $query = array(), $value = '') {
146147 * */
147148 function contentstackComparision ($ operator = '' , $ query = array (), $ key = '' , $ value = '' ) {
148149 if (!(!Utility::isEmpty ($ key ) && is_string ($ key ) && !Utility::isEmpty ($ value )))
149- throw contentstackCreateError (' Invalid input for " ' . contentstackGetFunctionName (). ' ". Key must be string and value should be valid not empty. ' );
150+ throw contentstackCreateError (ErrorMessages:: formatMessage (ErrorMessages:: INVALID_KEY_VALUE , contentstackGetFunctionName ()) );
150151 $ query [$ key ] = array ($ operator => $ value );
151152 return $ query ;
152153 }
@@ -165,7 +166,7 @@ function contentstackComparision($operator = '', $query = array(), $key = '', $v
165166 * */
166167 function contentstackLogical ($ operator = '' , $ query = array (), $ value = array ()) {
167168 if (!(is_array ($ value ) && count ($ value ) > 0 ))
168- throw contentstackCreateError (' Invalid input for " ' . contentstackGetFunctionName (). ' ". At least one Query or array object is expected ' );
169+ throw contentstackCreateError (ErrorMessages:: formatMessage (ErrorMessages:: INVALID_QUERY_INPUT , contentstackGetFunctionName ()) );
169170 foreach ($ value as $ key => $ _qry ) {
170171 if (!Utility::isKeySet ($ query , $ operator )) $ query [$ operator ] = array ();
171172 if ($ _qry instanceof \Contentstack \Stack \BaseQuery)
@@ -174,7 +175,7 @@ function contentstackLogical($operator = '', $query = array(), $value = array())
174175 array_push ($ query [$ operator ], $ _qry );
175176 else {
176177 unset($ query [$ operator ]);
177- throw contentstackCreateError (' Query objects are expected as arguments ' );
178+ throw contentstackCreateError (ErrorMessages:: INVALID_QUERY_OBJECTS );
178179 }
179180 }
180181 return $ query ;
@@ -194,7 +195,7 @@ function contentstackLogical($operator = '', $query = array(), $value = array())
194195 * */
195196 function contentstackContains ($ operator = '' , $ query = array (), $ key = '' , $ value = array ()) {
196197 if (!(!Utility::isEmpty ($ key ) && is_string ($ key ) && is_array ($ value )))
197- throw contentstackCreateError (' Invalid input for " ' . contentstackGetFunctionName (). ' ". Key should be string and value must be array. ' );
198+ throw contentstackCreateError (ErrorMessages:: formatMessage (ErrorMessages:: INVALID_KEY_ARRAY_VALUE , contentstackGetFunctionName ()) );
198199 $ query [$ key ] = array ($ operator => $ value );
199200 return $ query ;
200201 }
@@ -212,7 +213,7 @@ function contentstackContains($operator = '', $query = array(), $key = '', $valu
212213 * */
213214 function contentstackPagination ($ operator = '' , $ query = array (), $ value = '' ) {
214215 if (!(!Utility::isEmpty ($ value ) && is_numeric ($ value )))
215- throw contentstackCreateError (' Invalid input for " ' . contentstackGetFunctionName (). ' ", it should be Numeric. ' );
216+ throw contentstackCreateError (ErrorMessages:: formatMessage (ErrorMessages:: INVALID_NUMERIC_INPUT , contentstackGetFunctionName ()) );
216217 $ query [$ operator ] = $ value ;
217218 return $ query ;
218219 }
@@ -231,7 +232,7 @@ function contentstackPagination($operator = '', $query = array(), $value = '') {
231232 function contentstackLanguage ($ operator = '' , $ query = array (), $ value = '' ) {
232233
233234 if (!(!Utility::isEmpty ($ value ) && is_string ($ value )))
234- throw contentstackCreateError (' Invalid input for " ' . contentstackGetFunctionName (). ' ", it should be String. ' );
235+ throw contentstackCreateError (ErrorMessages:: formatMessage (ErrorMessages:: INVALID_STRING_INPUT , contentstackGetFunctionName ()) );
235236 $ query [$ operator ] = $ value ;
236237 return $ query ;
237238 }
@@ -249,7 +250,7 @@ function contentstackLanguage($operator = '', $query = array(), $value = '') {
249250 * */
250251 function contentstackSorting ($ operator = '' , $ query = array (), $ key = '' ) {
251252 if (!(!Utility::isEmpty ($ key ) && is_string ($ key )))
252- throw contentstackCreateError (' Invalid input for " ' . contentstackGetFunctionName (). ' ". Value should be valid field in entry ' );
253+ throw contentstackCreateError (ErrorMessages:: formatMessage (ErrorMessages:: INVALID_FIELD_INPUT , contentstackGetFunctionName ()) );
253254 $ query [$ operator ] = $ key ;
254255 return $ query ;
255256 }
@@ -300,7 +301,7 @@ function contentstackAddParam($key = '', $query = array(), $value = '') {
300301 * */
301302 function contentstackExistence ($ operator = '' , $ query = array (), $ key = '' , $ value = false ) {
302303 if (!(!Utility::isEmpty ($ key ) && is_string ($ key )))
303- throw contentstackCreateError (' Invalid input for " ' . contentstackGetFunctionName (). ' ". Key should be valid String field uid ' );
304+ throw contentstackCreateError (ErrorMessages:: formatMessage (ErrorMessages:: INVALID_FIELD_UID , contentstackGetFunctionName ()) );
304305 $ query [$ key ] = array ($ operator => $ value );
305306 return $ query ;
306307 }
0 commit comments