-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract JSON renderer data collector service.
- Loading branch information
Igor Nikolaev
committed
Nov 24, 2020
1 parent
c076979
commit 12970b3
Showing
5 changed files
with
81 additions
and
23 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* @author Igor Nikolaev <igor.sv.n@gmail.com> | ||
* @copyright Copyright (c) 2020, Darvin Studio | ||
* @link https://www.darvin-studio.ru | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Darvin\MenuBundle\Renderer\Json; | ||
|
||
use Knp\Menu\ItemInterface; | ||
|
||
/** | ||
* JSON renderer data collector | ||
*/ | ||
class DataCollector implements DataCollectorInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getData(ItemInterface $item, array $ids): array | ||
{ | ||
return [ | ||
'id' => $ids[$item->getName()], | ||
'name' => $item->getLabel(), | ||
'href' => $item->getUri(), | ||
'hasChild' => $item->hasChildren(), | ||
'parentId' => null !== $item->getParent() && !$item->getParent()->isRoot() ? $ids[$item->getParent()->getName()] : null, | ||
]; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* @author Igor Nikolaev <igor.sv.n@gmail.com> | ||
* @copyright Copyright (c) 2020, Darvin Studio | ||
* @link https://www.darvin-studio.ru | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Darvin\MenuBundle\Renderer\Json; | ||
|
||
use Knp\Menu\ItemInterface; | ||
|
||
/** | ||
* JSON renderer data collector | ||
*/ | ||
interface DataCollectorInterface | ||
{ | ||
/** | ||
* @param \Knp\Menu\ItemInterface $item Menu item | ||
* @param array $ids IDs | ||
* | ||
* @return array | ||
*/ | ||
public function getData(ItemInterface $item, array $ids): array; | ||
} |
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
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