本文整理汇总了PHP中Minify::serve方法的典型用法代码示例。如果您正苦于以下问题:PHP Minify::serve方法的具体用法?PHP Minify::serve怎么用?PHP Minify::serve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Minify
的用法示例。
在下文中一共展示了Minify::serve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionIndex
public function actionIndex()
{
$incPath = get_include_path();
$docRoot = $_SERVER['DOCUMENT_ROOT'];
$_SERVER['DOCUMENT_ROOT'] = dirname(Yii::app()->request->getScriptFile());
set_include_path(Yii::app()->getExtensionPath()."/minify" . PATH_SEPARATOR . $incPath);
require 'Minify.php';
$option['debug'] = $this->_debug;
$option['maxAge'] = $this->_maxAge;
$option['bubbleCssImports'] = $this->_bubbleCssImports;
$option['encodeOutput'] = $this->_encodeOutput;
$option['encodeMethod'] = $this->_encodeMethod;
foreach ($this->_symlinks as $link => $target) {
$link = str_replace('//', realpath($_SERVER['DOCUMENT_ROOT'])."/", $link);
$link = strtr($link, '/', DIRECTORY_SEPARATOR);
$option['minifierOptions']['text/css']['symlinks'][$link] = realpath($target);
}
Minify::setCache(Yii::app()->getRuntimePath(), $this->_cacheFileLocking);
if ($this->_errorLogger) {
require_once 'Minify/Logger.php';
require_once 'FirePHP.php';
Minify_Logger::setLogger(FirePHP::getInstance(true));
}
$mgv = Yii::app()->getRuntimePath()."/minifyGroups.var";
$minifyGroups = unserialize(file_get_contents($mgv));
$option['files'] = $minifyGroups[$_GET['group']];
Minify::serve('Files', $option);
set_include_path($incPath);
$_SERVER['DOCUMENT_ROOT'] = $docRoot;
}
示例2: action_minify
public function action_minify()
{
// load config
$config = Kohana::config('minify');
//require MINIFY_MIN_DIR.'/Minify.php';
Minify::$uploaderHoursBehind = $config['uploaderHoursBehind'];
Minify::setCache(isset($config['cachePath']) ? $config['cachePath'] : '', $config['cacheFileLocking']);
if ($config['documentRoot']) {
$_SERVER['DOCUMENT_ROOT'] = $config['documentRoot'];
} elseif (0 === stripos(PHP_OS, 'win')) {
Minify::setDocRoot();
// IIS may need help
}
$config['serveOptions']['minifierOptions']['text/css']['symlinks'] = $config['symlinks'];
// auto-add targets to allowDirs
foreach ($config['symlinks'] as $uri => $target) {
$config['serveOptions']['minApp']['allowDirs'][] = $target;
}
if ($config['allowDebugFlag']) {
if (!empty($_COOKIE['minDebug'])) {
foreach (preg_split('/\\s+/', $_COOKIE['minDebug']) as $debugUri) {
if (false !== strpos($_SERVER['REQUEST_URI'], $debugUri)) {
$config['serveOptions']['debug'] = true;
break;
}
}
}
// allow GET to override
if (isset($_GET['debug'])) {
$config['serveOptions']['debug'] = true;
}
}
if ($config['errorLogger']) {
//require _once MINIFY_MIN_DIR . '/Minify/Logger.php';
if (true === $config['errorLogger']) {
//require _once MINIFY_MIN_DIR . '/FirePHP.php';
Minify_Logger::setLogger(FirePHP::getInstance(true));
} else {
Minify_Logger::setLogger($config['errorLogger']);
}
}
// check for URI versioning
if (preg_match('/&\\d/', $_SERVER['QUERY_STRING'])) {
$config['serveOptions']['maxAge'] = 31536000;
}
if (isset($_GET['g'])) {
// well need groups config
$config['serveOptions']['minApp']['groups'] = $config['groupsConfig'];
}
if (isset($_GET['f']) || isset($_GET['g'])) {
// serve!
Minify::serve('MinApp', $config['serveOptions']);
exit;
}
}
示例3: serve_css
public function serve_css($files)
{
$opt = array('files' => $this->get_css_files($files), 'contentTypeCharset' => $this->charset);
/*
* Bazı sunucularda fpassthru engelli olduğundan problem çıkarabiliyor.
* Bu durumda fonksiyonun kullanıldığı filelocking seçeneğini FALSE gönderiyoruz.
* Bu işlemi de function_exists(fpassthru) ile otomatik yapıyoruz.
*/
Minify::setCache($this->cache_path, function_exists('fpassthru'));
Minify::serve('Files', $opt);
}
示例4: process
/**
* Runs minify
*/
function process()
{
require_once W3TC_LIB_MINIFY_DIR . '/Minify.php';
require_once W3TC_LIB_MINIFY_DIR . '/HTTP/Encoder.php';
HTTP_Encoder::$encodeToIe6 = $this->_config->get_boolean('minify.comprss.ie6');
Minify::$uploaderHoursBehind = $this->_config->get_integer('minify.fixtime');
Minify::setCache($this->_get_cache());
$serve_options = $this->_config->get_array('minify.options');
$serve_options['maxAge'] = $this->_config->get_integer('minify.maxage');
$serve_options['encodeOutput'] = $this->_config->get_boolean('minify.compress');
$serve_options['postprocessor'] = array(&$this, 'postprocessor');
if (stripos(PHP_OS, 'win') === 0) {
Minify::setDocRoot();
}
foreach ($this->_config->get_array('minify.symlinks') as $link => $target) {
$link = str_replace('//', realpath($_SERVER['DOCUMENT_ROOT']), $link);
$link = strtr($link, '/', DIRECTORY_SEPARATOR);
$serve_options['minifierOptions']['text/css']['symlinks'][$link] = realpath($target);
}
if ($this->_config->get_boolean('minify.debug')) {
$serve_options['debug'] = true;
}
if ($this->_config->get('minify.debug')) {
require_once W3TC_LIB_MINIFY_DIR . '/Minify/Logger.php';
Minify_Logger::setLogger($this);
}
if (isset($_GET['f']) || isset($_GET['gg']) && isset($_GET['g']) && isset($_GET['t'])) {
if (isset($_GET['gg']) && isset($_GET['g']) && isset($_GET['t'])) {
$serve_options['minApp']['groups'] = $this->get_groups($_GET['gg'], $_GET['t']);
if ($_GET['t'] == 'js' && (in_array($_GET['g'], array('include', 'include-nb')) && $this->_config->get_boolean('minify.js.combine.header') || in_array($_GET['g'], array('include-footer', 'include-footer-nb')) && $this->_config->get_boolean('minify.js.combine.footer'))) {
$serve_options['minifiers']['application/x-javascript'] = array($this, 'minify_stub');
}
/**
* Setup user-friendly cache ID for disk cache
*/
if ($this->_config->get_string('minify.engine') == 'file') {
$cacheId = sprintf('%s.%s.%s', $_GET['gg'], $_GET['g'], $_GET['t']);
Minify::setCacheId($cacheId);
}
}
@header('Pragma: public');
try {
Minify::serve('MinApp', $serve_options);
} catch (Exception $exception) {
printf('<strong>W3 Total Cache Error:</strong> Minify error: %s', $exception->getMessage());
}
} else {
die('This file cannot be accessed directly');
}
}
示例5: get
public function get()
{
$_assetsList = array();
for ($i = 0; $i < count($this->assetsList); $i++) {
if (file_exists(PUBLIC_PATH . 'css/' . $this->assetsList[$i])) {
$_assetsList[] = '//css/' . $this->assetsList[$i];
}
}
unset($this->assetsList);
if (count($_assetsList) > 0) {
$options = array('files' => $_assetsList, 'maxAge' => \Application::$config['assets']['maxAge'], 'debug' => \Application::$config['assets']['debug']);
\Minify::serve('Files', $options);
unset($options);
}
}
示例6: test_Lines
function test_Lines()
{
global $thisDir;
$exp = file_get_contents("{$thisDir}/_test_files/minify/lines_output.js");
Minify::setCache(null);
// no cache
$ret = Minify::serve('Files', array('debug' => true, 'quiet' => true, 'encodeOutput' => false, 'files' => array("{$thisDir}/_test_files/minify/email.js", "{$thisDir}/_test_files/minify/lines_bugs.js", "{$thisDir}/_test_files/minify/QueryString.js", "{$thisDir}/_test_files/js/before.js")));
$passed = assertTrue($exp === $ret['content'], 'Minify_Lines');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
echo "\n---Output: " . countBytes($ret['content']) . " bytes\n\n{$ret['content']}\n\n";
if (!$passed) {
echo "---Expected: " . countBytes($exp) . " bytes\n\n{$exp}\n\n\n";
}
}
}
示例7: serve
public function serve()
{
// Adapted from index.php and config.php in the Minify distribution
$min_serveOptions = array();
$min_uploaderHoursBehind = isset($this->_config['min_uploaderHoursBehind']) ? $this->_config['min_uploaderHoursBehind'] : 0;
Minify::$uploaderHoursBehind = $min_uploaderHoursBehind;
$min_cacheFileLocking = isset($this->_config['min_cacheFileLocking']) ? $this->_config['min_cacheFileLocking'] : true;
$min_cachePath = $this->_config['cache_dir'];
Minify::setCache($min_cachePath, $min_cacheFileLocking);
$min_symlinks = isset($this->_config['min_symlinks']) ? $this->_config['min_symlinks'] : array();
foreach ($min_symlinks as $link => $target) {
$link = str_replace('//', realpath($_SERVER['DOCUMENT_ROOT']), $link);
$link = strtr($link, '/', DIRECTORY_SEPARATOR);
$min_serveOptions['minifierOptions']['text/css']['symlinks'][$link] = realpath($target);
}
$min_serveOptions['minifierOptions']['text/css']['symlinks'] = $min_symlinks;
if (isset($this->_config['debug_minify_logger'])) {
require_once 'Minify/Logger.php';
if (true === $this->_config['debug_minify_logger']) {
require_once 'FirePHP.php';
Minify_Logger::setLogger(FirePHP::getInstance(true));
} else {
Minify_Logger::setLogger($this->_config['debug_minify_logger']);
}
}
// check for URI versioning
if (!empty($this->_version)) {
$min_serveOptions['maxAge'] = 31536000;
} else {
# don't cache if we are not using a version number
$min_serveOptions['maxAge'] = 0;
}
$min_serveOptions['swift']['files'] = array();
foreach ($this->_current_modules as $module) {
if (!empty($this->_config['debug_use_alt_resources']) && !empty($this->_config['modules'][$module]['debug_path'])) {
$min_serveOptions['swift']['files'][] = $this->_config['modules'][$module]['debug_path'];
} else {
$min_serveOptions['swift']['files'][] = $this->_config['modules'][$module]['path'];
}
}
# check what format we're working on by looking at the extension on the first file
# if we are in debug mode for the current type of files use Minify's debug mode
if (!empty($this->_config['debug_minify_js_off']) && pathinfo($min_serveOptions['swift']['files'][0], PATHINFO_EXTENSION) == 'js' || !empty($this->_config['debug_minify_css_off']) && pathinfo($min_serveOptions['swift']['files'][0], PATHINFO_EXTENSION) == 'css') {
$min_serveOptions['debug'] = true;
}
Minify::serve('Swift', $min_serveOptions);
}
示例8: serve
public static function serve()
{
// try to disable output_compression (may not have an effect)
ini_set('zlib.output_compression', '0');
Minify::setCache(OX_PATH . '/var/cache', true);
if (isset($_GET['g'])) {
// serve!
$options = array();
$options['minApp']['groupsOnly'] = true;
$options['rewriteCssUris'] = false;
$options['minApp']['groups'] = self::prepareGroups();
Minify::serve('MinApp', $options);
} else {
header("Location: /");
exit;
}
}
示例9: minify
function minify($files)
{
global $CFG;
$cachedir = $CFG->cachedir . '/js';
// make sure the cache dir exist
if (!file_exists($cachedir)) {
@mkdir($cachedir, $CFG->directorypermissions, true);
}
if (0 === stripos(PHP_OS, 'win')) {
Minify::setDocRoot();
// IIS may need help
}
Minify::setCache($cachedir, true);
$options = array('maxAge' => 60 * 60 * 24 * 20, 'files' => $files);
Minify::serve('Files', $options);
die;
}
示例10: output
public function output(array $filesGroup)
{
$sources = array();
foreach ($filesGroup as $fileGroup) {
foreach ($fileGroup as $file) {
$path = null;
$altPath = null;
if (isset($file['path']) and !empty($file['path'])) {
$altPath = $file['path'];
}
switch ($file['type']) {
case MinifySmartyWrapper::TYPE_JS:
if (strpos($file['src'], "https://") === false and strpos($file['src'], "http://") === false and substr($file['src'], 0, 1) != "/") {
$path = Reg::get('smarty')->findFilePath("js/" . $file['src'], $altPath);
} else {
$sources[] = new Minify_Source(array('id' => $file['src'], 'getContentFunc' => 'remoteFetch', 'contentType' => Minify::TYPE_JS, 'lastModified' => $_SERVER['REQUEST_TIME'] - $_SERVER['REQUEST_TIME'] % 86400));
}
if (!empty($path)) {
array_push($sources, $path);
}
break;
case MinifySmartyWrapper::TYPE_CSS:
if (strpos($file['src'], "https://") === false and strpos($file['src'], "http://") === false and substr($file['src'], 0, 1) != "/") {
$path = Reg::get('smarty')->findFilePath("css/" . $file['src'], $altPath);
} else {
$sources[] = new Minify_Source(array('id' => $file['src'], 'getContentFunc' => 'remoteFetch', 'contentType' => Minify::TYPE_CSS, 'lastModified' => $_SERVER['REQUEST_TIME'] - $_SERVER['REQUEST_TIME'] % 86400));
}
if (!empty($path)) {
array_push($sources, $path);
}
break;
case MinifySmartyWrapper::TYPE_JS_SMART:
$path = Reg::get('smarty')->findFilePath("js/" . $file['src'], $altPath);
$sources[] = new Minify_Source(array('id' => $path, 'getContentFunc' => 'getSmartFile', 'contentType' => Minify::TYPE_JS, 'lastModified' => filemtime($path)));
break;
case MinifySmartyWrapper::TYPE_CSS_SMART:
$path = Reg::get('smarty')->findFilePath("css/" . $file['src'], $altPath);
$sources[] = new Minify_Source(array('id' => $path, 'getContentFunc' => 'getSmartFile', 'contentType' => Minify::TYPE_CSS, 'lastModified' => filemtime($path)));
break;
}
}
}
$min_serveController = new Minify_Controller_MinApp();
$options = array('files' => $sources, 'maxAge' => 86400);
Minify::serve('Files', $options);
}
示例11: test_Lines
function test_Lines()
{
global $thisDir;
$exp = file_get_contents("{$thisDir}/_test_files/minify/lines_output.js");
$env = new Minify_Env();
$sourceFactory = new Minify_Source_Factory($env, array(), new Minify_Cache_Null());
$controller = new Minify_Controller_Files($env, $sourceFactory);
$minify = new Minify(new Minify_Cache_Null());
$ret = $minify->serve($controller, array('debug' => true, 'quiet' => true, 'encodeOutput' => false, 'files' => array("{$thisDir}/_test_files/js/before.js")));
$passed = assertTrue($exp === $ret['content'], 'Minify_Lines');
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
echo "\n---Output: " . countBytes($ret['content']) . " bytes\n\n{$ret['content']}\n\n";
if (!$passed) {
echo "---Expected: " . countBytes($exp) . " bytes\n\n{$exp}\n\n\n";
}
}
}
示例12: action_template_header
public function action_template_header()
{
$modified = Stack::get_sorted_stack('template_header_javascript');
foreach ($modified as $key => $value) {
Stack::remove('template_header_javascript', $key);
}
Stack::add('template_header_javascript', Site::get_url('user') . "/files/minified.js", 'Minified');
if (!Cache::has(self::$cache_name . '_js') || !Cache::has(self::$cache_name . '_css')) {
set_include_path(dirname(__FILE__) . '/min/lib' . PATH_SEPARATOR . get_include_path());
require_once 'Minify/Source.php';
require_once 'Minify/HTML.php';
require_once 'Minify/CSS.php';
require_once 'Minify/HTML.php';
require_once 'Minify.php';
require_once 'Minify/Cache/File.php';
}
if (!Cache::has(self::$cache_name . '_js')) {
$js_stack = array();
foreach ($modified as $js) {
$js_stack[] = Site::get_path('base') . str_replace(Site::get_url('habari') . '/', '', $js);
}
$options = array('files' => $js_stack, 'encodeOutput' => false, 'quiet' => true, 'maxAge' => 86400);
$result = Minify::serve('Files', $options);
file_put_contents(site::get_dir('user') . '/files/minified.js', $result['content']);
Cache::set(self::$cache_name . '_js', 'true');
}
/* CSS */
$modified = Stack::get_sorted_stack('template_stylesheet');
$tmp = array();
foreach ($modified as $key => $value) {
$tmp[] = $value[0];
Stack::remove('template_stylesheet', $key);
}
Stack::add('template_stylesheet', array(Site::get_url('user') . "/files/minified.css", 'screen'), 'style');
if (!Cache::has(self::$cache_name . '_css')) {
$css_stack = array();
foreach ($tmp as $css) {
$css_stack[] = Site::get_path('base') . str_replace(Site::get_url('habari') . '/', '', $css);
}
$options = array('files' => $css_stack, 'encodeOutput' => false, 'quiet' => true, 'maxAge' => 86400);
// handle request
$result = Minify::serve('Files', $options);
file_put_contents(site::get_dir('user') . '/files/minified.css', $result['content']);
Cache::set(self::$cache_name . '_css', 'true');
}
}
示例13: action_index
public function action_index()
{
$group = $this->request->param('group');
if (!empty($group)) {
$_GET['g'] = $group;
}
$config = Kohana::$config->load('minify');
Minify::$uploaderHoursBehind = $config['uploaderHoursBehind'];
Minify::setCache(isset($config['cachePath']) ? $config['cachePath'] : '', $config['cacheFileLocking']);
if ($config['documentRoot']) {
$_SERVER['DOCUMENT_ROOT'] = $config['documentRoot'];
Minify::$isDocRootSet = TRUE;
}
$serve_options = $config['serveOptions'];
$serve_options['minifierOptions']['text/css']['symlinks'] = $config['symlinks'];
foreach ($config['symlinks'] as $uri => $target) {
$serve_options['minApp']['allowDirs'][] = $target;
}
if ($config['allowDebugFlag']) {
$serve_options['debug'] = Minify_DebugDetector::shouldDebugRequest($_COOKIE, $_GET, $_SERVER['REQUEST_URI']);
}
if ($config['errorLogger']) {
if (TRUE === $config['errorLogger']) {
Minify_Logger::setLogger(FirePHP::getInstance(true));
} else {
Minify_Logger::setLogger($config['errorLogger']);
}
}
// Check for URI versioning
if (preg_match('/&\\d/', Arr::get($_SERVER, 'QUERY_STRING'))) {
$serve_options['maxAge'] = 31536000;
}
if (isset($_GET['g'])) {
// well need groups config
$serve_options['minApp']['groups'] = $config['groupsConfig'];
}
if (isset($_GET['f']) or isset($_GET['g'])) {
$response = Minify::serve(new Minify_Controller_MinApp(), array('quiet' => TRUE) + $serve_options);
$this->response->headers($response['headers'])->status($response['statusCode'])->body($response['content']);
}
}
示例14: action_index
public function action_index()
{
extract(Kohana::$config->load('minify')->as_array(), EXTR_SKIP);
if ($this->request->param('group')) {
$_GET['g'] = $this->request->param('group');
}
Minify::$uploaderHoursBehind = $uploaderHoursBehind;
Minify::setCache(isset($cachePath) ? $cachePath : '', $cacheFileLocking);
if ($documentRoot) {
$_SERVER['DOCUMENT_ROOT'] = $documentRoot;
Minify::$isDocRootSet = TRUE;
}
$serveOptions['minifierOptions']['text/css']['symlinks'] = $symlinks;
$serveOptions['minApp']['allowDirs'] += array_values($symlinks);
if ($allowDebugFlag) {
$serveOptions['debug'] = Minify_DebugDetector::shouldDebugRequest($_COOKIE, $_GET, $_SERVER['REQUEST_URI']);
}
if ($errorLogger) {
if (TRUE === $errorLogger) {
$errorLogger = FirePHP::getInstance(TRUE);
}
Minify_Logger::setLogger($errorLogger);
}
// Check for URI versioning
if (preg_match('/&\\d/', $_SERVER['QUERY_STRING'])) {
$serveOptions['maxAge'] = 31536000;
}
if (isset($_GET['g'])) {
// Well need groups config
$serveOptions['minApp']['groups'] = $groupsConfig;
}
if (isset($_GET['f']) or isset($_GET['g'])) {
set_time_limit(0);
// Serve!
$response = Minify::serve(new Minify_Controller_MinApp(), array('quiet' => TRUE) + $serveOptions);
$this->response->headers($response['headers'])->body($response['content'])->status($response['statusCode']);
}
}
示例15: minify
function minify($files)
{
global $CFG;
$cachedir = $CFG->cachedir . '/js';
// make sure the cache dir exist
if (!file_exists($cachedir)) {
@mkdir($cachedir, $CFG->directorypermissions, true);
}
if (0 === stripos(PHP_OS, 'win')) {
Minify::setDocRoot();
// IIS may need help
}
Minify::setCache($cachedir, true);
$options = array('maxAge' => 60 * 60 * 24 * 20, 'files' => $files);
try {
Minify::serve('Files', $options);
die;
} catch (Exception $e) {
$error = $e->getMessage();
$error = str_replace("\r", ' ', $error);
$error = str_replace("\n", ' ', $error);
}
// minification failed - try to inform the developer and include the non-minified version
$js = <<<EOD
try {console.log('Error: Minimisation of javascript failed!');} catch (e) {}
// Error: {$error}
// Problem detected during javascript minimisation, please review the following code
// =================================================================================
EOD;
echo $js;
foreach ($files as $jsfile) {
echo file_get_contents($jsfile) . "\n";
}
}