Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Created a new URLGenerator to talk to Apontador Api <http://api.apont…
Browse files Browse the repository at this point in the history
  • Loading branch information
Eher committed Jun 20, 2011
1 parent 7031ca3 commit 2a6228a
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions lib/Doctrine/REST/Client/URLGenerator/ApontadorURLGenerator.php
Original file line number Original file line Diff line number Diff line change
@@ -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.