ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
ZipStructureMachine.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
30 
36 {
37  public function __construct()
38  {
39  }
40 
41  public function getId(): string
42  {
43  return 'zip_structure_reader';
44  }
45 
46  public function canHandleDefinition(FlavourDefinition $definition): bool
47  {
48  return $definition instanceof ZipStructureDefinition;
49  }
50 
51  public function dependsOnEngine(): ?string
52  {
53  return NoEngine::class;
54  }
55 
56  public function withEngine(Engine $engine): FlavourMachine
57  {
58  return $this;
59  }
60 
61  public function getEngine(): Engine
62  {
63  return new NoEngine();
64  }
65 
66  public function processStream(
67  FileInformation $information,
68  FileStream $stream,
69  FlavourDefinition $for_definition
70  ): \Generator {
71  if (!$for_definition instanceof ZipStructureDefinition) {
72  throw new \InvalidArgumentException('Invalid definition');
73  }
74  $reader = new ZipReader($stream);
75 
76  $data = $reader->getStructure();
77 
78  yield new Result(
79  $for_definition,
80  Streams::ofString($for_definition->sleep($data)),
81  0,
82  $for_definition->persist()
83  );
84  }
85 
86 }
persist()
Define whether the generated flavor and the respective streams should be persisted, or whether they should only be generated and used in-memory.
withEngine(Engine $engine)
The demanded Engine will be passed here.
processStream(FileInformation $information, FileStream $stream, FlavourDefinition $for_definition)
canHandleDefinition(FlavourDefinition $definition)
Check if a corresponding configuration can be processed by this Machine.
__construct()
FlavourMachines must be able to be created without further dependencies.
dependsOnEngine()
Return the class name of the Engine that is required for this Machine to work.
The base interface for all filesystem streams.
Definition: FileStream.php:31