Skip to content

Commit

Permalink
Add TagsService::sudo to public API
Browse files Browse the repository at this point in the history
  • Loading branch information
emodric committed Apr 1, 2019
1 parent befcd68 commit 905da90
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 44 deletions.
24 changes: 24 additions & 0 deletions bundle/API/Repository/TagsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Netgen\TagsBundle\API\Repository\Values\Tags\Tag;
use Netgen\TagsBundle\API\Repository\Values\Tags\TagCreateStruct;
use Netgen\TagsBundle\API\Repository\Values\Tags\TagUpdateStruct;
use Closure;

interface TagsService
{
Expand Down Expand Up @@ -314,4 +315,27 @@ public function newSynonymCreateStruct($mainTagId, $mainLanguageCode);
* @return \Netgen\TagsBundle\API\Repository\Values\Tags\TagUpdateStruct
*/
public function newTagUpdateStruct();

/**
* Allows tags API execution to be performed with full access sand-boxed.
*
* The closure sandbox will do a catch all on exceptions and rethrow after
* re-setting the sudo flag.
*
* Example use:
* $tag = $tagsService->sudo(
* function (TagsService $tagsService) use ($tagId) {
* return $tagsService->loadTag($tagId);
* }
* );
*
* @param \Closure $callback
* @param \Netgen\TagsBundle\API\Repository\TagsService $outerTagsService
*
* @throws \RuntimeException Thrown on recursive sudo() use
* @throws \Exception Re throws exceptions thrown inside $callback
*
* @return mixed
*/
public function sudo(Closure $callback, TagsService $outerTagsService = null);
}
21 changes: 0 additions & 21 deletions bundle/Core/Repository/TagsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1011,27 +1011,6 @@ public function newTagUpdateStruct()
return new TagUpdateStruct();
}

/**
* Allows tags API execution to be performed with full access sand-boxed.
*
* The closure sandbox will do a catch all on exceptions and rethrow after
* re-setting the sudo flag.
*
* Example use:
* $tag = $tagsService->sudo(
* function (TagsService $tagsService) use ($tagId) {
* return $tagsService->loadTag($tagId);
* }
* );
*
* @param \Closure $callback
* @param \Netgen\TagsBundle\API\Repository\TagsService $outerTagsService
*
* @throws \RuntimeException Thrown on recursive sudo() use
* @throws \Exception Re throws exceptions thrown inside $callback
*
* @return mixed
*/
public function sudo(Closure $callback, TagsServiceInterface $outerTagsService = null)
{
++$this->sudoNestingLevel;
Expand Down
25 changes: 2 additions & 23 deletions bundle/Core/SignalSlot/TagsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,29 +506,8 @@ public function newTagUpdateStruct()
return $this->service->newTagUpdateStruct();
}

/**
* Allows tags API execution to be performed with full access sand-boxed.
*
* The closure sandbox will do a catch all on exceptions and rethrow after
* re-setting the sudo flag.
*
* Example use:
* $tag = $tagsService->sudo(
* function ( TagsService $tagsService ) use ( $tagId )
* {
* return $tagsService->loadTag( $tagId );
* }
* );
*
* @param \Closure $callback
*
* @throws \RuntimeException Thrown on recursive sudo() use
* @throws \Exception Re throws exceptions thrown inside $callback
*
* @return mixed
*/
public function sudo(Closure $callback)
public function sudo(Closure $callback, TagsServiceInterface $outerTagsService = null)
{
return $this->service->sudo($callback, $this);
return $this->service->sudo($callback, $outerTagsService !== null ? $outerTagsService : $this);
}
}

0 comments on commit 905da90

Please sign in to comment.