-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted common code for Binary and Media field type (#407)
For more details see #407 Key changes: * Extracted redundant Binary and Media SearchField into a common base * [Tests] Extracted common base for Binary and Media ft integration tests * [Tests] Made MediaIntegrationTest::getValidFieldSettings return type more strict * [PHPStan] Aligned baseline with the changes --------- Co-authored-by: Adam Wójs <[email protected]> Co-authored-by: Mikolaj Adamczyk <[email protected]>
- Loading branch information
Showing
7 changed files
with
381 additions
and
901 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/lib/FieldType/BinaryBase/AbstractBinarySearchField.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Core\FieldType\BinaryBase; | ||
|
||
use Ibexa\Contracts\Core\FieldType\Indexable; | ||
use Ibexa\Contracts\Core\Persistence\Content\Field; | ||
use Ibexa\Contracts\Core\Persistence\Content\Type\FieldDefinition; | ||
use Ibexa\Contracts\Core\Search; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
abstract class AbstractBinarySearchField implements Indexable | ||
{ | ||
/** | ||
* @return \Ibexa\Contracts\Core\Search\Field[] | ||
*/ | ||
public function getIndexData(Field $field, FieldDefinition $fieldDefinition): array | ||
{ | ||
return [ | ||
new Search\Field( | ||
'file_name', | ||
$field->value->externalData['fileName'] ?? null, | ||
new Search\FieldType\StringField() | ||
), | ||
new Search\Field( | ||
'file_size', | ||
$field->value->externalData['fileSize'] ?? null, | ||
new Search\FieldType\IntegerField() | ||
), | ||
new Search\Field( | ||
'mime_type', | ||
$field->value->externalData['mimeType'] ?? null, | ||
new Search\FieldType\StringField() | ||
), | ||
]; | ||
} | ||
|
||
/** | ||
* @return array<string, \Ibexa\Contracts\Core\Search\FieldType> | ||
*/ | ||
public function getIndexDefinition(): array | ||
{ | ||
return [ | ||
'file_name' => new Search\FieldType\StringField(), | ||
'file_size' => new Search\FieldType\IntegerField(), | ||
'mime_type' => new Search\FieldType\StringField(), | ||
]; | ||
} | ||
|
||
public function getDefaultMatchField(): string | ||
{ | ||
return 'file_name'; | ||
} | ||
|
||
public function getDefaultSortField(): string | ||
{ | ||
return $this->getDefaultMatchField(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.