NelmioApiDocBundle/Parser/CollectionParser.php

75 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2014-08-07 17:02:15 -07:00
<?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\Parser;
use Nelmio\ApiDocBundle\DataTypes;
/**
* Handles models that are specified as collections.
*
* @author Bez Hermoso <bez@activelamp.com>
*/
class CollectionParser implements ParserInterface, PostParserInterface
{
/**
* Return true/false whether this class supports parsing the given class.
*
2015-03-06 11:19:08 +01:00
* @param array $item containing the following fields: class, groups. Of which groups is optional
2014-08-07 17:02:15 -07:00
*
2024-10-01 15:54:04 +03:00
* @return bool
2014-08-07 17:02:15 -07:00
*/
public function supports(array $item)
{
2024-10-01 15:54:04 +03:00
return isset($item['collection']) && true === $item['collection'];
2014-08-07 17:02:15 -07:00
}
/**
* This doesn't parse anything at this stage.
*
* @return array
*/
public function parse(array $item)
{
2024-10-01 15:54:04 +03:00
return [];
2014-08-07 17:02:15 -07:00
}
/**
* @param array|string $item The string type of input to parse.
2015-03-06 11:19:08 +01:00
* @param array $parameters The previously-parsed parameters array.
2014-08-07 17:02:15 -07:00
*
* @return array
*/
public function postParse(array $item, array $parameters)
{
$origParameters = $parameters;
foreach ($parameters as $name => $body) {
$parameters[$name] = null;
}
2024-10-01 15:54:04 +03:00
$collectionName = $item['collectionName'] ?? '';
2014-08-07 17:02:15 -07:00
2024-10-01 15:54:04 +03:00
$parameters[$collectionName] = [
2014-08-07 17:02:15 -07:00
'dataType' => null, // Delegates to ApiDocExtractor#generateHumanReadableTypes
'subType' => $item['class'],
'actualType' => DataTypes::COLLECTION,
'readonly' => true,
'required' => true,
'default' => true,
'description' => '',
'children' => $origParameters,
2024-10-01 15:54:04 +03:00
];
2014-08-07 17:02:15 -07:00
return $parameters;
}
2015-03-06 11:19:08 +01:00
}