-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
286 additions
and
4 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
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
33 changes: 33 additions & 0 deletions
33
src/lib/REST/Input/Parser/ContentTree/LoadExtendedNodeInfoRequest.php
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 | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\AdminUi\REST\Input\Parser\ContentTree; | ||
|
||
use Ibexa\AdminUi\REST\Value\ContentTree\LoadNodeExtendedInfoRequest as LoadNodeExtendedInfoRequestValue; | ||
use Ibexa\Contracts\Rest\Exceptions; | ||
use Ibexa\Contracts\Rest\Input\ParsingDispatcher; | ||
use Ibexa\Rest\Input\BaseParser; | ||
|
||
class LoadExtendedNodeInfoRequest extends BaseParser | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function parse(array $data, ParsingDispatcher $parsingDispatcher): LoadNodeExtendedInfoRequestValue | ||
Check failure on line 21 in src/lib/REST/Input/Parser/ContentTree/LoadExtendedNodeInfoRequest.php GitHub Actions / Tests (7.4)
Check failure on line 21 in src/lib/REST/Input/Parser/ContentTree/LoadExtendedNodeInfoRequest.php GitHub Actions / Tests (8.0)
Check failure on line 21 in src/lib/REST/Input/Parser/ContentTree/LoadExtendedNodeInfoRequest.php GitHub Actions / Tests (8.1)
|
||
{ | ||
if (!array_key_exists('locationId', $data) || !is_int($data['locationId'])) { | ||
throw new Exceptions\Parser( | ||
sprintf("Missing or invalid 'locationId' property for %s.", self::class) | ||
); | ||
} | ||
|
||
$locationId = $data['locationId']; | ||
|
||
return new LoadNodeExtendedInfoRequestValue($locationId); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/lib/REST/Output/ValueObjectVisitor/ContentTree/NodeExtendedInfo.php
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,70 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\AdminUi\REST\Output\ValueObjectVisitor\ContentTree; | ||
|
||
use Ibexa\Contracts\Rest\Output\Generator; | ||
use Ibexa\Contracts\Rest\Output\ValueObjectVisitor; | ||
use Ibexa\Contracts\Rest\Output\Visitor; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* @phpstan-import-type PermissionRestrictions from \Ibexa\AdminUi\REST\Value\ContentTree\NodeExtendedInfo | ||
*/ | ||
class NodeExtendedInfo extends ValueObjectVisitor | ||
{ | ||
/** | ||
* Visit struct returned by controllers. | ||
* | ||
* @param \Ibexa\Contracts\Rest\Output\Visitor $visitor | ||
* @param \Ibexa\Contracts\Rest\Output\Generator $generator | ||
* @param \Ibexa\AdminUi\REST\Value\ContentTree\NodeExtendedInfo $data | ||
*/ | ||
public function visit(Visitor $visitor, Generator $generator, $data): void | ||
{ | ||
$generator->startObjectElement('ContentTreeNodeExtendedInfo'); | ||
$visitor->setHeader('Content-Type', $generator->getMediaType('ContentTreeNodeExtendedInfo')); | ||
$visitor->setStatus(Response::HTTP_OK); | ||
|
||
$this->buildPermissionNode($data->getPermissionRestrictions(), $generator); | ||
|
||
$generator->endObjectElement('ContentTreeNodeExtendedInfo'); | ||
} | ||
|
||
/** | ||
* @phpstan-param PermissionRestrictions $permissionRestrictions | ||
*/ | ||
protected function buildPermissionNode( | ||
?array $permissionRestrictions, | ||
Generator $generator | ||
): void { | ||
if (null === $permissionRestrictions) { | ||
return; | ||
} | ||
|
||
$generator->startHashElement('permissions'); | ||
|
||
foreach ($permissionRestrictions as $function => $restrictions) { | ||
$generator->startHashElement($function); | ||
foreach ($restrictions as $restrictionKey => $restrictionValue) { | ||
if (is_array($restrictionValue)) { | ||
$generator->startList($restrictionKey); | ||
foreach ($restrictionValue as $value) { | ||
$generator->valueElement($restrictionKey, $value); | ||
} | ||
$generator->endList($restrictionKey); | ||
} else { | ||
$generator->valueElement($restrictionKey, $restrictionValue); | ||
} | ||
} | ||
$generator->endHashElement($function); | ||
} | ||
|
||
$generator->endHashElement('permissions'); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/lib/REST/Value/ContentTree/LoadNodeExtendedInfoRequest.php
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,21 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\AdminUi\REST\Value\ContentTree; | ||
|
||
use Ibexa\Rest\Value as RestValue; | ||
|
||
class LoadNodeExtendedInfoRequest extends RestValue | ||
{ | ||
public int $locationId; | ||
|
||
public function __construct(int $locationId) | ||
{ | ||
$this->locationId = $locationId; | ||
} | ||
} |
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,46 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\AdminUi\REST\Value\ContentTree; | ||
|
||
use Ibexa\Rest\Value as RestValue; | ||
|
||
/** | ||
* @phpstan-type Restrictions array{ | ||
* hasAccess: bool, | ||
* restrictedContentTypeIds: array<int>, | ||
* restrictedLanguageCodes: array<string>, | ||
* } | ||
* | ||
* @phpstan-type PermissionRestrictions array{ | ||
* create: Restrictions, | ||
* edit: Restrictions, | ||
* } | ||
*/ | ||
class NodeExtendedInfo extends RestValue | ||
{ | ||
/** @phpstan-var PermissionRestrictions|null */ | ||
private ?array $permissions; | ||
|
||
/** | ||
* @phpstan-param PermissionRestrictions|null $permissions | ||
*/ | ||
public function __construct( | ||
?array $permissions = null, | ||
) { | ||
$this->permissions = $permissions; | ||
} | ||
|
||
/** | ||
* @return PermissionRestrictions|null | ||
*/ | ||
public function getPermissionRestrictions(): ?array | ||
{ | ||
return $this->permissions; | ||
} | ||
} |