Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dbp-relay-core-bundle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
digital blueprint
Relay API Gateway
dbp-relay-core-bundle
Commits
8639d935
Commit
8639d935
authored
2 years ago
by
Tobias Gross-Vogt
Browse files
Options
Downloads
Patches
Plain Diff
using new locale service in abstractdataprovider
parent
b1d1eaa5
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/DataProvider/AbstractDataProvider.php
+30
-13
30 additions, 13 deletions
src/DataProvider/AbstractDataProvider.php
src/Locale/Locale.php
+2
-0
2 additions, 0 deletions
src/Locale/Locale.php
src/Resources/config/services.yaml
+5
-0
5 additions, 0 deletions
src/Resources/config/services.yaml
with
37 additions
and
13 deletions
src/DataProvider/AbstractDataProvider.php
+
30
−
13
View file @
8639d935
...
...
@@ -7,12 +7,13 @@ namespace Dbp\Relay\CoreBundle\DataProvider;
use
ApiPlatform\Core\DataProvider\CollectionDataProviderInterface
;
use
ApiPlatform\Core\DataProvider\ItemDataProviderInterface
;
use
ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface
;
use
Dbp\Relay\CoreBundle\Helpers\Locale
;
use
Dbp\Relay\CoreBundle\LocalData\LocalData
;
use
Dbp\Relay\CoreBundle\Locale\Locale
;
use
Dbp\Relay\CoreBundle\Pagination\Pagination
;
use
Dbp\Relay\CoreBundle\Pagination\PartialPaginator
;
use
Symfony\Bundle\FrameworkBundle\Controller\AbstractController
;
use
Symfony\Component\HttpFoundation\RequestStack
;
use
Symfony\Component\Security\Core\Exception\AccessDeniedException
;
abstract
class
AbstractDataProvider
extends
AbstractController
implements
RestrictedDataProviderInterface
,
ItemDataProviderInterface
,
CollectionDataProviderInterface
{
...
...
@@ -24,9 +25,19 @@ abstract class AbstractDataProvider extends AbstractController implements Restri
/** @var Locale */
private
$locale
;
public
function
__construct
(
RequestStack
$requestStack
)
/**
* @deprecated Use default constructor
*/
public
function
__construct
(
RequestStack
$requestStack
)
/** @phpstan-ignore-line */
{
$this
->
locale
=
new
Locale
(
$requestStack
);
}
/**
* @required
*/
public
function
setLocale
(
Locale
$locale
):
void
{
$this
->
locale
=
$locale
;
}
public
function
supports
(
string
$resourceClass
,
string
$operationName
=
null
,
array
$context
=
[]):
bool
...
...
@@ -43,11 +54,9 @@ abstract class AbstractDataProvider extends AbstractController implements Restri
$currentPageNumber
=
Pagination
::
getCurrentPageNumber
(
$filters
);
$maxNumItemsPerPage
=
Pagination
::
getMaxNumItemsPerPage
(
$filters
);
$options
=
[];
LocalData
::
addOptions
(
$options
,
$filters
);
$this
->
locale
->
addLanguageOption
(
$options
);
return
new
PartialPaginator
(
$this
->
getPage
(
$currentPageNumber
,
$maxNumItemsPerPage
,
$filters
,
$options
),
$currentPageNumber
,
$maxNumItemsPerPage
);
return
new
PartialPaginator
(
$this
->
getPage
(
$currentPageNumber
,
$maxNumItemsPerPage
,
$filters
,
$this
->
getOptions
(
$filters
)),
$currentPageNumber
,
$maxNumItemsPerPage
);
}
public
function
getItem
(
string
$resourceClass
,
$id
,
string
$operationName
=
null
,
array
$context
=
[]):
?object
...
...
@@ -56,13 +65,12 @@ abstract class AbstractDataProvider extends AbstractController implements Restri
$filters
=
$context
[
self
::
FILTERS_KEY
]
??
[];
$options
=
[];
LocalData
::
addOptions
(
$options
,
$filters
);
$this
->
locale
->
addLanguageOption
(
$options
);
return
$this
->
getItemById
(
$id
,
$options
);
return
$this
->
getItemById
(
$id
,
$this
->
getOptions
(
$filters
));
}
/**
* @throws AccessDeniedException
*/
protected
function
onOperationStart
(
int
$operation
)
{
$this
->
denyAccessUnlessGranted
(
'IS_AUTHENTICATED_FULLY'
);
...
...
@@ -73,4 +81,13 @@ abstract class AbstractDataProvider extends AbstractController implements Restri
abstract
protected
function
getItemById
(
$id
,
array
$options
=
[]):
object
;
abstract
protected
function
getPage
(
int
$currentPageNumber
,
int
$maxNumItemsPerPage
,
array
$filters
=
[],
array
$options
=
[]):
array
;
private
function
getOptions
(
array
$filters
):
array
{
$options
=
[];
$options
[
Locale
::
LANGUAGE_OPTION
]
=
$this
->
locale
->
getCurrentPrimaryLanguage
();
LocalData
::
addOptions
(
$options
,
$filters
);
return
$options
;
}
}
This diff is collapsed.
Click to expand it.
src/Locale/Locale.php
+
2
−
0
View file @
8639d935
...
...
@@ -16,6 +16,8 @@ use Symfony\Component\HttpFoundation\RequestStack;
*/
class
Locale
{
public
const
LANGUAGE_OPTION
=
'lang'
;
/** @var RequestStack */
private
$requestStack
;
...
...
This diff is collapsed.
Click to expand it.
src/Resources/config/services.yaml
+
5
−
0
View file @
8639d935
...
...
@@ -108,3 +108,8 @@ services:
Dbp\Relay\CoreBundle\Locale\Locale
:
autowire
:
true
autoconfigure
:
true
Dbp\Relay\CoreBundle\DataProvider\AbstractDataProvider
:
abstract
:
true
calls
:
-
setLocale
:
[
'
@locale'
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment