Skip to content
Browse files

Updated formatting for consistency

  • Loading branch information...
1 parent 893247b commit ae1788de2d998c529c4a3e697493591e3f7251a6 @jbroadway committed Oct 11, 2012
Showing with 56 additions and 56 deletions.
  1. +56 −56 ActiveResource.php
View
112 ActiveResource.php
@@ -7,38 +7,38 @@
*
* Usage:
*
- * <?php
- *
- * require_once ('ActiveResource.php');
- *
- * class Song extends ActiveResource {
- * var $site = 'http://localhost:3000/';
- * var $element_name = 'songs';
- * }
- *
- * // create new item
- * $song = new Song (array ('artist' => 'Joe Cocker', 'title' => 'A Little Help From My Friends'));
- * $song->save ();
- *
- * // fetch and update an item
- * $song->find (44)->set ('title', 'The River')->save ();
- *
- * // line by line
- * $song->find (44);
- * $song->title = 'The River';
- * $song->save ();
- *
- * // get all songs
- * $songs = $song->find ('all');
- *
- * // delete a song
- * $song->find (44);
- * $song->destroy ();
- *
- * // custom method
- * $songs = $song->get ('by_year', array ('year' => 1999));
- *
- * ?>
+ * <?php
+ *
+ * require_once ('ActiveResource.php');
+ *
+ * class Song extends ActiveResource {
+ * var $site = 'http://localhost:3000/';
+ * var $element_name = 'songs';
+ * }
+ *
+ * // create new item
+ * $song = new Song (array ('artist' => 'Joe Cocker', 'title' => 'A Little Help From My Friends'));
+ * $song->save ();
+ *
+ * // fetch and update an item
+ * $song->find (44)->set ('title', 'The River')->save ();
+ *
+ * // line by line
+ * $song->find (44);
+ * $song->title = 'The River';
+ * $song->save ();
+ *
+ * // get all songs
+ * $songs = $song->find ('all');
+ *
+ * // delete a song
+ * $song->find (44);
+ * $song->destroy ();
+ *
+ * // custom method
+ * $songs = $song->get ('by_year', array ('year' => 1999));
+ *
+ * ?>
*
* @author John Luxford <lux@companymachine.com>
* @version 0.14 beta
@@ -165,10 +165,9 @@ function __construct ($data = array ()) {
$this->element_name = $this->element_name ? $this->element_name : strtolower (get_class ($this));
// Detect for namespaces, and take just the class name
- if (stripos($this->element_name, '\\'))
- {
- $classItems = explode('\\', $this->element_name);
- $this->element_name = end($classItems);
+ if (stripos ($this->element_name, '\\')) {
+ $classItems = explode ('\\', $this->element_name);
+ $this->element_name = end ($classItems);
}
// Get the plural name after removing namespaces
@@ -211,8 +210,8 @@ function pleuralize ($word) {
/**
* Saves a new record or updates an existing one via:
*
- * POST /collection.xml
- * PUT /collection/id.xml
+ * POST /collection.xml
+ * PUT /collection/id.xml
*/
function save () {
if (isset ($this->_data['id'])) {
@@ -224,7 +223,7 @@ function save () {
/**
* Deletes a record via:
*
- * DELETE /collection/id.xml
+ * DELETE /collection/id.xml
*/
function destroy () {
return $this->_send_and_receive ($this->site . $this->element_name_plural . '/' . $this->_data['id'] . '.xml', 'DELETE');
@@ -233,15 +232,15 @@ function destroy () {
/**
* Finds a record or records via:
*
- * GET /collection/id.xml
- * GET /collection.xml
+ * GET /collection/id.xml
+ * GET /collection.xml
*/
function find ($id = false, $options = array ()) {
if (! $id) {
$id = $this->_data['id'];
}
$options_string = '';
- if (count($options) > 0) {
+ if (count ($options) > 0) {
$options_string = '?' . http_build_query ($options);
}
if ($id == 'all') {
@@ -254,12 +253,12 @@ function find ($id = false, $options = array ()) {
/**
* Gets a specified custom method on the current object via:
*
- * GET /collection/id/method.xml
- * GET /collection/id/method.xml?attr=value
+ * GET /collection/id/method.xml
+ * GET /collection/id/method.xml?attr=value
*/
function get ($method, $options = array ()) {
$req = $this->site . $this->element_name_plural;
- if (isset($this->_data['id']) && $this->_data['id']) {
+ if (isset ($this->_data['id']) && $this->_data['id']) {
$req .= '/' . $this->_data['id'];
}
$req .= '/' . $method . '.xml';
@@ -272,9 +271,9 @@ function get ($method, $options = array ()) {
/**
* Posts to a specified custom method on the current object via:
*
- * POST /collection/id/method.xml
+ * POST /collection/id/method.xml
*/
- function post ($method, $options = array (), $start_tag=FALSE) {
+ function post ($method, $options = array (), $start_tag = false) {
$req = $this->site . $this->element_name_plural;
if ($this->_data['id']) {
$req .= '/' . $this->_data['id'];
@@ -286,16 +285,16 @@ function post ($method, $options = array (), $start_tag=FALSE) {
/**
* Puts to a specified custom method on the current object via:
*
- * PUT /collection/id/method.xml
+ * PUT /collection/id/method.xml
*/
- function put ($method, $options = array (), $options_as_xml=FALSE, $start_tag=FALSE) {
+ 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 .= '/' . $this->_data['id'];
}
$req .= '/' . $method . '.xml';
if ($options_as_xml) {
- return $this->_send_and_receive ($req, 'PUT', $options, $start_tag);
+ return $this->_send_and_receive ($req, 'PUT', $options, $start_tag);
}
if (count ($options) > 0) {
$req .= '?' . http_build_query ($options);
@@ -366,7 +365,7 @@ function _build_xml ($k, $v) {
* @author Dom Hastings - modified to suit my needs
* @see http://www.php.net/manual/en/function.ord.php#78032
*/
- function _unicode_ord(&$c, &$i = 0) {
+ function _unicode_ord (&$c, &$i = 0) {
// get the character length
$l = strlen($c);
// copy the offset
@@ -424,7 +423,7 @@ function _xml_entities ($s, $hex = true) {
// just return it
return $s;
}
- $s = (string)$s;
+ $s = (string) $s;
// create the return string
$r = '';
@@ -505,7 +504,7 @@ function _xml_entities ($s, $hex = true) {
/**
* Build the request, call _fetch() and parse the results.
*/
- function _send_and_receive ($url, $method, $data = array (), $start_tag=FALSE) {
+ function _send_and_receive ($url, $method, $data = array (), $start_tag = false) {
$params = '';
$el = $start_tag ? $start_tag : $this->element_name; // Singular this time
if ($this->request_format == 'url') {
@@ -560,8 +559,9 @@ function _send_and_receive ($url, $method, $data = array (), $start_tag=FALSE) {
// parse XML response
$xml = new SimpleXMLElement ($res);
+
// normalize xml element name in case rails ressource contains an underscore
- if (str_replace("-","_", $xml->getName ()) == $this->element_name_plural) {
+ if (str_replace ('-', '_', $xml->getName ()) == $this->element_name_plural) {
// multiple
$res = array ();
$cls = get_class ($this);
@@ -703,4 +703,4 @@ function set ($k, $v = false) {
}
}
-?>
+?>

0 comments on commit ae1788d

Please sign in to comment.
Something went wrong with that request. Please try again.