Example #1
0
 /**
  * Defined by Zend\Filter\Filter
  *
  * 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;
 }
Example #2
0
    /**
     * Defined by Zend\Filter\Filter
     *
     * 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 Exception\InvalidArgumentException("File '$value' not found");
        }

        if (!is_writable($value)) {
            throw new Exception\RuntimeException("File '$value' is not writable");
        }

        $content = file_get_contents($value);
        if (!$content) {
            throw new Exception\RuntimeException("Problem while reading file '$value'");
        }

        $content = parent::__invoke($content);
        $result  = file_put_contents($value, $content);

        if (!$result) {
            throw new Exception\RuntimeException("Problem while writing file '$value'");
        }

        return $value;
    }