| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace Michel\PQueue\Michel\Package;
- use Michel\Package\PackageInterface;
- use Michel\PQueue\Command\PQueueWorkerRunCommand;
- use Michel\PQueue\HandlerResolver\ContainerHandlerResolver;
- use Michel\PQueue\PQueueConsumer;
- use Michel\PQueue\PQueueConsumerFactory;
- use Michel\PQueue\PQueueHandlerFinder;
- use Michel\PQueue\Transport\FilesystemTransport;
- use Michel\PQueue\Transport\TransportInterface;
- use Psr\Container\ContainerInterface;
- class MichelPQueuePackage implements PackageInterface
- {
- public function getDefinitions(): array
- {
- return [
- TransportInterface::class => static function (ContainerInterface $container) {
- $class = $container->get('pqueue.transport.class');
- if (!is_subclass_of($class, TransportInterface::class)) {
- throw new \InvalidArgumentException("Invalid transport class provided");
- }
- $options = $container->get('pqueue.transport.options');
- return $class::create($options);
- },
- PQueueHandlerFinder::class => static function (ContainerInterface $container) {
- $sources = $container->has('pqueue.handlers.sources') ? $container->get('pqueue.handlers.sources') : [];
- $classes = $container->has('pqueue.handlers.classes') ? $container->get('pqueue.handlers.classes') : [];
- return new PQueueHandlerFinder(
- array_merge($classes, $sources),
- $container->get('michel.environment') === 'dev' ? null : $container->get('pqueue.handlers.cache_dir')
- );
- },
- PQueueConsumerFactory::class => static function (ContainerInterface $container) {
- /**
- * @var PQueueHandlerFinder $finder
- */
- $finder = $container->get(PQueueHandlerFinder::class);
- return new PQueueConsumerFactory(new ContainerHandlerResolver($container),$finder->find());
- },
- PQueueConsumer::class => static function (ContainerInterface $container) {
- /**
- * @var PQueueConsumerFactory $factory
- */
- $factory = $container->get(PQueueConsumerFactory::class);
- return $factory->createConsumer();
- }
- ];
- }
- public function getParameters(): array
- {
- return [
- 'pqueue.transport.class' => FilesystemTransport::class,
- 'pqueue.transport.options' => function (ContainerInterface $container) {
- return [
- 'directory' => $container->get('michel.project_dir').DIRECTORY_SEPARATOR.'var/pqueue'
- ];
- },
- 'pqueue.handlers.sources' => function (ContainerInterface $container) {
- return [
- $container->get('michel.project_dir').DIRECTORY_SEPARATOR.'src/MessageHandler'
- ];
- },
- 'pqueue.handlers.classes' => [],
- 'pqueue.handlers.cache_dir' => function (ContainerInterface $container) {
- return $container->get('michel.cache_dir');
- },
- ];
- }
- public function getRoutes(): array
- {
- return [];
- }
- public function getControllerSources(): array
- {
- return [];
- }
- public function getListeners(): array
- {
- return [];
- }
- public function getCommandSources(): array
- {
- return [
- PQueueWorkerRunCommand::class
- ];
- }
- }
|