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
54c44a8a
Commit
54c44a8a
authored
Dec 07, 2020
by
Patrick Barroca
😁
Browse files
fix images base path versus images urls
parent
9c340ba4
Pipeline
#11869
passed with stage
in 44 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
9 deletions
+38
-9
src/Models/Media.php
src/Models/Media.php
+2
-3
src/Providers/ElectreRest2.php
src/Providers/ElectreRest2.php
+5
-0
src/Url.php
src/Url.php
+25
-5
tests/MediaElectreRest2Test.php
tests/MediaElectreRest2Test.php
+3
-1
tests/MediaTest.php
tests/MediaTest.php
+3
-0
No files found.
src/Models/Media.php
View file @
54c44a8a
...
...
@@ -46,7 +46,7 @@ class Media extends ModelAbstract {
'updated_at'
=>
1
]);
if
(
$attribs
[
'fullsize'
])
$attribs
[
'fullsize'
]
=
(
new
Url
)
->
absolute
(
$attribs
[
'fullsize'
]);
$attribs
[
'fullsize'
]
=
(
new
Url
)
->
absolute
Media
(
$attribs
[
'fullsize'
]);
return
$attribs
;
}
...
...
@@ -76,8 +76,7 @@ class Media extends ModelAbstract {
public
function
_getFilePathFromIdentifier
(
$identifier
=
''
)
{
return
'/'
.
implode
(
'/'
,
array_merge
([
'images'
,
$this
->
getSize
(),
array_merge
([
$this
->
getSize
(),
$this
->
getType
()],
$this
->
splitId
(
$identifier
)))
.
'/'
.
$identifier
;
...
...
src/Providers/ElectreRest2.php
View file @
54c44a8a
...
...
@@ -32,6 +32,11 @@ class ElectreRest2 extends Provider {
}
public
function
providerName
()
{
return
'Electre'
;
}
public
function
fetchRecord
()
{
if
(
!
$this
->
_id
||
!
$this
->
_secret
)
return
$this
->
_newError
(
StatusCodeInterface
::
STATUS_UNAUTHORIZED
,
'invalid_credentials'
);
...
...
src/Url.php
View file @
54c44a8a
<?php
namespace
Pellicule
;
use
\
Pellicule\FileSystem
;
class
Url
{
public
function
absoluteMedia
(
$path
)
{
if
(
!
$base_path
=
(
new
FileSystem
)
->
getBasePath
())
return
$this
->
absolute
(
$path
);
if
(
!
preg_match
(
'|([^./]+)|'
,
$base_path
,
$matches
,
PREG_OFFSET_CAPTURE
))
return
$this
->
absolute
(
$path
);
$base_path
=
$this
->
_ensureSlash
(
substr
(
$base_path
,
$matches
[
1
][
1
]));
if
(
'/'
==
substr
(
$base_path
,
-
1
))
$base_path
=
substr
(
$base_path
,
0
,
strlen
(
$base_path
)
-
1
);
return
$this
->
absolute
(
$base_path
.
$this
->
_ensureSlash
(
$path
));
}
public
function
absolute
(
$path
)
{
if
(
$this
->
_hasScheme
(
$path
))
return
$path
;
return
$this
->
_hasScheme
(
$path
)
?
$path
:
$_SERVER
[
'REQUEST_SCHEME'
]
.
'://'
.
$_SERVER
[
'HTTP_HOST'
]
.
$path
;
}
if
(
'/'
!=
substr
(
$path
,
0
,
1
))
$path
=
'/'
.
$path
;
return
$_SERVER
[
'REQUEST_SCHEME'
]
.
'://'
.
$_SERVER
[
'HTTP_HOST'
]
.
$path
;
protected
function
_ensureSlash
(
$path
)
{
return
(
'/'
!=
substr
(
$path
,
0
,
1
))
?
'/'
.
$path
:
$path
;
}
...
...
tests/MediaElectreRest2Test.php
View file @
54c44a8a
...
...
@@ -14,6 +14,8 @@ class MediaElectreRest2Test extends TestCase {
Media
::
getFileSystem
()
->
whenCalled
(
'fileExists'
)
->
answers
(
true
);
FileSystem
::
setBasePath
(
'./images'
);
FileSystem
::
getFileSystem
()
->
whenCalled
(
'fileExists'
)
->
answers
(
true
)
->
whenCalled
(
'filePutContents'
)
->
answers
(
null
)
...
...
@@ -45,7 +47,7 @@ class MediaElectreRest2Test extends TestCase {
$call_params
=
FileSystem
::
getFileSystem
()
->
getAttributesForLastCallOn
(
'filePutContents'
);
$this
->
assertEquals
(
'
vfs://myDir
/images/fullsize/cover/9/7/8/2/9782818976173.jpg'
,
$this
->
assertEquals
(
'
.
/images/fullsize/cover/9/7/8/2/9782818976173.jpg'
,
$call_params
[
0
]);
}
...
...
tests/MediaTest.php
View file @
54c44a8a
...
...
@@ -3,6 +3,7 @@ namespace Pellicule\Tests;
use
\
Pellicule\Models\Record
;
use
\
Pellicule\Models\Media
;
use
\
Pellicule\FileSystem
;
class
MediaLocalRecordTest
extends
TestCase
{
...
...
@@ -134,6 +135,7 @@ abstract class MediaWithElectreTestCase extends TestCase {
public
function
setUp
(){
parent
::
setUp
();
FileSystem
::
setBasePath
(
'./images'
);
Media
::
setFileSystem
(
$this
->
mock
()
->
whenCalled
(
'fileExists'
)
->
answers
(
true
));
$this
->
_http_client
...
...
@@ -406,6 +408,7 @@ abstract class MediaWithOrbTestCase extends TestCase {
public
function
setUp
(){
parent
::
setUp
();
FileSystem
::
setBasePath
(
'./images'
);
Media
::
setFileSystem
(
$this
->
mock
()
->
whenCalled
(
'fileExists'
)
->
answers
(
true
));
Media
::
setTimeSource
(
new
TimeSourceForTest
(
'2020-01-01 00:00:00'
));
...
...
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