Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ protected function cleanupParameters($params)
unset($params['module']);
unset($params['action']);

$additional_params = <?php var_export($this->configuration->getValue('get.additional_params', array())); ?>;

foreach ($params as $name => $value)
{
if ((null === $value) || ('' === $value) || in_array($name, $additional_params))
if ((null === $value) || ('' === $value) || in_array($name, $this->additional_params))
{
unset($params[$name]);
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Format objects for output
*
* @param array $params The request parameters
* @return void
*/
protected function formatObjects(array $params)
{
<?php if (count($this->configuration->getValue('get.object_additional_fields')) > 0): ?>

foreach ($this->objects as $key => $object)
{
<?php foreach ($this->configuration->getValue('get.object_additional_fields') as $field): ?>
$this->embedAdditional<?php echo $field ?>($key, $params);
<?php endforeach; ?>
}
<?php endif; ?>
<?php foreach ($this->configuration->getValue('get.global_additional_fields') as $field): ?>
$this->embedGlobalAdditional<?php echo $field ?>($params);
<?php endforeach; ?>

// configure the fields of the returned objects and eventually hide some
$this->setFieldVisibility();
$this->configureFields();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,15 @@ public function getIndexValidators()
<?php foreach ($this->getColumns() as $column): ?>
$validators['<?php echo $column->getFieldName() ?>'] = new <?php echo $this->getIndexValidatorClassForColumn($column) ?>(<?php echo $this->getIndexValidatorOptionsForColumn($column) ?>);
<?php endforeach; ?>
<?php
$pagination_custom_page_size = $this->configuration->getValue('get.pagination_custom_page_size');
$pagination_enabled = $this->configuration->getValue('get.pagination_enabled');
$max_items = $this->configuration->getValue('get.max_items'); ?>
<?php if ($pagination_enabled): ?>
$validators['page'] = new sfValidatorInteger(array('min' => 1, 'required' => false));
<?php if ($pagination_custom_page_size && ($max_items > 0)): ?>
$params = array(
'min' => 1,
'max' => <?php echo $max_items ?>,
'required' => false
);
$validators['page_size'] = new sfValidatorInteger($params);
<?php endif; ?>
<?php endif; ?>
<?php $sort_custom = $this->configuration->getValue('get.sort_custom'); ?>
<?php if ($sort_custom): ?>
$validators['sort_by'] = new sfValidatorChoice(array('choices' => <?php echo var_export($this->table->getColumnNames()) ?>, 'required' => false));
$validators['sort_order'] = new sfValidatorChoice(array('choices' => array('asc', 'desc'), 'required' => false));
<?php endif; ?>
<?php $additional_params = $this->configuration->getValue('get.additional_params'); ?>
<?php if ($additional_params): ?>
<?php foreach ($additional_params as $param): ?>
$validators['<?php echo $param; ?>'] = new sfValidatorPass(array('required' => false));
<?php endforeach; ?>
<?php endif; ?>

$validators = array_merge($validators, $this->getPaginationValidators());

$validators = array_merge($validators, $this->getSortValidators());

foreach ($this->additional_params as $param)
{
$validators[$param] = new sfValidatorPass(array('required' => false));
}

return $validators;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
$pagination_custom_page_size = $this->configuration->getValue('get.pagination_custom_page_size');
$max_items = $this->configuration->getValue('get.max_items');
?>
/**
* Returns the list of pagination validators
* @return array an array of validators
*/
protected function getPaginationValidators()
{
$validators = array();
$validators['page'] = new sfValidatorInteger(array('min' => 1, 'required' => false));
<?php if ($pagination_custom_page_size && ($max_items > 0)): ?>
$validators['page_size'] = new sfValidatorInteger(array(
'min' => 1,
'max' => <?php echo $max_items ?>,
'required' => false
));
<?php endif; ?>
return $validators;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Returns the list of sort validators
* @return array an array of validators
*/
protected function getSortValidators()
{
$validators['sort_by'] = new sfValidatorChoice(array(
'choices' => <?php echo var_export($this->table->getColumnNames()) ?>,
'required' => false,
));
$validators['sort_order'] = new sfValidatorChoice(array(
'choices' => array('asc', 'desc'),
'required' => false,
));
return $validators;
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public function executeIndex(sfWebRequest $request)
$this->dispatcher->notify(new sfEvent($this, 'sfDoctrineRestGenerator.get.pre', array('params' => $params)));

$request->setRequestFormat('html');
$this->setTemplate('index');
$params = $this->cleanupParameters($params);

try
Expand All @@ -22,27 +23,7 @@ public function executeIndex(sfWebRequest $request)
catch (Exception $e)
{
$this->getResponse()->setStatusCode(406);
$serializer = $this->getSerializer();
$this->getResponse()->setContentType($serializer->getContentType());
$error = $e->getMessage();

// event filter to enable customisation of the error message.
$result = $this->dispatcher->filter(
new sfEvent($this, 'sfDoctrineRestGenerator.filter_error_output'),
$error
)->getReturnValue();

if ($error === $result)
{
$error = array(array('message' => $error));
$this->output = $serializer->serialize($error, 'error');
}
else
{
$this->output = $serializer->serialize($result);
}

return sfView::SUCCESS;
return $this->handleException($e);
}

$this->queryExecute($params);
Expand All @@ -62,27 +43,9 @@ public function executeIndex(sfWebRequest $request)
<?php if ($this->isManyToManyRelation($embed_relation)): ?>
$this->embedManyToMany<?php echo $embed_relation ?>($params);
<?php endif; ?><?php endforeach; ?>
<?php $object_additional_fields = $this->configuration->getValue('get.object_additional_fields'); ?>
<?php if (count($object_additional_fields) > 0): ?>

foreach ($this->objects as $key => $object)
{
<?php foreach ($object_additional_fields as $field): ?>
$this->embedAdditional<?php echo $field ?>($key, $params);
<?php endforeach; ?>
}
<?php endif; ?><?php $global_additional_fields = $this->configuration->getValue('get.global_additional_fields'); ?>
<?php foreach ($global_additional_fields as $field): ?>

$this->embedGlobalAdditional<?php echo $field ?>($params);
<?php endforeach; ?>

// configure the fields of the returned objects and eventually hide some
$this->setFieldVisibility();
$this->configureFields();
$this->formatObjects($params);

$serializer = $this->getSerializer();
$this->getResponse()->setContentType($serializer->getContentType());
$this->output = $serializer->serialize($this->objects, $this->model);
$this->outputObjects(true);
unset($this->objects);
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,15 @@ public function executeShow(sfWebRequest $request)
}
catch (Exception $e)
{
$this->getResponse()->setStatusCode(406);
$serializer = $this->getSerializer();
$this->getResponse()->setContentType($serializer->getContentType());
$error = $e->getMessage();

// event filter to enable customisation of the error message.
$result = $this->dispatcher->filter(
new sfEvent($this, 'sfDoctrineRestGenerator.filter_error_output'),
$error
)->getReturnValue();

if ($error === $result)
{
$error = array(array('message' => $error));
$this->output = $serializer->serialize($error, 'error');
}
else
{
$this->output = $serializer->serialize($result);
}

return sfView::SUCCESS;
$this->getResponse()->setStatusCode(406);
return $this->handleException($e);
}

$this->queryFetchOne($params);
$this->forward404Unless(is_array($this->objects[0]));

<?php foreach ($this->configuration->getValue('get.object_additional_fields') as $field): ?>
$this->embedAdditional<?php echo $field ?>(0, $params);
<?php endforeach; ?>
<?php foreach ($this->configuration->getValue('get.global_additional_fields') as $field): ?>
$this->embedGlobalAdditional<?php echo $field ?>($params);
<?php endforeach; ?>

$this->setFieldVisibility();
$this->configureFields();
$this->formatObjects($params);

$serializer = $this->getSerializer();
$this->getResponse()->setContentType($serializer->getContentType());
$this->output = $serializer->serialize($this->objects[0], $this->model, false);
$this->outputObjects(false);
unset($this->objects);
}
Loading