Source of file Decrypt.php
Size: 2,899 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Filter/File/Decrypt.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Filter\File; use Zend\Filter; use Zend\Filter\Exception; /** * Decrypts a given file and stores the decrypted file content */ class Decrypt extends Filter\Decrypt { /** * New filename to set * * @var string */ protected $filename; /** * Returns the new filename where the content will be stored * * @return string */ public function getFilename() { return $this->filename; } /** * Sets the new filename where the content will be stored * * @param string $filename (Optional) New filename to set * @return self */ public function setFilename($filename = null) { $this->filename = $filename; return $this; } /** * Defined by Zend\Filter\FilterInterface * * Decrypts the file $value with the defined settings * * @param string|array $value Full path of file to change or $_FILES data array * @return string|array The filename which has been set * @throws Exception\InvalidArgumentException * @throws Exception\RuntimeException */ public function filter($value) { if (!is_scalar($value) && !is_array($value)) { return $value; } // An uploaded file? Retrieve the 'tmp_name' $isFileUpload = false; if (is_array($value)) { if (!isset($value['tmp_name'])) { return $value; } $isFileUpload = true; $uploadData = $value; $value = $value['tmp_name']; } if (!file_exists($value)) { throw new Exception\InvalidArgumentException("File '$value' not found"); } if (!isset($this->filename)) { $this->filename = $value; } if (file_exists($this->filename) and !is_writable($this->filename)) { throw new Exception\RuntimeException("File '{$this->filename}' is not writable"); } $content = file_get_contents($value); if (!$content) { throw new Exception\RuntimeException("Problem while reading file '$value'"); } $decrypted = parent::filter($content); $result = file_put_contents($this->filename, $decrypted); if (!$result) { throw new Exception\RuntimeException("Problem while writing file '{$this->filename}'"); } if ($isFileUpload) { $uploadData['tmp_name'] = $this->filename; return $uploadData; } return $this->filename; } } |