11111
SDO Functions
Внимание. Это расширение является ЭКСПЕРИМЕНТАЛЬНЫМ. Поведение этого расширения, включая имена его функций и относящуюся к нему документацию, может измениться в последующих версиях PHP без уведомления. Используйте это расширение на свой страх и риск.
- Service Data Objects (SDOs) enable PHP applications to work with data from different sources (like a database query, an XML file, and a spreadsheet) using a single interface.
- Each different kind of data source requires a Data Access Service (DAS) to provide access to the data in the data source. In your PHP application, you use a DAS to create an SDO instance that represents some data in the data source. You can then set and get values in the SDO instance using the standard SDO interface. Finally, you use a DAS to write the modified data back to a data source (typically the same one).
- See the list of Data Access Services for details on those currently available. In addition to the provided DASs, SDO also provides interfaces to enable others to be implemented (see the section on SDO Data Access Services Interface for more details).
- This extension is derived from concepts taken from the - Service Data Objects specification
- A Service Data Object instance is made up of a tree of data objects. The tree is defined by containment references between the data objects. For example, a Company data object might consist of a number of Department data objects and therefore the Company would have a containment reference to the Departments. Deleting a data object which has a containment reference to another data object will delete the referenced data object. For example, deleting the Company data object will also delete the Departments.
- An SDO may also have non-containment references between data objects in the tree. For example, one Employee data object might reference another Employee to identify a career mentor. Deleting a data object which has a non-containment reference to another data object does not delete the referenced data object.
- As well as data objects referencing each other, they can also have primitive properties. For example, the Company data object might have a property called "name" of type string, for holding the name of the company (for example, "Acme").
- The SDO extension requires PHP5.1 or higher.
- SDO XML Data Access Service, which is built as part of this extension, requires libxml2 (Tested with libxml2 2.6.19) which can be downloaded from http://www.xmlsoft.org/.
- There are several options, depending on whether you are installing on Windows or Linux, and depending on whether you are installing a released version (a .tgz file from the PECL site) or the latest from CVS. The Relational DAS also needs special attention as it is written in PHP.
- The instructions are likely to change as PHP5.1 progresses in status from beta to stable release. The instructions here were correct on 3rd August 2005, when PHP5.1.0b3 was the current beta release of PHP, and 0.5.0 was the current beta release of SDO.
The options are summarised in the following table:
latest/Release | Windows | Linux | |||
---|---|---|---|---|---|
- latest CVS | -
-
| - Release | -
| - - pear -B install sdo-0.5.0 -
| . This will build the SDO and XML shared libraries as well as installing the PHP files that make the Relational DAS. |
- Regardless of which platform or which level of the code you have installed you will need add the two extension libraries to your php.ini file. On Windows, add:
|
On Linux, add:
|
You may also need to update your extension_dir in php.ini to point to the location of these libraries.
- The Relational DAS is written in PHP. You may need to update your include_path in php.ini to point to the directory that contains sdo/DAS/Relational .
- This section describes how to build the SDO core and XML DAS on Linux. Currently you would only need to know how to do this if you wish to build a recent version that you have checked out of CVS.
- The table below lists the currently provided SDO Data Access Services:
DAS Name | Description |
---|---|
- SDO_DAS_XML | - An XML Data Access Service supporting reading/writing SDOs as XML documents or via a Web URL to supporting things like RSS feeds. |
- SDO_DAS_Relational | - A PDO-based Data Access Service supporting reading/writing SDO to relational data sources. Implements an optimistic concurrency policy for updates. |
- The following are limitations in the current SDO implementation:
- As a bypass, the global constants SDO_DAS_CHANGE_SUMMARY_NONE, SDO_DAS_CHANGE_SUMMARY_MODIFICATION, SDO_DAS_CHANGE_SUMMARY_ADDITION, SDO_DAS_CHANGE_SUMMARY_DELETION are provided.
- The following SDO 2.0 concepts are not supported in the current PHP implementation. It is not necessarily the case that these will all be added over time. Their inclusion will depend on community requirements.
- The examples below assume an SDO created with the schema and instance information shown below, using the XML Data Access Service.
- The schema describes a company data object. The company contains department data objects, and each department contains employee data objects. Each data object has a number of primitive properties to describe things like name, serial number, etc. Finally, the company data object also has a non-containment reference to one of the employee data objects to identify them as the 'employeeOfTheMonth'.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sdo="commonj.sdo" xmlns:sdoxml="commonj.sdo/xml" xmlns:company="companyNS" targetNamespace="companyNS"> <xsd:element name="company" type="company:CompanyType"/> <xsd:complexType name="CompanyType"> <xsd:sequence> <xsd:element name="departments" type="company:DepartmentType" maxOccurs="unbounded"/> </xsd:sequence> <xsd:attribute name="name" type="xsd:string"/> <xsd:attribute name="employeeOfTheMonth" type="xsd:IDREF" |
- The instance document below describes a single company, called 'MegaCorp', which contains a single department, called 'Advanced Technologies'. The Advanced Technologies department contains three employees. The company employeeOfTheMonth is referencing the second employee, 'Jane Doe'.
<?xml version="1.0" encoding="UTF-8" ?> |
- The following examples assume $company is a data object created from the schema and instance document shown above.
Пример 2. Access via Property index - Data object properties can be accessed via their property index using array syntax. The property index is the position at which the property's definition appears in the model (in this case the xml schema). We can see from the schema listing above that the departments element is the first company property defined and the company name attribute is the second company property (the SDO interface makes no distinction between XML attributes and elements). The following gets the list of departments (containing a single department), and sets the company name to 'Acme'.
|
Пример 3. Data Object Iteration - We can iterate over the properties of a data object using foreach. The following iterates over the company properties; name, departments and employeeOfTheMonth.
- For the first iteration, $name will be 'name' and $value will be 'Acme'. For the second iteration, $name will be 'departments' and $value will be an SDO_List (because departments is a many-valued property (stated maxOccurs="unbouded" in the schema)) containing a single data object of type DepartmentType. For the third iteration, $name will be 'employeeOfTheMonth' and $value will be a data object of type EmployeeType. |
Пример 4. Many-valued Property Iteration - Many-valued properties can also be iterated over using foreach. The following iterates over the company's departments.
- Each iteration will assign the next department in the list to the variable $department. |
Пример 5. Many-valued Element Access - We can access individual elements of many-valued properties using array syntax. The following accesses the first department in the company.
|
Пример 6. Nested Property Access - We can use nested property access to navigate the data object instance structure. The following gets and sets the name of the first department.
|
Пример 7. Simple XPath support - We can access properties using XPath-like (an augmented sub-set of XPath) expressions, the simplest form of which is the property name. The following sets the company name and gets the employeeOfTheMonth.
|
Пример 8. Simple XPath support - We can use chained array access calls to navigate the data object instance structure. The following gets and sets the name of the first department.
|
Пример 9. XPath Navigation - We can use XPath expressions to navigate the data object instance structure. Two forms of indexing into many-valued properties are supported. The first is the standard XPath array syntax with the indexing starting at one, the second is an SDO extension to XPath with an index starting at zero. The following both get the second employee from the first department.
|
Пример 10. XPath Querying - We can use XPath to query and identify parts of a data object based on instance data. The following retrieves the manager from the 'Advanced Technologies' department.
|
Пример 11. Creating child data object - A data object can be a factory for its child data objects. A child data object is automatically part of the data graph. The following add a new employee to the 'Advanced Technologies' department.
|
Пример 12. Unset referenced data object - We can use the isset() and unset() functions to test and remove items from the data object. - The following removes the 'employeeOfTheMonth' from the company. If this were a containment reference then the employee would be removed from the company (probably not a good idea to sack your best employee each month!), but since this is a non-containment reference, the employee being referenced will remain in the department in the company, but will no longer be accessible via the employeeOfTheMonth property.
|
- Sequenced data objects are SDOs which can track property ordering across the properties of a data object. They can also contain unstructured text elements (text element which do not belong to any of the SDO's properties). Sequenced data objects are useful for working with XML documents which allow unstructured text (i.e. mixed=true) or if the elements can be interleaved ( <A/><B/><A/>). This can occur for example when the schema defines maxOccurs>1 on a element which is a complexType with a choice order indicator.
- The examples below assume an SDO created with the following schema and instance information, using the XML Data Access Service.
- The schema below describes the format of a letter. The letter can optionally contain three properties; date, firstName, and lastName. The schema states mixed="true" which means that unstructured text can be interspersed between the three properties.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:letter="http://letterSchema" targetNamespace="http://letterSchema"> <xsd:element name="letters" type="letter:FormLetter"/> <xsd:complexType name="FormLetter" mixed="true"> <xsd:sequence> <xsd:element name="date" minOccurs="0" type="xsd:string"/> <xsd:element name="firstName" minOccurs="0" type="xsd:string"/> <xsd:element name="lastName" minOccurs="0" type="xsd:string"/> </xsd:sequence> </xsd:complexType> |
- The following is an instance letter document. It contains the three letter properties; date, firstName and lastName, and has unstructured text elements for the address and letter body.
<letter:letters xmlns:letter="http://letterSchema"> <date>March 1, 2005</date> Mutual of Omaha Wild Kingdom, USA Dear <firstName>Casy</firstName> <lastName>Crocodile</lastName> Please buy more shark repellent. Your premium is past due. |
- When loaded, the letter data object will have the sequence and property indices shown in the table below:
Sequence Index | Property Index:Name | Value |
---|---|---|
0 | 0:date | March 1, 2005 |
1 | - | Mutual of Omaha |
2 | - | Wild Kingdom, USA |
3 | - | Dear |
4 | 1:firstName | Casy |
5 | 2:lastName | Crocodile |
6 | - | Please buy more shark repellent. |
7 | - | Your premium is past due. |
- To ensure sequence indices are maintained, sequenced data objects should be manipulated through the SDO_Sequence interface. This allows the data object's instance data to be manipulated in terms of the sequence index as opposed to the property index (shown in the table above). The following examples assume the letter instance has been loaded into a data object referenced by the variable $letter.
Пример 13. Getting the SDO_Sequence interface - We obtain a data object's sequence using the getSequence() method. The follow gets the sequence for the letter data object.
|
- All subsequent examples assume that the $letter_seq variable has been assigned the sequence for the letter data object.
Пример 14. Get/set sequence values - We can get and set individual values (including unstructured text) using the sequence index. The following sets the firstName to 'Snappy' and gets the last sequence values (the unstructured text, 'Your premium is past due.').
|
Пример 15. Sequence iteration - We can iterate through the individual sequence values using foreach. The following runs through the individual values in sequence order.
|
Пример 16. Sequence versus Data Object - Setting values through the data object interface may result in the value not being part of the sequence. A value set through the data object will only be accessible through the sequence if the property was already part of the sequence. The following example sets the lastName through the data object and gets it through the sequence. This is fine because lastName already exists in the sequence. If it had not previously been set, then lastName would be set to 'Smith', but would not be part of the sequence.
|
Пример 17. Adding to a sequence - We can add new values to a sequence using the - SDO_Sequence::insert() method. The following examples assume that the 'firstName' and 'lastName' properties are initially unset.
|
Пример 18. Removing from a sequence - We can use the isset() and unset() functions to test and remove items from the sequence (Note: unset() currently leaves the values in the data object, but this behaviour is likely to change to also remove the data from the data object). A sequence behaves like a contiguous list; therefore, removing items from the middle will shift entries at higher indices down. The following example tests to see if the first sequence element is set and unsets it if is.
|
- SDO consists of two sets of interfaces. The first set covers those interfaces for use by SDO client applications. These are identified by the package prefix 'SDO_'. The second set is those for use by Data Access Service implementations and are identified by the package prefix 'SDO_DAS_'. The majority of SDO users will not need to use or understand the 'SDO_DAS_' interfaces.
- The main interface through which data objects are manipulated. In addition to the methods below, SDO_DataObject extends the ArrayAccess, SDO_PropertyAccess (defines __get() / __set() methods for property access overloading), Iterator, and Countable interfaces.
- The interface through which sequenced data objects can be accessed to preserve ordering across a data object's properties and to allow unstructured text. SDO_Sequence preserves contiguous indices and therefore inserting or removing elements may shift other elements up or down. In addition to the methods below, SDO_Sequence extends the ArrayAccess, Iterator and Countable interface.
- The interface through which many-valued properties are manipulated. In addition to the method defined below, SDO_List extends ArrayAccess, Iterator and Countable. SDO_List preserves contiguous indices and therefore inserting or removing elements may shift other elements up or down.
- The interface through which data objects can be created. A Data Access Service is responsible for populating the model (i.e. configuring the data factory with the type and structure information for the data objects it can create.) for the factory and can then optionally return an instance of, or implement, the SDO_DataFactory interface.
- The interface through which a Data Access Service can access a data object's - SDO_DAS_ChangeSummary. The change summary is used by the Data Access Service to check for conflicts when applying changes back to a data source.
- The interface through which the change history of a data object is accessed. The change summary holds information for any modifications on a data object which occurred since logging was activated. In the case of deletions and modifications, the old values are also held in the change summary.
- If logging is no longer active then the change summary only holds changes made up to the point when logging was deactivated. Reactivating logging clears the change summary. This is useful when a set of changes have been written out by a DAS and the data object is to be reused.
- The interface through which the old value for a property is accessed. A list of settings is returned by the change summary method - getOldValues().
- The interface for constructing the model for an SDO_DataObject. The SDO_DAS_DataFactory is an abstract class providing a static method which returns a concrete data factory implementation. The implementation is used by Data Access Services to create an SDO model from their model. For example, a Relational Data Access Service might create and populate an SDO_DAS_DataFactory model based on a schema for a relational database.
-Перечисленные ниже константы определены данным расширением и могут быть
доступны только в том случае, если PHP был собран с
поддержкой этого расширения или же в том случае, если
данное расширение подгружается во время выполнения.
SDO_DAS_ChangeSummary::NONE=0 (integer)
- Represents a change type of 'none'.
SDO_DAS_ChangeSummary::MODIFICATION=1 (integer)
- Represents a change type of 'modification'.
SDO_DAS_ChangeSummary::ADDITION=2 (integer)
- Represents a change type of 'addition'.
SDO_DAS_ChangeSummary::DELETION=3 (integer)
- Represents a change type of 'deletion'.
Содержание
SDO_DAS_ChangeSummary::beginLogging -- Begin change logging.
SDO_DAS_ChangeSummary::endLogging -- End change logging.
SDO_DAS_ChangeSummary::getChangeType -- Get the type of change made to an SDO_DataObject.
SDO_DAS_ChangeSummary::getChangedDataObjects -- Get the changed data objects from a change summary.
SDO_DAS_ChangeSummary::getOldContainer -- Get the old container for a deleted SDO_DataObject.
SDO_DAS_ChangeSummary::getOldValues -- Get the old values for a given changed SDO_DataObject.
SDO_DAS_ChangeSummary::isLogging -- Test to see whether change logging is switched on.
SDO_DAS_DataFactory::addPropertyToType -- Adds a property to a type.
SDO_DAS_DataFactory::addType -- Add a new type to a model.
SDO_DAS_DataFactory::getDataFactory -- Get a data factory instance.
SDO_DAS_DataObject::getChangeSummary -- Get a data object's change summary.
SDO_DAS_Setting::getListIndex -- Get the list index for a changed many-valued property.
SDO_DAS_Setting::getPropertyIndex -- Get the property index for a changed property.
SDO_DAS_Setting::getPropertyName -- Get the property name for a changed property.
SDO_DAS_Setting::getValue -- Get the old value for the changed property.
SDO_DAS_Setting::isSet -- Test whether a property was set prior to being modified.
SDO_DataFactory::create -- Create an SDO_DataObject.
SDO_DataObject::clear -- Clear an SDO_DataObject's properties.
SDO_DataObject::createDataObject -- Create a child SDO_DataObject.
SDO_DataObject::getContainer -- Get a data object's container.
SDO_DataObject::getContainmentPropertyName -- Get the container's property name.
SDO_DataObject::getSequence -- Get the sequence for a data object.
SDO_DataObject::getType -- Get the type of a data object.
SDO_List::insert -- Insert into a list.
SDO_Sequence::getPropertyIndex -- Return the property index for the specified sequence index.
SDO_Sequence::getPropertyName -- Return the property name for the specified sequence index.
SDO_Sequence::insert -- Insert into a sequence.
SDO_Sequence::move -- Move an item to another sequence position.
SDO_DAS_XML::saveDocumentToString
SDO_DAS_ChangeSummary::beginLogging 22222