Skip to content

Commit

Permalink
- allow CodeSettings to be passed to minify_js
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrejoye committed Dec 8, 2010
1 parent a7c6d60 commit 070471f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
34 changes: 16 additions & 18 deletions ajaxmin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ using namespace System::IO;
using namespace Microsoft::Ajax::Utilities;
using namespace msclr;
#include "csssettings.hpp"
#include "codesettings.hpp"

static zend_object_value php_csssettings_object_new(zend_class_entry *class_type TSRMLS_DC);
static void php_csssettings_object_free_storage(void *object TSRMLS_DC);
Expand All @@ -49,12 +50,12 @@ PHP_FUNCTION(ajaxmin_minify_css);

ZEND_BEGIN_ARG_INFO_EX(arginfo_ajaxmin_minify_js, 0, 0, 1)
ZEND_ARG_INFO(0, str)
ZEND_ARG_INFO(0, options)
ZEND_ARG_INFO(0, settings)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_ajaxmin_minify_css, 0, 0, 1)
ZEND_ARG_INFO(0, str)
ZEND_ARG_INFO(0, options)
ZEND_ARG_INFO(0, settings)
ZEND_ARG_INFO(0, filename_out)
ZEND_END_ARG_INFO()

Expand Down Expand Up @@ -117,8 +118,10 @@ PHP_FUNCTION(ajaxmin_minify_js) /* {{{ */
int str_len = 0;
char *filename = NULL;
int filename_len = 0;
zval *codesettings = NULL;
ze_codesettings_object *obj = NULL;

if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE)
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sO", &str, &str_len, &codesettings, codesettings_class_entry) == FAILURE)
{
RETURN_FALSE;
}
Expand All @@ -128,25 +131,20 @@ PHP_FUNCTION(ajaxmin_minify_js) /* {{{ */
}
String^ strString = gcnew String(str, 0, str_len);

Minifier ^mini = gcnew Minifier;
if (codesettings) {
obj = (ze_codesettings_object *)zend_objects_get_address(codesettings TSRMLS_CC);
}

try {
String^ miniString;
#if 0 /* TODO: add settings support for fine grained options */
CodeSettings^ settings = gcnew CodeSettings();
settings->CollapseToLiteral = true;
settings->CombineDuplicateLiterals = true;
settings->InlineSafeStrings = true;
settings->LocalRenaming = LocalRenaming::CrunchAll;
settings->MinifyCode = true;
settings->PreserveFunctionNames = false;
settings->RemoveUnneededCode = true;


miniString = mini->MinifyJavaScript(strString, settings);
#endif
miniString = mini->MinifyJavaScript(strString);
Minifier ^mini = gcnew Minifier;

if (codesettings) {
CodeSettings^ m_settings = obj->settings.get();
miniString = mini->MinifyJavaScript(strString, m_settings);
} else {
miniString = mini->MinifyJavaScript(strString);
}
UTF8Encoding^ utf8 = gcnew UTF8Encoding;
array<Byte>^encodedBytes = utf8->GetBytes(miniString);
cli::pin_ptr<unsigned char> utf8_char = &encodedBytes[0];
Expand Down
5 changes: 1 addition & 4 deletions codesettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ static int codesettings_set_StripDebugStatements(ze_codesettings_object *obj, zv
/* }}} */




static HashTable *php_codesettings_get_properties(zval *object TSRMLS_DC) /* {{{ */
{
HashTable *h;
Expand Down Expand Up @@ -357,7 +355,7 @@ PHP_MINIT_FUNCTION(codesettings) { /* {{{ */
zend_class_entry codesettings_ce;

memcpy(&codesettings_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
codesettings_object_handlers.clone_obj = NULL;
codesettings_object_handlers.clone_obj = NULL;
codesettings_object_handlers.get_property_ptr_ptr = NULL;
codesettings_object_handlers.get_properties = php_codesettings_get_properties;
codesettings_object_handlers.write_property = php_codesettings_write_property;
Expand All @@ -380,7 +378,6 @@ PHP_MINIT_FUNCTION(codesettings) { /* {{{ */
ajaxmin_register_prop_handler(&codesettings_prop_handlers, "RemoveUnneededCode", codesettings_get_RemoveUnneededCode, codesettings_set_RemoveUnneededCode TSRMLS_CC);
ajaxmin_register_prop_handler(&codesettings_prop_handlers, "StripDebugStatements", codesettings_get_StripDebugStatements, codesettings_set_StripDebugStatements TSRMLS_CC);


REGISTER_CODESETTINGS_CLASS_CONST_LONG("COLOR_STRICT", 0);
REGISTER_CODESETTINGS_CLASS_CONST_LONG("COLOR_HEX", 1);
REGISTER_CODESETTINGS_CLASS_CONST_LONG("COLOR_MAJOR", 2);
Expand Down
3 changes: 3 additions & 0 deletions examples/js.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ function bar() {c = 233;}
$settings = new CodeSettings();
//$settings->IndentSize = 3;
var_dump($settings->IndentSize);

$ret = ajaxmin_minify_js($js, $settings);
echo $ret;

0 comments on commit 070471f

Please sign in to comment.