Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
afi
Pellicule
Commits
00eb138b
Commit
00eb138b
authored
Dec 01, 2020
by
Patrick Barroca
😁
Browse files
fullsize in JSON response is an absolute url
parent
9b25f3d8
Pipeline
#11808
passed with stage
in 45 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
43 additions
and
15 deletions
+43
-15
src/Controllers/Media.php
src/Controllers/Media.php
+2
-3
src/Models/Media.php
src/Models/Media.php
+13
-7
src/Providers/FetchRecordResult.php
src/Providers/FetchRecordResult.php
+1
-0
src/Providers/Provider.php
src/Providers/Provider.php
+2
-3
src/Url.php
src/Url.php
+20
-0
tests/MediaTest.php
tests/MediaTest.php
+2
-2
tests/TestCase.php
tests/TestCase.php
+3
-0
No files found.
src/Controllers/Media.php
View file @
00eb138b
...
...
@@ -11,9 +11,8 @@ class Media {
$response
->
getBody
()
->
write
(
$fetch_result
->
asJSON
());
return
$response
->
withStatus
(
$fetch_result
->
getStatusCode
())
->
withHeader
(
'Content-Type'
,
'application/json'
);
return
$response
->
withStatus
(
$fetch_result
->
getStatusCode
())
->
withHeader
(
'Content-Type'
,
'application/json'
);
}
...
...
src/Models/Media.php
View file @
00eb138b
...
...
@@ -3,6 +3,7 @@ namespace Pellicule\Models;
use
\
Storm\Model\ModelAbstract
;
use
\
Pellicule\StormFileSystem
;
use
\
Pellicule\Url
;
use
\
Pellicule\Traits\TimeSource
;
...
...
@@ -36,13 +37,18 @@ class Media extends ModelAbstract {
public
function
getJsonAttributes
()
{
return
array_intersect_key
(
$this
->
getRawAttributes
(),
[
'type'
=>
1
,
'url'
=>
1
,
'fullsize'
=>
1
,
'provider'
=>
1
,
'created_at'
=>
1
,
'updated_at'
=>
1
]);
$attribs
=
array_intersect_key
(
$this
->
getRawAttributes
(),
[
'type'
=>
1
,
'url'
=>
1
,
'fullsize'
=>
1
,
'provider'
=>
1
,
'created_at'
=>
1
,
'updated_at'
=>
1
]);
if
(
$attribs
[
'fullsize'
])
$attribs
[
'fullsize'
]
=
(
new
Url
)
->
absolute
(
$attribs
[
'fullsize'
]);
return
$attribs
;
}
...
...
src/Providers/FetchRecordResult.php
View file @
00eb138b
...
...
@@ -29,6 +29,7 @@ class FetchRecordResult {
:
json_encode
([
'error'
=>
$this
->
_error_code
]);
}
public
function
getStatusCode
(){
return
$this
->
_status_code
;
}
...
...
src/Providers/Provider.php
View file @
00eb138b
...
...
@@ -3,9 +3,8 @@ namespace Pellicule\Providers;
use
\
Pellicule\HttpClientAware
;
use
\
Pellicule\Models\Record
;
use
\
Pellicule\Providers\FetchRecordResult
;
use
\
Fig\Http\Message\StatusCodeInterface
;
use
\
Storm\Collection
;
use
\
Fig\Http\Message\StatusCodeInterface
;
...
...
@@ -78,7 +77,7 @@ abstract class Provider {
public
function
setSearchArgs
(
$args
)
{
if
(
isset
(
$args
[
'isbn'
])
||
isset
(
$args
[
'ean'
]))
if
(
isset
(
$args
[
'isbn'
])
||
isset
(
$args
[
'ean'
]))
$this
->
_search_args
=
$args
;
return
$this
;
...
...
src/Url.php
0 → 100644
View file @
00eb138b
<?php
namespace
Pellicule
;
class
Url
{
public
function
absolute
(
$path
)
{
if
(
$this
->
_hasScheme
(
$path
))
return
$path
;
if
(
'/'
!=
substr
(
$path
,
0
,
1
))
$path
=
'/'
.
$path
;
return
$_SERVER
[
'REQUEST_SCHEME'
]
.
'://'
.
$_SERVER
[
'HTTP_HOST'
]
.
$path
;
}
protected
function
_hasScheme
(
$url
)
{
return
preg_match
(
'|http[s]?://|'
,
$url
);
}
}
tests/MediaTest.php
View file @
00eb138b
...
...
@@ -150,7 +150,7 @@ abstract class MediaWithElectreTestCase extends TestCase {
[
'media'
=>
[
[
'url'
=>
'http://image.org/city.jpg'
,
'provider'
=>
'Electre'
,
'fullsize'
=>
'/images/fullsize/cover/2/2/5/9/2259228194'
,
'fullsize'
=>
'
http://pellicule.io:8899
/images/fullsize/cover/2/2/5/9/2259228194'
,
'type'
=>
'cover'
,
'created_at'
=>
(
new
\
DateTime
())
->
format
(
'Y-m-d H:i:s'
),
'updated_at'
=>
(
new
\
DateTime
())
->
format
(
'Y-m-d H:i:s'
)
...
...
@@ -428,7 +428,7 @@ abstract class MediaWithOrbTestCase extends TestCase {
[
'media'
=>
[
[
'url'
=>
'https://products-images.di-static.com/image/orb-9162f416a0b7b2e64a1f5480db8d4394/2259228234-475x500-1.jpg'
,
'provider'
=>
'Orb'
,
'fullsize'
=>
'/images/fullsize/cover/2/2/5/9/2259228234'
,
'fullsize'
=>
'
http://pellicule.io:8899
/images/fullsize/cover/2/2/5/9/2259228234'
,
'type'
=>
'cover'
,
'created_at'
=>
'2020-01-01 00:00:00'
,
'updated_at'
=>
'2020-01-01 00:00:00'
...
...
tests/TestCase.php
View file @
00eb138b
...
...
@@ -31,6 +31,9 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
$this
->
_http_client
=
$this
->
mock
();
Provider
::
setDefaultHttpClient
(
$this
->
_http_client
);
$_SERVER
[
'REQUEST_SCHEME'
]
=
'http'
;
$_SERVER
[
'HTTP_HOST'
]
=
'pellicule.io:8899'
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment