This repository has been archived by the owner on Aug 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a new URLGenerator to talk to Apontador Api <http://api.apont…
- Loading branch information
Eher
committed
Jun 20, 2011
1 parent
7031ca3
commit 2a6228a
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
lib/Doctrine/REST/Client/URLGenerator/ApontadorURLGenerator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |||
} | |||
} |