示例#1
0
文件: Encrypt.php 项目: stunti/zf2
 /**
  * Defined by Zend\Filter\Filter
  *
  * Encrypts the file $value with the defined settings
  *
  * @param  string $value Full path of file to change
  * @return string The filename which has been set, or false when there were errors
  */
 public function _invoke($value)
 {
     if (!file_exists($value)) {
         throw new Filter\Exception("File '{$value}' not found");
     }
     if (!isset($this->_filename)) {
         $this->_filename = $value;
     }
     if (file_exists($this->_filename) and !is_writable($this->_filename)) {
         throw new Filter\Exception("File '{$this->_filename}' is not writable");
     }
     $content = file_get_contents($value);
     if (!$content) {
         throw new Filter\Exception("Problem while reading file '{$value}'");
     }
     $encrypted = parent::__invoke($content);
     $result = file_put_contents($this->_filename, $encrypted);
     if (!$result) {
         throw new Filter\Exception("Problem while writing file '{$this->_filename}'");
     }
     return $this->_filename;
 }