Last active
May 17, 2018 09:23
-
-
Save IvanAlekseevichPopov/640bd8b03d4b72d75d8cd0c1ec843bde to your computer and use it in GitHub Desktop.
nelmio doc view
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
<?php | |
class CustomsStatisticsController { | |
/** | |
* @SWG\Response( | |
* response=200, | |
* description="Returns customs statistics list joined by tnved", | |
* @Model(type=\App\Form\Model\View\CustomStatisticsListView::class) | |
*/ | |
public function customsStatisticsListAction(Request $request, Tnved $tnved) | |
{ | |
//....... | |
return new CustomStatisticsListView($paginatedList); | |
} | |
} |
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
<?php | |
declare(strict_types = 1); | |
namespace App\Form\Model\View; | |
use App\Form\Model\Response\PaginatedList; | |
/** | |
* Class ListView | |
*/ | |
abstract class AbstractListView | |
{ | |
/** | |
* @var array | |
*/ | |
public $data; | |
/** | |
* @var MetaView | |
*/ | |
public $meta; | |
/** | |
* CustomStatisticsView constructor. | |
* | |
* @param PaginatedList $list | |
*/ | |
public function __construct(PaginatedList $list) | |
{ | |
$this->setData($list); | |
$this->setMeta($list); | |
} | |
abstract protected function setData(PaginatedList $list); | |
protected function setMeta(PaginatedList $list) | |
{ | |
$this->meta = new MetaView($list); | |
} | |
} |
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
<?php | |
declare(strict_types = 1); | |
namespace App\Form\Model\View; | |
use App\Entity\CustomsStatisticsEntry; | |
use App\Form\Model\Response\PaginatedList; | |
/** | |
* Class CustomStatisticsView | |
*/ | |
class CustomStatisticsListView extends AbstractListView | |
{ | |
/** | |
* @var CustomStatisticsView[] | |
*/ | |
public $data; | |
protected function setData(PaginatedList $list) | |
{ | |
$this->data = array_map( | |
function (CustomsStatisticsEntry $entry) { | |
return new CustomStatisticsView($entry); | |
}, | |
$list->getData() | |
); | |
} | |
} |
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
<?php | |
declare(strict_types = 1); | |
namespace App\Form\Model\View; | |
use App\Entity\CustomsStatisticsEntry; | |
/** | |
* Class CustomStatisticsView | |
*/ | |
class CustomStatisticsView | |
{ | |
/** | |
* @var int | |
* | |
*/ | |
public $id; | |
/** | |
* CustomStatisticsView constructor. | |
* | |
* @param CustomsStatisticsEntry $customsStatisticsEntry | |
*/ | |
public function __construct(CustomsStatisticsEntry $customsStatisticsEntry) | |
{ | |
$this->id = $customsStatisticsEntry->getId(); | |
} | |
} |
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
<?php | |
declare(strict_types = 1); | |
namespace App\Form\Model\View; | |
use App\Form\Model\Response\PaginatedList; | |
/** | |
* Class MetaView | |
*/ | |
class MetaView | |
{ | |
/** | |
* @var int | |
*/ | |
public $total; | |
/** | |
* @var int | |
*/ | |
public $totalPages; | |
/** | |
* MetaView constructor. | |
* | |
* @param PaginatedList $list | |
*/ | |
public function __construct(PaginatedList $list) | |
{ | |
$this->totalPages = $list->getTotalPages(); | |
$this->total = $list->getTotal(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment