ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ContainerManager.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 
32 final class ContainerManager extends BaseManager
33 {
34  protected function normalizePath(string $path_inside_container): string
35  {
36  $path_inside_container = '/' . ltrim($path_inside_container, './');
37  $path_inside_container = rtrim($path_inside_container, '/');
38 
39  return $path_inside_container;
40  }
41 
42  public function containerFromUpload(
43  UploadResult $result,
44  ResourceStakeholder $stakeholder,
45  ?string $revision_title = null
47  // check if stream is a ZIP
48  $this->checkZIP(mime_content_type($result->getMimeType()));
49 
50  return $this->upload($result, $stakeholder, $revision_title);
51  }
52 
53  public function containerFromStream(
54  FileStream $stream,
55  ResourceStakeholder $stakeholder,
56  ?string $revision_title = null
58  // check if stream is a ZIP
59  $this->checkZIP(mime_content_type($stream->getMetadata()['uri']));
60 
61  return $this->newStreamBased(
62  $stream,
63  $stakeholder,
65  $revision_title
66  );
67  }
68 
71  string $path_inside_container
72  ): bool {
73  $path_inside_container = $this->normalizePath($path_inside_container);
74  if (empty($path_inside_container)) {
75  return false;
76  }
77  return $this->resource_builder->createDirectoryInsideContainer(
78  $this->getResource($container),
79  $path_inside_container
80  );
81  }
82 
83  public function removePathInsideContainer(
85  string $path_inside_container
86  ): bool {
87  if (empty($path_inside_container)) {
88  return false;
89  }
90  return $this->resource_builder->removePathInsideContainer(
91  $this->getResource($container),
92  $path_inside_container
93  );
94  }
95 
96  public function addUploadToContainer(
98  UploadResult $result,
99  string $parent_path_inside_container,
100  ): bool {
101  $parent_path_inside_container = $this->normalizePath($parent_path_inside_container);
102  if (empty($parent_path_inside_container)) {
103  $parent_path_inside_container = '/';
104  }
105  return $this->resource_builder->addUploadToContainer(
106  $this->getResource($container),
107  $result,
108  $parent_path_inside_container
109  );
110  }
111 
112  public function addStreamToContainer(
114  FileStream $stream,
115  string $path_inside_container,
116  ): bool {
117  $path_inside_container = $this->normalizePath($path_inside_container);
118  if (empty($path_inside_container)) {
119  return false;
120  }
121  return $this->resource_builder->addStreamToContainer(
122  $this->getResource($container),
123  $stream,
124  $path_inside_container
125  );
126  }
127 
128 }
containerFromStream(FileStream $stream, ResourceStakeholder $stakeholder, ?string $revision_title=null)
addStreamToContainer(ResourceIdentification $container, FileStream $stream, string $path_inside_container,)
addUploadToContainer(ResourceIdentification $container, UploadResult $result, string $parent_path_inside_container,)
removePathInsideContainer(ResourceIdentification $container, string $path_inside_container)
normalizePath(string $path_inside_container)
$container
Definition: wac.php:36
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getResource(ResourceIdentification $i)
containerFromUpload(UploadResult $result, ResourceStakeholder $stakeholder, ?string $revision_title=null)
upload(UploadResult $result, ResourceStakeholder $stakeholder, ?string $revision_title=null)
Creates a new resource from an upload, the status in this case is always PUBLISHED.
Definition: Manager.php:38
The base interface for all filesystem streams.
Definition: FileStream.php:31
newStreamBased(FileStream $stream, ResourceStakeholder $stakeholder, ResourceType $type, ?string $revision_title=null)
Definition: BaseManager.php:79
createDirectoryInsideContainer(ResourceIdentification $container, string $path_inside_container)