Skip to content

Commit 5059ab2

Browse files
committed
optimization
TR TD merged + getColIndex JsUtils CompileLibrary BaseHtml => JString removed PropertyWrapper
1 parent f662ec7 commit 5059ab2

File tree

7 files changed

+77
-28
lines changed

7 files changed

+77
-28
lines changed

Ajax/JsUtils.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ abstract class JsUtils{
4848
*/
4949
protected $config;
5050

51+
5152
abstract public function getUrl($url);
5253
abstract public function addViewElement($identifier,$content,&$view);
5354
abstract public function createScriptVariable(&$view,$view_var, $output);
@@ -167,6 +168,9 @@ public function __construct($params=array(),$injected=NULL) {
167168

168169
$this->params=$params;
169170
$this->injected=$injected;
171+
if(isset($params['gc'])){
172+
\gc_disable();
173+
}
170174
}
171175

172176
public function __set($property, $value){
@@ -222,9 +226,15 @@ public function output($array_js) {
222226
* @return string
223227
*/
224228
public function compile(&$view=NULL, $view_var='script_foot', $script_tags=TRUE) {
225-
$this->_compileLibrary($this->ui(),$view);
226-
$this->_compileLibrary($this->bootstrap(),$view);
227-
$this->_compileLibrary($this->semantic(),$view);
229+
if(isset($this->_ui)){
230+
$this->_compileLibrary($this->_ui,$view);
231+
}
232+
if(isset($this->_bootstrap)){
233+
$this->_compileLibrary($this->_bootstrap,$view);
234+
}
235+
if(isset($this->_semantic)){
236+
$this->_compileLibrary($this->_semantic,$view);
237+
}
228238

229239
if (\sizeof($this->jquery_code_for_compile)==0) {
230240
return;

Ajax/common/html/BaseHtml.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Ajax\common\html;
44

55

6-
use Ajax\service\JString;
76
use Ajax\common\components\SimpleExtComponent;
87
use Ajax\JsUtils;
98
use Ajax\common\html\traits\BaseHtmlEventsTrait;
@@ -34,7 +33,7 @@ abstract public function run(JsUtils $js);
3433

3534
private function _callSetter($setter,$key,$value,&$array){
3635
$result=false;
37-
if (method_exists($this, $setter) && !JString::startswith($key, "_")) {
36+
if (method_exists($this, $setter) && substr($setter, 0, 1) !== "_") {
3837
try {
3938
$this->$setter($value);
4039
unset($array[$key]);
@@ -211,17 +210,16 @@ public function compile(JsUtils $js=NULL, &$view=NULL) {
211210
$this->compile_once($js,$view);
212211
$result=$this->getTemplate($js);
213212
foreach ( $this as $key => $value ) {
214-
if (JString::startswith($key, "_") === false && $key !== "events") {
215-
if (\is_array($value)) {
216-
$v=PropertyWrapper::wrap($value, $js);
217-
} else {
218-
if($value instanceof \stdClass)
219-
$v=\print_r($value,true);
220-
else
213+
if(\strstr($result, "%{$key}%")!==false){
214+
if (\is_array($value)) {
215+
$v=PropertyWrapper::wrap($value, $js);
216+
}elseif($value instanceof \stdClass){
217+
$v=\print_r($value,true);
218+
}else{
221219
$v=$value;
220+
}
221+
$result=str_replace("%{$key}%", $v, $result);
222222
}
223-
$result=str_ireplace("%" . $key . "%", $v, $result);
224-
}
225223
}
226224
if (isset($js)===true) {
227225
$this->run($js);

Ajax/common/html/PropertyWrapper.php

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
class PropertyWrapper {
88

99
public static function wrap($input, $js=NULL, $separator=' ', $valueQuote='"') {
10-
$output="";
1110
if (is_string($input)) {
12-
$output=$input;
11+
return $input;
1312
}
13+
$output="";
1414
if (\is_array($input)) {
1515
if (sizeof($input) > 0) {
1616
if (self::containsElement($input) === false) {
@@ -37,19 +37,50 @@ public static function wrapStrings($input, $separator=' ', $valueQuote='"') {
3737
return $k . '=' . $valueQuote . $v . $valueQuote;
3838
}, $input, array_keys($input)));
3939
} else {
40-
$result=implode($separator, array_values($input));
40+
$result=implode($separator, $input);
4141
}
4242
return $result;
4343
}
4444

4545
public static function wrapObjects($input, $js=NULL, $separator=' ', $valueQuote='"') {
4646
return implode($separator, array_map(function ($v) use($js, $separator, $valueQuote) {
47-
if ($v instanceof BaseHtml)
47+
if(\is_string($v)){
48+
return $v;
49+
}
50+
if ($v instanceof BaseHtml){
4851
return $v->compile($js);
49-
elseif (\is_array($v)) {
52+
}
53+
if (\is_array($v)) {
5054
return self::wrap($v, $js, $separator, $valueQuote);
51-
} elseif(!\is_callable($v))
55+
}
56+
if(!\is_callable($v)){
5257
return $v;
58+
}
5359
}, $input));
60+
/*$result='';
61+
foreach ($input as $value) {
62+
if($result!==''){
63+
$result.=$separator;
64+
}
65+
if(\is_string($value)){
66+
$result.=$value;
67+
}else{
68+
$result.=self::wrapValue($value,$js,$separator,$valueQuote);
69+
}
70+
}
71+
return $result;*/
72+
}
73+
74+
protected static function wrapValue($value,$js=NULL, $separator=' ', $valueQuote='"'){
75+
if (\is_array($value)) {
76+
return self::wrap($value, $js, $separator, $valueQuote);
77+
}
78+
if ($value instanceof BaseHtml){
79+
return $value->compile($js);
80+
}
81+
if(!\is_callable($value)){
82+
return $value;
83+
}
84+
return '';
5485
}
5586
}

Ajax/common/traits/JsUtilsInternalTrait.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ protected function _addToCompile($jsScript) {
1616
* @param mixed $view
1717
*/
1818
protected function _compileLibrary(BaseGui $library=NULL, &$view=NULL){
19-
if ($library!=NULL) {
20-
if(isset($view))
21-
$library->compileHtml($this, $view);
22-
if ($library->isAutoCompile()) {
23-
$library->compile(true);
24-
}
19+
if(isset($view))
20+
$library->compileHtml($this, $view);
21+
if ($library->isAutoCompile()) {
22+
$library->compile(true);
2523
}
2624
}
2725

Ajax/semantic/html/content/table/HtmlTD.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function setRowspan($rowspan) {
5454
$this->_container->toDelete($i, $this->_col);
5555
}
5656
$this->setProperty("rowspan", $rowspan);
57-
return $this->_container;
57+
return $this->_container->_setMerged(true);
5858
}
5959

6060
public function mergeRow() {
@@ -79,7 +79,7 @@ public function setColspan($colspan) {
7979
$this->_container->toDelete($this->_row, $this->_col + 1);
8080
}
8181
$this->setProperty("colspan", $colspan);
82-
return $this->_container;
82+
return $this->_container->_setMerged(true);
8383
}
8484

8585
public function getColspan() {

Ajax/semantic/html/content/table/HtmlTR.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ public function mergeRow($colIndex=0) {
120120
}
121121

122122
public function getColPosition($colIndex) {
123+
if($this->_container->_isMerged()!==true)
124+
return $colIndex;
123125
$pos=0;
124126
$rows=$this->_container->getContent();
125127
for($i=0; $i < $this->_row; $i++) {

Ajax/semantic/html/content/table/HtmlTableContent.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
class HtmlTableContent extends HtmlSemCollection {
1414
protected $_tdTagNames=[ "thead" => "th","tbody" => "td","tfoot" => "th" ];
15+
protected $_merged=false;
1516

1617
/**
1718
*
@@ -366,4 +367,13 @@ public function mergeIdentiqualValues($colIndex,$function="strip_tags"){
366367
}
367368
return $this;
368369
}
370+
371+
public function _isMerged(){
372+
return $this->_merged;
373+
}
374+
375+
public function _setMerged($value){
376+
$this->_merged=$value;
377+
return $this;
378+
}
369379
}

0 commit comments

Comments
 (0)