-
-
Notifications
You must be signed in to change notification settings - Fork 312
Extending XmlFormat? #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
There is a much simpler way to achieve that. :) You can use the following in <?php
XmlFormat::$root_name = 'result';
XmlFormat::$attribute_names = array (
'bmi',
'message',
'height',
'weight'
); which will result with the following xml for the Multi-fomat example <result bmi="31.77" message="Obesity">
<metric height="162.6 centimeter" weight="84 kilograms"/>
<imperial height="5 feet 4 inches" weight="185.19 pounds"/>
</result> If you still prefer creating your own subclass you can write it as shown below <?php
class MyXmlFormat extends XmlFormat {
public function __construct() {
parent::$root_name = 'result';
parent::$attribute_names = array (
'bmi',
'message',
'height',
'weight'
);
}
} We found a bug with the auto-loader that comes with |
…allowing us to subclass format classes with out manually including them
Thought there should be - thanks for the pointers, and for Restler in general - it fits in exactly with the project I'm doing at the moment :-) |
For a method in a class, for which I want the XML root name and list of values that should be attributes to be changed, I know I can do:
...before the method. However, I'm potentially going to have hundreds of methods across various classes, and this duplication seems somewhat redundant as I'll want the same root name across all of them, and same attribute sets across most of them.
What I'd like to do (but I couldn't get working), is to create my own format, that extends XmlFormat, but sets new default values for properties. Something like:
or
...with
in the
index.php
.Is such a thing possible / am I heading along the right lines? Some use of
var_dump()
showed that aMyXmlFormat
object was being used, but the static properties being returned viaself::$...
were not picking up the new values.The text was updated successfully, but these errors were encountered: