Permalink
Browse files

adding in override example and versioned downloads

  • Loading branch information...
1 parent 8da369e commit cc202f9a6e8a9dc8881f95646f61d3a6221957c0 @nategood committed May 9, 2012
View
BIN downloads/httpful-0.1.0.phar
Binary file not shown.
View
BIN downloads/httpful-0.1.2.phar
Binary file not shown.
View
44 examples/override.php
@@ -0,0 +1,44 @@
+<?php
+require(__DIR__ . '/../bootstrap.php');
+
+// We can override the default parser configuration options be registering
+// a parser with different configuration options for a particular mime type
+
+// Example setting a namespace for the XMLHandler parser
+$conf = array('namespace' => 'http://example.com');
+\Httpful\Httpful::register(\Httpful\Mime::XML, new \Httpful\Handlers\XmlHandler($conf));
+
+// We can also add the parsers with our own...
+class SimpleCsvHandler extends \Httpful\Handlers\MimeHandlerAdapter
+{
+ /**
+ * Takes a response body, and turns it into
+ * a two dimensional array.
+ *
+ * @param string $body
+ * @return mixed
+ */
+ public function parse($body)
+ {
+ return str_getcsv($body);
+ }
+
+ /**
+ * Takes a two dimensional array and turns it
+ * into a serialized string to include as the
+ * body of a request
+ *
+ * @param mixed $payload
+ * @return string
+ */
+ public function serialize($payload)
+ {
+ $serialized = '';
+ foreach ($payload as $line) {
+ $serialized .= '"' . implode('","', $line) . '"' . "\n";
+ }
+ return $serialized;
+ }
+}
+
+\Httpful\Httpful::register('text/csv', new SimpleCsvHandler());

0 comments on commit cc202f9

Please sign in to comment.