NelmioApiDocBundle/Formatter/AbstractFormatter.php
William DURAND cca97cf6af Refactoring
Move logic to extract data in the Extractor
Remove logic in the AbstractFormatter
Use ApiDoc class as data container
Update tests
Add test to prove the bug with FOSRestBundle annotations (\\d+ instead of \d+)
2012-07-20 01:32:16 +02:00

55 lines
1.2 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*
* This file is part of the NelmioApiDocBundle.
*
* (c) Nelmio <hello@nelm.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\Formatter;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
abstract class AbstractFormatter implements FormatterInterface
{
/**
* {@inheritdoc}
*/
public function formatOne(ApiDoc $annotation)
{
return $this->renderOne($annotation->toArray());
}
/**
* {@inheritdoc}
*/
public function format(array $collection)
{
$array = array();
foreach ($collection as $coll) {
$array[$coll['resource']][] = $coll['annotation']->toArray();
}
return $this->render($array);
}
/**
* Format a single array of data
*
* @param array $data
* @return string|array
*/
abstract protected function renderOne(array $data);
/**
* Format a set of resource sections.
*
* @param array $collection
* @return string|array
*/
abstract protected function render(array $collection);
}