From 8fc39afae821077d85d9372c00b161175c2fe6e8 Mon Sep 17 00:00:00 2001 From: Evgeny Ivanov Date: Sat, 21 Mar 2015 10:33:25 +0300 Subject: [PATCH] loops example --- .../{02-blocks.docx => 02-loops.docx} | Bin 11743 -> 11808 bytes .../{02-blocks.docx => 02-loops.docx} | Bin 11754 -> 11852 bytes .../scripts/{02-blocks.php => 02-loops.php} | 10 ++-- .../Content/Collection/LoopCollection.php | 44 +++++++----------- src/DocxTemplate/Content/MarkedContent.php | 7 ++- src/DocxTemplate/Matcher.php | 13 ++++-- 6 files changed, 33 insertions(+), 41 deletions(-) rename examples/docs/original/{02-blocks.docx => 02-loops.docx} (57%) rename examples/docs/processed/{02-blocks.docx => 02-loops.docx} (56%) rename examples/scripts/{02-blocks.php => 02-loops.php} (57%) diff --git a/examples/docs/original/02-blocks.docx b/examples/docs/original/02-loops.docx similarity index 57% rename from examples/docs/original/02-blocks.docx rename to examples/docs/original/02-loops.docx index 1df58ea879fd507397091ab3b3dc053defef4e1d..3dfd05679a25ce4bc5c745cd8a998adec1792f37 100644 GIT binary patch delta 3355 zcmZ8kcRU>2wjCKgBWmDCKxiE_nNn)$r0JC&kJ^Jzc_6l6>^iqB;ZB0Fp`L92-{zD zTzAGE2nrb81@zv_xjrA%Zkx9V)?JO3VomM%k`Z5T)CC&sPjUxzsw;85mYtC4IkLYA+V5l>{J`+n zfzd!tELllY6?jcP;yOBljfC(O9ea&p1P{6S({(3>JZ6;|-swS)OSS%qK+!vJX2*0x z6=ef^e71Ds%yq7BgY*5LXTIaoHw!5f>_>0{+<`DzB#;oe%au zizU22+3_(Zj_swCFi?K9h!sp85Df@ZDDY_ZNTe9kLOnWR|ETo`wK zhLFhSrTJwyaN1s%zp-n`C#L&NQ1yL9Mb?Ct%8%dHdAwV>k#B?;Tv1wSW%A|1i6iVU z+rhWF_M$H~M+49&i1Vkq(*EpsCx;=%pO_*#i3$QQh+X&B=!s>dOLd0$WOWLJcB1Yw zL>nQN`4iu**q3!WZ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1j_ot{F;=O2! zmZd<_ivn*UtIdPbQSJB3E(Q-|keiq)<$V9rdV>4l7?XOUqJl-R+Y%hT8wb?;+CNwE za$bcNjl4L2=TMSAX|lKGOTgu>FMMW3wecxTP_u;w3goo?SUU5*KP5r;jO@6bIBglg zs%OeaB{&uxcZ_oiv{@-mpAJ(JP#1u7U=uQw&u9REiwhvY#1Kfu2A~1Z;Sj9UxHq!Q z&DMMxAV$51DA*qdoyh3ldq=Mzu0)&*a~tVDt-uzox2knBnw0e%xlvZ3U%Su`G}9$s z3E~%53Ay_gjbvEu3VvkR3~E68sxgP>J?bAK9ghzeMC*oAHMN!H=Y`VzrQy^{n;ynd zg9A-gvrqK2FcT%Frrq{d7|`TVl9834#j+CRz%9)|3AzOQ>y%w+wH5~AmHc(FBR{ln z_k*R)M5-S*r;x}F%^gO*6fl@GZwQ-QUZ}W7`!!l+M{TB1?lue^ARHfZ@<-{r>i2~K z2JYkCx$e;2xUk)(Xwjn0>HYrwvs3;fKv{*6d`p5Qx}wAxW;#B^;j=a4NAK|YYx8QJ ziFh3EaR=K7>$S6AKbSE19^dw1iD9$U>?aAE)Vf>tFYzsPQ?cfThm3$O_f{{`MYQ0z zRRh5z%;Y43YAhmlh!#x;j^Gi|mPv)=dGKAc!>{UjVN zS#4dI*D*~*h`(OTtd&_Ok%1<~S2z+ozbJk(P8{mGYKp?E2Cdb5r8H4e846LziBo>< zUf*wtN*t+`xrOlsS=u5`;DZn-nxF=ce7Ja*3=zXCGW1;ul?I=HCtgRlIYd|xY3-h4 zEykZjnmJxQPB*=HzH;^9%$ryFUzFoVzQaxQcd}O>#4f1mkX}DAn@2t)E^<86*+|p( zTk)|3dzeQVi?+{<#*gNgh`7^dZXa#Vy=_Pt+M^lumjjY$wVF}VToerd@Bl7X20getOriginalPath()); -$template->loop("block", [ +$template->loop("loop", [ [ - 'block_var' => "var1" + 'var' => "iteration1" ], [ - 'block_var' => "var2" + 'var' => "iteration2" ], [ - 'block_var' => "var3" + 'var' => "iteration3" ] ]); diff --git a/src/DocxTemplate/Content/Collection/LoopCollection.php b/src/DocxTemplate/Content/Collection/LoopCollection.php index 8750e27..5ad25c9 100644 --- a/src/DocxTemplate/Content/Collection/LoopCollection.php +++ b/src/DocxTemplate/Content/Collection/LoopCollection.php @@ -13,7 +13,7 @@ class LoopCollection extends ContentCollection /** * @var MarkedContent */ - private $currentItem; + private $currentIteration; /** * @param MarkedContent $content @@ -34,46 +34,36 @@ public function getBaseContent() /** * @return MarkedContent */ - public function getCurrentItem() + public function getCurrentIteration() { - return $this->currentItem; - } - - /** - * @param array $row - * @return $this - */ - public function assignRow(array $row) - { - $item = $this->itemStart(); - $item->assign($row); - $this->itemEnd(); - - return $this; + return $this->currentIteration; } /** + * @param array $values * @return MarkedContent */ - public function itemStart() + public function iterate(array $values = []) { - if (!$this->currentItem) { - $this->currentItem = clone $this->baseContent; + if ($this->currentIteration) { + $this->addContent($this->currentIteration); } - return $this->currentItem; - } - - public function itemEnd() - { - if ($this->currentItem) { - $this->addContent($this->currentItem); - $this->currentItem = null; + $this->currentIteration = clone $this->baseContent; + if ($values) { + $this->currentIteration->assign($values); } + + return $this->currentIteration; } public function finish() { + if ($this->currentIteration) { + $this->addContent($this->currentIteration); + $this->currentIteration = null; + } + $this->baseContent->getBindedTo()->assign([ $this->baseContent->getBindedMark() => $this ]); diff --git a/src/DocxTemplate/Content/MarkedContent.php b/src/DocxTemplate/Content/MarkedContent.php index c3bc8a7..97f7aa3 100644 --- a/src/DocxTemplate/Content/MarkedContent.php +++ b/src/DocxTemplate/Content/MarkedContent.php @@ -46,12 +46,11 @@ public function assign($key, $value = null) public function extractContent($name) { $content = $this->getContent(); - $uniqName = uniqid($name); - $extracted = $this->matcher->extractRange($name . "_start", $name . "_end", $uniqName, $content); + $extracted = $this->matcher->extractRange($name, $name, $name, $content); $this->setContent($content); $content = new MarkedContent($extracted, $this->matcher); - $content->bindTo($uniqName, $this); + $content->bindTo($name, $this); return $content; } @@ -66,7 +65,7 @@ public function loop($name, $rows = []) $loop = new LoopCollection($block); foreach ($rows as $row) { - $loop->assignRow($row); + $loop->iterate($row); } $loop->finish(); diff --git a/src/DocxTemplate/Matcher.php b/src/DocxTemplate/Matcher.php index cac7ad0..ce9616c 100644 --- a/src/DocxTemplate/Matcher.php +++ b/src/DocxTemplate/Matcher.php @@ -110,12 +110,15 @@ public function getMarks($text) public function extractRange($fromMark, $toMark, $placeMark, &$text) { $uniqId = uniqid(); - $text = $this->replaceMarks([ - $fromMark => "FROM_MARK_" . $uniqId, - $toMark => "TO_MARK_" . $uniqId - ], $text); + $tmpReplace = [ + $fromMark => "MARK_" . $uniqId, + ]; + if ($toMark != $fromMark) { + $tmpReplace[$toMark] = "MARK_" . $uniqId; + } + $text = $this->replaceMarks($tmpReplace, $text); - $pattern = "/FROM_MARK_{$uniqId}(.*)TO_MARK_{$uniqId}/"; + $pattern = "/MARK_{$uniqId}(.*)MARK_{$uniqId}/"; $rangeContent = ""; $text = preg_replace_callback($pattern, function ($matches) use (&$rangeContent, $placeMark) { if (isset($matches[1])) {