-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IBX-4123: [Backport] Added /languages
and /languages/{code}
endpoints
#107
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9f6fcce
IBX-4123: [Backport] Added `/languages` and `/languages/{code}` endpo…
Steveb-p 0608432
IBX-4123: [Backport] Added `/languages` and `/languages/{code}` endpo…
Steveb-p 5c0c1fe
IBX-4123: [Backport] Added `/languages` and `/languages/{code}` endpo…
Steveb-p dc270cc
IBX-4123: [Backport] Added `/languages` and `/languages/{code}` endpo…
Steveb-p f36a54b
IBX-4123: [Backport] Added `/languages` and `/languages/{code}` endpo…
Steveb-p 6c69db6
IBX-4123: [Backport] Added `/languages` and `/languages/{code}` endpo…
Steveb-p 0acd10f
IBX-4123: [Backport] Added `/languages` and `/languages/{code}` endpo…
Steveb-p 79983af
IBX-4123: [Backport] Added `/languages` and `/languages/{code}` endpo…
Steveb-p a48f66f
Switched to new Ibexa namespace for new classes
Steveb-p caa2eb7
Switched to new Ibexa namespace for new classes
Steveb-p ee4fe51
Switched to new Ibexa namespace for new classes
Steveb-p File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformRest\Server\Controller; | ||
|
||
use eZ\Publish\API\Repository\LanguageService; | ||
use eZ\Publish\API\Repository\Values\Content\Language as ApiLanguage; | ||
use EzSystems\EzPlatformRest\Server\Controller as RestController; | ||
use EzSystems\EzPlatformRest\Server\Values\LanguageList; | ||
use Traversable; | ||
|
||
final class Language extends RestController | ||
{ | ||
/** @var \eZ\Publish\API\Repository\LanguageService */ | ||
private $languageService; | ||
|
||
public function __construct(LanguageService $languageService) | ||
{ | ||
$this->languageService = $languageService; | ||
} | ||
|
||
public function listLanguages(): LanguageList | ||
{ | ||
$languages = $this->languageService->loadLanguages(); | ||
|
||
if ($languages instanceof Traversable) { | ||
$languages = iterator_to_array($languages); | ||
} | ||
|
||
return new LanguageList($languages); | ||
} | ||
|
||
public function loadLanguage(string $languageCode): ApiLanguage | ||
{ | ||
return $this->languageService->loadLanguage($languageCode); | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformRest\Server\Output\ValueObjectVisitor; | ||
|
||
use EzSystems\EzPlatformRest\Output\Generator; | ||
use EzSystems\EzPlatformRest\Output\ValueObjectVisitor; | ||
use EzSystems\EzPlatformRest\Output\Visitor; | ||
|
||
final class LanguageList extends ValueObjectVisitor | ||
{ | ||
/** | ||
* @param \EzSystems\EzPlatformRest\Server\Values\LanguageList $data | ||
*/ | ||
public function visit(Visitor $visitor, Generator $generator, $data): void | ||
{ | ||
$generator->startObjectElement('LanguageList'); | ||
$visitor->setHeader('Content-Type', $generator->getMediaType('LanguageList')); | ||
|
||
$generator->attribute('href', $this->router->generate('ibexa.rest.languages.list')); | ||
|
||
$generator->startList('Language'); | ||
foreach ($data->languages as $language) { | ||
$visitor->visitValueObject($language); | ||
} | ||
$generator->endList('Language'); | ||
|
||
$generator->endObjectElement('LanguageList'); | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformRest\Server\Values; | ||
|
||
use EzSystems\EzPlatformRest\Value as RestValue; | ||
|
||
final class LanguageList extends RestValue | ||
{ | ||
/** @var \eZ\Publish\API\Repository\Values\Content\Language[] */ | ||
public $languages; | ||
|
||
/** | ||
* @param array<\eZ\Publish\API\Repository\Values\Content\Language> $languages | ||
*/ | ||
public function __construct(array $languages) | ||
{ | ||
$this->languages = $languages; | ||
} | ||
} |
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,38 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object", | ||
"properties": { | ||
"Language": { | ||
"type": "object", | ||
"properties": { | ||
"_media-type": { | ||
"type": "string" | ||
}, | ||
"_href": { | ||
"type": "string" | ||
}, | ||
"languageId": { | ||
"type": "integer" | ||
}, | ||
"languageCode": { | ||
"type": "string", | ||
"minLength": 1, | ||
"pattern": "^[[:alnum:]_]+" | ||
}, | ||
"name": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"_media-type", | ||
"_href", | ||
"languageId", | ||
"languageCode", | ||
"name" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"Language" | ||
] | ||
} |
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,56 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object", | ||
"properties": { | ||
"LanguageList": { | ||
"type": "object", | ||
"properties": { | ||
"_media-type": { | ||
"type": "string" | ||
}, | ||
"_href": { | ||
"type": "string" | ||
}, | ||
"Language": { | ||
"type":"array", | ||
"items": { | ||
"properties": { | ||
"_media-type": { | ||
"type": "string" | ||
}, | ||
"_href": { | ||
"type": "string" | ||
}, | ||
"languageId": { | ||
"type": "integer" | ||
}, | ||
"languageCode": { | ||
"type": "string", | ||
"minLength": 1, | ||
"pattern": "^[[:alnum:]_]+" | ||
}, | ||
"name": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"_media-type", | ||
"_href", | ||
"languageId", | ||
"languageCode", | ||
"name" | ||
] | ||
} | ||
} | ||
}, | ||
"required": [ | ||
"_media-type", | ||
"_href", | ||
"Language" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"LanguageList" | ||
] | ||
} |
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,64 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformRestBundle\Tests\Functional; | ||
|
||
use EzSystems\EzPlatformRestBundle\Tests\Functional\TestCase as RESTFunctionalTestCase; | ||
|
||
final class LanguageTest extends RESTFunctionalTestCase | ||
{ | ||
use ResourceAssertionsTrait; | ||
|
||
private const SNAPSHOT_DIR = __DIR__ . '/_snapshot'; | ||
|
||
public function testLanguageListJson(): void | ||
{ | ||
$request = $this->createHttpRequest('GET', '/api/ezp/v2/languages', '', 'LanguageList+json'); | ||
$response = $this->sendHttpRequest($request); | ||
|
||
self::assertHttpResponseCodeEquals($response, 200); | ||
$content = $response->getBody()->getContents(); | ||
self::assertJson($content); | ||
|
||
self::assertJsonResponseIsValid($content, 'LanguageList'); | ||
self::assertResponseMatchesJsonSnapshot($content, self::SNAPSHOT_DIR . '/LanguageList.json'); | ||
} | ||
|
||
public function testLanguageListXml(): void | ||
{ | ||
$request = $this->createHttpRequest('GET', '/api/ezp/v2/languages'); | ||
$response = $this->sendHttpRequest($request); | ||
|
||
self::assertHttpResponseCodeEquals($response, 200); | ||
$content = $response->getBody()->getContents(); | ||
self::assertResponseMatchesXmlSnapshot($content, self::SNAPSHOT_DIR . '/LanguageList.xml'); | ||
} | ||
|
||
public function testLanguageViewJson(): void | ||
{ | ||
$request = $this->createHttpRequest('GET', '/api/ezp/v2/languages/eng-GB', '', 'LanguageList+json'); | ||
$response = $this->sendHttpRequest($request); | ||
|
||
self::assertHttpResponseCodeEquals($response, 200); | ||
$content = $response->getBody()->getContents(); | ||
self::assertJson($content); | ||
|
||
self::assertJsonResponseIsValid($content, 'Language'); | ||
self::assertResponseMatchesJsonSnapshot($content, self::SNAPSHOT_DIR . '/Language.json'); | ||
} | ||
|
||
public function testLanguageViewXml(): void | ||
{ | ||
$request = $this->createHttpRequest('GET', '/api/ezp/v2/languages/eng-GB'); | ||
$response = $this->sendHttpRequest($request); | ||
|
||
self::assertHttpResponseCodeEquals($response, 200); | ||
$content = $response->getBody()->getContents(); | ||
self::assertResponseMatchesXmlSnapshot($content, self::SNAPSHOT_DIR . '/Language.xml'); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
legacy namespaces for new classes are technically not allowed after rebranding due to BC policy. I see 2 options here:
either use
Ibexa
namespace or make the class internal so we don't have to keep BC (we don't do it for controller classes anyway, but at least it would be more clear that way).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alongosz Replaced all new classes with new namespace in a48f66f.