William Candillon has proposed merging lp:~zorba-coders/zorba/phpapi into
lp:zorba.
Requested reviews:
Matthias Brantner (matthias-brantner)
David Graf (davidagraf)
Rodolfo Ochoa (rodolfo-ochoa)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/phpapi/+merge/86856
This merge adds the PHP API that was introduced at the PHP Tour 2011.
It contains a test for it (php2).
It also fix issues with the PHP include paths to ease the deployment of the API
into PHP apps.
The two key tests are:
- php1
- php2
--
https://code.launchpad.net/~zorba-coders/zorba/phpapi/+merge/86856
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'doc/php/examples/CMakeLists.txt'
--- doc/php/examples/CMakeLists.txt 2011-08-19 00:03:31 +
+++ doc/php/examples/CMakeLists.txt 2011-12-24 16:33:26 +
@@ -20,14 +20,21 @@
MESSAGE(STATUS "PHP Path:" ${phpPath})
SET(phpExtensionPath ${CMAKE_BINARY_DIR}/swig/php)
MESSAGE(STATUS "PHP Extension Path: " ${phpExtensionPath})
+ SET(phpIncludePath ${CMAKE_BINARY_DIR}/swig/php)
+ MESSAGE(STATUS "PHP Include Path: " ${phpExtensionPath})
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/php.ini.in ${CMAKE_CURRENT_BINARY_DIR}/php.ini)
MESSAGE(STATUS "Configuration file: " ${CMAKE_CURRENT_BINARY_DIR}/php.ini)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/simple.php.in ${CMAKE_CURRENT_BINARY_DIR}/simple.php)
MESSAGE(STATUS "Simple configuration file: " ${CMAKE_CURRENT_BINARY_DIR}/simple.php)
- ADD_TEST("php" ${PHP5_EXECUTABLE} -c ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/simple.php)
+ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test.php.in ${CMAKE_CURRENT_BINARY_DIR}/test.php)
+ MESSAGE(STATUS "PHP test file configured: " ${CMAKE_CURRENT_BINARY_DIR}/test.php)
+ ADD_TEST("php1" ${PHP5_EXECUTABLE} -c ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/simple.php)
MESSAGE(STATUS "Installing: " ${CMAKE_CURRENT_BINARY_DIR}/simple.php)
-
- INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/simple.php
+ ADD_TEST("php2" ${PHP5_EXECUTABLE} -c ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/test.php)
+ MESSAGE(STATUS "Installing: " ${CMAKE_CURRENT_BINARY_DIR}/test.php)
+
+
+ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/simple.php ${CMAKE_CURRENT_BINARY_DIR}/test.php
COMPONENT "php_examples"
DESTINATION
share/doc/zorba-${ZORBA_MAJOR_NUMBER}.${ZORBA_MINOR_NUMBER}.${ZORBA_PATCH_NUMBER}/php/examples)
=== modified file 'doc/php/examples/php.ini.in'
--- doc/php/examples/php.ini.in 2009-10-30 16:34:37 +
+++ doc/php/examples/php.ini.in 2011-12-24 16:33:26 +
@@ -1,2 +1,3 @@
enable_dl=On
extension_dir=@phpExtensionPath@
+include_path=".:@phpIncludePath@"
\ No newline at end of file
=== modified file 'doc/php/examples/simple.php.in'
--- doc/php/examples/simple.php.in 2011-08-04 02:14:56 +
+++ doc/php/examples/simple.php.in 2011-12-24 16:33:26 +
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-require '@phpPath@/zorba_api_wrapper.php';
+require '@phpPath@/Zorba/zorba_api_wrapper.php';
function example_1(Zorba $aZorba)
{
=== added file 'doc/php/examples/test.php.in'
--- doc/php/examples/test.php.in 1970-01-01 00:00:00 +
+++ doc/php/examples/test.php.in 2011-12-24 16:33:26 +
@@ -0,0 +1,69 @@
+http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+require '@phpPath@/Zorba/XQueryProcessor.php';
+
+function omitXMLDecl($xml)
+{
+ $xml = str_replace('', '', $xml);
+ $xml = trim($xml);
+ return $xml;
+}
+
+function assertEquality($test, $reference, $label)
+{
+
+ if($test == $reference) {
+throw new Exception(
+ "Test "
+ . $label
+ . " failed. Result:\n"
+ . $test
+ . "\nDoesn't match reference:\n"
+ . $reference
+);
+ }
+}
+/* Test 1 */
+$xquery = new XQueryProcessor();
+$xquery->importQuery('1+1');
+$result = $xquery->execute();
+assertEquality($result, '2', "1+1");
+
+/* Test 2 */
+$query = <<<'XQ'
+declare variable $foo as xs:string external;
+declare variable $bar as xs:integer external;
+declare variable $doc1 as document-node() external;
+declare variable $doc2 as document-node() external;
+
+$foo, $bar, $doc1, $doc2
+XQ;
+
+$xquery->importQuery($query);
+
+$xquery->setVariable("foo", "bar");
+$xquery->setVariable("bar", 3);
+
+$doc = simplexml_load_string('');
+$xquery->setVariable("doc1", $doc);
+
+$doc = $xquery->parseXML("");
+$xquery->setVariable("doc2", $doc);
+
+$result = trim($xquery->execute());
+assertEquality($result, "bar 3", "Scalar Types");
+?>
=== modified file 'swig/php/CMakeLists.txt'
--- swig/php/CMa