Skip to content

Instantly share code, notes, and snippets.

@bwaidelich
Created November 15, 2023 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwaidelich/68aafae0dd882c91ccc06db8f732e0f2 to your computer and use it in GitHub Desktop.
Save bwaidelich/68aafae0dd882c91ccc06db8f732e0f2 to your computer and use it in GitHub Desktop.
Creating a service for the Neos 9.0 Content Repository
<?php
declare(strict_types=1);
final class CatchUpWorkerCommandController extends CommandController {
public function __construct(
private readonly ContentRepositoryRegistry $contentRepositoryRegistry,
private readonly ProjectionCatchUpServiceFactory $projectionCatchUpServiceFactory,
) {
parent::__construct();
}
/**
* @param string $contentRepository ID of the content repository to catch up projections for
**/
public function catchUpAllCommand(string $contentRepository): void {
$catchUpService = $this->contentRepositoryRegistry->buildService(
ContentRepositoryId::fromString($contentRepository),
$this->projectionCatchUpServiceFactory,
);
$catchUpService->catchUpAll(CatchUpOptions::create());
}
}
<?php
declare(strict_types=1);
final class ProjectionCatchUpService implements ContentRepositoryServiceInterface
{
public function __construct(
private readonly Projections $projections,
private readonly ContentRepository $contentRepository,
) {
}
public function catchUpAllProjections(CatchUpOptions $options): void
{
$this->contentRepository->catchUpProjection($classNamesAndAlias['className'], $options);
}
}
<?php
declare(strict_types=1);
#[Flow\Scope("singleton")]
final class ProjectionCatchUpServiceFactory implements ContentRepositoryServiceFactoryInterface {
public function build(ContentRepositoryServiceFactoryDependencies $serviceFactoryDependencies): ContentRepositoryServiceInterface
{
return new ProjectionCatchUpService($serviceFactoryDependencies->projections, $serviceFactoryDependencies->contentRepository);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment