@@ -31,68 +31,68 @@ |
||
| 31 | 31 | |
| 32 | 32 | class Version010401Date20181207190718 extends SimpleMigrationStep { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param IOutput $output |
|
| 36 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 37 | - * @param array $options |
|
| 38 | - * @return null|ISchemaWrapper |
|
| 39 | - */ |
|
| 40 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
| 41 | - /** @var ISchemaWrapper $schema */ |
|
| 42 | - $schema = $schemaClosure(); |
|
| 34 | + /** |
|
| 35 | + * @param IOutput $output |
|
| 36 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 37 | + * @param array $options |
|
| 38 | + * @return null|ISchemaWrapper |
|
| 39 | + */ |
|
| 40 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
| 41 | + /** @var ISchemaWrapper $schema */ |
|
| 42 | + $schema = $schemaClosure(); |
|
| 43 | 43 | |
| 44 | - if (!$schema->hasTable('oauth2_clients')) { |
|
| 45 | - $table = $schema->createTable('oauth2_clients'); |
|
| 46 | - $table->addColumn('id', 'integer', [ |
|
| 47 | - 'autoincrement' => true, |
|
| 48 | - 'notnull' => true, |
|
| 49 | - 'unsigned' => true, |
|
| 50 | - ]); |
|
| 51 | - $table->addColumn('name', 'string', [ |
|
| 52 | - 'notnull' => true, |
|
| 53 | - 'length' => 64, |
|
| 54 | - ]); |
|
| 55 | - $table->addColumn('redirect_uri', 'string', [ |
|
| 56 | - 'notnull' => true, |
|
| 57 | - 'length' => 2000, |
|
| 58 | - ]); |
|
| 59 | - $table->addColumn('client_identifier', 'string', [ |
|
| 60 | - 'notnull' => true, |
|
| 61 | - 'length' => 64, |
|
| 62 | - ]); |
|
| 63 | - $table->addColumn('secret', 'string', [ |
|
| 64 | - 'notnull' => true, |
|
| 65 | - 'length' => 64, |
|
| 66 | - ]); |
|
| 67 | - $table->setPrimaryKey(['id']); |
|
| 68 | - $table->addIndex(['client_identifier'], 'oauth2_client_id_idx'); |
|
| 69 | - } |
|
| 44 | + if (!$schema->hasTable('oauth2_clients')) { |
|
| 45 | + $table = $schema->createTable('oauth2_clients'); |
|
| 46 | + $table->addColumn('id', 'integer', [ |
|
| 47 | + 'autoincrement' => true, |
|
| 48 | + 'notnull' => true, |
|
| 49 | + 'unsigned' => true, |
|
| 50 | + ]); |
|
| 51 | + $table->addColumn('name', 'string', [ |
|
| 52 | + 'notnull' => true, |
|
| 53 | + 'length' => 64, |
|
| 54 | + ]); |
|
| 55 | + $table->addColumn('redirect_uri', 'string', [ |
|
| 56 | + 'notnull' => true, |
|
| 57 | + 'length' => 2000, |
|
| 58 | + ]); |
|
| 59 | + $table->addColumn('client_identifier', 'string', [ |
|
| 60 | + 'notnull' => true, |
|
| 61 | + 'length' => 64, |
|
| 62 | + ]); |
|
| 63 | + $table->addColumn('secret', 'string', [ |
|
| 64 | + 'notnull' => true, |
|
| 65 | + 'length' => 64, |
|
| 66 | + ]); |
|
| 67 | + $table->setPrimaryKey(['id']); |
|
| 68 | + $table->addIndex(['client_identifier'], 'oauth2_client_id_idx'); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - if (!$schema->hasTable('oauth2_access_tokens')) { |
|
| 72 | - $table = $schema->createTable('oauth2_access_tokens'); |
|
| 73 | - $table->addColumn('id', 'integer', [ |
|
| 74 | - 'autoincrement' => true, |
|
| 75 | - 'notnull' => true, |
|
| 76 | - 'unsigned' => true, |
|
| 77 | - ]); |
|
| 78 | - $table->addColumn('token_id', 'integer', [ |
|
| 79 | - 'notnull' => true, |
|
| 80 | - ]); |
|
| 81 | - $table->addColumn('client_id', 'integer', [ |
|
| 82 | - 'notnull' => true, |
|
| 83 | - ]); |
|
| 84 | - $table->addColumn('hashed_code', 'string', [ |
|
| 85 | - 'notnull' => true, |
|
| 86 | - 'length' => 128, |
|
| 87 | - ]); |
|
| 88 | - $table->addColumn('encrypted_token', 'string', [ |
|
| 89 | - 'notnull' => true, |
|
| 90 | - 'length' => 786, |
|
| 91 | - ]); |
|
| 92 | - $table->setPrimaryKey(['id']); |
|
| 93 | - $table->addUniqueIndex(['hashed_code'], 'oauth2_access_hash_idx'); |
|
| 94 | - $table->addIndex(['client_id'], 'oauth2_access_client_id_idx'); |
|
| 95 | - } |
|
| 96 | - return $schema; |
|
| 97 | - } |
|
| 71 | + if (!$schema->hasTable('oauth2_access_tokens')) { |
|
| 72 | + $table = $schema->createTable('oauth2_access_tokens'); |
|
| 73 | + $table->addColumn('id', 'integer', [ |
|
| 74 | + 'autoincrement' => true, |
|
| 75 | + 'notnull' => true, |
|
| 76 | + 'unsigned' => true, |
|
| 77 | + ]); |
|
| 78 | + $table->addColumn('token_id', 'integer', [ |
|
| 79 | + 'notnull' => true, |
|
| 80 | + ]); |
|
| 81 | + $table->addColumn('client_id', 'integer', [ |
|
| 82 | + 'notnull' => true, |
|
| 83 | + ]); |
|
| 84 | + $table->addColumn('hashed_code', 'string', [ |
|
| 85 | + 'notnull' => true, |
|
| 86 | + 'length' => 128, |
|
| 87 | + ]); |
|
| 88 | + $table->addColumn('encrypted_token', 'string', [ |
|
| 89 | + 'notnull' => true, |
|
| 90 | + 'length' => 786, |
|
| 91 | + ]); |
|
| 92 | + $table->setPrimaryKey(['id']); |
|
| 93 | + $table->addUniqueIndex(['hashed_code'], 'oauth2_access_hash_idx'); |
|
| 94 | + $table->addIndex(['client_id'], 'oauth2_access_client_id_idx'); |
|
| 95 | + } |
|
| 96 | + return $schema; |
|
| 97 | + } |
|
| 98 | 98 | } |
@@ -89,8 +89,8 @@ |
||
| 89 | 89 | 'displayName' => $user->getDisplayName(), |
| 90 | 90 | 'uid' => $user->getUID(), |
| 91 | 91 | 'dn' => $user->getDN(), |
| 92 | - 'lastLogin' => $this->formatDate($user->getLastLogin(), '-', (bool)$input->getOption('short-date')), |
|
| 93 | - 'detectedOn' => $this->formatDate($user->getDetectedOn(), 'unknown', (bool)$input->getOption('short-date')), |
|
| 92 | + 'lastLogin' => $this->formatDate($user->getLastLogin(), '-', (bool) $input->getOption('short-date')), |
|
| 93 | + 'detectedOn' => $this->formatDate($user->getDetectedOn(), 'unknown', (bool) $input->getOption('short-date')), |
|
| 94 | 94 | 'homePath' => $user->getHomePath(), |
| 95 | 95 | 'sharer' => $user->getHasActiveShares() ? 'Y' : 'N', |
| 96 | 96 | ]; |
@@ -17,64 +17,64 @@ |
||
| 17 | 17 | use Symfony\Component\Console\Output\OutputInterface; |
| 18 | 18 | |
| 19 | 19 | class ShowRemnants extends Command { |
| 20 | - public function __construct( |
|
| 21 | - protected DeletedUsersIndex $dui, |
|
| 22 | - protected IDateTimeFormatter $dateFormatter, |
|
| 23 | - ) { |
|
| 24 | - parent::__construct(); |
|
| 25 | - } |
|
| 20 | + public function __construct( |
|
| 21 | + protected DeletedUsersIndex $dui, |
|
| 22 | + protected IDateTimeFormatter $dateFormatter, |
|
| 23 | + ) { |
|
| 24 | + parent::__construct(); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - protected function configure(): void { |
|
| 28 | - $this |
|
| 29 | - ->setName('ldap:show-remnants') |
|
| 30 | - ->setDescription('shows which users are not available on LDAP anymore, but have remnants in Nextcloud.') |
|
| 31 | - ->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.') |
|
| 32 | - ->addOption('short-date', null, InputOption::VALUE_NONE, 'show dates in Y-m-d format'); |
|
| 33 | - } |
|
| 27 | + protected function configure(): void { |
|
| 28 | + $this |
|
| 29 | + ->setName('ldap:show-remnants') |
|
| 30 | + ->setDescription('shows which users are not available on LDAP anymore, but have remnants in Nextcloud.') |
|
| 31 | + ->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.') |
|
| 32 | + ->addOption('short-date', null, InputOption::VALUE_NONE, 'show dates in Y-m-d format'); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - protected function formatDate(int $timestamp, string $default, bool $showShortDate): string { |
|
| 36 | - if (!($timestamp > 0)) { |
|
| 37 | - return $default; |
|
| 38 | - } |
|
| 39 | - if ($showShortDate) { |
|
| 40 | - return date('Y-m-d', $timestamp); |
|
| 41 | - } |
|
| 42 | - return $this->dateFormatter->formatDate($timestamp); |
|
| 43 | - } |
|
| 35 | + protected function formatDate(int $timestamp, string $default, bool $showShortDate): string { |
|
| 36 | + if (!($timestamp > 0)) { |
|
| 37 | + return $default; |
|
| 38 | + } |
|
| 39 | + if ($showShortDate) { |
|
| 40 | + return date('Y-m-d', $timestamp); |
|
| 41 | + } |
|
| 42 | + return $this->dateFormatter->formatDate($timestamp); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * executes the command, i.e. creates and outputs a table of LDAP users marked as deleted |
|
| 47 | - * |
|
| 48 | - * {@inheritdoc} |
|
| 49 | - */ |
|
| 50 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 51 | - /** @var \Symfony\Component\Console\Helper\Table $table */ |
|
| 52 | - $table = new Table($output); |
|
| 53 | - $table->setHeaders([ |
|
| 54 | - 'Nextcloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login', |
|
| 55 | - 'Detected on', 'Dir', 'Sharer' |
|
| 56 | - ]); |
|
| 57 | - $rows = []; |
|
| 58 | - $resultSet = $this->dui->getUsers(); |
|
| 59 | - foreach ($resultSet as $user) { |
|
| 60 | - $rows[] = [ |
|
| 61 | - 'ocName' => $user->getOCName(), |
|
| 62 | - 'displayName' => $user->getDisplayName(), |
|
| 63 | - 'uid' => $user->getUID(), |
|
| 64 | - 'dn' => $user->getDN(), |
|
| 65 | - 'lastLogin' => $this->formatDate($user->getLastLogin(), '-', (bool)$input->getOption('short-date')), |
|
| 66 | - 'detectedOn' => $this->formatDate($user->getDetectedOn(), 'unknown', (bool)$input->getOption('short-date')), |
|
| 67 | - 'homePath' => $user->getHomePath(), |
|
| 68 | - 'sharer' => $user->getHasActiveShares() ? 'Y' : 'N', |
|
| 69 | - ]; |
|
| 70 | - } |
|
| 45 | + /** |
|
| 46 | + * executes the command, i.e. creates and outputs a table of LDAP users marked as deleted |
|
| 47 | + * |
|
| 48 | + * {@inheritdoc} |
|
| 49 | + */ |
|
| 50 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 51 | + /** @var \Symfony\Component\Console\Helper\Table $table */ |
|
| 52 | + $table = new Table($output); |
|
| 53 | + $table->setHeaders([ |
|
| 54 | + 'Nextcloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login', |
|
| 55 | + 'Detected on', 'Dir', 'Sharer' |
|
| 56 | + ]); |
|
| 57 | + $rows = []; |
|
| 58 | + $resultSet = $this->dui->getUsers(); |
|
| 59 | + foreach ($resultSet as $user) { |
|
| 60 | + $rows[] = [ |
|
| 61 | + 'ocName' => $user->getOCName(), |
|
| 62 | + 'displayName' => $user->getDisplayName(), |
|
| 63 | + 'uid' => $user->getUID(), |
|
| 64 | + 'dn' => $user->getDN(), |
|
| 65 | + 'lastLogin' => $this->formatDate($user->getLastLogin(), '-', (bool)$input->getOption('short-date')), |
|
| 66 | + 'detectedOn' => $this->formatDate($user->getDetectedOn(), 'unknown', (bool)$input->getOption('short-date')), |
|
| 67 | + 'homePath' => $user->getHomePath(), |
|
| 68 | + 'sharer' => $user->getHasActiveShares() ? 'Y' : 'N', |
|
| 69 | + ]; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - if ($input->getOption('json')) { |
|
| 73 | - $output->writeln(json_encode($rows)); |
|
| 74 | - } else { |
|
| 75 | - $table->setRows($rows); |
|
| 76 | - $table->render(); |
|
| 77 | - } |
|
| 78 | - return self::SUCCESS; |
|
| 79 | - } |
|
| 72 | + if ($input->getOption('json')) { |
|
| 73 | + $output->writeln(json_encode($rows)); |
|
| 74 | + } else { |
|
| 75 | + $table->setRows($rows); |
|
| 76 | + $table->render(); |
|
| 77 | + } |
|
| 78 | + return self::SUCCESS; |
|
| 79 | + } |
|
| 80 | 80 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | |
| 53 | 53 | public function setName($name) { |
| 54 | - throw new Forbidden('Renaming ' . self::FILENAME . ' is forbidden'); |
|
| 54 | + throw new Forbidden('Renaming '.self::FILENAME.' is forbidden'); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @throws Forbidden |
| 66 | 66 | */ |
| 67 | 67 | public function delete() { |
| 68 | - throw new Forbidden(self::FILENAME . ' may not be deleted.'); |
|
| 68 | + throw new Forbidden(self::FILENAME.' may not be deleted.'); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -86,6 +86,6 @@ discard block |
||
| 86 | 86 | * @throws Forbidden |
| 87 | 87 | */ |
| 88 | 88 | public function propPatch(PropPatch $propPatch) { |
| 89 | - throw new Forbidden(self::FILENAME . '\'s properties may not be altered.'); |
|
| 89 | + throw new Forbidden(self::FILENAME.'\'s properties may not be altered.'); |
|
| 90 | 90 | } |
| 91 | 91 | } |
@@ -12,60 +12,60 @@ |
||
| 12 | 12 | use Sabre\DAV\PropPatch; |
| 13 | 13 | |
| 14 | 14 | class AppleProvisioningNode implements INode, IProperties { |
| 15 | - public const FILENAME = 'apple-provisioning.mobileconfig'; |
|
| 15 | + public const FILENAME = 'apple-provisioning.mobileconfig'; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @param ITimeFactory $timeFactory |
|
| 19 | - */ |
|
| 20 | - public function __construct( |
|
| 21 | - protected ITimeFactory $timeFactory, |
|
| 22 | - ) { |
|
| 23 | - } |
|
| 17 | + /** |
|
| 18 | + * @param ITimeFactory $timeFactory |
|
| 19 | + */ |
|
| 20 | + public function __construct( |
|
| 21 | + protected ITimeFactory $timeFactory, |
|
| 22 | + ) { |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @return string |
|
| 27 | - */ |
|
| 28 | - public function getName() { |
|
| 29 | - return self::FILENAME; |
|
| 30 | - } |
|
| 25 | + /** |
|
| 26 | + * @return string |
|
| 27 | + */ |
|
| 28 | + public function getName() { |
|
| 29 | + return self::FILENAME; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | - public function setName($name) { |
|
| 34 | - throw new Forbidden('Renaming ' . self::FILENAME . ' is forbidden'); |
|
| 35 | - } |
|
| 33 | + public function setName($name) { |
|
| 34 | + throw new Forbidden('Renaming ' . self::FILENAME . ' is forbidden'); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @return null |
|
| 39 | - */ |
|
| 40 | - public function getLastModified() { |
|
| 41 | - return null; |
|
| 42 | - } |
|
| 37 | + /** |
|
| 38 | + * @return null |
|
| 39 | + */ |
|
| 40 | + public function getLastModified() { |
|
| 41 | + return null; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @throws Forbidden |
|
| 46 | - */ |
|
| 47 | - public function delete() { |
|
| 48 | - throw new Forbidden(self::FILENAME . ' may not be deleted.'); |
|
| 49 | - } |
|
| 44 | + /** |
|
| 45 | + * @throws Forbidden |
|
| 46 | + */ |
|
| 47 | + public function delete() { |
|
| 48 | + throw new Forbidden(self::FILENAME . ' may not be deleted.'); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param array $properties |
|
| 53 | - * @return array |
|
| 54 | - */ |
|
| 55 | - public function getProperties($properties) { |
|
| 56 | - $datetime = $this->timeFactory->getDateTime(); |
|
| 51 | + /** |
|
| 52 | + * @param array $properties |
|
| 53 | + * @return array |
|
| 54 | + */ |
|
| 55 | + public function getProperties($properties) { |
|
| 56 | + $datetime = $this->timeFactory->getDateTime(); |
|
| 57 | 57 | |
| 58 | - return [ |
|
| 59 | - '{DAV:}getcontentlength' => 42, |
|
| 60 | - '{DAV:}getlastmodified' => $datetime->format(\DateTimeInterface::RFC2822), |
|
| 61 | - ]; |
|
| 62 | - } |
|
| 58 | + return [ |
|
| 59 | + '{DAV:}getcontentlength' => 42, |
|
| 60 | + '{DAV:}getlastmodified' => $datetime->format(\DateTimeInterface::RFC2822), |
|
| 61 | + ]; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param PropPatch $propPatch |
|
| 66 | - * @throws Forbidden |
|
| 67 | - */ |
|
| 68 | - public function propPatch(PropPatch $propPatch) { |
|
| 69 | - throw new Forbidden(self::FILENAME . '\'s properties may not be altered.'); |
|
| 70 | - } |
|
| 64 | + /** |
|
| 65 | + * @param PropPatch $propPatch |
|
| 66 | + * @throws Forbidden |
|
| 67 | + */ |
|
| 68 | + public function propPatch(PropPatch $propPatch) { |
|
| 69 | + throw new Forbidden(self::FILENAME . '\'s properties may not be altered.'); |
|
| 70 | + } |
|
| 71 | 71 | } |
@@ -30,10 +30,10 @@ |
||
| 30 | 30 | * @since 16.0.0 |
| 31 | 31 | */ |
| 32 | 32 | interface IConfigHandler { |
| 33 | - /** |
|
| 34 | - * @param mixed $optionValue |
|
| 35 | - * @return mixed the same type as $optionValue |
|
| 36 | - * @since 16.0.0 |
|
| 37 | - */ |
|
| 38 | - public function handle($optionValue); |
|
| 33 | + /** |
|
| 34 | + * @param mixed $optionValue |
|
| 35 | + * @return mixed the same type as $optionValue |
|
| 36 | + * @since 16.0.0 |
|
| 37 | + */ |
|
| 38 | + public function handle($optionValue); |
|
| 39 | 39 | } |
@@ -27,12 +27,12 @@ |
||
| 27 | 27 | * Allow the backend to mark groups to be excluded from being shown in search dialogs |
| 28 | 28 | */ |
| 29 | 29 | interface IHideFromCollaborationBackend { |
| 30 | - /** |
|
| 31 | - * Check if a group should be hidden from search dialogs |
|
| 32 | - * |
|
| 33 | - * @param string $groupId |
|
| 34 | - * @return bool |
|
| 35 | - * @since 16.0.0 |
|
| 36 | - */ |
|
| 37 | - public function hideGroup(string $groupId): bool; |
|
| 30 | + /** |
|
| 31 | + * Check if a group should be hidden from search dialogs |
|
| 32 | + * |
|
| 33 | + * @param string $groupId |
|
| 34 | + * @return bool |
|
| 35 | + * @since 16.0.0 |
|
| 36 | + */ |
|
| 37 | + public function hideGroup(string $groupId): bool; |
|
| 38 | 38 | } |
@@ -389,7 +389,7 @@ |
||
| 389 | 389 | foreach ($ak as $source) { |
| 390 | 390 | $tags = $this->subTags[$source]; |
| 391 | 391 | foreach ($tags as $tag) { |
| 392 | - $subTags[] = $source . '_' . $tag; |
|
| 392 | + $subTags[] = $source.'_'.$tag; |
|
| 393 | 393 | } |
| 394 | 394 | } |
| 395 | 395 | |
@@ -30,745 +30,745 @@ |
||
| 30 | 30 | * @package OC\FullTextSearch\Model |
| 31 | 31 | */ |
| 32 | 32 | class IndexDocument implements IIndexDocument, JsonSerializable { |
| 33 | - protected string $id = ''; |
|
| 33 | + protected string $id = ''; |
|
| 34 | 34 | |
| 35 | - protected DocumentAccess $access; |
|
| 35 | + protected DocumentAccess $access; |
|
| 36 | 36 | |
| 37 | - protected ?IIndex $index = null; |
|
| 37 | + protected ?IIndex $index = null; |
|
| 38 | 38 | |
| 39 | - protected int $modifiedTime = 0; |
|
| 39 | + protected int $modifiedTime = 0; |
|
| 40 | 40 | |
| 41 | - protected string $source = ''; |
|
| 41 | + protected string $source = ''; |
|
| 42 | 42 | |
| 43 | - protected array $tags = []; |
|
| 43 | + protected array $tags = []; |
|
| 44 | 44 | |
| 45 | - protected array $metaTags = []; |
|
| 45 | + protected array $metaTags = []; |
|
| 46 | 46 | |
| 47 | - protected array $subTags = []; |
|
| 47 | + protected array $subTags = []; |
|
| 48 | 48 | |
| 49 | - protected string $title = ''; |
|
| 49 | + protected string $title = ''; |
|
| 50 | 50 | |
| 51 | - protected string $content = ''; |
|
| 51 | + protected string $content = ''; |
|
| 52 | 52 | |
| 53 | - protected string $hash = ''; |
|
| 53 | + protected string $hash = ''; |
|
| 54 | 54 | |
| 55 | - protected array $parts = []; |
|
| 55 | + protected array $parts = []; |
|
| 56 | 56 | |
| 57 | - protected string $link = ''; |
|
| 57 | + protected string $link = ''; |
|
| 58 | 58 | |
| 59 | - protected array $more = []; |
|
| 59 | + protected array $more = []; |
|
| 60 | 60 | |
| 61 | - protected array $excerpts = []; |
|
| 61 | + protected array $excerpts = []; |
|
| 62 | 62 | |
| 63 | - protected string $score = ''; |
|
| 63 | + protected string $score = ''; |
|
| 64 | 64 | |
| 65 | - protected array $info = []; |
|
| 65 | + protected array $info = []; |
|
| 66 | 66 | |
| 67 | - protected int $contentEncoded = 0; |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * IIndexDocument constructor. |
|
| 72 | - * |
|
| 73 | - * On creation, we assure the uniqueness of the object using the providerId |
|
| 74 | - * and the Id of the original document. |
|
| 75 | - * |
|
| 76 | - * @since 15.0.0 |
|
| 77 | - */ |
|
| 78 | - public function __construct( |
|
| 79 | - protected string $providerId, |
|
| 80 | - string $documentId, |
|
| 81 | - ) { |
|
| 82 | - $this->id = $documentId; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Returns the Id of the original document. |
|
| 88 | - * |
|
| 89 | - * @since 15.0.0 |
|
| 90 | - */ |
|
| 91 | - final public function getId(): string { |
|
| 92 | - return $this->id; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Returns the Id of the provider. |
|
| 98 | - * |
|
| 99 | - * @since 15.0.0 |
|
| 100 | - */ |
|
| 101 | - final public function getProviderId(): string { |
|
| 102 | - return $this->providerId; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Set the Index related to the IIndexDocument. |
|
| 108 | - * |
|
| 109 | - * @see IIndex |
|
| 110 | - * |
|
| 111 | - * @since 15.0.0 |
|
| 112 | - */ |
|
| 113 | - final public function setIndex(IIndex $index): IIndexDocument { |
|
| 114 | - $this->index = $index; |
|
| 115 | - |
|
| 116 | - return $this; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Get the Index. |
|
| 121 | - * |
|
| 122 | - * @throws FullTextSearchIndexNotAvailableException |
|
| 123 | - * @since 15.0.0 |
|
| 124 | - */ |
|
| 125 | - final public function getIndex(): IIndex { |
|
| 126 | - if ($this->index === null) { |
|
| 127 | - throw new FullTextSearchIndexNotAvailableException('No IIndex generated'); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - return $this->index; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * return if Index is defined. |
|
| 135 | - * |
|
| 136 | - * @since 16.0.0 |
|
| 137 | - */ |
|
| 138 | - final public function hasIndex(): bool { |
|
| 139 | - return $this->index !== null; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Set the modified time of the original document. |
|
| 144 | - * |
|
| 145 | - * @since 15.0.0 |
|
| 146 | - */ |
|
| 147 | - final public function setModifiedTime(int $modifiedTime): IIndexDocument { |
|
| 148 | - $this->modifiedTime = $modifiedTime; |
|
| 149 | - |
|
| 150 | - return $this; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Get the modified time of the original document. |
|
| 155 | - * |
|
| 156 | - * @since 15.0.0 |
|
| 157 | - */ |
|
| 158 | - final public function getModifiedTime(): int { |
|
| 159 | - return $this->modifiedTime; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Check if the original document of the IIndexDocument is older than $time. |
|
| 164 | - * |
|
| 165 | - * @since 15.0.0 |
|
| 166 | - */ |
|
| 167 | - final public function isOlderThan(int $time): bool { |
|
| 168 | - return ($this->modifiedTime < $time); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Set the read rights of the original document using a IDocumentAccess. |
|
| 174 | - * |
|
| 175 | - * @see IDocumentAccess |
|
| 176 | - * |
|
| 177 | - * @since 15.0.0 |
|
| 178 | - */ |
|
| 179 | - final public function setAccess(IDocumentAccess $access): IIndexDocument { |
|
| 180 | - $this->access = $access; |
|
| 181 | - |
|
| 182 | - return $this; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Get the IDocumentAccess related to the original document. |
|
| 187 | - * |
|
| 188 | - * @since 15.0.0 |
|
| 189 | - */ |
|
| 190 | - final public function getAccess(): IDocumentAccess { |
|
| 191 | - return $this->access; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Add a tag to the list. |
|
| 197 | - * |
|
| 198 | - * @since 15.0.0 |
|
| 199 | - */ |
|
| 200 | - final public function addTag(string $tag): IIndexDocument { |
|
| 201 | - $this->tags[] = $tag; |
|
| 202 | - |
|
| 203 | - return $this; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Set the list of tags assigned to the original document. |
|
| 208 | - * |
|
| 209 | - * @since 15.0.0 |
|
| 210 | - */ |
|
| 211 | - final public function setTags(array $tags): IIndexDocument { |
|
| 212 | - $this->tags = $tags; |
|
| 213 | - |
|
| 214 | - return $this; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Get the list of tags assigned to the original document. |
|
| 219 | - * |
|
| 220 | - * @since 15.0.0 |
|
| 221 | - */ |
|
| 222 | - final public function getTags(): array { |
|
| 223 | - return $this->tags; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Add a meta tag to the list. |
|
| 229 | - * |
|
| 230 | - * @since 15.0.0 |
|
| 231 | - */ |
|
| 232 | - final public function addMetaTag(string $tag): IIndexDocument { |
|
| 233 | - $this->metaTags[] = $tag; |
|
| 234 | - |
|
| 235 | - return $this; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Set the list of meta tags assigned to the original document. |
|
| 240 | - * |
|
| 241 | - * @since 15.0.0 |
|
| 242 | - */ |
|
| 243 | - final public function setMetaTags(array $tags): IIndexDocument { |
|
| 244 | - $this->metaTags = $tags; |
|
| 245 | - |
|
| 246 | - return $this; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Get the list of meta tags assigned to the original document. |
|
| 251 | - * |
|
| 252 | - * @since 15.0.0 |
|
| 253 | - */ |
|
| 254 | - final public function getMetaTags(): array { |
|
| 255 | - return $this->metaTags; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Add a sub tag to the list. |
|
| 261 | - * |
|
| 262 | - * @since 15.0.0 |
|
| 263 | - */ |
|
| 264 | - final public function addSubTag(string $sub, string $tag): IIndexDocument { |
|
| 265 | - if (!array_key_exists($sub, $this->subTags)) { |
|
| 266 | - $this->subTags[$sub] = []; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - $this->subTags[$sub][] = $tag; |
|
| 270 | - |
|
| 271 | - return $this; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * Set the list of sub tags assigned to the original document. |
|
| 277 | - * |
|
| 278 | - * @since 15.0.0 |
|
| 279 | - */ |
|
| 280 | - final public function setSubTags(array $tags): IIndexDocument { |
|
| 281 | - $this->subTags = $tags; |
|
| 282 | - |
|
| 283 | - return $this; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Get the list of sub tags assigned to the original document. |
|
| 288 | - * If $formatted is true, the result will be formatted in a one |
|
| 289 | - * dimensional array. |
|
| 290 | - * |
|
| 291 | - * @since 15.0.0 |
|
| 292 | - */ |
|
| 293 | - final public function getSubTags(bool $formatted = false): array { |
|
| 294 | - if ($formatted === false) { |
|
| 295 | - return $this->subTags; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - $subTags = []; |
|
| 299 | - $ak = array_keys($this->subTags); |
|
| 300 | - foreach ($ak as $source) { |
|
| 301 | - $tags = $this->subTags[$source]; |
|
| 302 | - foreach ($tags as $tag) { |
|
| 303 | - $subTags[] = $source . '_' . $tag; |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - return $subTags; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Set the source of the original document. |
|
| 313 | - * |
|
| 314 | - * @since 15.0.0 |
|
| 315 | - */ |
|
| 316 | - final public function setSource(string $source): IIndexDocument { |
|
| 317 | - $this->source = $source; |
|
| 318 | - |
|
| 319 | - return $this; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Get the source of the original document. |
|
| 324 | - * |
|
| 325 | - * @since 15.0.0 |
|
| 326 | - */ |
|
| 327 | - final public function getSource(): string { |
|
| 328 | - return $this->source; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Set the title of the original document. |
|
| 334 | - * |
|
| 335 | - * @since 15.0.0 |
|
| 336 | - */ |
|
| 337 | - final public function setTitle(string $title): IIndexDocument { |
|
| 338 | - $this->title = $title; |
|
| 339 | - |
|
| 340 | - return $this; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Get the title of the original document. |
|
| 345 | - * |
|
| 346 | - * @since 15.0.0 |
|
| 347 | - */ |
|
| 348 | - final public function getTitle(): string { |
|
| 349 | - return $this->title; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * Set the content of the document. |
|
| 355 | - * $encoded can be NOT_ENCODED or ENCODED_BASE64 if the content is raw or |
|
| 356 | - * encoded in base64. |
|
| 357 | - * |
|
| 358 | - * @since 15.0.0 |
|
| 359 | - */ |
|
| 360 | - final public function setContent(string $content, int $encoded = 0): IIndexDocument { |
|
| 361 | - $this->content = $content; |
|
| 362 | - $this->contentEncoded = $encoded; |
|
| 363 | - |
|
| 364 | - return $this; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * Get the content of the original document. |
|
| 369 | - * |
|
| 370 | - * @since 15.0.0 |
|
| 371 | - */ |
|
| 372 | - final public function getContent(): string { |
|
| 373 | - return $this->content; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Returns the type of the encoding on the content. |
|
| 378 | - * |
|
| 379 | - * @since 15.0.0 |
|
| 380 | - */ |
|
| 381 | - final public function isContentEncoded(): int { |
|
| 382 | - return $this->contentEncoded; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Return the size of the content. |
|
| 387 | - * |
|
| 388 | - * @since 15.0.0 |
|
| 389 | - */ |
|
| 390 | - final public function getContentSize(): int { |
|
| 391 | - return strlen($this->getContent()); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * Generate a hash, based on the content of the original document. |
|
| 397 | - * |
|
| 398 | - * @since 15.0.0 |
|
| 399 | - */ |
|
| 400 | - final public function initHash(): IIndexDocument { |
|
| 401 | - if ($this->getContent() === '' || is_null($this->getContent())) { |
|
| 402 | - return $this; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - $this->hash = hash('md5', $this->getContent()); |
|
| 406 | - |
|
| 407 | - return $this; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Set the hash of the original document. |
|
| 412 | - * |
|
| 413 | - * @since 15.0.0 |
|
| 414 | - */ |
|
| 415 | - final public function setHash(string $hash): IIndexDocument { |
|
| 416 | - $this->hash = $hash; |
|
| 417 | - |
|
| 418 | - return $this; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Get the hash of the original document. |
|
| 423 | - * |
|
| 424 | - * @since 15.0.0 |
|
| 425 | - */ |
|
| 426 | - final public function getHash(): string { |
|
| 427 | - return $this->hash; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * Add a part, identified by a string, and its content. |
|
| 433 | - * |
|
| 434 | - * It is strongly advised to use alphanumerical chars with no space in the |
|
| 435 | - * $part string. |
|
| 436 | - * |
|
| 437 | - * @since 15.0.0 |
|
| 438 | - */ |
|
| 439 | - final public function addPart(string $part, string $content): IIndexDocument { |
|
| 440 | - $this->parts[$part] = $content; |
|
| 441 | - |
|
| 442 | - return $this; |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * Set all parts and their content. |
|
| 447 | - * |
|
| 448 | - * @since 15.0.0 |
|
| 449 | - */ |
|
| 450 | - final public function setParts(array $parts): IIndexDocument { |
|
| 451 | - $this->parts = $parts; |
|
| 452 | - |
|
| 453 | - return $this; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - /** |
|
| 457 | - * Get all parts of the IIndexDocument. |
|
| 458 | - * |
|
| 459 | - * @since 15.0.0 |
|
| 460 | - */ |
|
| 461 | - final public function getParts(): array { |
|
| 462 | - return $this->parts; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * Add a link, usable by the frontend. |
|
| 468 | - * |
|
| 469 | - * @since 15.0.0 |
|
| 470 | - */ |
|
| 471 | - final public function setLink(string $link): IIndexDocument { |
|
| 472 | - $this->link = $link; |
|
| 473 | - |
|
| 474 | - return $this; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * Get the link. |
|
| 479 | - * |
|
| 480 | - * @since 15.0.0 |
|
| 481 | - */ |
|
| 482 | - final public function getLink(): string { |
|
| 483 | - return $this->link; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Set more information that couldn't be set using other method. |
|
| 489 | - * |
|
| 490 | - * @since 15.0.0 |
|
| 491 | - */ |
|
| 492 | - final public function setMore(array $more): IIndexDocument { |
|
| 493 | - $this->more = $more; |
|
| 494 | - |
|
| 495 | - return $this; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * Get more information. |
|
| 500 | - * |
|
| 501 | - * @since 15.0.0 |
|
| 502 | - */ |
|
| 503 | - final public function getMore(): array { |
|
| 504 | - return $this->more; |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * Add some excerpt of the content of the original document, usually based |
|
| 510 | - * on the search request. |
|
| 511 | - * |
|
| 512 | - * @since 16.0.0 |
|
| 513 | - */ |
|
| 514 | - final public function addExcerpt(string $source, string $excerpt): IIndexDocument { |
|
| 515 | - $this->excerpts[] = |
|
| 516 | - [ |
|
| 517 | - 'source' => $source, |
|
| 518 | - 'excerpt' => $this->cleanExcerpt($excerpt) |
|
| 519 | - ]; |
|
| 520 | - |
|
| 521 | - return $this; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * Set all excerpts of the content of the original document. |
|
| 527 | - * |
|
| 528 | - * @since 16.0.0 |
|
| 529 | - */ |
|
| 530 | - final public function setExcerpts(array $excerpts): IIndexDocument { |
|
| 531 | - $new = []; |
|
| 532 | - foreach ($excerpts as $entry) { |
|
| 533 | - $new[] = [ |
|
| 534 | - 'source' => $entry['source'], |
|
| 535 | - 'excerpt' => $this->cleanExcerpt($entry['excerpt']) |
|
| 536 | - ]; |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - $this->excerpts = $new; |
|
| 540 | - |
|
| 541 | - return $this; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * Get all excerpts of the content of the original document. |
|
| 546 | - * |
|
| 547 | - * @since 15.0.0 |
|
| 548 | - */ |
|
| 549 | - final public function getExcerpts(): array { |
|
| 550 | - return $this->excerpts; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - /** |
|
| 554 | - * Clean excerpt. |
|
| 555 | - * |
|
| 556 | - * @since 16.0.0 |
|
| 557 | - */ |
|
| 558 | - private function cleanExcerpt(string $excerpt): string { |
|
| 559 | - $excerpt = str_replace('\\n', ' ', $excerpt); |
|
| 560 | - $excerpt = str_replace('\\r', ' ', $excerpt); |
|
| 561 | - $excerpt = str_replace('\\t', ' ', $excerpt); |
|
| 562 | - $excerpt = str_replace("\n", ' ', $excerpt); |
|
| 563 | - $excerpt = str_replace("\r", ' ', $excerpt); |
|
| 564 | - $excerpt = str_replace("\t", ' ', $excerpt); |
|
| 565 | - |
|
| 566 | - return $excerpt; |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * Set the score to the result assigned to this document during a search |
|
| 572 | - * request. |
|
| 573 | - * |
|
| 574 | - * @since 15.0.0 |
|
| 575 | - */ |
|
| 576 | - final public function setScore(string $score): IIndexDocument { |
|
| 577 | - $this->score = $score; |
|
| 578 | - |
|
| 579 | - return $this; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - /** |
|
| 583 | - * Get the score. |
|
| 584 | - * |
|
| 585 | - * @since 15.0.0 |
|
| 586 | - */ |
|
| 587 | - final public function getScore(): string { |
|
| 588 | - return $this->score; |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * Set some information about the original document that will be available |
|
| 594 | - * to the front-end when displaying search result. (as string) |
|
| 595 | - * Because this information will not be indexed, this method can also be |
|
| 596 | - * used to manage some data while filling the IIndexDocument before its |
|
| 597 | - * indexing. |
|
| 598 | - * |
|
| 599 | - * @since 15.0.0 |
|
| 600 | - */ |
|
| 601 | - final public function setInfo(string $info, string $value): IIndexDocument { |
|
| 602 | - $this->info[$info] = $value; |
|
| 603 | - |
|
| 604 | - return $this; |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * Get an information about a document. (string) |
|
| 609 | - * |
|
| 610 | - * @since 15.0.0 |
|
| 611 | - */ |
|
| 612 | - final public function getInfo(string $info, string $default = ''): string { |
|
| 613 | - if (!key_exists($info, $this->info)) { |
|
| 614 | - return $default; |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - return $this->info[$info]; |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * Set some information about the original document that will be available |
|
| 622 | - * to the front-end when displaying search result. (as array) |
|
| 623 | - * Because this information will not be indexed, this method can also be |
|
| 624 | - * used to manage some data while filling the IIndexDocument before its |
|
| 625 | - * indexing. |
|
| 626 | - * |
|
| 627 | - * @since 15.0.0 |
|
| 628 | - */ |
|
| 629 | - final public function setInfoArray(string $info, array $value): IIndexDocument { |
|
| 630 | - $this->info[$info] = $value; |
|
| 631 | - |
|
| 632 | - return $this; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - /** |
|
| 636 | - * Get an information about a document. (array) |
|
| 637 | - * |
|
| 638 | - * @since 15.0.0 |
|
| 639 | - */ |
|
| 640 | - final public function getInfoArray(string $info, array $default = []): array { |
|
| 641 | - if (!key_exists($info, $this->info)) { |
|
| 642 | - return $default; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - return $this->info[$info]; |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * Set some information about the original document that will be available |
|
| 650 | - * to the front-end when displaying search result. (as int) |
|
| 651 | - * Because this information will not be indexed, this method can also be |
|
| 652 | - * used to manage some data while filling the IIndexDocument before its |
|
| 653 | - * indexing. |
|
| 654 | - * |
|
| 655 | - * @since 15.0.0 |
|
| 656 | - */ |
|
| 657 | - final public function setInfoInt(string $info, int $value): IIndexDocument { |
|
| 658 | - $this->info[$info] = $value; |
|
| 659 | - |
|
| 660 | - return $this; |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * Get an information about a document. (int) |
|
| 665 | - * |
|
| 666 | - * @since 15.0.0 |
|
| 667 | - */ |
|
| 668 | - final public function getInfoInt(string $info, int $default = 0): int { |
|
| 669 | - if (!key_exists($info, $this->info)) { |
|
| 670 | - return $default; |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - return $this->info[$info]; |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - /** |
|
| 677 | - * Set some information about the original document that will be available |
|
| 678 | - * to the front-end when displaying search result. (as bool) |
|
| 679 | - * Because this information will not be indexed, this method can also be |
|
| 680 | - * used to manage some data while filling the IIndexDocument before its |
|
| 681 | - * indexing. |
|
| 682 | - * |
|
| 683 | - * @since 15.0.0 |
|
| 684 | - */ |
|
| 685 | - final public function setInfoBool(string $info, bool $value): IIndexDocument { |
|
| 686 | - $this->info[$info] = $value; |
|
| 687 | - |
|
| 688 | - return $this; |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * Get an information about a document. (bool) |
|
| 693 | - * |
|
| 694 | - * @since 15.0.0 |
|
| 695 | - */ |
|
| 696 | - final public function getInfoBool(string $info, bool $default = false): bool { |
|
| 697 | - if (!key_exists($info, $this->info)) { |
|
| 698 | - return $default; |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - return $this->info[$info]; |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - /** |
|
| 705 | - * Get all info. |
|
| 706 | - * |
|
| 707 | - * @since 15.0.0 |
|
| 708 | - */ |
|
| 709 | - final public function getInfoAll(): array { |
|
| 710 | - $info = []; |
|
| 711 | - foreach ($this->info as $k => $v) { |
|
| 712 | - if (str_starts_with($k, '_')) { |
|
| 713 | - continue; |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - $info[$k] = $v; |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - return $info; |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - |
|
| 723 | - /** |
|
| 724 | - * @since 15.0.0 |
|
| 725 | - * |
|
| 726 | - * On some version of PHP, it is better to force destruct the object. |
|
| 727 | - * And during the index, the number of generated IIndexDocument can be |
|
| 728 | - * _huge_. |
|
| 729 | - */ |
|
| 730 | - public function __destruct() { |
|
| 731 | - unset($this->id); |
|
| 732 | - unset($this->providerId); |
|
| 733 | - unset($this->access); |
|
| 734 | - unset($this->modifiedTime); |
|
| 735 | - unset($this->title); |
|
| 736 | - unset($this->content); |
|
| 737 | - unset($this->hash); |
|
| 738 | - unset($this->link); |
|
| 739 | - unset($this->source); |
|
| 740 | - unset($this->tags); |
|
| 741 | - unset($this->metaTags); |
|
| 742 | - unset($this->subTags); |
|
| 743 | - unset($this->more); |
|
| 744 | - unset($this->excerpts); |
|
| 745 | - unset($this->score); |
|
| 746 | - unset($this->info); |
|
| 747 | - unset($this->contentEncoded); |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * @since 15.0.0 |
|
| 752 | - */ |
|
| 753 | - public function jsonSerialize(): array { |
|
| 754 | - return [ |
|
| 755 | - 'id' => $this->getId(), |
|
| 756 | - 'providerId' => $this->getProviderId(), |
|
| 757 | - 'access' => $this->access, |
|
| 758 | - 'modifiedTime' => $this->getModifiedTime(), |
|
| 759 | - 'title' => $this->getTitle(), |
|
| 760 | - 'link' => $this->getLink(), |
|
| 761 | - 'index' => $this->index, |
|
| 762 | - 'source' => $this->getSource(), |
|
| 763 | - 'info' => $this->getInfoAll(), |
|
| 764 | - 'hash' => $this->getHash(), |
|
| 765 | - 'contentSize' => $this->getContentSize(), |
|
| 766 | - 'tags' => $this->getTags(), |
|
| 767 | - 'metatags' => $this->getMetaTags(), |
|
| 768 | - 'subtags' => $this->getSubTags(), |
|
| 769 | - 'more' => $this->getMore(), |
|
| 770 | - 'excerpts' => $this->getExcerpts(), |
|
| 771 | - 'score' => $this->getScore() |
|
| 772 | - ]; |
|
| 773 | - } |
|
| 67 | + protected int $contentEncoded = 0; |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * IIndexDocument constructor. |
|
| 72 | + * |
|
| 73 | + * On creation, we assure the uniqueness of the object using the providerId |
|
| 74 | + * and the Id of the original document. |
|
| 75 | + * |
|
| 76 | + * @since 15.0.0 |
|
| 77 | + */ |
|
| 78 | + public function __construct( |
|
| 79 | + protected string $providerId, |
|
| 80 | + string $documentId, |
|
| 81 | + ) { |
|
| 82 | + $this->id = $documentId; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Returns the Id of the original document. |
|
| 88 | + * |
|
| 89 | + * @since 15.0.0 |
|
| 90 | + */ |
|
| 91 | + final public function getId(): string { |
|
| 92 | + return $this->id; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Returns the Id of the provider. |
|
| 98 | + * |
|
| 99 | + * @since 15.0.0 |
|
| 100 | + */ |
|
| 101 | + final public function getProviderId(): string { |
|
| 102 | + return $this->providerId; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Set the Index related to the IIndexDocument. |
|
| 108 | + * |
|
| 109 | + * @see IIndex |
|
| 110 | + * |
|
| 111 | + * @since 15.0.0 |
|
| 112 | + */ |
|
| 113 | + final public function setIndex(IIndex $index): IIndexDocument { |
|
| 114 | + $this->index = $index; |
|
| 115 | + |
|
| 116 | + return $this; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Get the Index. |
|
| 121 | + * |
|
| 122 | + * @throws FullTextSearchIndexNotAvailableException |
|
| 123 | + * @since 15.0.0 |
|
| 124 | + */ |
|
| 125 | + final public function getIndex(): IIndex { |
|
| 126 | + if ($this->index === null) { |
|
| 127 | + throw new FullTextSearchIndexNotAvailableException('No IIndex generated'); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + return $this->index; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * return if Index is defined. |
|
| 135 | + * |
|
| 136 | + * @since 16.0.0 |
|
| 137 | + */ |
|
| 138 | + final public function hasIndex(): bool { |
|
| 139 | + return $this->index !== null; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Set the modified time of the original document. |
|
| 144 | + * |
|
| 145 | + * @since 15.0.0 |
|
| 146 | + */ |
|
| 147 | + final public function setModifiedTime(int $modifiedTime): IIndexDocument { |
|
| 148 | + $this->modifiedTime = $modifiedTime; |
|
| 149 | + |
|
| 150 | + return $this; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Get the modified time of the original document. |
|
| 155 | + * |
|
| 156 | + * @since 15.0.0 |
|
| 157 | + */ |
|
| 158 | + final public function getModifiedTime(): int { |
|
| 159 | + return $this->modifiedTime; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Check if the original document of the IIndexDocument is older than $time. |
|
| 164 | + * |
|
| 165 | + * @since 15.0.0 |
|
| 166 | + */ |
|
| 167 | + final public function isOlderThan(int $time): bool { |
|
| 168 | + return ($this->modifiedTime < $time); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Set the read rights of the original document using a IDocumentAccess. |
|
| 174 | + * |
|
| 175 | + * @see IDocumentAccess |
|
| 176 | + * |
|
| 177 | + * @since 15.0.0 |
|
| 178 | + */ |
|
| 179 | + final public function setAccess(IDocumentAccess $access): IIndexDocument { |
|
| 180 | + $this->access = $access; |
|
| 181 | + |
|
| 182 | + return $this; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Get the IDocumentAccess related to the original document. |
|
| 187 | + * |
|
| 188 | + * @since 15.0.0 |
|
| 189 | + */ |
|
| 190 | + final public function getAccess(): IDocumentAccess { |
|
| 191 | + return $this->access; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Add a tag to the list. |
|
| 197 | + * |
|
| 198 | + * @since 15.0.0 |
|
| 199 | + */ |
|
| 200 | + final public function addTag(string $tag): IIndexDocument { |
|
| 201 | + $this->tags[] = $tag; |
|
| 202 | + |
|
| 203 | + return $this; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Set the list of tags assigned to the original document. |
|
| 208 | + * |
|
| 209 | + * @since 15.0.0 |
|
| 210 | + */ |
|
| 211 | + final public function setTags(array $tags): IIndexDocument { |
|
| 212 | + $this->tags = $tags; |
|
| 213 | + |
|
| 214 | + return $this; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Get the list of tags assigned to the original document. |
|
| 219 | + * |
|
| 220 | + * @since 15.0.0 |
|
| 221 | + */ |
|
| 222 | + final public function getTags(): array { |
|
| 223 | + return $this->tags; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Add a meta tag to the list. |
|
| 229 | + * |
|
| 230 | + * @since 15.0.0 |
|
| 231 | + */ |
|
| 232 | + final public function addMetaTag(string $tag): IIndexDocument { |
|
| 233 | + $this->metaTags[] = $tag; |
|
| 234 | + |
|
| 235 | + return $this; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Set the list of meta tags assigned to the original document. |
|
| 240 | + * |
|
| 241 | + * @since 15.0.0 |
|
| 242 | + */ |
|
| 243 | + final public function setMetaTags(array $tags): IIndexDocument { |
|
| 244 | + $this->metaTags = $tags; |
|
| 245 | + |
|
| 246 | + return $this; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Get the list of meta tags assigned to the original document. |
|
| 251 | + * |
|
| 252 | + * @since 15.0.0 |
|
| 253 | + */ |
|
| 254 | + final public function getMetaTags(): array { |
|
| 255 | + return $this->metaTags; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Add a sub tag to the list. |
|
| 261 | + * |
|
| 262 | + * @since 15.0.0 |
|
| 263 | + */ |
|
| 264 | + final public function addSubTag(string $sub, string $tag): IIndexDocument { |
|
| 265 | + if (!array_key_exists($sub, $this->subTags)) { |
|
| 266 | + $this->subTags[$sub] = []; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + $this->subTags[$sub][] = $tag; |
|
| 270 | + |
|
| 271 | + return $this; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * Set the list of sub tags assigned to the original document. |
|
| 277 | + * |
|
| 278 | + * @since 15.0.0 |
|
| 279 | + */ |
|
| 280 | + final public function setSubTags(array $tags): IIndexDocument { |
|
| 281 | + $this->subTags = $tags; |
|
| 282 | + |
|
| 283 | + return $this; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Get the list of sub tags assigned to the original document. |
|
| 288 | + * If $formatted is true, the result will be formatted in a one |
|
| 289 | + * dimensional array. |
|
| 290 | + * |
|
| 291 | + * @since 15.0.0 |
|
| 292 | + */ |
|
| 293 | + final public function getSubTags(bool $formatted = false): array { |
|
| 294 | + if ($formatted === false) { |
|
| 295 | + return $this->subTags; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + $subTags = []; |
|
| 299 | + $ak = array_keys($this->subTags); |
|
| 300 | + foreach ($ak as $source) { |
|
| 301 | + $tags = $this->subTags[$source]; |
|
| 302 | + foreach ($tags as $tag) { |
|
| 303 | + $subTags[] = $source . '_' . $tag; |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + return $subTags; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Set the source of the original document. |
|
| 313 | + * |
|
| 314 | + * @since 15.0.0 |
|
| 315 | + */ |
|
| 316 | + final public function setSource(string $source): IIndexDocument { |
|
| 317 | + $this->source = $source; |
|
| 318 | + |
|
| 319 | + return $this; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Get the source of the original document. |
|
| 324 | + * |
|
| 325 | + * @since 15.0.0 |
|
| 326 | + */ |
|
| 327 | + final public function getSource(): string { |
|
| 328 | + return $this->source; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Set the title of the original document. |
|
| 334 | + * |
|
| 335 | + * @since 15.0.0 |
|
| 336 | + */ |
|
| 337 | + final public function setTitle(string $title): IIndexDocument { |
|
| 338 | + $this->title = $title; |
|
| 339 | + |
|
| 340 | + return $this; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Get the title of the original document. |
|
| 345 | + * |
|
| 346 | + * @since 15.0.0 |
|
| 347 | + */ |
|
| 348 | + final public function getTitle(): string { |
|
| 349 | + return $this->title; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * Set the content of the document. |
|
| 355 | + * $encoded can be NOT_ENCODED or ENCODED_BASE64 if the content is raw or |
|
| 356 | + * encoded in base64. |
|
| 357 | + * |
|
| 358 | + * @since 15.0.0 |
|
| 359 | + */ |
|
| 360 | + final public function setContent(string $content, int $encoded = 0): IIndexDocument { |
|
| 361 | + $this->content = $content; |
|
| 362 | + $this->contentEncoded = $encoded; |
|
| 363 | + |
|
| 364 | + return $this; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * Get the content of the original document. |
|
| 369 | + * |
|
| 370 | + * @since 15.0.0 |
|
| 371 | + */ |
|
| 372 | + final public function getContent(): string { |
|
| 373 | + return $this->content; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Returns the type of the encoding on the content. |
|
| 378 | + * |
|
| 379 | + * @since 15.0.0 |
|
| 380 | + */ |
|
| 381 | + final public function isContentEncoded(): int { |
|
| 382 | + return $this->contentEncoded; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Return the size of the content. |
|
| 387 | + * |
|
| 388 | + * @since 15.0.0 |
|
| 389 | + */ |
|
| 390 | + final public function getContentSize(): int { |
|
| 391 | + return strlen($this->getContent()); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * Generate a hash, based on the content of the original document. |
|
| 397 | + * |
|
| 398 | + * @since 15.0.0 |
|
| 399 | + */ |
|
| 400 | + final public function initHash(): IIndexDocument { |
|
| 401 | + if ($this->getContent() === '' || is_null($this->getContent())) { |
|
| 402 | + return $this; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + $this->hash = hash('md5', $this->getContent()); |
|
| 406 | + |
|
| 407 | + return $this; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Set the hash of the original document. |
|
| 412 | + * |
|
| 413 | + * @since 15.0.0 |
|
| 414 | + */ |
|
| 415 | + final public function setHash(string $hash): IIndexDocument { |
|
| 416 | + $this->hash = $hash; |
|
| 417 | + |
|
| 418 | + return $this; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Get the hash of the original document. |
|
| 423 | + * |
|
| 424 | + * @since 15.0.0 |
|
| 425 | + */ |
|
| 426 | + final public function getHash(): string { |
|
| 427 | + return $this->hash; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * Add a part, identified by a string, and its content. |
|
| 433 | + * |
|
| 434 | + * It is strongly advised to use alphanumerical chars with no space in the |
|
| 435 | + * $part string. |
|
| 436 | + * |
|
| 437 | + * @since 15.0.0 |
|
| 438 | + */ |
|
| 439 | + final public function addPart(string $part, string $content): IIndexDocument { |
|
| 440 | + $this->parts[$part] = $content; |
|
| 441 | + |
|
| 442 | + return $this; |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * Set all parts and their content. |
|
| 447 | + * |
|
| 448 | + * @since 15.0.0 |
|
| 449 | + */ |
|
| 450 | + final public function setParts(array $parts): IIndexDocument { |
|
| 451 | + $this->parts = $parts; |
|
| 452 | + |
|
| 453 | + return $this; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + /** |
|
| 457 | + * Get all parts of the IIndexDocument. |
|
| 458 | + * |
|
| 459 | + * @since 15.0.0 |
|
| 460 | + */ |
|
| 461 | + final public function getParts(): array { |
|
| 462 | + return $this->parts; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * Add a link, usable by the frontend. |
|
| 468 | + * |
|
| 469 | + * @since 15.0.0 |
|
| 470 | + */ |
|
| 471 | + final public function setLink(string $link): IIndexDocument { |
|
| 472 | + $this->link = $link; |
|
| 473 | + |
|
| 474 | + return $this; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * Get the link. |
|
| 479 | + * |
|
| 480 | + * @since 15.0.0 |
|
| 481 | + */ |
|
| 482 | + final public function getLink(): string { |
|
| 483 | + return $this->link; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * Set more information that couldn't be set using other method. |
|
| 489 | + * |
|
| 490 | + * @since 15.0.0 |
|
| 491 | + */ |
|
| 492 | + final public function setMore(array $more): IIndexDocument { |
|
| 493 | + $this->more = $more; |
|
| 494 | + |
|
| 495 | + return $this; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * Get more information. |
|
| 500 | + * |
|
| 501 | + * @since 15.0.0 |
|
| 502 | + */ |
|
| 503 | + final public function getMore(): array { |
|
| 504 | + return $this->more; |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * Add some excerpt of the content of the original document, usually based |
|
| 510 | + * on the search request. |
|
| 511 | + * |
|
| 512 | + * @since 16.0.0 |
|
| 513 | + */ |
|
| 514 | + final public function addExcerpt(string $source, string $excerpt): IIndexDocument { |
|
| 515 | + $this->excerpts[] = |
|
| 516 | + [ |
|
| 517 | + 'source' => $source, |
|
| 518 | + 'excerpt' => $this->cleanExcerpt($excerpt) |
|
| 519 | + ]; |
|
| 520 | + |
|
| 521 | + return $this; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * Set all excerpts of the content of the original document. |
|
| 527 | + * |
|
| 528 | + * @since 16.0.0 |
|
| 529 | + */ |
|
| 530 | + final public function setExcerpts(array $excerpts): IIndexDocument { |
|
| 531 | + $new = []; |
|
| 532 | + foreach ($excerpts as $entry) { |
|
| 533 | + $new[] = [ |
|
| 534 | + 'source' => $entry['source'], |
|
| 535 | + 'excerpt' => $this->cleanExcerpt($entry['excerpt']) |
|
| 536 | + ]; |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + $this->excerpts = $new; |
|
| 540 | + |
|
| 541 | + return $this; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * Get all excerpts of the content of the original document. |
|
| 546 | + * |
|
| 547 | + * @since 15.0.0 |
|
| 548 | + */ |
|
| 549 | + final public function getExcerpts(): array { |
|
| 550 | + return $this->excerpts; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + /** |
|
| 554 | + * Clean excerpt. |
|
| 555 | + * |
|
| 556 | + * @since 16.0.0 |
|
| 557 | + */ |
|
| 558 | + private function cleanExcerpt(string $excerpt): string { |
|
| 559 | + $excerpt = str_replace('\\n', ' ', $excerpt); |
|
| 560 | + $excerpt = str_replace('\\r', ' ', $excerpt); |
|
| 561 | + $excerpt = str_replace('\\t', ' ', $excerpt); |
|
| 562 | + $excerpt = str_replace("\n", ' ', $excerpt); |
|
| 563 | + $excerpt = str_replace("\r", ' ', $excerpt); |
|
| 564 | + $excerpt = str_replace("\t", ' ', $excerpt); |
|
| 565 | + |
|
| 566 | + return $excerpt; |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * Set the score to the result assigned to this document during a search |
|
| 572 | + * request. |
|
| 573 | + * |
|
| 574 | + * @since 15.0.0 |
|
| 575 | + */ |
|
| 576 | + final public function setScore(string $score): IIndexDocument { |
|
| 577 | + $this->score = $score; |
|
| 578 | + |
|
| 579 | + return $this; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * Get the score. |
|
| 584 | + * |
|
| 585 | + * @since 15.0.0 |
|
| 586 | + */ |
|
| 587 | + final public function getScore(): string { |
|
| 588 | + return $this->score; |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * Set some information about the original document that will be available |
|
| 594 | + * to the front-end when displaying search result. (as string) |
|
| 595 | + * Because this information will not be indexed, this method can also be |
|
| 596 | + * used to manage some data while filling the IIndexDocument before its |
|
| 597 | + * indexing. |
|
| 598 | + * |
|
| 599 | + * @since 15.0.0 |
|
| 600 | + */ |
|
| 601 | + final public function setInfo(string $info, string $value): IIndexDocument { |
|
| 602 | + $this->info[$info] = $value; |
|
| 603 | + |
|
| 604 | + return $this; |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * Get an information about a document. (string) |
|
| 609 | + * |
|
| 610 | + * @since 15.0.0 |
|
| 611 | + */ |
|
| 612 | + final public function getInfo(string $info, string $default = ''): string { |
|
| 613 | + if (!key_exists($info, $this->info)) { |
|
| 614 | + return $default; |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + return $this->info[$info]; |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * Set some information about the original document that will be available |
|
| 622 | + * to the front-end when displaying search result. (as array) |
|
| 623 | + * Because this information will not be indexed, this method can also be |
|
| 624 | + * used to manage some data while filling the IIndexDocument before its |
|
| 625 | + * indexing. |
|
| 626 | + * |
|
| 627 | + * @since 15.0.0 |
|
| 628 | + */ |
|
| 629 | + final public function setInfoArray(string $info, array $value): IIndexDocument { |
|
| 630 | + $this->info[$info] = $value; |
|
| 631 | + |
|
| 632 | + return $this; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + /** |
|
| 636 | + * Get an information about a document. (array) |
|
| 637 | + * |
|
| 638 | + * @since 15.0.0 |
|
| 639 | + */ |
|
| 640 | + final public function getInfoArray(string $info, array $default = []): array { |
|
| 641 | + if (!key_exists($info, $this->info)) { |
|
| 642 | + return $default; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + return $this->info[$info]; |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * Set some information about the original document that will be available |
|
| 650 | + * to the front-end when displaying search result. (as int) |
|
| 651 | + * Because this information will not be indexed, this method can also be |
|
| 652 | + * used to manage some data while filling the IIndexDocument before its |
|
| 653 | + * indexing. |
|
| 654 | + * |
|
| 655 | + * @since 15.0.0 |
|
| 656 | + */ |
|
| 657 | + final public function setInfoInt(string $info, int $value): IIndexDocument { |
|
| 658 | + $this->info[$info] = $value; |
|
| 659 | + |
|
| 660 | + return $this; |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * Get an information about a document. (int) |
|
| 665 | + * |
|
| 666 | + * @since 15.0.0 |
|
| 667 | + */ |
|
| 668 | + final public function getInfoInt(string $info, int $default = 0): int { |
|
| 669 | + if (!key_exists($info, $this->info)) { |
|
| 670 | + return $default; |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + return $this->info[$info]; |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + /** |
|
| 677 | + * Set some information about the original document that will be available |
|
| 678 | + * to the front-end when displaying search result. (as bool) |
|
| 679 | + * Because this information will not be indexed, this method can also be |
|
| 680 | + * used to manage some data while filling the IIndexDocument before its |
|
| 681 | + * indexing. |
|
| 682 | + * |
|
| 683 | + * @since 15.0.0 |
|
| 684 | + */ |
|
| 685 | + final public function setInfoBool(string $info, bool $value): IIndexDocument { |
|
| 686 | + $this->info[$info] = $value; |
|
| 687 | + |
|
| 688 | + return $this; |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * Get an information about a document. (bool) |
|
| 693 | + * |
|
| 694 | + * @since 15.0.0 |
|
| 695 | + */ |
|
| 696 | + final public function getInfoBool(string $info, bool $default = false): bool { |
|
| 697 | + if (!key_exists($info, $this->info)) { |
|
| 698 | + return $default; |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + return $this->info[$info]; |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + /** |
|
| 705 | + * Get all info. |
|
| 706 | + * |
|
| 707 | + * @since 15.0.0 |
|
| 708 | + */ |
|
| 709 | + final public function getInfoAll(): array { |
|
| 710 | + $info = []; |
|
| 711 | + foreach ($this->info as $k => $v) { |
|
| 712 | + if (str_starts_with($k, '_')) { |
|
| 713 | + continue; |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + $info[$k] = $v; |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + return $info; |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + |
|
| 723 | + /** |
|
| 724 | + * @since 15.0.0 |
|
| 725 | + * |
|
| 726 | + * On some version of PHP, it is better to force destruct the object. |
|
| 727 | + * And during the index, the number of generated IIndexDocument can be |
|
| 728 | + * _huge_. |
|
| 729 | + */ |
|
| 730 | + public function __destruct() { |
|
| 731 | + unset($this->id); |
|
| 732 | + unset($this->providerId); |
|
| 733 | + unset($this->access); |
|
| 734 | + unset($this->modifiedTime); |
|
| 735 | + unset($this->title); |
|
| 736 | + unset($this->content); |
|
| 737 | + unset($this->hash); |
|
| 738 | + unset($this->link); |
|
| 739 | + unset($this->source); |
|
| 740 | + unset($this->tags); |
|
| 741 | + unset($this->metaTags); |
|
| 742 | + unset($this->subTags); |
|
| 743 | + unset($this->more); |
|
| 744 | + unset($this->excerpts); |
|
| 745 | + unset($this->score); |
|
| 746 | + unset($this->info); |
|
| 747 | + unset($this->contentEncoded); |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * @since 15.0.0 |
|
| 752 | + */ |
|
| 753 | + public function jsonSerialize(): array { |
|
| 754 | + return [ |
|
| 755 | + 'id' => $this->getId(), |
|
| 756 | + 'providerId' => $this->getProviderId(), |
|
| 757 | + 'access' => $this->access, |
|
| 758 | + 'modifiedTime' => $this->getModifiedTime(), |
|
| 759 | + 'title' => $this->getTitle(), |
|
| 760 | + 'link' => $this->getLink(), |
|
| 761 | + 'index' => $this->index, |
|
| 762 | + 'source' => $this->getSource(), |
|
| 763 | + 'info' => $this->getInfoAll(), |
|
| 764 | + 'hash' => $this->getHash(), |
|
| 765 | + 'contentSize' => $this->getContentSize(), |
|
| 766 | + 'tags' => $this->getTags(), |
|
| 767 | + 'metatags' => $this->getMetaTags(), |
|
| 768 | + 'subtags' => $this->getSubTags(), |
|
| 769 | + 'more' => $this->getMore(), |
|
| 770 | + 'excerpts' => $this->getExcerpts(), |
|
| 771 | + 'score' => $this->getScore() |
|
| 772 | + ]; |
|
| 773 | + } |
|
| 774 | 774 | } |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | $providers = $this->registry->getProviderStates($event->getUser()); |
| 54 | 54 | |
| 55 | 55 | // Loop over all providers. If all are disabled we remove the job |
| 56 | - $state = array_reduce($providers, function (bool $carry, bool $enabled) { |
|
| 56 | + $state = array_reduce($providers, function(bool $carry, bool $enabled) { |
|
| 57 | 57 | return $carry || $enabled; |
| 58 | 58 | }, false); |
| 59 | 59 | |
@@ -18,26 +18,26 @@ |
||
| 18 | 18 | /** @template-implements IEventListener<TwoFactorProviderForUserUnregistered> */ |
| 19 | 19 | class ProviderDisabled implements IEventListener { |
| 20 | 20 | |
| 21 | - public function __construct( |
|
| 22 | - private IRegistry $registry, |
|
| 23 | - private IJobList $jobList, |
|
| 24 | - ) { |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - public function handle(Event $event): void { |
|
| 28 | - if (!($event instanceof TwoFactorProviderForUserUnregistered)) { |
|
| 29 | - return; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - $providers = $this->registry->getProviderStates($event->getUser()); |
|
| 33 | - |
|
| 34 | - // Loop over all providers. If all are disabled we remove the job |
|
| 35 | - $state = array_reduce($providers, function (bool $carry, bool $enabled) { |
|
| 36 | - return $carry || $enabled; |
|
| 37 | - }, false); |
|
| 38 | - |
|
| 39 | - if ($state === false) { |
|
| 40 | - $this->jobList->remove(RememberBackupCodesJob::class, ['uid' => $event->getUser()->getUID()]); |
|
| 41 | - } |
|
| 42 | - } |
|
| 21 | + public function __construct( |
|
| 22 | + private IRegistry $registry, |
|
| 23 | + private IJobList $jobList, |
|
| 24 | + ) { |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + public function handle(Event $event): void { |
|
| 28 | + if (!($event instanceof TwoFactorProviderForUserUnregistered)) { |
|
| 29 | + return; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + $providers = $this->registry->getProviderStates($event->getUser()); |
|
| 33 | + |
|
| 34 | + // Loop over all providers. If all are disabled we remove the job |
|
| 35 | + $state = array_reduce($providers, function (bool $carry, bool $enabled) { |
|
| 36 | + return $carry || $enabled; |
|
| 37 | + }, false); |
|
| 38 | + |
|
| 39 | + if ($state === false) { |
|
| 40 | + $this->jobList->remove(RememberBackupCodesJob::class, ['uid' => $event->getUser()->getUID()]); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | 43 | } |
@@ -30,31 +30,31 @@ |
||
| 30 | 30 | * @deprecated 17.0.0 use IProviderV2 instead |
| 31 | 31 | */ |
| 32 | 32 | interface IProvider { |
| 33 | - /** |
|
| 34 | - * @return string Regex with the mimetypes that are supported by this provider |
|
| 35 | - * @since 8.1.0 |
|
| 36 | - */ |
|
| 37 | - public function getMimeType(); |
|
| 33 | + /** |
|
| 34 | + * @return string Regex with the mimetypes that are supported by this provider |
|
| 35 | + * @since 8.1.0 |
|
| 36 | + */ |
|
| 37 | + public function getMimeType(); |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Check if a preview can be generated for $path |
|
| 41 | - * |
|
| 42 | - * @param \OCP\Files\FileInfo $file |
|
| 43 | - * @return bool |
|
| 44 | - * @since 8.1.0 |
|
| 45 | - */ |
|
| 46 | - public function isAvailable(\OCP\Files\FileInfo $file); |
|
| 39 | + /** |
|
| 40 | + * Check if a preview can be generated for $path |
|
| 41 | + * |
|
| 42 | + * @param \OCP\Files\FileInfo $file |
|
| 43 | + * @return bool |
|
| 44 | + * @since 8.1.0 |
|
| 45 | + */ |
|
| 46 | + public function isAvailable(\OCP\Files\FileInfo $file); |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * get thumbnail for file at path $path |
|
| 50 | - * |
|
| 51 | - * @param string $path Path of file |
|
| 52 | - * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 53 | - * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 54 | - * @param bool $scalingup Disable/Enable upscaling of previews |
|
| 55 | - * @param \OC\Files\View $fileview fileview object of user folder |
|
| 56 | - * @return bool|\OCP\IImage false if no preview was generated |
|
| 57 | - * @since 8.1.0 |
|
| 58 | - */ |
|
| 59 | - public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview); |
|
| 48 | + /** |
|
| 49 | + * get thumbnail for file at path $path |
|
| 50 | + * |
|
| 51 | + * @param string $path Path of file |
|
| 52 | + * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 53 | + * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 54 | + * @param bool $scalingup Disable/Enable upscaling of previews |
|
| 55 | + * @param \OC\Files\View $fileview fileview object of user folder |
|
| 56 | + * @return bool|\OCP\IImage false if no preview was generated |
|
| 57 | + * @since 8.1.0 |
|
| 58 | + */ |
|
| 59 | + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview); |
|
| 60 | 60 | } |
@@ -29,29 +29,29 @@ |
||
| 29 | 29 | * @since 17.0.0 |
| 30 | 30 | */ |
| 31 | 31 | interface IProviderV2 { |
| 32 | - /** |
|
| 33 | - * @return string Regex with the mimetypes that are supported by this provider |
|
| 34 | - * @since 17.0.0 |
|
| 35 | - */ |
|
| 36 | - public function getMimeType(): string; |
|
| 32 | + /** |
|
| 33 | + * @return string Regex with the mimetypes that are supported by this provider |
|
| 34 | + * @since 17.0.0 |
|
| 35 | + */ |
|
| 36 | + public function getMimeType(): string; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Check if a preview can be generated for $path |
|
| 40 | - * |
|
| 41 | - * @param FileInfo $file |
|
| 42 | - * @return bool |
|
| 43 | - * @since 17.0.0 |
|
| 44 | - */ |
|
| 45 | - public function isAvailable(FileInfo $file): bool; |
|
| 38 | + /** |
|
| 39 | + * Check if a preview can be generated for $path |
|
| 40 | + * |
|
| 41 | + * @param FileInfo $file |
|
| 42 | + * @return bool |
|
| 43 | + * @since 17.0.0 |
|
| 44 | + */ |
|
| 45 | + public function isAvailable(FileInfo $file): bool; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * get thumbnail for file at path $path |
|
| 49 | - * |
|
| 50 | - * @param File $file |
|
| 51 | - * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 52 | - * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 53 | - * @return null|\OCP\IImage null if no preview was generated |
|
| 54 | - * @since 17.0.0 |
|
| 55 | - */ |
|
| 56 | - public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage; |
|
| 47 | + /** |
|
| 48 | + * get thumbnail for file at path $path |
|
| 49 | + * |
|
| 50 | + * @param File $file |
|
| 51 | + * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 52 | + * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 53 | + * @return null|\OCP\IImage null if no preview was generated |
|
| 54 | + * @since 17.0.0 |
|
| 55 | + */ |
|
| 56 | + public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage; |
|
| 57 | 57 | } |