Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
apitools
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
apitools
Commits
c1c3bd9d
Commit
c1c3bd9d
authored
1 year ago
by
Alan Sherry
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3407114
: Fixes getData function to return iterable data that can be overridden
parent
a242b736
No related branches found
No related tags found
1 merge request
!8
Removes deprecated model naming scheme and moves client object naming over to...
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/IterableResponse.php
+35
-20
35 additions, 20 deletions
src/IterableResponse.php
with
35 additions
and
20 deletions
src/IterableResponse.php
+
35
−
20
View file @
c1c3bd9d
...
...
@@ -10,52 +10,64 @@ use Traversable;
/**
* A hybrid class to allow array iterating and ResponseInterface functionality.
*/
class
IterableResponse
extends
Response
implements
\IteratorAggregate
,
\Countable
,
\ArrayAccess
{
class
IterableResponse
extends
Response
implements
\IteratorAggregate
,
\Countable
,
\ArrayAccess
{
protected
$responseData
;
protected
$iterableData
;
public
function
getIterator
():
Traversable
{
/**
* {@inheritdoc}
*/
public
function
getIterator
():
Traversable
{
return
new
\ArrayIterator
(
$this
->
iterableData
);
}
public
function
count
():
int
{
/**
* {@inheritdoc}
*/
public
function
count
():
int
{
return
count
(
$this
->
iterableData
);
}
public
function
offsetExists
(
mixed
$offset
):
bool
{
/**
* {@inheritdoc}
*/
public
function
offsetExists
(
mixed
$offset
):
bool
{
return
isset
(
$this
->
iterableData
[
$offset
]);
}
public
function
offsetGet
(
mixed
$offset
):
mixed
{
/**
* {@inheritdoc}
*/
public
function
offsetGet
(
mixed
$offset
):
mixed
{
return
$this
->
offsetExists
(
$offset
)
?
$this
->
iterableData
[
$offset
]
:
NULL
;
}
public
function
offsetSet
(
mixed
$offset
,
mixed
$value
):
void
{
/**
* {@inheritdoc}
*/
public
function
offsetSet
(
mixed
$offset
,
mixed
$value
):
void
{
$this
->
iterableData
[
$offset
]
=
$value
;
}
public
function
offsetUnset
(
mixed
$offset
):
void
{
/**
* {@inheritdoc}
*/
public
function
offsetUnset
(
mixed
$offset
):
void
{
unset
(
$this
->
iterableData
[
$offset
]);
}
public
function
__construct
(
array
$parents
,
$data
,
$status
=
200
,
array
$headers
=
[],
$body
=
null
,
$version
=
'1.1'
,
$reason
=
null
)
{
/**
* {@inheritdoc}
*/
public
function
__construct
(
array
$parents
,
$data
,
$status
=
200
,
array
$headers
=
[],
$body
=
null
,
$version
=
'1.1'
,
$reason
=
null
)
{
parent
::
__construct
(
$status
,
$headers
,
$body
,
$version
,
$reason
);
$this
->
responseData
=
$data
;
$this
->
iterableData
=
&
NestedArray
::
getValue
(
$data
,
$parents
);
}
public
static
function
create
(
array
$parents
,
array
$data
,
ResponseInterface
$response
)
{
public
static
function
create
(
array
$parents
,
array
$data
,
ResponseInterface
$response
)
{
return
new
static
(
$parents
,
$data
,
...
...
@@ -67,8 +79,11 @@ class IterableResponse extends Response implements \IteratorAggregate, \Countabl
);
}
public
function
getData
()
{
public
function
getData
()
{
return
$this
->
iterableData
;
}
public
function
getResponseData
()
{
return
$this
->
responseData
;
}
}
\ No newline at end of file
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