Skip to content

Commit

Permalink
schema/File: mime type fetching made compatible with Guzzle/Psr7 v1 a…
Browse files Browse the repository at this point in the history
…nd v2
  • Loading branch information
zozlak committed Jul 7, 2021
1 parent 03c6452 commit f1abefa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/acdhOeaw/arche/lib/ingest/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ private function indexEntry(DirectoryIterator $i) {
$location = self::getRelPath(self::sanitizePath($i->getPathname()), $this->containerDir);
$id = $this->containerToUriPrefix . str_replace('%2F', '/', rawurlencode($location));
$class = $i->isDir() ? $this->collectionClass : $this->binaryClass;
$parent = $this->parent === null ? null : $this->parent->getUri();
$parent = isset($this->parent) ? $this->parent->getUri() : null;
$file = new File($this->repo, $id, $i->getPathname(), $location, $class, $parent);
if ($this->metaLookup !== null) {
$file->setMetaLookup($this->metaLookup, $this->metaLookupRequire);
Expand Down
6 changes: 5 additions & 1 deletion src/acdhOeaw/arche/lib/ingest/schema/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
*/
class File extends SchemaObject {

const GUZZLE_PSR7_V1_MIME_FUNC = '\GuzzleHttp\Psr7\mimetype_from_filename';
const GUZZLE_PSR7_V2_MIME_FUNC = '\GuzzleHttp\Psr7\MimeType::fromFilename';

/**
* File path
* @var string
Expand Down Expand Up @@ -170,7 +173,8 @@ public function setMetaLookup(MetaLookupInterface $metaLookup,
* @return string
*/
public function getMime(): ?string {
$mime = \GuzzleHttp\Psr7\mimetype_from_filename(basename($this->path));
$f = function_exists(self::GUZZLE_PSR7_V1_MIME_FUNC) ? self::GUZZLE_PSR7_V1_MIME_FUNC : self::GUZZLE_PSR7_V2_MIME_FUNC;
$mime = $f(basename($this->path));
if ($mime === null) {
$mime = mime_content_type($this->path);
}
Expand Down

0 comments on commit f1abefa

Please sign in to comment.