Skip to content

Commit

Permalink
feat: require FilterDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
thorbrink committed Mar 4, 2025
1 parent b266725 commit 865e9b2
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 262 deletions.
239 changes: 1 addition & 238 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions library/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,7 @@ private function setupExternalContent(): void
* Sync external content.
*/
$this->wpService->addAction('Municipio/ExternalContent/Sync', function (string $postType, ?int $postId = null) use ($sourceConfigs) {

$sourceConfig = reset(array_filter($sourceConfigs, fn($config) => $config->getPostType() === $postType));
$sourceReader = (new \Municipio\ExternalContent\SourceReaders\Factories\SourceReaderFromConfig())->create($sourceConfig);
$schemaObjectToPost = (new \Municipio\ExternalContent\WpPostArgsFromSchemaObject\Factory\Factory($sourceConfig))->create();
Expand Down
33 changes: 22 additions & 11 deletions library/ExternalContent/Config/SourceConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Municipio\ExternalContent\Config;

use Municipio\ExternalContent\PropertyPathFilter\FilterDefinition\Contracts\FilterDefinition;

/**
* Class SourceConfig
*
Expand All @@ -25,17 +27,18 @@ class SourceConfig implements SourceConfigInterface
* @param string $sourceTypesenseCollection
*/
public function __construct(
private string $postType = '',
private string $automaticImportSchedule = '',
private string $schemaType = '',
private string $sourceType = '',
private array $taxonomies = [],
private string $sourceJsonFilePath = '',
private string $sourceTypesenseApiKey = '',
private string $sourceTypesenseProtocol = '',
private string $sourceTypesenseHost = '',
private string $sourceTypesensePort = '',
private string $sourceTypesenseCollection = ''
private string $postType,
private string $automaticImportSchedule,
private string $schemaType,
private string $sourceType,
private array $taxonomies,
private string $sourceJsonFilePath,
private string $sourceTypesenseApiKey,
private string $sourceTypesenseProtocol,
private string $sourceTypesenseHost,
private string $sourceTypesensePort,
private string $sourceTypesenseCollection,
private FilterDefinition $filterDefinition
) {
}

Expand Down Expand Up @@ -134,4 +137,12 @@ public function getId(): string
{
return $this->postType;
}

/**
* @inheritDoc
*/
public function getFilterDefinition(): FilterDefinition
{
return $this->filterDefinition;
}
}
4 changes: 3 additions & 1 deletion library/ExternalContent/Config/SourceConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Municipio\ExternalContent\Config;

use Municipio\Config\Features\SchemaData\SchemaDataConfigInterface;
use Municipio\ExternalContent\PropertyPathFilter\FilterDefinition\FilterDefinition;
use WpService\Contracts\GetOption;
use WpService\Contracts\GetOptions;

Expand Down Expand Up @@ -77,7 +78,8 @@ private function createSourceConfigsFromNamedSettings(array $namedSettings): Sou
$namedSettings['source_typesense_protocol'] ?? '',
$namedSettings['source_typesense_host'] ?? '',
$namedSettings['source_typesense_port'] ?? '',
$namedSettings['source_typesense_collection'] ?? ''
$namedSettings['source_typesense_collection'] ?? '',
new FilterDefinition([])
);
}

Expand Down
9 changes: 9 additions & 0 deletions library/ExternalContent/Config/SourceConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Municipio\ExternalContent\Config;

use Municipio\ExternalContent\PropertyPathFilter\FilterDefinition\Contracts\FilterDefinition;

interface SourceConfigInterface
{
/**
Expand Down Expand Up @@ -85,4 +87,11 @@ public function getSourceTypesenseCollection(): string;
* Get the source unique ID
*/
public function getId(): string;

/**
* Retrieves the filter definition.
*
* @return FilterDefinition The filter definition.
*/
public function getFilterDefinition(): FilterDefinition;
}
10 changes: 10 additions & 0 deletions library/ExternalContent/Config/SourceConfigWithUniqueId.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Municipio\ExternalContent\Config;

use Municipio\ExternalContent\PropertyPathFilter\FilterDefinition\Contracts\FilterDefinition;

/**
* Class SourceConfig
*
Expand Down Expand Up @@ -103,6 +105,14 @@ public function getSourceTypesenseCollection(): string
return $this->inner->getSourceTypesenseCollection();
}

/**
* @inheritDoc
*/
public function getFilterDefinition(): FilterDefinition
{
return $this->inner->getFilterDefinition();
}

/**
* @inheritDoc
*/
Expand Down
Loading

0 comments on commit 865e9b2

Please sign in to comment.