Merge lp:~zorba-coders/zorba/phpapi into lp:zorba

Proposed by William Candillon
Status: Superseded
Proposed branch: lp:~zorba-coders/zorba/phpapi
Merge into: lp:zorba
Diff against target: 735 lines (+556/-16)
12 files modified
ChangeLog (+1/-0)
doc/php/CMakeLists.txt (+1/-1)
doc/php/examples/CMakeLists.txt (+11/-4)
doc/php/examples/php.ini.in (+1/-0)
doc/php/examples/simple.php.in (+2/-2)
doc/php/examples/test.php.in (+120/-0)
doc/php/examples/zorba_api.php (+1/-1)
swig/php/CMakeLists.txt (+19/-6)
swig/php/XQueryProcessor.php (+397/-0)
swig/php/generate_proxy.php.in (+1/-1)
swig/php/test.xq (+1/-0)
swig/php/zorba_api.i (+1/-1)
To merge this branch: bzr merge lp:~zorba-coders/zorba/phpapi
Reviewer Review Type Date Requested Status
Rodolfo Ochoa Approve
Matthias Brantner Needs Fixing
David Graf Pending
Review via email: mp+88713@code.launchpad.net

This proposal supersedes a proposal from 2012-01-12.

This proposal has been superseded by a proposal from 2012-01-17.

Description of the change

This merge adds the PHP API that was introduced at the PHP Tour 2011.
It contains a test for it (php2).

From the last merge proposal, the following things have been done:
- Revert bogus change in swig/php/generate_proxy.php.in (renaming of libPrefix to prefix).
- Introduce a STD Iterator for streaming results.
- Make the parseXML() method private.
- Improve importQueryFromURI

The two key tests are:
- php1
- php2

To post a comment you must log in.
Revision history for this message
Matthias Brantner (matthias-brantner) wrote : Posted in a previous version of this proposal

- One thing that I don't understand is the relationship with the existing PHP binding.
- The first three changes in swig/php/generate_proxy.php.in should be reverted (renaming of libPrefix to prefix)
- executeToURI is only capable of writing to files. Also, it currently doesn't stream.
- importQueryFromURI only works for file URIs.
- The parse functionality should probably be removed. It merges two functionalities which don't really belong together (retrieving of data and parsing xml). The latter can also be done in XQuery. If this philosophy is to push more functionality into XQuery, the parse functionality should be removed or made symmetric to the existing C++ and XQuery data manager APIs.
- getItem doesn't have a comment and is incomplete. Shouldn't it support more/all XQuery types?

review: Needs Fixing
Revision history for this message
William Candillon (wcandillon) wrote : Posted in a previous version of this proposal

> - One thing that I don't understand is the relationship with the existing PHP binding.
The low level API enables us to extend/debug the XQueryProcessor API more easily.

> - The first three changes in swig/php/generate_proxy.php.in should be reverted (renaming of libPrefix to prefix)
This is fixed in commit 10597.

> - executeToURI is only capable of writing to files. Also, it currently doesn't stream.
This is fixed in commit 10598.

> - importQueryFromURI only works for file URIs.
This is fixed in commit 10600. There is a test for it in commit 10601.

> - The parse functionality should probably be removed. It merges two functionalities which don't really belong together (retrieving of data and parsing xml). The latter can also be done in XQuery. If this philosophy is to push more functionality into XQuery, the parse functionality should be removed or made symmetric to the existing C++ and XQuery data manager APIs.

This is fixed in commit 10598. Unfortunately there two orthogonal things in commit 10598.

> - getItem doesn't have a comment and is incomplete. Shouldn't it support more/all XQuery types?
It should support any kind of PHP type. Currently objects are not supported. Maybe in the futur we will introduce support for objects.

Revision history for this message
Matthias Brantner (matthias-brantner) wrote : Posted in a previous version of this proposal

Here are some more comments and questions:

* Copyright 2006-2008 The FLWOR Foundation.
=> * Copyright 2006-2012 The FLWOR Foundation.

* Iterate over an instance of the XML Data Model (i.e, a sequence of items).
* This class implements the SPL Iterator interface.

You can only iterate over a sequence of instances of the XDM. The sequence
is not an instance by itself.

* The XQueryProcessor class allows to invoke
* <a href="http://www.zorba-xquery.com">Zorba XQuery Processor</a>.

to invoke _the_ ...

* Instruction to install the extension can be found at <a href=""></a>.

Instruction_s_

* Shutdowns

Shuts down

* In the following code snippet, the following code snippets imports and execute an <em>Hello World</em> query:

confusing sentence

* Import a query to execute from its filename.

Import a query to execute from a file with the given name.

* $xquery->importQueryiFromURI('hello_world.xq');

$xquery->importQueryFromURI('hello_world.xq');

* Filename of the query to execute.

Filename containing the query to execute.

* Set value for an external variable.

Set a value for an external variable.

* The following code snippet sets the value of the variable
* <em>$i</em> with <em>1</em>.

The following code snippet sets the value of the variable
<em>$i</em> to <em>1</em> with type xs:integer.

* The following code snippet sets the value of the variable <em>$i</em> in
* the local namespace with the value <em>1</em>.

The following code snippet sets the value of the variable <em>$i</em> in
the local namespace to the value <em>1</em>.

getIterator and compile() don't have comments. Also, the indentation of compile() and getItem() seem to be broken

Why do you repeat the conversion rules from setVariable in the comment of getItem. Why does one rule include SimpleXMLElement and the other one doesn't?

Did you drop the streaming execution for execute()? If so, why?

review: Needs Fixing
Revision history for this message
William Candillon (wcandillon) wrote : Posted in a previous version of this proposal

Copyright statements are updated in r10603.
All the typos you sent are fixed in r10604.
PHPDoc docs comments are added for compile() and getIterator() in r10605.
The indentation of the compile() and getItem() is fixed in r10606.
r10607 is a fix for the duplicate and inconsistent description of the PHP to XQuery type mapping.
William finds out about IteratorAggregate in r10608 (http://php.net/manual/en/class.iteratoraggregate.php).

Revision history for this message
Matthias Brantner (matthias-brantner) wrote : Posted in a previous version of this proposal

- Is it on purpose that the only thing that is returned by the iterator is a serialized version of the item? For example, this will return an error for attribute nodes.

- There is a tab at the beginning of

  /**
   * Internal

- Is this wrapper supposed to be merged before the implementation of execute() can stream?

review: Needs Information
Revision history for this message
William Candillon (wcandillon) wrote : Posted in a previous version of this proposal

> - Is it on purpose that the only thing that is returned by the iterator is a
> serialized version of the item? For example, this will return an error for
> attribute nodes.
Yes.
We have two use cases for XQPHP:
- The mobile app which uses execute().
- The google earth demo which uses the iterator.

>
> - There is a tab at the beginning of
>
> /**
> * Internal
>
> - Is this wrapper supposed to be merged before the implementation of execute()
> can stream?
Yes

Revision history for this message
William Candillon (wcandillon) wrote : Posted in a previous version of this proposal

This new proposal is removing unwanted tabs.

Revision history for this message
Matthias Brantner (matthias-brantner) wrote : Posted in a previous version of this proposal

I'm fine with it now. Before merging, please make sure the change is contained in the ChangeLog. Also, don't mention the obsolete comment in the description or commit message "- Revert bogus change in swig/php/generate_proxy.php.in (renaming of libPrefix to prefix).".

As an aside, importQueryFromURI still allows file system access only. I saw that the comment mentions that but it's still strange.

Revision history for this message
William Candillon (wcandillon) wrote : Posted in a previous version of this proposal

importQueryFromURI() can read any kind of stream and there is even a test for it.
It is commented out so the php tests don't rely on http connections.

Revision history for this message
William Candillon (wcandillon) wrote :

I've updated the changelog.

Revision history for this message
Matthias Brantner (matthias-brantner) wrote :

When I tried it, I was confused about the return value of the iterator. I think it deserves a comment that it return the string value of the current item.

Also a minor typo:

 The following code snippets imports and execute an <em>Hello World</em> query:
=>
 The following code snippets imports and execute_s a_ <em>Hello World</em> query:

review: Needs Fixing
Revision history for this message
Rodolfo Ochoa (rodolfo-ochoa) :
review: Approve
lp:~zorba-coders/zorba/phpapi updated
10619. By Markos Zaharioudakis

Fixed bug 917923 (bug in copying outer var values into the eval dynamic context) Approved: Markos Zaharioudakis

10620. By Gabriel Petrovay

Added Ctrl-C hooking in the debugger. Ctrl-C can not kill the debugger anymore. It will only stop the running query. Approved: David Graf, Gabriel Petrovay

10621. By William Candillon

This merge adds the PHP API that was introduced at the PHP Tour 2011. Approved: Rodolfo Ochoa, William Candillon

10622. By Chris Hillery

This merge adds the PHP API that was introduced at the PHP Tour 2011. Approved: Rodolfo Ochoa, William Candillon

10623. By Sorin Marian Nasoi <email address hidden>

Added the information about the Zorba module version in the generated XQDoc documentation. Approved: William Candillon, Sorin Marian Nasoi

10624. By Markos Zaharioudakis

fix for bug #919189 Approved: Markos Zaharioudakis

10625. By Markos Zaharioudakis

fix for bug #866423 Approved: Markos Zaharioudakis

10626. By Matthias Brantner

fn:serialize avoids copying the result but returns a streamable string instead Approved: Till Westmann, Matthias Brantner

10627. By Matthias Brantner

Implemented StaticContext::getNamespaceBindings to resolve bug #905035. In the same commit, the function getNamespaceURIByPrefix was deprecated because it's superseded by the new function. Approved: Rodolfo Ochoa, Markos Zaharioudakis

10628. By Markos Zaharioudakis

fix for bug #866932 (string pool not empty on shutdown)
 Approved: Markos Zaharioudakis

10629. By Chris Hillery

Remove test case sc3_ex3 in order to merge the removal of the non-core JSON module. sc3_ex3 will be re-added along with the core JSON module. Approved: Paul J. Lucas, Chris Hillery

10630. By Markos Zaharioudakis

More types-related optimizations for the comparison operators Approved: Markos Zaharioudakis

10631. By Markos Zaharioudakis

Fixed bug involving positional var and groupby Approved: Markos Zaharioudakis

10632. By Chris Hillery

- updated the import scripts to use the latest version of XQTS, XQUTS and XQFTTS as of 25.01.2012
- added EXPECTED_FAILURES for XQFTTS XQuery and XQueryX tests
- updated the W3C conformance documentation
- included fix for the XQFTTS XQueryX tests created by Daniel in lp:~zorba-coders/zorba/xqueryx_fulltext branch Approved: Chris Hillery, Sorin Marian Nasoi

10633. By Markos Zaharioudakis

type-related optimizagtions of boolean iterators Approved: Markos Zaharioudakis

10634. By Paul J. Lucas

Migrated several unit tests to libunittest. Approved: Chris Hillery, Paul J. Lucas

10635. By Chris Hillery

Fix filename when creating library for unversioned module. Approved: Dennis Knochenwefel, Chris Hillery

10636. By Markos Zaharioudakis

type-related optimizations for sequence-type iterators Approved: Markos Zaharioudakis

10637. By Paul J. Lucas

Fixed bug 924063 (sentence is incorrectly incremented when token characters end without sentence terminator) Approved: Matthias Brantner, Paul J. Lucas

10638. By Chris Hillery

Install the XHTML DTD locally so we don't ask w3.org for it. Approved: Chris Hillery, Sorin Marian Nasoi

10639. By Chris Hillery

Added DECLARE_ZORBA_URI_FILE() for installing files of any type that we would like to load by URI. Also made built-in URI mappers look on the filesystem for any kind of URIs, not just modules and schemas. Approved: Cezar Andrei, Chris Hillery

10640. By Daniel Turcanu

several fixes for the plan serializer + implemented materialize_clause::clone() Approved: Matthias Brantner, Chris Hillery

10641. By Markos Zaharioudakis

w3c test modules-schema-context now passes Approved: Markos Zaharioudakis

10642. By Ghislain Fourny

Correcting two typos (parameter name and document debug output). Approved: Ghislain Fourny, Matthias Brantner

10643. By William Candillon

Fix for bug #918592 Approved: Chris Hillery, Rodolfo Ochoa

10644. By Chris Hillery

Several fixes related to test breakages caused by zorba-xquery.com changes:
1. Don't attempt HTTP resolution w/ HttpStream if Zorba compiled without CURL.
2. store/example_3 test: load content from zorbatest site like other tests.
3. fetch_bogus2 and impot5 test: change "ver" test module to be identified with a flworfound.org URI, so we'll get a 404 when loading it wrong. (Both example.com and zorba-xquery.com don't return 404 for unknown URLs.)
 Approved: Matthias Brantner, Chris Hillery

10645. By Rodolfo Ochoa

Added recognition for URIs without authority, this is a JAVA URI case. Approved: Rodolfo Ochoa, Cezar Andrei

10646. By Rodolfo Ochoa

added
#include "stdafx.h"

and changed uri_util.h having
ZORBA_DLL_PUBLIC extern char const uri_safe[];
ZORBA_DLL_PUBLIC extern signed char const hex2dec[]; Approved: Cezar Andrei, Matthias Brantner

10647. By Sorin Marian Nasoi <email address hidden>

Downloaded the latest version of the W3C Working Draft 13 December 2011for XQuery 3.0 F&O to be used in test "xquery_3_0". Approved: Juan Zacarias, Sorin Marian Nasoi

10648. By Ghislain Fourny

Using GET_PUL_FACTORY macro. Approved: Markos Zaharioudakis

10649. By Markos Zaharioudakis

optimization for the Item::add/removeReference methods Approved: Markos Zaharioudakis

10650. By Chris Hillery

Ensure same module is not declared twice with the same version number (including twice with no declared version).
 Approved: Sorin Marian Nasoi, Chris Hillery

10651. By Chris Hillery

Download v1.0 of http-client. Approved: Sorin Marian Nasoi, Chris Hillery

10652. By Ghislain Fourny

Made same-directory simple store includes. Approved: Matthias Brantner, Markos Zaharioudakis

10653. By Paul J. Lucas

Simple fix. Approved: William Candillon, Paul J. Lucas

10654. By Markos Zaharioudakis

use SUBSEQUENCE_INT function, instead of SUBSEQUENCE_INT in partial_eval_eq rewrite rule Approved: Markos Zaharioudakis

10655. By Paul J. Lucas

Added clone(). Approved: Matthias Brantner, William Candillon

10656. By Markos Zaharioudakis

small optimization for subsequence iterators Approved: Markos Zaharioudakis

10657. By Markos Zaharioudakis

1. Optimization: preallocate and reuse temp sequence iterator for LetVarITerator and CtxVarIterator.
2. Optimization: enhanced push-down of positional predicate into LetVarITerator and CtxVarIterator. Approved: Markos Zaharioudakis

10658. By Markos Zaharioudakis

Fixed bug #872288 Approved: Markos Zaharioudakis

10659. By Till Westmann

added a new unit test for the plan serializer Approved: Matthias Brantner, Till Westmann

10660. By Markos Zaharioudakis

Fixed bug #867022 Approved: Markos Zaharioudakis

10661. By Markos Zaharioudakis

fix for bug #867266 Approved: Markos Zaharioudakis

10662. By Paul J. Lucas

New JSON parser and module. Approved: Sorin Marian Nasoi, Paul J. Lucas

10663. By Paul J. Lucas

- Added transcode_streambuf
- file:read-text now respects encodings
- http:send-request now respects encodings Approved: Matthias Brantner, Paul J. Lucas

10664. By Markos Zaharioudakis

Optimization: changed the implementation of the free-vars annotation and got rid of the annotations map in expressions Approved: Markos Zaharioudakis

10665. By Matthias Brantner

Put the state file written by the uuid functionality into the system's temp directory (temporary solution). Approved: Till Westmann, Matthias Brantner

10666. By Paul J. Lucas

Fixed return type. Approved: Juan Zacarias, Matthias Brantner, Paul J. Lucas

10667. By Matthias Brantner

added two api functions to introspect the functions of a static context Approved: Till Westmann, Matthias Brantner

10668. By William Candillon <email address hidden>

Fix typos in doxygen documentation. Approved: Cezar Andrei, Matthias Brantner

10669. By William Candillon

Update the XQDDF ebnf to fit with XQuery 3.0 syntax. Approved: William Candillon, Matthias Brantner

10670. By William Candillon

Add support for return and parameters elements in XQDoc. Approved: William Candillon, Sorin Marian Nasoi

10671. By Rodolfo Ochoa

Just some precompiled headers included Approved: Matthias Brantner, Cezar Andrei

10672. By William Candillon

XQuery 3.0 concat operator Approved: Matthias Brantner, William Candillon

10673. By David Graf

Added the new external variable value tests that will be added to the w3c testsuite to the zorba rbkt tests. Inclusive the failing once. Added launchpad entries for them and marked the tests as expected failures. Approved: Matthias Brantner, David Graf

10674. By Chris Hillery

Update data-cleaning module to release 1.0 (fixes conversion tests).
 Approved: Sorin Marian Nasoi, Chris Hillery

10675. By William Candillon

Add --compile-plan and --execute-plan option to zorba command line.
Example:
zorba -q 1+1 --compile-plan > test.xqc
zorba -q test.xqc -f --execute-plan Approved: William Candillon, Matthias Brantner

10676. By Chris Hillery

Error checking for DownloadModules.cmake; try three times on failures.
 Approved: Sorin Marian Nasoi, Chris Hillery

10677. By Matthias Brantner

more efficient implementation of xs:base64Binary items Approved: Till Westmann, Matthias Brantner

10678. By Ghislain Fourny

Makes same-directory store includes in the headers as well. Approved: Till Westmann, Matthias Brantner

10679. By Markos Zaharioudakis

Fixed bug in codegen: do not create a materialize clause if one exists already Approved: Markos Zaharioudakis

10680. By William Candillon

Remove conflicting shortcut -e for --execute-plan option. Approved: Matthias Brantner, William Candillon

10681. By Ghislain Fourny

Replacing ulong positions with xs_integer for positions in collections. Approved: Ghislain Fourny, Matthias Brantner

10682. By Ghislain Fourny

Refactored CollectionSet class. zorba::store::CollectionSet is abstract, zorba::simplestore::SimpleCollectionSet is its implementation for the simple store. Approved: Matthias Brantner, Till Westmann

10683. By Paul J. Lucas

Fixed bug 942808. Approved: Matthias Brantner, Paul J. Lucas

10684. By Markos Zaharioudakis

removed properties-generating scripts and restored zorba_properties.h and store_properties.h files. Approved: Markos Zaharioudakis

10685. By Daniel Turcanu

Making https work on Windows. Approved: Gabriel Petrovay, Sorin Marian Nasoi

10686. By Ghislain Fourny

Refactored QName pool and QNameItem class. Approved: Markos Zaharioudakis

10687. By Sorin Marian Nasoi <email address hidden>

Updated the web crawler tutorial. Approved: Nicolae Brinza, Sorin Marian Nasoi

10688. By William Candillon

Optimize iterator generation for the concat operator (fixes bug #942011) Approved: Matthias Brantner, Markos Zaharioudakis

10689. By Paul J. Lucas

Better implementation of ZORBA_WITH_BIG_INTEGER=OFF: now limited to 63 bits (for a 64-bit implementation of a long long). Also added build_options.dox. Approved: Markos Zaharioudakis, Matthias Brantner

10690. By Markos Zaharioudakis

fixed bug involing eval and the no-copy rule Approved: Markos Zaharioudakis

10691. By Matthias Brantner

fix for bug #943788 (streamable string is not seekable) Approved: Till Westmann, Matthias Brantner

10692. By Federico Cavalieri <federico@M702X>

Fixed bug #912579 (validate-in-place on non-root elements)
Fixed merge of updput primitives
Fixed merge conflict. Approved: Markos Zaharioudakis, Cezar Andrei

10693. By Markos Zaharioudakis

Added test that illustrates bug #944002 Approved: Markos Zaharioudakis

10694. By Markos Zaharioudakis

Fixed another bug involving eval and the no-copy rule Approved: Markos Zaharioudakis

10695. By Paul J. Lucas

Added ~XmlNodeTokenizerCallback() to destroy tokenizers. Approved: Matthias Brantner, Paul J. Lucas

10696. By Ghislain Fourny

Introduces an abstract layer between zorba::store::collection and zorba::simplestore::SimpleCollection. Approved: Matthias Brantner, Markos Zaharioudakis

10697. By Markos Zaharioudakis

fixed bug #944002
 Approved: Markos Zaharioudakis

10698. By Ghislain Fourny

Making two non-abstract functions in simplecollection API also non-virtual. Approved: Matthias Brantner, Markos Zaharioudakis

10699. By Ghislain Fourny

Added default constructors for index classes in simple store. Approved: Markos Zaharioudakis, Matthias Brantner

10700. By Markos Zaharioudakis

Fixed bug #867024 Approved: Markos Zaharioudakis

10701. By Sorin Marian Nasoi <email address hidden>

Fixed bug lp:946896. Approved: William Candillon, Sorin Marian Nasoi

10702. By Markos Zaharioudakis

Fixed memory leak in no-copy rule Approved: Markos Zaharioudakis

10703. By Matthias Brantner

A new module that provides URL-related functions. Currently, it provides functions to do URL-decoding but other URL-related functions (e.g. to retrieve the scheme or path) will be added later. Approved: Matthias Brantner, Chris Hillery

10704. By Markos Zaharioudakis

fixes bug 924987
- extended TypeIdentifier to also support schema-element, schema-attribute
  and namespace-node sequence types
- fixed TypeOps::get_type_identifier
- added a test to the staticcollectionmanager unit test
- added operator<< for TypeIdentifier Approved: Markos Zaharioudakis, Till Westmann

10705. By Paul J. Lucas

Set dispose_data_using_delete_ = false in reserve(). Approved: Markos Zaharioudakis, Matthias Brantner

10706. By Cezar Andrei <email address hidden>

Fix for bug 891209 : validation with xsi:type returns untyped. Approved: Matthias Brantner, Markos Zaharioudakis, Cezar Andrei

10707. By Sorin Marian Nasoi <email address hidden>

- fixed the test 'moduleDocumentation': all modules that appear in ZorbaManifest.xml are checked for correct XQDoc documentation
- re-enabled the 'moduleDocumentation' test that was previously disabled. Approved: Sorin Marian Nasoi, Chris Hillery

10708. By Markos Zaharioudakis

bug fixes: some methods in atomic_item.h should have been virtual + use myChild local var in children iterators" Approved: Markos Zaharioudakis

10709. By Paul J. Lucas

Added links to full-text documentation. Approved: Matthias Brantner, Paul J. Lucas

10710. By Paul J. Lucas

fix Bug #949111: getUnsignedIntValue() not implemented for Integer Approved: Matthias Brantner, Paul J. Lucas

10711. By Paul J. Lucas

Added delete theSerStream; Approved: Matthias Brantner, Paul J. Lucas

10712. By Sorin Marian Nasoi <email address hidden>

Fix for bug lp:948712: Added a way for easy copy&paste of the import schema statements. Approved: Matthias Brantner, Sorin Marian Nasoi

10713. By Matthias Brantner

StaticCollectionManager::declaredIndexes() doesn't return temporary indexes anymore. Also isDeclaredIndex also doesn't return true if asked whether a temporary index is declared. Approved: Till Westmann, Matthias Brantner

10714. By Matthias Brantner

- fix bug #938934 "collection dml:truncate function missing"
- fixes documentation bug: raise zerr:ZDDY0003 instead of zerr:ZDDY0009 Approved: Till Westmann, Markos Zaharioudakis, Matthias Brantner

10715. By Matthias Brantner

fixed bug #951772 Comment node crashes serialization) Approved: William Candillon, Matthias Brantner

10716. By Matthias Brantner

Fixed bug #952829 (Nondeterministic annotation doesn't seem to be checked) Approved: Matthias Brantner, William Candillon

10717. By Rodolfo Ochoa

This fixes the error:
n strings remain in the pool.
and change it to a more comprehensive error with reference to document that helps to prevent the error. Approved: Matthias Brantner, Markos Zaharioudakis, Cezar Andrei

10718. By Markos Zaharioudakis

Fixed bug #948259 Approved: Markos Zaharioudakis

10719. By Ghislain Fourny

Introduced function OrdPathNode::getDescendantNodeByOrdPath (from Sausalito). Approved: Markos Zaharioudakis, Matthias Brantner

10720. By Matthias Brantner

2.2 release preparations Approved: Chris Hillery, Matthias Brantner

10721. By Rodolfo Ochoa

- Fixed bug for PHP wrapper pointing to a wrong DLL name
- Fixed precompiled headers bug
- Fixed warning -> Conversion Int to Bool - Performance warning Approved: Cezar Andrei, William Candillon, Matthias Brantner

10722. By William Candillon

Minor update of the PHP example page.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2012-01-11 17:30:25 +0000
3+++ ChangeLog 2012-01-17 13:34:25 +0000
4@@ -20,6 +20,7 @@
5 * Added split function to the string module that allows for streamable tokenization but doesn't have regular expression
6 support.
7 * zerr is not predeclared anymore to be http://www.zorba-xquery.com/errors
8+ * Add new XQuery interface for the PHP bindings.
9 * Added API method Item::getNamespaceBindings().
10
11 version 2.1
12
13=== modified file 'doc/php/CMakeLists.txt'
14--- doc/php/CMakeLists.txt 2011-06-20 12:44:21 +0000
15+++ doc/php/CMakeLists.txt 2012-01-17 13:34:25 +0000
16@@ -1,4 +1,4 @@
17-# Copyright 2006-2008 The FLWOR Foundation.
18+# Copyright 2006-2012 The FLWOR Foundation.
19 #
20 # Licensed under the Apache License, Version 2.0 (the "License");
21 # you may not use this file except in compliance with the License.
22
23=== modified file 'doc/php/examples/CMakeLists.txt'
24--- doc/php/examples/CMakeLists.txt 2011-08-19 00:03:31 +0000
25+++ doc/php/examples/CMakeLists.txt 2012-01-17 13:34:25 +0000
26@@ -1,4 +1,4 @@
27-# Copyright 2006-2008 The FLWOR Foundation.
28+# Copyright 2006-2012 The FLWOR Foundation.
29 #
30 # Licensed under the Apache License, Version 2.0 (the "License");
31 # you may not use this file except in compliance with the License.
32@@ -20,14 +20,21 @@
33 MESSAGE(STATUS "PHP Path:" ${phpPath})
34 SET(phpExtensionPath ${CMAKE_BINARY_DIR}/swig/php)
35 MESSAGE(STATUS "PHP Extension Path: " ${phpExtensionPath})
36+ SET(phpIncludePath ${CMAKE_BINARY_DIR}/swig/php)
37+ MESSAGE(STATUS "PHP Include Path: " ${phpExtensionPath})
38 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/php.ini.in ${CMAKE_CURRENT_BINARY_DIR}/php.ini)
39 MESSAGE(STATUS "Configuration file: " ${CMAKE_CURRENT_BINARY_DIR}/php.ini)
40 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/simple.php.in ${CMAKE_CURRENT_BINARY_DIR}/simple.php)
41 MESSAGE(STATUS "Simple configuration file: " ${CMAKE_CURRENT_BINARY_DIR}/simple.php)
42- ADD_TEST("php" ${PHP5_EXECUTABLE} -c ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/simple.php)
43+ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test.php.in ${CMAKE_CURRENT_BINARY_DIR}/test.php)
44+ MESSAGE(STATUS "PHP test file configured: " ${CMAKE_CURRENT_BINARY_DIR}/test.php)
45+ ADD_TEST("php1" ${PHP5_EXECUTABLE} -c ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/simple.php)
46 MESSAGE(STATUS "Installing: " ${CMAKE_CURRENT_BINARY_DIR}/simple.php)
47-
48- INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/simple.php
49+ ADD_TEST("php2" ${PHP5_EXECUTABLE} -c ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/test.php)
50+ MESSAGE(STATUS "Installing: " ${CMAKE_CURRENT_BINARY_DIR}/test.php)
51+
52+
53+ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/simple.php ${CMAKE_CURRENT_BINARY_DIR}/test.php
54 COMPONENT "php_examples"
55 DESTINATION
56 share/doc/zorba-${ZORBA_MAJOR_NUMBER}.${ZORBA_MINOR_NUMBER}.${ZORBA_PATCH_NUMBER}/php/examples)
57
58=== modified file 'doc/php/examples/php.ini.in'
59--- doc/php/examples/php.ini.in 2009-10-30 16:34:37 +0000
60+++ doc/php/examples/php.ini.in 2012-01-17 13:34:25 +0000
61@@ -1,2 +1,3 @@
62 enable_dl=On
63 extension_dir=@phpExtensionPath@
64+include_path=".:@phpIncludePath@"
65\ No newline at end of file
66
67=== modified file 'doc/php/examples/simple.php.in'
68--- doc/php/examples/simple.php.in 2011-08-04 02:14:56 +0000
69+++ doc/php/examples/simple.php.in 2012-01-17 13:34:25 +0000
70@@ -1,6 +1,6 @@
71 <?php
72 /*
73- * Copyright 2006-2008 The FLWOR Foundation.
74+ * Copyright 2006-2012 The FLWOR Foundation.
75 *
76 * Licensed under the Apache License, Version 2.0 (the "License");
77 * you may not use this file except in compliance with the License.
78@@ -14,7 +14,7 @@
79 * See the License for the specific language governing permissions and
80 * limitations under the License.
81 */
82-require '@phpPath@/zorba_api_wrapper.php';
83+require '@phpPath@/Zorba/zorba_api_wrapper.php';
84
85 function example_1(Zorba $aZorba)
86 {
87
88=== added file 'doc/php/examples/test.php.in'
89--- doc/php/examples/test.php.in 1970-01-01 00:00:00 +0000
90+++ doc/php/examples/test.php.in 2012-01-17 13:34:25 +0000
91@@ -0,0 +1,120 @@
92+<?php
93+/*
94+ * Copyright 2006-2012 The FLWOR Foundation.
95+ *
96+ * Licensed under the Apache License, Version 2.0 (the "License");
97+ * you may not use this file except in compliance with the License.
98+ * You may obtain a copy of the License at
99+ *
100+ * http://www.apache.org/licenses/LICENSE-2.0
101+ *
102+ * Unless required by applicable law or agreed to in writing, software
103+ * distributed under the License is distributed on an "AS IS" BASIS,
104+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
105+ * See the License for the specific language governing permissions and
106+ * limitations under the License.
107+ */
108+require '@phpPath@/Zorba/XQueryProcessor.php';
109+
110+function omitXMLDecl($xml)
111+{
112+ $xml = str_replace('<?xml version="1.0" encoding="UTF-8"?>', '', $xml);
113+ $xml = trim($xml);
114+ return $xml;
115+}
116+
117+function assertEquality($test, $reference, $label)
118+{
119+ $test = omitXMLDecl($test);
120+ echo "=====================================\n";
121+ var_dump($test);
122+ var_dump($reference);
123+ if($test != $reference) {
124+ throw new Exception(
125+ "Test "
126+ . $label
127+ . " failed. Result:\n"
128+ . $test
129+ . "\nDoesn't match reference:\n"
130+ . $reference
131+ );
132+ }
133+}
134+/* Test 1 */
135+$xquery = new XQueryProcessor();
136+$xquery->importQuery('1+1');
137+$result = $xquery->execute();
138+assertEquality($result, '2', "1+1");
139+
140+/* Test 2 */
141+$query = <<<'XQ'
142+declare variable $foo as xs:string external;
143+declare variable $bar as xs:integer external;
144+declare variable $doc1 as document-node() external;
145+declare variable $doc2-str as xs:string external;
146+declare variable $doc2 as document-node() := parse-xml($doc2-str);
147+
148+$foo, $bar, $doc1 , $doc2
149+XQ;
150+
151+$xquery->importQuery($query);
152+
153+$xquery->setVariable("foo", "bar");
154+$xquery->setVariable("bar", 3);
155+
156+$doc = simplexml_load_string('<root />');
157+$xquery->setVariable("doc1", $doc);
158+
159+$doc = "<root />";
160+$xquery->setVariable("doc2-str", $doc);
161+
162+$result = trim($xquery->execute());
163+assertEquality($result, "bar 3<root/><root/>", "Test PHP Types Mapping");
164+
165+/* Test 3 */
166+$xquery->importQuery("(1, 2, <foo bar='bar' />)");
167+$it = $xquery->getIterator();
168+
169+foreach($it as $pos => $value) {
170+ switch($pos) {
171+ case 0:
172+ assertEquality($value, "1", "Consume the item at position {$pos}");
173+ break;
174+ case 1:
175+ assertEquality($value, "2", "Consume the item at position {$pos}");
176+ break;
177+ case 3:
178+ assertEquality($value, '<foo bar="bar"/>', "Consume the item at position {$pos}");
179+ break;
180+ }
181+}
182+
183+//Let's do it again by leveraging the SPL IteratorAggregate
184+foreach($xquery as $pos => $value) {
185+ switch($pos) {
186+ case 0:
187+ assertEquality($value, "1", "Consume the item at position {$pos}");
188+ break;
189+ case 1:
190+ assertEquality($value, "2", "Consume the item at position {$pos}");
191+ break;
192+ case 3:
193+ assertEquality($value, '<foo bar="bar"/>', "Consume the item at position {$pos}");
194+ break;
195+ }
196+}
197+
198+//Try the same query with execute
199+$result = $xquery->execute();
200+assertEquality($result, "1 2<foo bar=\"bar\"/>", "Execute To URI");
201+
202+/* Test 4 */
203+$xquery->importQueryFromURI("@phpPath@/test.xq");
204+$result = $xquery->execute();
205+assertEquality($result, "2", "Test importQueryFromURI");
206+
207+/* Test 5 */
208+//$xquery->importQueryFromURI("http://zorba.s3.amazonaws.com/test.xq");
209+//$result = $xquery->execute();
210+//assertEquality($result, "2", "Test importQueryFromURI");
211+?>
212
213=== modified file 'doc/php/examples/zorba_api.php'
214--- doc/php/examples/zorba_api.php 2010-01-27 13:25:24 +0000
215+++ doc/php/examples/zorba_api.php 2012-01-17 13:34:25 +0000
216@@ -1,6 +1,6 @@
217 <?php
218 /*
219- * Copyright 2006-2008 The FLWOR Foundation.
220+ * Copyright 2006-2012 The FLWOR Foundation.
221 *
222 * Licensed under the Apache License, Version 2.0 (the "License");
223 * you may not use this file except in compliance with the License.
224
225=== modified file 'swig/php/CMakeLists.txt'
226--- swig/php/CMakeLists.txt 2011-12-21 14:40:33 +0000
227+++ swig/php/CMakeLists.txt 2012-01-17 13:34:25 +0000
228@@ -1,4 +1,4 @@
229-# Copyright 2006-2008 The FLWOR Foundation.
230+# Copyright 2006-2012 The FLWOR Foundation.
231 #
232 # Licensed under the Apache License, Version 2.0 (the "License");
233 # you may not use this file except in compliance with the License.
234@@ -38,6 +38,9 @@
235 SWIG_LINK_LIBRARIES (zorba_api ${PHP5_LIBRARY})
236 ENDIF (WIN32)
237
238+ #Copy test to the build folder
239+ CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/test.xq" "${CMAKE_CURRENT_BINARY_DIR}/test.xq")
240+
241 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../StaticContext.h" "${CMAKE_CURRENT_BINARY_DIR}/StaticContext.h")
242 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../ItemFactory.h" "${CMAKE_CURRENT_BINARY_DIR}/ItemFactory.h")
243
244@@ -55,20 +58,23 @@
245
246 INSTALL (
247 FILES
248- ${CMAKE_CURRENT_BINARY_DIR}/zorba_api_wrapper.php
249+ ${CMAKE_CURRENT_BINARY_DIR}/Zorba/XQueryProcessor.php
250+ ${CMAKE_CURRENT_BINARY_DIR}/Zorba/zorba_api_wrapper.php
251 ${CMAKE_CURRENT_BINARY_DIR}/${ZORBA_SWIG_LIB_PREFIX}zorba_api.so
252 DESTINATION ${PHP5_INSTALL_PATH}
253 )
254 ELSE (NOT WIN32 OR CYGWIN)
255 IF (MSVC_IDE)
256 INSTALL ( FILES
257- ${CMAKE_CURRENT_BINARY_DIR}/zorba_api.php
258+ ${CMAKE_CURRENT_BINARY_DIR}/Zorba/XQueryProcessor.php
259+ ${CMAKE_CURRENT_BINARY_DIR}/Zorba/zorba_api_wrapper.php
260 ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/zorba_api.dll
261 COMPONENT "php_swig"
262 DESTINATION share/php )
263 ELSE (MSVC_IDE)
264 INSTALL ( FILES
265- ${CMAKE_CURRENT_BINARY_DIR}/zorba_api.php
266+ ${CMAKE_CURRENT_BINARY_DIR}/Zorba/XQueryProcessor.php
267+ ${CMAKE_CURRENT_BINARY_DIR}/Zorba/zorba_api_wrapper.php
268 ${CMAKE_CURRENT_BINARY_DIR}/php_zorba_api.dll
269 COMPONENT "php_swig"
270 DESTINATION share/php )
271@@ -77,6 +83,7 @@
272
273 ### Start PHP proxy generation
274 # Configure the test file
275+ SET (phpLibPrefix ${ZORBA_SWIG_LIB_PREFIX})
276 SET (phpAPIPath ${CMAKE_CURRENT_BINARY_DIR})
277 SET (phpLibPrefix ${ZORBA_SWIG_LIB_PREFIX})
278 CONFIGURE_FILE (
279@@ -84,8 +91,13 @@
280 ${CMAKE_CURRENT_BINARY_DIR}/generate_proxy.php
281 )
282
283+ CONFIGURE_FILE (
284+ ${CMAKE_CURRENT_SOURCE_DIR}/XQueryProcessor.php
285+ ${CMAKE_CURRENT_BINARY_DIR}/Zorba/XQueryProcessor.php
286+ )
287+
288 ADD_CUSTOM_COMMAND (
289- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zorba_api_wrapper.php
290+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Zorba/zorba_api_wrapper.php
291 # the following addes a dependency to the *.cxx file that is generated by swig
292 DEPENDS ${swig_generated_file_fullname}
293 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/generate_proxy.php.in
294@@ -94,7 +106,8 @@
295 )
296 ADD_CUSTOM_TARGET (
297 Api_PHP_Wrapper ALL
298- DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/zorba_api_wrapper.php
299+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Zorba/zorba_api_wrapper.php
300+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Zorba/XQueryProcessor.php
301 )
302 ### End PHP proxy generation
303
304
305=== added file 'swig/php/XQueryProcessor.php'
306--- swig/php/XQueryProcessor.php 1970-01-01 00:00:00 +0000
307+++ swig/php/XQueryProcessor.php 2012-01-17 13:34:25 +0000
308@@ -0,0 +1,397 @@
309+<?php
310+require_once 'Zorba/zorba_api_wrapper.php';
311+
312+class XQueryCompilerException extends Exception{}
313+class XQueryProcessorException extends Exception{}
314+
315+/**
316+ * Iterate over a sequence of XQuery items.
317+ * This class implements the SPL Iterator interface.
318+ *
319+ * The following code snippet iterates over a small sequence of items.
320+ * <code>
321+ * <?php
322+ * require_once 'Zorba/XQueryProcessor.php';
323+ *
324+ * $xquery = new XQueryProcessor();
325+ * $xquery->importQuery('(1, 2, 3)');
326+ *
327+ * $iterator = $xquery->getIterator();
328+ * foreach($it as $key => $value) {
329+ * echo $value."\n";
330+ * }
331+ * ?>
332+ * </code>
333+ */
334+class XQueryIterator implements Iterator {
335+
336+ private $xquery = null;
337+ private $iterator = null;
338+ private $item = null;
339+ private $position = 0;
340+ private $valid = false;
341+
342+ /**
343+ * XQueryIterator constructor.
344+ * This constructor is used internally only.
345+ *
346+ * @param XQuery XQuery object.
347+ *
348+ * @see XQueryProcessor::getIterator()
349+ */
350+ public function __construct(XQuery $xquery)
351+ {
352+ $this->xquery = $xquery;
353+ $this->item = Item::createEmptyItem();
354+ }
355+
356+
357+ public function __destruct()
358+ {
359+ $this->xquery->destroy();
360+ }
361+
362+ /**
363+ * Rewinds back to the first item of the Iterator.
364+ */
365+ public function rewind()
366+ {
367+ if ($this->iterator != null) {
368+ $this->iterator->close();
369+ $this->iterator->destroy();
370+ }
371+
372+ $this->position = 0;
373+ $this->iterator = $this->xquery->iterator();
374+ $this->iterator->open();
375+ $this->valid = $this->iterator->next($this->item);
376+ }
377+
378+ /**
379+ * Return the current item serialized as string.
380+ *
381+ * @return string The current item serialized as string.
382+ *
383+ */
384+ public function current()
385+ {
386+ return $this->item->serialize();
387+ }
388+
389+ /**
390+ * Return the position of current item.
391+ *
392+ * @return interger the position of the current item.
393+ */
394+ public function key()
395+ {
396+ return $this->position;
397+ }
398+
399+ /**
400+ * Move forward to the next item
401+ *
402+ */
403+ public function next()
404+ {
405+ ++$this->position;
406+ $this->valid = $this->iterator->next($this->item);
407+ }
408+
409+ /**
410+ * Checks if there are still items to process.
411+ *
412+ * @return boolean Returns true if the iterator has still items to process or false otherwise.
413+ */
414+ public function valid()
415+ {
416+ return $this->valid;
417+ }
418+}
419+
420+/**
421+ * The XQueryProcessor class allows to invoke the
422+ * <a href="http://www.zorba-xquery.com">Zorba XQuery Processor</a>.
423+ *
424+ * Instructions to install the extension can be found at <a href="http://www.zorba-xquery.com/site2/html/php.html">http://www.zorba-xquery.com/site2/html/php.html</a>.
425+ *
426+ * The following code snippet executes a small <em>Hello World</em> program:
427+ * <code>
428+ * <?php
429+ * require_once 'ZorbaXQueryProcessor.php';
430+ *
431+ * $xquery = new XQueryProcessor();
432+ *
433+ * $query = <<<'XQ'
434+ * declare variable $name external;
435+ *
436+ * <h1>Hello {$name}</h1>
437+ * XQ;
438+ *
439+ * $xquery->importQuery($query);
440+ *
441+ * $xquery->setVariable('name', 'World');
442+ *
443+ * echo $xquery->execute();
444+ * ?>
445+ * </code>
446+ */
447+class XQueryProcessor implements IteratorAggregate {
448+
449+ private $store = null;
450+ private $zorba = null;
451+ private $query = null;
452+ private $variables = array();
453+
454+ /**
455+ * Creates an XQueryProcessor instance.
456+ */
457+ public function __construct(){
458+ $this->store = InMemoryStore::getInstance();
459+ $this->zorba = Zorba::getInstance($this->store);
460+ }
461+
462+ /**
463+ * Shuts down the XQueryProcessor instance.
464+ */
465+ public function __destruct() {
466+ $this->zorba->shutdown();
467+ InMemoryStore::shutdown($this->store);
468+ }
469+
470+ /**
471+ * Import a query to execute.
472+ * For instance, the following code snippets imports and executes the query '1+1':
473+ * <code>
474+ * $xquery = new ZorbaXQueryProcessor();
475+ *
476+ * $xquery->importQuery('1+1');
477+ *
478+ * echo $xquery->execute() . '\n';
479+ * </code>
480+ * The following code snippets imports and executes an <em>Hello World</em> query:
481+ * <code>
482+ * <?php
483+ * $xquery = new XQueryProcessor();
484+ *
485+ * $query = <<<'XQ'
486+ * let $world := 'World'
487+ * return <h1>Hello {$world}</h1>
488+ * XQ;
489+ *
490+ * $xquery->importQuery($query);
491+ *
492+ * echo $xquery->execute() . '\n';
493+ * ?>
494+ * </code>
495+ *
496+ * @param $query Query to execute.
497+ * @return ZorbaXQueryProcessor instance.
498+ */
499+ public function importQuery($query) {
500+ if(!is_string($query)) {
501+ throw new XQueryProcessorException('The query parameter must be a string. For instance: XQueryProcessor->importQuery("1+1")');
502+ }
503+ $this->query = $query;
504+ return $this;
505+ }
506+
507+ /**
508+ * Import a query to execute from a file with the given name.
509+ * For instance, the following code snippet imports the query file named <em>hello_word.xq</em>:
510+ * <code>
511+ * $xquery = new ZorbaXQueryProcessor();
512+ *
513+ * $xquery->importQueryFromURI('hello_world.xq');
514+ *
515+ * echo $xquery->execute() . '\n';
516+ * </code>
517+ *
518+ * @param $filename Filename containing the query to execute.
519+ * @return ZorbaXQueryProcessor instance.
520+ */
521+ public function importQueryFromURI($filename) {
522+ $ctx = null;
523+ if(func_num_args() == 2) {
524+ $ctx = func_get_arg(1);
525+ }
526+ $query = file_get_contents($filename, FILE_USE_INCLUDE_PATH, $ctx);
527+ $this->importQuery($query);
528+ return $this;
529+ }
530+
531+ /**
532+ * Set a value for an external variable.
533+ *
534+ * The following code snippet sets the value of the variable
535+ * <em>$i</em> with <em>1</em> with type xs:integer.
536+ * <code>
537+ * $xquery = new ZorbaXQueryProcessor();
538+ *
539+ * $query = <<<'XQ'
540+ * declare variable $i as xs:integer external;
541+ *
542+ * $i + 1
543+ * 'XQ';
544+ *
545+ * $xquery->importQuery($query);
546+ * $xquery->setVariable($i, 1);
547+ *
548+ * echo $xquery->execute() . '\n';
549+ * </code>
550+ *
551+ * The following code snippet sets the value of the variable <em>$i</em> in
552+ * the local namespace to the value <em>1</em>.
553+ * <code>
554+ * $xquery = new ZorbaXQueryProcessor();
555+ *
556+ * $query = <<<'XQ'
557+ * declare variable $local:i as xs:integer external;
558+ *
559+ * $i + 1
560+ * 'XQ';
561+ *
562+ * $xquery->importQuery($query);
563+ * $xquery->setVariable("http://www.w3.org/2005/xquery-local-functions", $i, 1);
564+ *
565+ * echo $xquery->execute() . '\n';
566+ * </code>
567+ *
568+ * PHP types are converted to the following XML types:
569+ * - <b>DOMDocument</b> & <b>SimpleXMLElement</b>: document-node()
570+ * - <b>string</b>: xs:string
571+ * - <b>float</b>: xs:float
572+ * - <b>long</b>: xs:long
573+ * - <b>integer</b>: xs:integer
574+ * - <b>boolean</b>: xs:boolean
575+ * - <b>DOMDocument</b>: document-node()
576+ *
577+ * @param string $namespace optional Namespace URI of the external variable.
578+ * @param string $name Local name of the external variable.
579+ * @param mixed $value of the external variable.
580+ *
581+ * return ZorbaXQueryProcessor instance.
582+ */
583+ public function setVariable($arg1, $arg2) {
584+ $count = func_num_args();
585+ if($count == 2) {
586+ $name = func_get_arg(0);
587+ $value = func_get_arg(1);
588+ $this->variables['_'][$name] = $value;
589+ } else {
590+ $ns = func_get_arg(0);
591+ $name = func_get_arg(1);
592+ $value = func_get_arg(2);
593+ $this->variables[$ns][$name] = $value;
594+ }
595+ return $this;
596+ }
597+
598+ /**
599+ * Execute the Query.
600+ *
601+ * @return Query result.
602+ */
603+ public function execute() {
604+ //Execute
605+ $query = $this->compile();
606+ $result = $query->execute();
607+ $query->destroy();
608+ return $result;
609+ }
610+
611+ /**
612+ * Provide an intance of the SPL iterator to iterator over the
613+ * sequence of items produced by the query result.
614+ *
615+ * @return XQueryIterator
616+ */
617+ public function getIterator() {
618+ return new XQueryIterator($this->compile());
619+ }
620+
621+ /**
622+ * Internal method that creates an instance of the
623+ * XQuery class from the input parameters (importQuery and setVariable).
624+ *
625+ * @return XQuery compiled query.
626+ */
627+ private function compile()
628+ {
629+ //You need at least to import a query in order to compile it.
630+ if(!is_string($this->query)) {
631+ throw new XQueryCompilerException('No Query Imported. Use XQueryProcessor->importQuery($query).');
632+ }
633+
634+ //Compile Query
635+ $query = $this->zorba->compileQuery($this->query);
636+
637+ //Set Variables
638+ $dctx = $query->getDynamicContext();
639+ foreach($this->variables as $ns => $variables){
640+ foreach($variables as $name => $value) {
641+ if($ns == "_") $ns = "";
642+ $param = $this->zorba->compileQuery(".");
643+ $value = $this->getItem($value);
644+ $param->getDynamicContext()->setContextItem($value);
645+ $dctx->setVariable($ns, $name, $param->iterator());
646+ }
647+ }
648+ //Returns an instance of the XQuery class
649+ return $query;
650+ }
651+
652+ /**
653+ * Converts a PHP value to an XQuery Item.
654+ * The mapping between PHP and XQuery types in {@link setVariable}.
655+ *
656+ * @see setVariable()
657+ */
658+ private function getItem($value) {
659+ $itemFactory = $this->zorba->getItemFactory();
660+
661+ if($value instanceof DOMDocument or $value instanceof SimpleXMLElement) {
662+ $value = $this->parseXML($value->saveXML());
663+ } else if(is_string($value)) {
664+ $value = $itemFactory->createString($value);
665+ } else if(is_int($value)) {
666+ $value = $itemFactory->createInteger($value);
667+ } else if(is_bool($value)) {
668+ $value = $itemFactory->createBoolean($value);
669+ } else if(is_float($value)) {
670+ $value = $itemFactory->createFloat($value);
671+ } else if(is_long($value)) {
672+ $value = $itemFactory->createLong($value);
673+ } else {
674+ throw new XQueryCompilerException("Unsupported variable type: ".gettype($value));
675+ }
676+
677+ assert($value instanceof Item);
678+
679+ return $value;
680+ }
681+
682+ /**
683+ * Parse an XML string to an XQuery Item.
684+ * This function is used internally only.
685+ * @param $xml string XML string to parse.
686+ *
687+ * @return Item instance.
688+ */
689+ private function parseXML($xml)
690+ {
691+ $lDataManager = $this->zorba->getXmlDataManager();
692+ $lDocMgr = $lDataManager->getDocumentManager();
693+ $iter = $lDataManager->parseXML($xml);
694+
695+ $iter->open();
696+ $doc = Item::createEmptyItem();
697+
698+ $iter->next($doc);
699+ $iter->close();
700+ $iter->destroy();
701+
702+ return $doc;
703+ }
704+}
705+?>
706
707=== modified file 'swig/php/generate_proxy.php.in'
708--- swig/php/generate_proxy.php.in 2011-12-21 14:40:33 +0000
709+++ swig/php/generate_proxy.php.in 2012-01-17 13:34:25 +0000
710@@ -164,7 +164,7 @@
711 }
712 }
713
714-file_put_contents('zorba_api_wrapper.php', $wrapper);
715+file_put_contents('Zorba/zorba_api_wrapper.php', $wrapper);
716
717 function getRefParameters(ReflectionMethod $method, array $params) {
718 $result = "";
719
720=== added file 'swig/php/test.xq'
721--- swig/php/test.xq 1970-01-01 00:00:00 +0000
722+++ swig/php/test.xq 2012-01-17 13:34:25 +0000
723@@ -0,0 +1,1 @@
724+1+1
725
726=== modified file 'swig/php/zorba_api.i'
727--- swig/php/zorba_api.i 2011-10-12 20:56:27 +0000
728+++ swig/php/zorba_api.i 2012-01-17 13:34:25 +0000
729@@ -1,5 +1,5 @@
730 /*
731- * Copyright 2006-2008 The FLWOR Foundation.
732+ * Copyright 2006-2012 The FLWOR Foundation.
733 *
734 * Licensed under the Apache License, Version 2.0 (the "License");
735 * you may not use this file except in compliance with the License.

Subscribers

People subscribed via source and target branches