FileDocument.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
12 
15 
16 /**
17  * FileDocument represents a local file.
18  *
19  * @author ingo herwig <ingo@wemove.com>
20  */
22 
23  private $content = null;
24 
25  /**
26  * Constructor
27  * @param $file
28  * @param $isDownload
29  */
30  public function __construct($filename, $isDownload) {
31  if (!file_exists($filename)) {
32  throw new IOException("The file '$filename' does not exist.");
33  }
34  $mimeType = FileUtil::getMimeType($filename);
35  $this->content = file_get_contents($filename);
36  parent::__construct($mimeType, $isDownload, $filename);
37  }
38 
39  /**
40  * @see ResponseDocument::getCacheDate()
41  */
42  public function getCacheDate() {
43  return \DateTime::createFromFormat('U', filemtime($this->getFilename()));
44  }
45 
46  /**
47  * @see ResponseDocument::getContent()
48  */
49  public function getContent() {
50  return $this->content;
51  }
52 
53  /**
54  * @see ResponseDocument::output()
55  */
56  public function output() {
57  echo $this->content;
58  }
59 }
60 ?>
FileDocument represents a local file.
AbstractFormat is used as base class for specialized documents.
FileUtil provides basic support for file functionality like HTTP file upload.
Definition: FileUtil.php:22
IOException signals an exception in i/o operations.
Definition: IOException.php:18
__construct($filename, $isDownload)
Constructor.
static getMimeType($file)
Get the mime type of the given file.
Definition: FileUtil.php:66