Skip to content

Commit

Permalink
Merge pull request #1593 from dreamsxin/issue_1532
Browse files Browse the repository at this point in the history
Fix #1532 Add Phalcon\Assets\Collection::setTargetLocal
  • Loading branch information
Phalcon committed Nov 25, 2013
2 parents b67009d + b25cb10 commit cc0e879
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
28 changes: 28 additions & 0 deletions ext/assets/collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ PHALCON_INIT_CLASS(Phalcon_Assets_Collection){
zend_declare_property_null(phalcon_assets_collection_ce, SL("_targetUri"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_assets_collection_ce, SL("_targetPath"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_assets_collection_ce, SL("_sourcePath"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_bool(phalcon_assets_collection_ce, SL("_targetLocal"), 1, ZEND_ACC_PROTECTED TSRMLS_CC);

zend_class_implements(phalcon_assets_collection_ce TSRMLS_CC, 2, spl_ce_Countable, zend_ce_iterator);

Expand Down Expand Up @@ -580,3 +581,30 @@ PHP_METHOD(Phalcon_Assets_Collection, getRealTargetPath){
RETURN_CTOR(complete_path);
}

/**
* Sets the target local
*
* @param boolean $targetLocal
* @return Phalcon\Assets\Collection
*/
PHP_METHOD(Phalcon_Assets_Collection, setTargetLocal){

zval *target_local;

phalcon_fetch_params(0, 1, 0, &target_local);

phalcon_update_property_this(this_ptr, SL("_targetLocal"), target_local TSRMLS_CC);
RETURN_THISW();
}

/**
* Returns the target local
*
* @return boolean
*/
PHP_METHOD(Phalcon_Assets_Collection, getTargetLocal){


RETURN_MEMBER(this_ptr, "_targetLocal");
}

8 changes: 8 additions & 0 deletions ext/assets/collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ PHP_METHOD(Phalcon_Assets_Collection, getFilters);
PHP_METHOD(Phalcon_Assets_Collection, join);
PHP_METHOD(Phalcon_Assets_Collection, getJoin);
PHP_METHOD(Phalcon_Assets_Collection, getRealTargetPath);
PHP_METHOD(Phalcon_Assets_Collection, setTargetLocal);
PHP_METHOD(Phalcon_Assets_Collection, getTargetLocal);

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_collection_add, 0, 0, 1)
ZEND_ARG_INFO(0, resource)
Expand Down Expand Up @@ -108,6 +110,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_collection_getrealtargetpath, 0, 0
ZEND_ARG_INFO(0, basePath)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_assets_collection_settargetlocal, 0, 0, 1)
ZEND_ARG_INFO(0, targetLocal)
ZEND_END_ARG_INFO()

PHALCON_INIT_FUNCS(phalcon_assets_collection_method_entry){
PHP_ME(Phalcon_Assets_Collection, add, arginfo_phalcon_assets_collection_add, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, addCss, arginfo_phalcon_assets_collection_addcss, ZEND_ACC_PUBLIC)
Expand Down Expand Up @@ -137,6 +143,8 @@ PHALCON_INIT_FUNCS(phalcon_assets_collection_method_entry){
PHP_ME(Phalcon_Assets_Collection, join, arginfo_phalcon_assets_collection_join, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, getJoin, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, getRealTargetPath, arginfo_phalcon_assets_collection_getrealtargetpath, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, setTargetLocal, arginfo_phalcon_assets_collection_settargetlocal, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Assets_Collection, getTargetLocal, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};

7 changes: 2 additions & 5 deletions ext/assets/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -900,12 +900,9 @@ PHP_METHOD(Phalcon_Assets_Manager, output){
*/
PHALCON_INIT_NVAR(attributes);
phalcon_call_method(attributes, collection, "getattributes");

/**
* Joined resources are always local
*/

PHALCON_INIT_NVAR(local);
ZVAL_TRUE(local);
phalcon_call_method(local, collection, "gettargetlocal");

/**
* Prepare the parameters for the callback
Expand Down
19 changes: 19 additions & 0 deletions unit-tests/AssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,4 +529,23 @@ public function testIssue1198()
$this->assertEquals(file_get_contents(__DIR__ . '/assets/production/1198.css'), 'A{TEXT-DECORATION:NONE;}B{FONT-WEIGHT:BOLD;}');
@unlink(__DIR__ . '/assets/production/1198.css');
}

public function testIssue1532()
{
@unlink(__DIR__ . '/assets/production/1532.js');
$di = new \Phalcon\DI\FactoryDefault();
$assets = new \Phalcon\Assets\Manager();
$assets->useImplicitOutput(false);
$assets->collection('js')
->addJs('unit-tests/assets/jquery.js')
->join(true)
->addFilter(new Phalcon\Assets\Filters\Jsmin())
->setTargetPath(__DIR__ .'/assets/production/1532.js')
->setTargetLocal(FALSE)
->setPrefix('//phalconphp.com/')
->setTargetUri('js/jquery.js');

$this->assertEquals($assets->outputJs('js'), '<script type="text/javascript" src="//phalconphp.com/js/jquery.js"></script>' . PHP_EOL);
}

}

0 comments on commit cc0e879

Please sign in to comment.