Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Filter / File / Decrypt.php
blob8f8de27d36aad593fb08e56bae864682b3842847
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Filter\File;
12 use Zend\Filter;
13 use Zend\Filter\Exception;
15 /**
16 * Decrypts a given file and stores the decrypted file content
18 class Decrypt extends Filter\Decrypt
20 /**
21 * New filename to set
23 * @var string
25 protected $filename;
27 /**
28 * Returns the new filename where the content will be stored
30 * @return string
32 public function getFilename()
34 return $this->filename;
37 /**
38 * Sets the new filename where the content will be stored
40 * @param string $filename (Optional) New filename to set
41 * @return self
43 public function setFilename($filename = null)
45 $this->filename = $filename;
46 return $this;
49 /**
50 * Defined by Zend\Filter\FilterInterface
52 * Decrypts the file $value with the defined settings
54 * @param string|array $value Full path of file to change or $_FILES data array
55 * @return string|array The filename which has been set
56 * @throws Exception\InvalidArgumentException
57 * @throws Exception\RuntimeException
59 public function filter($value)
61 // An uploaded file? Retrieve the 'tmp_name'
62 $isFileUpload = (is_array($value) && isset($value['tmp_name']));
63 if ($isFileUpload) {
64 $uploadData = $value;
65 $value = $value['tmp_name'];
68 if (!file_exists($value)) {
69 throw new Exception\InvalidArgumentException("File '$value' not found");
72 if (!isset($this->filename)) {
73 $this->filename = $value;
76 if (file_exists($this->filename) and !is_writable($this->filename)) {
77 throw new Exception\RuntimeException("File '{$this->filename}' is not writable");
80 $content = file_get_contents($value);
81 if (!$content) {
82 throw new Exception\RuntimeException("Problem while reading file '$value'");
85 $decrypted = parent::filter($content);
86 $result = file_put_contents($this->filename, $decrypted);
88 if (!$result) {
89 throw new Exception\RuntimeException("Problem while writing file '{$this->filename}'");
92 if ($isFileUpload) {
93 $uploadData['tmp_name'] = $this->filename;
94 return $uploadData;
96 return $this->filename;