Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sg_rest
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
TYPO3
sg_rest
Commits
3492a57c
Commit
3492a57c
authored
8 years ago
by
Markus Guenther
Browse files
Options
Downloads
Patches
Plain Diff
[FEATURE] Enrich the file reference response with meta data
parent
dbb6e141
No related branches found
Branches containing commit
Tags
1.6.0
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Classes/Service/DataResolveService.php
+48
-2
48 additions, 2 deletions
Classes/Service/DataResolveService.php
with
48 additions
and
2 deletions
Classes/Service/DataResolveService.php
+
48
−
2
View file @
3492a57c
...
...
@@ -26,8 +26,9 @@ namespace SGalinski\SgRest\Service;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use
SGalinski\SgImpulse\Domain\Model\Impulse
;
use
SGalinski\SgRest\Utility\PathUtility
;
use
TYPO3\CMS\Core\Resource\AbstractFile
;
use
TYPO3\CMS\Core\Resource\File
;
use
TYPO3\CMS\Core\SingletonInterface
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Extbase\Domain\Model\FileReference
;
...
...
@@ -141,7 +142,8 @@ class DataResolveService implements SingletonInterface {
if
(
$object
instanceof
FileReference
&&
$identifier
)
{
return
[
'href'
=>
PathUtility
::
createFileUrl
(
$object
),
'uid'
=>
$identifier
'uid'
=>
$identifier
,
'metadata'
=>
$this
->
getFileMetaData
(
$object
)
];
}
...
...
@@ -264,4 +266,48 @@ class DataResolveService implements SingletonInterface {
return
lcfirst
(
array_pop
(
$classPath
));
}
/**
* Returns an array with meta data of the file.
* - fileSize
* - mime type
* - name
*
* And for images also:
* - height
* - width
* - aspect ratio
*
* @param FileReference $fileReference
* @return array
*/
protected
function
getFileMetaData
(
FileReference
$fileReference
)
{
$originalResource
=
$fileReference
->
getOriginalResource
();
if
(
!
$originalResource
)
{
return
[];
}
/** @var File $originalFile */
$originalFile
=
$originalResource
->
getOriginalFile
();
if
(
!
$originalFile
)
{
return
[];
}
$metadata
=
[
'fileSize'
=>
$originalFile
->
getSize
(),
'mimeType'
=>
$originalFile
->
getMimeType
(),
'name'
=>
$originalFile
->
getName
(),
];
if
(
$originalFile
->
getType
()
===
AbstractFile
::
FILETYPE_IMAGE
)
{
$height
=
$originalFile
->
getProperty
(
'height'
);
$width
=
$originalFile
->
getProperty
(
'width'
);
$metadata
[
'height'
]
=
$height
;
$metadata
[
'width'
]
=
$width
;
$metadata
[
'aspectRatio'
]
=
$height
/
$width
;
}
return
$metadata
;
}
}
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