Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Minor changes to better support Redmine REST API #14

Merged
merged 1 commit into from

3 participants

@NewAmsterdamIdeas

I've made a few minor changes to your most excellent phpactiveresource library to provide some additional flexibility for defining the XML and uris. The additional flexibility is needed to use this library fully with the Redmine REST API. None of my changes should alter existing functionality. They just provide a few additional options.

@jbroadway
Owner

Thanks, these are good changes!

@jbroadway jbroadway merged commit aeccf2f into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 17, 2012
  1. @sheldonrampton

    add some flexibility, fix a couple of minor bugs involving undefined …

    sheldonrampton authored
    …variables and numerical values not being recognized
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 11 deletions.
  1. +11 −11 ActiveResource.php
View
22 ActiveResource.php
@@ -251,7 +251,7 @@ function find ($id = false, $options = array ()) {
*/
function get ($method, $options = array ()) {
$req = $this->site . $this->element_name_plural;
- if ($this->_data['id']) {
+ if (isset($this->_data['id']) && $this->_data['id']) {
$req .= '/' . $this->_data['id'];
}
$req .= '/' . $method . '.xml';
@@ -266,13 +266,13 @@ function get ($method, $options = array ()) {
*
* POST /collection/id/method.xml
*/
- function post ($method, $options = array ()) {
+ function post ($method, $options = array (), $start_tag=FALSE) {
$req = $this->site . $this->element_name_plural;
if ($this->_data['id']) {
$req .= '/' . $this->_data['id'];
}
$req .= '/' . $method . '.xml';
- return $this->_send_and_receive ($req, 'POST', $options);
+ return $this->_send_and_receive ($req, 'POST', $options, $start_tag);
}
/**
@@ -280,12 +280,15 @@ function post ($method, $options = array ()) {
*
* PUT /collection/id/method.xml
*/
- function put ($method, $options = array ()) {
+ function put ($method, $options = array (), $options_as_xml=FALSE, $start_tag=FALSE) {
$req = $this->site . $this->element_name_plural;
if ($this->_data['id']) {
$req .= '/' . $this->_data['id'];
}
$req .= '/' . $method . '.xml';
+ if ($options_as_xml) {
+ return $this->_send_and_receive ($req, 'PUT', $options, $start_tag);
+ }
if (count ($options) > 0) {
$req .= '?' . http_build_query ($options);
}
@@ -413,6 +416,7 @@ function _xml_entities ($s, $hex = true) {
// just return it
return $s;
}
+ $s = (string)$s;
// create the return string
$r = '';
@@ -424,7 +428,7 @@ function _xml_entities ($s, $hex = true) {
// get the value of the character
$o = $this->_unicode_ord($s, $i);
- // valid cahracters
+ // valid characters
$v = (
// \t \n <vertical tab> <form feed> \r
($o >= 9 && $o <= 13) ||
@@ -493,9 +497,9 @@ function _xml_entities ($s, $hex = true) {
/**
* Build the request, call _fetch() and parse the results.
*/
- function _send_and_receive ($url, $method, $data = array ()) {
+ function _send_and_receive ($url, $method, $data = array (), $start_tag=FALSE) {
$params = '';
- $el = $this->element_name; // Singular this time
+ $el = $start_tag ? $start_tag : $this->element_name; // Singular this time
if ($this->request_format == 'url') {
foreach ($data as $k => $v) {
if ($k != 'id' && $k != 'created-at' && $k != 'updated-at') {
@@ -512,18 +516,14 @@ function _send_and_receive ($url, $method, $data = array ()) {
}
$params .= '</' . $el . '>';
}
-
if ($this->extra_params !== false)
{
$url = $url . $this->extra_params;
}
-
$this->request_body = $params;
$this->request_uri = $url;
$this->request_method = $method;
-
$res = $this->_fetch ($url, $method, $params);
-
if ($res === false)
{
return $this;
Something went wrong with that request. Please try again.