public function uglify(array $files, $outputFilename, array $options = [], $finalJsHeaderFilename=null) {
        foreach($files as $filename) {
            if(!is_readable($filename)) {
                throw new UglifyJSException("Filename " . $filename . " is not readable");
            }
        }
        $optionsString = $this->validateOptions($options);
        $fileNames = implode(' ', array_map('escapeshellarg', $files));

        $tmpUglifyJsOutput = tempnam(sys_get_temp_dir(), "uglify_js_intermediate_out_");
        $safeShellTmpUglifyJsFilename = escapeshellarg($tmpUglifyJsOutput);

        $commandString = $this->uglifyBinaryPath . " {$fileNames} --output {$safeShellTmpUglifyJsFilename} {$optionsString}";

        exec($commandString, $output, $returnCode);
        if($returnCode !== 0) {
            throw new UglifyJSException("Failed to run uglifyjs, something went wrong... command: " . $commandString);
        }

        if($finalJsHeaderFilename) {
            //If we have provided a header filename then we are going to get the uglified file then prepend the data
            $context = stream_context_create();
            //Open both files in stream mode so we dont load the entire file into memory, streams are the best!
            $uglifyJsOutputFileHandler = fopen($tmpUglifyJsOutput, 'r', false, $context);
            $jsHeaderFileHandler = fopen($finalJsHeaderFilename, 'r',false, $context);

            $tmpFinalOutput = tempnam(sys_get_temp_dir(), 'php_uglify_js_out_');
            file_put_contents($tmpFinalOutput, $jsHeaderFileHandler);
            file_put_contents($tmpFinalOutput, $uglifyJsOutputFileHandler, FILE_APPEND);

            //Close unlink and move the files we dont need
            fclose($uglifyJsOutputFileHandler);
            fclose($jsHeaderFileHandler);
            unlink($tmpUglifyJsOutput);
            rename($tmpFinalOutput, $outputFilename);
        }else{
            //Dont try and add any files, just move the temporary file into the final location
            rename($tmpUglifyJsOutput, $outputFilename);
        }

        return $output;
    }