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
10 namespace Zend\Filter\File
;
13 use Zend\Filter\Exception
;
16 * Decrypts a given file and stores the decrypted file content
18 class Decrypt
extends Filter\Decrypt
28 * Returns the new filename where the content will be stored
32 public function getFilename()
34 return $this->filename
;
38 * Sets the new filename where the content will be stored
40 * @param string $filename (Optional) New filename to set
43 public function setFilename($filename = null)
45 $this->filename
= $filename;
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']));
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);
82 throw new Exception\
RuntimeException("Problem while reading file '$value'");
85 $decrypted = parent
::filter($content);
86 $result = file_put_contents($this->filename
, $decrypted);
89 throw new Exception\
RuntimeException("Problem while writing file '{$this->filename}'");
93 $uploadData['tmp_name'] = $this->filename
;
96 return $this->filename
;