Пример #1
0
 /**
  * Defined by Zend\Filter\FilterInterface
  *
  * Does a lowercase on the content of the given file
  *
  * @param  string|array $value Full path of file to change or $_FILES data array
  * @return string|array The given $value
  * @throws Exception\RuntimeException
  * @throws Exception\InvalidArgumentException
  */
 public function filter($value)
 {
     // An uploaded file? Retrieve the 'tmp_name'
     $isFileUpload = is_array($value) && isset($value['tmp_name']);
     if ($isFileUpload) {
         $uploadData = $value;
         $value = $value['tmp_name'];
     }
     if (!file_exists($value)) {
         throw new Exception\InvalidArgumentException("File '{$value}' not found");
     }
     if (!is_writable($value)) {
         throw new Exception\InvalidArgumentException("File '{$value}' is not writable");
     }
     $content = file_get_contents($value);
     if (!$content) {
         throw new Exception\RuntimeException("Problem while reading file '{$value}'");
     }
     $content = parent::filter($content);
     $result = file_put_contents($value, $content);
     if (!$result) {
         throw new Exception\RuntimeException("Problem while writing file '{$value}'");
     }
     if ($isFileUpload) {
         return $uploadData;
     }
     return $value;
 }
Пример #2
0
 /**
  * Defined by Zend\Filter\FilterInterface
  *
  * Does a lowercase on the content of the given file
  *
  * @param  string $value Full path of file to change
  * @return string The given $value
  * @throws Exception\RuntimeException
  * @throws Exception\InvalidArgumentException
  */
 public function filter($value)
 {
     if (!file_exists($value)) {
         throw new Exception\InvalidArgumentException("File '{$value}' not found");
     }
     if (!is_writable($value)) {
         throw new Exception\InvalidArgumentException("File '{$value}' is not writable");
     }
     $content = file_get_contents($value);
     if (!$content) {
         throw new Exception\RuntimeException("Problem while reading file '{$value}'");
     }
     $content = parent::filter($content);
     $result = file_put_contents($value, $content);
     if (!$result) {
         throw new Exception\RuntimeException("Problem while writing file '{$value}'");
     }
     return $value;
 }
Пример #3
0
 /**
  * Defined by Zend_Filter_Interface
  *
  * Does a lowercase on the content of the given file
  *
  * @param  string $value Full path of file to change
  * @return string The given $value
  * @throws \Zend\Filter\Exception
  */
 public function __invoke($value)
 {
     if (!file_exists($value)) {
         throw new Filter\Exception("File '{$value}' not found");
     }
     if (!is_writable($value)) {
         throw new Filter\Exception("File '{$value}' is not writable");
     }
     $content = file_get_contents($value);
     if (!$content) {
         throw new Filter\Exception("Problem while reading file '{$value}'");
     }
     $content = parent::__invoke($content);
     $result = file_put_contents($value, $content);
     if (!$result) {
         throw new Filter\Exception("Problem while writing file '{$value}'");
     }
     return $value;
 }
Пример #4
0
 /**
  * @dataProvider returnUnfilteredDataProvider
  * @return void
  */
 public function testReturnUnfiltered($input)
 {
     $this->assertEquals($input, $this->_filter->filter($input));
 }