eZ\Publish\Core\Helper\ContentInfoLocationLoader\SudoMainLocationLoader::loadLocation PHP Метод

loadLocation() публичный Метод

public loadLocation ( eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo )
$contentInfo eZ\Publish\API\Repository\Values\Content\ContentInfo
    public function loadLocation(ContentInfo $contentInfo)
    {
        if (is_null($contentInfo->mainLocationId)) {
            throw new NotFoundException('main location of content', $contentInfo->id);
        }
        try {
            return $this->repository->sudo(function (Repository $repository) use($contentInfo) {
                return $repository->getLocationService()->loadLocation($contentInfo->mainLocationId);
            });
        } catch (Exception $e) {
            throw new NotFoundException('main location of content', $contentInfo->id);
        }
    }

Usage Example

 /**
  * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
  */
 public function testLoadLocationError()
 {
     $contentInfo = new ContentInfo(['mainLocationId' => 42]);
     $location = new Location();
     $this->getRepositoryMock()->expects($this->any())->method('getPermissionResolver')->will($this->returnValue($this->getPermissionResolverMock()));
     $this->getRepositoryMock()->expects($this->any())->method('getLocationService')->will($this->returnValue($this->getLocationServiceMock()));
     $this->getLocationServiceMock()->expects($this->once())->method('loadLocation')->with(42)->will($this->throwException(new NotFoundException('main location of content', 42)));
     $this->assertSame($location, $this->loader->loadLocation($contentInfo));
 }
SudoMainLocationLoader