Browse files

Created a new URLGenerator to talk to Apontador Api <http://api.apont…

  • Loading branch information...
1 parent 7031ca3 commit 2a6228ac13e3a9cbbd3b5fa57c806a12fce7b16e Eher committed Jun 19, 2011
Showing with 46 additions and 0 deletions.
  1. +46 −0 lib/Doctrine/REST/Client/URLGenerator/ApontadorURLGenerator.php
View
46 lib/Doctrine/REST/Client/URLGenerator/ApontadorURLGenerator.php
@@ -0,0 +1,46 @@
+<?php
+
+namespace Doctrine\REST\Client\URLGenerator;
+
+/**
+ * Apontador REST request URL generator
+ *
+ * @author Alexandre Eher <alexandre@eher.com.br>
+ */
+class ApontadorURLGenerator extends AbstractURLGenerator
+{
+ public function generate(array $options)
+ {
+ $id = isset($options['id']) ? $options['id'] : null;
+ $action = isset($options['action']) ? $options['action'] : null;
+ $parameters = isset($options['parameters']) ? $options['parameters'] : array();
+
+ $parameters['type'] = $this->_entityConfiguration->getResponseType();
+ if ($id)
+ {
+ if ($action !== null)
+ {
+ $path = sprintf('/%s/%s', $id, $action);
+ } else {
+ $path = sprintf('/%s', $id);
+ }
+ } else {
+ if ($action !== null)
+ {
+ $path = sprintf('/%s', $action);
+ } else {
+ $path = '';
+ }
+ }
+ $url = $this->_entityConfiguration->getUrl() . '/' . $this->_entityConfiguration->getName() . $path;
+ if (is_array($parameters) && $parameters) {
+ foreach ($this->_entityConfiguration->getProperties() as $field) {
+ unset($parameters[$field]);
+ }
+ if ($parameters) {
+ $url .= '?' . http_build_query($parameters);
+ }
+ }
+ return $url;
+ }
+}

0 comments on commit 2a6228a

Please sign in to comment.