From ba6ec9c1afa2cbbe00ae00b68d2854f73c5c3884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 9 Nov 2013 00:42:21 +0200 Subject: [PATCH] allow possibility to configure closure-compiler url --- min/lib/Minify/JS/ClosureCompiler.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/min/lib/Minify/JS/ClosureCompiler.php b/min/lib/Minify/JS/ClosureCompiler.php index 51f7cd1..d4358a0 100644 --- a/min/lib/Minify/JS/ClosureCompiler.php +++ b/min/lib/Minify/JS/ClosureCompiler.php @@ -14,7 +14,10 @@ * @todo can use a stream wrapper to unit test this? */ class Minify_JS_ClosureCompiler { - const URL = 'http://closure-compiler.appspot.com/compile'; + /** + * @var $url URL to compiler server. defaults to google server + */ + protected $url = 'http://closure-compiler.appspot.com/compile'; /** * Minify Javascript code via HTTP request to the Closure Compiler API @@ -34,12 +37,17 @@ class Minify_JS_ClosureCompiler { * @param array $options * * fallbackFunc : default array($this, 'fallback'); + * compilerUrl : URL to closure compiler server */ public function __construct(array $options = array()) { $this->_fallbackFunc = isset($options['fallbackMinifier']) ? $options['fallbackMinifier'] : array($this, '_fallback'); + + if (isset($options['compilerUrl'])) { + $this->url = $options['compilerUrl']; + } } public function min($js) @@ -76,7 +84,7 @@ class Minify_JS_ClosureCompiler { { $allowUrlFopen = preg_match('/1|yes|on|true/i', ini_get('allow_url_fopen')); if ($allowUrlFopen) { - $contents = file_get_contents(self::URL, false, stream_context_create(array( + $contents = file_get_contents($this->url, false, stream_context_create(array( 'http' => array( 'method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded\r\nConnection: close\r\n", @@ -86,7 +94,7 @@ class Minify_JS_ClosureCompiler { ) ))); } elseif (defined('CURLOPT_POST')) { - $ch = curl_init(self::URL); + $ch = curl_init($this->url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded'));