ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
PreProcessorManagerImpl.php
Go to the documentation of this file.
1<?php
2
20
24
38{
42 private array $processors = [];
43
44 public function __construct(PreProcessorCollection $collection)
45 {
46 foreach ($collection->processors() as $processor) {
47 $this->processors[] = $processor;
48 }
49 }
50
54 public function with(PreProcessor $processor): void
55 {
56 $this->processors[] = $processor;
57 }
58
59
63 public function process(FileStream $stream, Metadata $metadata): ProcessingStatus
64 {
65 try {
66 $result = null;
67 foreach ($this->processors as $processor) {
68 $stream->rewind();
69 $result = $processor->process($stream, $metadata);
70 if ($result->getCode() === ProcessingStatus::REJECTED || $result->getCode() === ProcessingStatus::DENIED) {
71 return $result;
72 }
73 }
74
75 if (is_null($result)) {
76 return new ProcessingStatus(ProcessingStatus::OK, 'No processors were registered.');
77 }
78
79 return $result;
80 } catch (\Exception $ex) {
81 return new ProcessingStatus(ProcessingStatus::REJECTED, 'Processor failed with exception message "' . $ex->getMessage() . '"');
82 }
83 }
84}
process(FileStream $stream, Metadata $metadata)
@inheritDoc
Collection of pre-processors contributed by components via the bootstrap $contribute/$seek mechanism.
The base interface for all filesystem streams.
Definition: FileStream.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...