Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: frapi/frapi
base: ec4b88428f
...
head fork: frapi/frapi
compare: api-versioning
  • 3 commits
  • 21 files changed
  • 0 commit comments
  • 1 contributor
Showing with 397 additions and 5 deletions.
  1. BIN  src/frapi/admin/application/languages/en_GB.mo
  2. +9 −0 src/frapi/admin/application/languages/en_GB.po
  3. +3 −2 src/frapi/admin/application/modules/default/controllers/ActionController.php
  4. +91 −0 src/frapi/admin/application/modules/default/controllers/VersionsController.php
  5. +13 −0 src/frapi/admin/application/modules/default/forms/Action.php
  6. +42 −0 src/frapi/admin/application/modules/default/forms/Versions.php
  7. +6 −2 src/frapi/admin/application/modules/default/models/Action.php
  8. +153 −0 src/frapi/admin/application/modules/default/models/Versions.php
  9. +1 −0  src/frapi/admin/application/modules/default/views/scripts/versions/add.phtml
  10. 0  src/frapi/admin/application/modules/default/views/scripts/versions/delete.phtml
  11. +6 −0 src/frapi/admin/application/modules/default/views/scripts/versions/edit.phtml
  12. +47 −0 src/frapi/admin/application/modules/default/views/scripts/versions/index.phtml
  13. +4 −0 src/frapi/admin/application/views/scripts/submenu.phtml
  14. +1 −1  src/frapi/custom/AllFiles.php
  15. +10 −0 src/frapi/custom/Config/actions.xml
  16. 0  src/frapi/custom/Config/configurations.xml
  17. 0  src/frapi/custom/Config/errors.xml
  18. 0  src/frapi/custom/Config/outputs.xml
  19. 0  src/frapi/custom/Config/partners.xml
  20. 0  src/frapi/custom/Config/users.xml
  21. +11 −0 src/frapi/custom/Config/versions.xml
View
BIN  src/frapi/admin/application/languages/en_GB.mo
Binary file not shown
View
9 src/frapi/admin/application/languages/en_GB.po
@@ -376,3 +376,12 @@ msgstr "This file is not writeable, please give the web-user write access to the
msgid "FILE_CONTENT_UPDATED"
msgstr "The content of the file has been updated with success."
+
+msgid "VERSIONS"
+msgstr "Versions"
+
+msgid "URL_PREFIX"
+msgstr "URL Prefix"
+
+msgid "ADD_NEW_VERSION"
+msgstr "Add new version"
View
5 src/frapi/admin/application/modules/default/controllers/ActionController.php
@@ -95,8 +95,9 @@ public function indexAction()
*/
public function addAction()
{
- $form = new Default_Form_Action;
- $model = new Default_Model_Action;
+ $form = new Default_Form_Action;
+ $model = new Default_Model_Action;
+ $versions = new Default_Model_Versions;
$request = $this->getRequest();
if ($request->isPost()) {
View
91 src/frapi/admin/application/modules/default/controllers/VersionsController.php
@@ -0,0 +1,91 @@
+<?php
+/**
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://getfrapi.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@getfrapi.com so we can send you a copy immediately.
+ *
+ * @license New BSD
+ * @copyright echolibre ltd.
+ * @package frapi-admin
+ */
+class VersionsController extends Lupin_Controller_Base
+{
+ public function init($styles = array())
+ {
+ $actions = array('index', 'add', 'edit', 'delete');
+ $this->_helper->_acl->allow('admin', $actions);
+ parent::init($styles);
+ }
+
+ public function indexAction()
+ {
+ $model = new Default_Model_Versions;
+ $this->view->data = $model->getAll();
+ }
+
+ public function addAction()
+ {
+ $form = new Default_Form_Versions;
+ $model = new Default_Model_Versions;
+
+ $request = $this->getRequest();
+ if ($request->isPost()) {
+ if ($form->isValid($request->getPost())) {
+ $data = $form->getValues();
+
+ // Save data
+ $model->add($data);
+
+ // Bit of xss here and there.
+ $this->addMessage('Version ' . $data['name'] . ' added.');
+ $this->_redirect('/versions');
+ }
+ }
+
+ $this->view->form = $form;
+ }
+
+ public function editAction()
+ {
+ $model = new Default_Model_Versions;
+ $form = new Default_Form_Versions;
+
+ $request = $this->getRequest();
+ $id = $request->getParam('id');
+ if ($request->isPost()) {
+ if ($form->isValid($request->getPost())) {
+ $data = $form->getValues();
+
+ // Save data
+ $model->update($data, $id);
+ $this->addMessage('Version updated.');
+ $this->_redirect('/versions/edit/id/' . $id);
+ }
+ } else {
+ $version = $model->getVersion($id);
+ $form->populate($version);
+ }
+
+ $this->view->form = $form;
+ }
+
+ public function deleteAction()
+ {
+ $id = $this->getRequest()->getParam('id');
+ if ($id === null) {
+ $this->addErrorMessage('ID parameter is missing.');
+ return;
+ }
+
+ $model = new Default_Model_Versions;
+ $model->delete($id);
+ $this->addMessage('Version deleted');
+ $this->_redirect('/versions');
+ }
+}
View
13 src/frapi/admin/application/modules/default/forms/Action.php
@@ -25,6 +25,19 @@ public function init()
$name->setRequired(true);
$this->addElement($name);
+ $model = new Default_Model_Versions;
+ $versions = $model->getAll();
+ $select = array();
+ foreach ($versions as $key => $version) {
+ $select[$version['hash']] = $version['name'];
+ }
+
+ $version = new Zend_Form_Element_Select('version');
+ $version->setLabel($tr->_('VERSION'));
+ $version->setRequired(true);
+ $version->addMultioptions(array(null => 'API Version') + $select);
+ $this->addElement($version);
+
$enabled = new Zend_Form_Element_Checkbox('enabled');
$enabled->setLabel($tr->_('IS_ACTION_ENABLED'));
$this->addElement($enabled);
View
42 src/frapi/admin/application/modules/default/forms/Versions.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://getfrapi.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@getfrapi.com so we can send you a copy immediately.
+ *
+ * @license New BSD
+ * @copyright echolibre ltd.
+ * @package frapi-admin
+ */
+class Default_Form_Versions extends Lupin_Form
+{
+ public function init()
+ {
+ $tr = Zend_Registry::get('tr');
+
+ $handle = new Zend_Form_Element_Text('name');
+ $handle->setLabel($tr->_('NAME'));
+ $handle->setRequired(true);
+ $this->addElement($handle);
+
+ $value = new Zend_Form_Element_Text('value');
+ $value->setLabel($tr->_('VALUE'));
+ $value->setRequired(true);
+ $this->addElement($value);
+
+ $value = new Zend_Form_Element_Text('urlPrefix');
+ $value->setLabel($tr->_('URL_PREFIX'));
+ $value->setRequired(true);
+ $this->addElement($value);
+
+ $this->addElement(new Zend_Form_Element_Submit($tr->_('SUBMIT')));
+
+ parent::init();
+ }
+}
View
8 src/frapi/admin/application/modules/default/models/Action.php
@@ -50,7 +50,8 @@ public function add(array $data)
{
$whitelist = array(
'name', 'enabled', 'description', 'public',
- 'param', 'required', 'route', 'use_custom_route'
+ 'param', 'required', 'route', 'use_custom_route',
+ 'version',
);
$this->whiteList($whitelist, $data);
@@ -67,7 +68,7 @@ public function add(array $data)
// Routes can only be lower case!
$data['route'] = strtolower($data['route']);
-
+
// Validate the route does not already exist and is valid
$router = new Frapi_Router();
$router->loadAndPrepareRoutes();
@@ -94,6 +95,7 @@ public function add(array $data)
'public' => $data['public'],
'description' => $data['description'],
'route' => $data['route'],
+ 'version' => $data['version'],
);
$values['parameters'] = array();
@@ -356,6 +358,8 @@ public function sync()
chmod($file, 0777);
}
}
+
+ $this->refreshAPCCache();
}
/**
View
153 src/frapi/admin/application/modules/default/models/Versions.php
@@ -0,0 +1,153 @@
+<?php
+/**
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://getfrapi.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@getfrapi.com so we can send you a copy immediately.
+ *
+ * @license New BSD
+ * @copyright echolibre ltd.
+ * @package frapi-admin
+ */
+class Default_Model_Versions extends Lupin_Model_DB
+{
+ /**
+ * A config object holding the Lupin_Config_Xml object
+ *
+ * @var Lupin_Config_Xml $config The config object.
+ */
+ protected $config;
+
+ /**
+ * Constructor
+ *
+ * The constructor for the Users model
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ $this->config = new Lupin_Config_Xml('versions');
+ }
+
+ /**
+ * Add a new users
+ *
+ * This method is invoked whenever the version adding controller
+ * is invoked.
+ *
+ * @param array $data The data to create the version with.
+ *
+ * @return boolean true
+ */
+ public function add(array $data)
+ {
+ if (!$this->nameAvailable($data['name'])) {
+ return false;
+ }
+
+ $whitelist = array('name', 'value', 'urlPrefix');
+ $this->whitelist($whitelist, $data);
+
+ $values = array(
+ 'name' => $data['name'],
+ 'value' => $data['value'],
+ 'urlPrefix' => $data['urlPrefix'],
+ 'hash' => sha1($data['name'] . time() . mt_rand(1, 100000)),
+ );
+
+ try {
+ $this->config->add('version', $values);
+ } catch (Exception $e) { }
+ return true;
+ }
+
+ /**
+ * Update a user
+ *
+ * This method updates a version using data passed
+ * to the $data method parameter.
+ *
+ * @param array $data The data array to update the version with.
+ * @param string $id An hash that contains the id of the version to update.
+ * @return boolean true
+ */
+ public function update(array $data, $id)
+ {
+ $whitelist = array('value', 'urlPrefix');
+ $this->whitelist($whitelist, $data);
+
+ $values = array('value' => $data['value'], 'urlPrefix' => $data['urlPrefix']);
+
+ try {
+ $this->config->update('version', 'hash', $id, $values);
+ } catch (Exception $e) { }
+
+ return true;
+ }
+
+ /**
+ * Delete a version
+ *
+ * This method deletes a version by it's hash-id
+ *
+ * @param string $id The id of the version to delete.
+ * @return void
+ */
+ public function delete($id)
+ {
+ $this->config->deleteByField('version', 'hash', $id);
+ }
+
+ /**
+ * Get a version
+ *
+ * This method is used to get a version by it's id.
+ *
+ * @param string $id The id of the version to get.
+ * @return mixed Either boolean false or the version information.
+ */
+ public function getVersion($id)
+ {
+ $version = $this->config->getByField('version', 'hash', $id);
+ return isset($version) ? $version : false;
+ }
+
+ /**
+ * Checks if a name exists
+ *
+ * This method is used to validate whether or not a name is
+ * available for a new version.
+ *
+ * @param string $name The name to validate.
+ * @return boolean True if the version name is free and false if the handle is taken.
+ */
+ public function nameAvailable($name)
+ {
+ $name = $this->config->getByField('version', 'name', $name);
+
+ if (isset($name) && $name !== false) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Get all versions
+ *
+ * Get all the versions.
+ *
+ * @return mixed Either boolean false or an array of all versions.
+ */
+ public function getAll()
+ {
+ $versions = $this->config->getAll('version');
+ return $versions;
+ }
+}
View
1  src/frapi/admin/application/modules/default/views/scripts/versions/add.phtml
@@ -0,0 +1 @@
+<?php echo $this->form; ?>
View
0  src/frapi/admin/application/modules/default/views/scripts/versions/delete.phtml
No changes.
View
6 src/frapi/admin/application/modules/default/views/scripts/versions/edit.phtml
@@ -0,0 +1,6 @@
+<div class="field-block">
+<label for="name"><?php echo $this->tr->_('NAME'); ?></label>
+<?php echo $this->name; ?>
+</div>
+
+<?php echo $this->form; ?>
View
47 src/frapi/admin/application/modules/default/views/scripts/versions/index.phtml
@@ -0,0 +1,47 @@
+<div style="float: left"><form id="filter-form"><?php echo $this->tr->_('FILTER'); ?>: <input name="filter" id="filter" value="" maxlength="30" size="30" type="text"></form></div>
+<br /><br /><br /><br /><br />
+
+ <table id="list">
+ <thead>
+ <tr>
+ <th><?php echo $this->tr->_('NAME'); ?></th>
+ <th><?php echo $this->tr->_('URL_PREFIX'); ?></th>
+ </tr>
+ </thead>
+ <tbody>
+<?php if (!empty($this->data)): foreach ($this->data as $d) : if (is_array($d) && !empty($d)) : ?>
+ <tr>
+ <td><?php echo $d['name']; ?></td>
+ <td style="text-align: center;">
+ <a href="/versions/edit/id/<?php echo $d['hash']; ?>"><?php echo $this->tr->_('EDIT'); ?></a> |
+ <a href="/versions/delete/id/<?php echo $d['hash']; ?>"><?php echo $this->tr->_('DELETE'); ?></a>
+ </td>
+ </tr>
+<?php endif; endforeach; endif; ?>
+ </tbody>
+ </table>
+
+
+<script type="text/javascript">
+$(function() {
+ var t = $('table#list')
+ t.tablesorter({
+ sortList:[[0,0]],
+ widgets: ['zebra'],
+ dateFormat: 'dd.mm.yyyy',
+ headers: {
+ 1: { sorter: false }
+ }
+ });
+
+
+ $("#filter").keyup(function() {
+ $.uiTableFilter(t, this.value);
+ })
+
+ $('#filter-form').submit(function(){
+ t.find("tbody > tr:visible > td:eq(1)").mousedown();
+ return false;
+ }).focus(); //Give focus to input field
+});
+</script>
View
4 src/frapi/admin/application/views/scripts/submenu.phtml
@@ -29,6 +29,8 @@ if ($pos !== false && $pos === $lpos) {
<li<?php echo $item == '/user' ? ' class="active"' : '' ?>><a href="/user"><?php echo $this->tr->_('USERS'); ?></a></li>
<li<?php echo $item == '/output' ? ' class="active"' : '' ?>><a href="/output"><?php echo $this->tr->_('OUTPUT'); ?></a></li>
<li<?php echo $item == '/database' ? ' class="active"' : '' ?>><a href="/database"><?php echo $this->tr->_('DATABASE'); ?></a></li>
+ <li<?php echo $item == '/versions' ? ' class="active"' : '' ?>><a href="/versions"><?php echo $this->tr->_('VERSIONS'); ?></a></li>
+
<?php } elseif ($item == '/user') { ?>
<li<?php echo $item == '/user/add' ? ' class="active"' : '' ?>><a href="/user/add"><?php echo $this->tr->_('ADD_NEW_USER'); ?></a></li>
<?php } elseif ($item == '/partners') { ?>
@@ -37,6 +39,8 @@ if ($pos !== false && $pos === $lpos) {
<li<?php echo $item == '/errors/add' ? ' class="active"' : '' ?>><a href="/errors/add"><?php echo $this->tr->_('ADD_NEW_ERROR'); ?></a></li>
<?php } elseif ($item == '/action') { ?>
<li<?php echo $item == '/action/add' ? ' class="active"' : '' ?>><a href="/action/add"><?php echo $this->tr->_('ADD_NEW_ACTION'); ?></a></li>
+ <?php } elseif ($item == '/versions') { ?>
+ <li<?php echo $item == '/versions/add' ? ' class="active"' : '' ?>><a href="/versions/add"><?php echo $this->tr->_('ADD_NEW_VERSION'); ?></a></li>
<?php } ?>
</div>
<?php endif; ?>
View
2  src/frapi/custom/AllFiles.php
@@ -1,6 +1,6 @@
<?php
// If you remove this. You might die.
-define('FRAPI_CACHE_ADAPTER', 'dummy');
+define('FRAPI_CACHE_ADAPTER', 'apc');
// Use the constant CUSTOM_MODEL to access the custom model directory
// IE: require CUSTOM_MODEL . DIRECTORY_SEPARATOR . 'ModelName.php';
View
10 src/frapi/custom/Config/actions.xml 100644 → 100755
@@ -28,5 +28,15 @@
</parameter>
</parameters>
</action>
+ <action>
+ <name>Testing3</name>
+ <enabled>1</enabled>
+ <public>1</public>
+ <description></description>
+ <route>/custom/route/:var</route>
+ <version>d7b36825b1141a96e7181a6fee277944d61edd9a</version>
+ <parameters></parameters>
+ <hash>95f61f431f09d2b8dc13c173d570edf8776b785e</hash>
+ </action>
</actions>
</frapi-config>
View
0  src/frapi/custom/Config/configurations.xml 100644 → 100755
File mode changed
View
0  src/frapi/custom/Config/errors.xml 100644 → 100755
File mode changed
View
0  src/frapi/custom/Config/outputs.xml 100644 → 100755
File mode changed
View
0  src/frapi/custom/Config/partners.xml 100644 → 100755
File mode changed
View
0  src/frapi/custom/Config/users.xml 100644 → 100755
File mode changed
View
11 src/frapi/custom/Config/versions.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<frapi-config>
+ <versions>
+ <version>
+ <name>latest</name>
+ <value>latest</value>
+ <urlPrefix>latest</urlPrefix>
+ <hash>d7b36825b1141a96e7181a6fee277944d61edd9a</hash>
+ </version>
+ </versions>
+</frapi-config>

No commit comments for this range

Something went wrong with that request. Please try again.