public function jsMin($jsText = "") { if ($this->shouldMinify) { $jsText = \JSMin\JSMin::minify($jsText); } return $jsText; }
/** * @dataProvider exceptionProvider */ public function testExpections($input, $label, $expClass, $expMessage) { $eClass = $eMsg = ''; try { JSMin::minify($input); } catch (\Exception $e) { $eClass = get_class($e); $eMsg = $e->getMessage(); } $this->assertTrue($eClass === $expClass && $eMsg === $expMessage, 'JSMin : throw on ' . $label); }
function test_JSMin_exception($js, $label, $expClass, $expMessage) { $eClass = $eMsg = ''; try { JSMin::minify($js); } catch (Exception $e) { $eClass = get_class($e); $eMsg = $e->getMessage(); } $passed = assertTrue($eClass === $expClass && $eMsg === $expMessage, 'JSMin : throw on ' . $label); if (!$passed && isset($e) && __FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) { echo "\n ---", $e, "\n\n"; } }
/** * JS Minifier. * * @static * @method minify_js * @param {String} $data * @return {String} */ public static function minify_js($data) { // Run the minifier $data = \JSMin\JSMin::minify($data); // Replace all new line chars $data = str_replace("\n", ' ', $data); // Force removing first block of comments return self::remove_first_comment_block($data); }
/** * Minifies passed JS source if $this->minify == true * @access public * @param string source * @return string minified source */ protected function minify_js($source) { if ($this->minify == true) { return JSMin::minify($source); } else { return "\n\n/** " . $this->file_path . " **/\n\n;" . $source; } }
<?php require __DIR__ . '/../vendor/autoload.php'; function h($txt) { return htmlspecialchars($txt, ENT_QUOTES, 'UTF-8'); } $tpl = array(); if (isset($_POST['textIn'])) { $textIn = str_replace("\r\n", "\n", $_POST['textIn']); $tpl['inBytes'] = strlen($textIn); $startTime = microtime(true); try { $tpl['output'] = \JSMin\JSMin::minify($textIn); } catch (Exception $e) { $tpl['exceptionMsg'] = getExceptionMsg($e, $textIn); $tpl['output'] = $textIn; sendPage($tpl); } $tpl['time'] = microtime(true) - $startTime; $tpl['outBytes'] = strlen($tpl['output']); } sendPage($tpl); /** * @param Exception $e * @param string $input * @return string HTML */ function getExceptionMsg(Exception $e, $input) { $msg = "<p>" . h($e->getMessage()) . "</p>";
public static function compile($string) { return \JSMin\JSMin::minify($string); }
public function filterDump(AssetInterface $asset) { $asset->setContent(JSMin::minify($asset->getContent())); }