Skip to content

Commit 6a7a180

Browse files
committed
syntax fix
1 parent 951c55a commit 6a7a180

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

src/PhpWord/TemplateProcessor.php

+23-27
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class TemplateProcessor
7474
*
7575
* @var string
7676
*/
77-
protected $tempDocumentContentTypes = "";
77+
protected $tempDocumentContentTypes = '';
7878

7979
/**
8080
* new inserted images list
@@ -134,6 +134,7 @@ protected function readPartWithRels($fileName)
134134
if ($partRelations !== false) {
135135
$this->tempDocumentRelations[$fileName] = $partRelations;
136136
}
137+
137138
return $this->fixBrokenMacros($this->zipClass->getFromName($fileName));
138139
}
139140

@@ -269,9 +270,7 @@ public function setValue($search, $replace, $limit = self::MAXIMUM_REPLACEMENTS_
269270
/**
270271
* @param mixed $search
271272
* @param mixed $replace Path to image, or array("path" => xx, "width" => yy, "height" => zz)
272-
* @param integer $limit
273-
*
274-
* @return void
273+
* @param int $limit
275274
*/
276275
public function setImageValue($search, $replace, $limit = self::MAXIMUM_REPLACEMENTS_DEFAULT)
277276
{
@@ -281,7 +280,7 @@ public function setImageValue($search, $replace, $limit = self::MAXIMUM_REPLACEM
281280
}
282281

283282
$replacesList = array();
284-
if (!is_array($replace) || isset($replace["path"])) {
283+
if (!is_array($replace) || isset($replace['path'])) {
285284
$replacesList[] = $replace;
286285
} else {
287286
$replacesList = array_values($replace);
@@ -291,31 +290,29 @@ public function setImageValue($search, $replace, $limit = self::MAXIMUM_REPLACEM
291290
foreach ($search as $searchIdx => $searchString) {
292291
$searchReplace[$searchString] = isset($replacesList[$searchIdx]) ? $replacesList[$searchIdx] : $replacesList[0];
293292
}
294-
//
295293

296294
// define templates
297295
// result can be verified via "Open XML SDK 2.5 Productivity Tool" (http://www.microsoft.com/en-us/download/details.aspx?id=30425)
298296
$imgTpl = '<w:pict><v:shape type="#_x0000_t75" style="width:{WIDTH}px;height:{HEIGHT}px"><v:imagedata r:id="{RID}" o:title=""/></v:shape></w:pict>';
299297
$typeTpl = '<Override PartName="/word/media/{IMG}" ContentType="image/{EXT}"/>';
300298
$relationTpl = '<Relationship Id="{RID}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/{IMG}"/>';
301-
$newRelationsTpl = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'."\n".'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"></Relationships>';
299+
$newRelationsTpl = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' . "\n" . '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"></Relationships>';
302300
$newRelationsTypeTpl = '<Override PartName="/{RELS}" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>';
303301
$extTransform = array(
304-
"jpg" => "jpeg",
305-
"JPG" => "jpeg",
306-
"png" => "png",
307-
"PNG" => "png",
302+
'jpg' => 'jpeg',
303+
'JPG' => 'jpeg',
304+
'png' => 'png',
305+
'PNG' => 'png',
308306
);
309-
//
310307

311308
$searchParts = array(
312309
$this->getMainPartName() => &$this->tempDocumentMainPart,
313310
);
314311
foreach (array_keys($this->tempDocumentHeaders) as $headerIndex) {
315-
$searchParts[ $this->getHeaderName($headerIndex) ] = &$this->tempDocumentHeaders[$headerIndex];
312+
$searchParts[$this->getHeaderName($headerIndex)] = &$this->tempDocumentHeaders[$headerIndex];
316313
}
317314
foreach (array_keys($this->tempDocumentFooters) as $headerIndex) {
318-
$searchParts[ $this->getFooterName($headerIndex) ] = &$this->tempDocumentFooters[$headerIndex];
315+
$searchParts[$this->getFooterName($headerIndex)] = &$this->tempDocumentFooters[$headerIndex];
319316
}
320317

321318
foreach ($searchParts as $partFileName => &$partContent) {
@@ -330,13 +327,13 @@ public function setImageValue($search, $replace, $limit = self::MAXIMUM_REPLACEM
330327
// get image path and size
331328
$width = 115;
332329
$height = 70;
333-
if (is_array($replace) && isset($replace["path"])) {
334-
$imgPath = $replace["path"];
335-
if (isset($replace["width"])) {
336-
$width = $replace["width"];
330+
if (is_array($replace) && isset($replace['path'])) {
331+
$imgPath = $replace['path'];
332+
if (isset($replace['width'])) {
333+
$width = $replace['width'];
337334
}
338-
if (isset($replace["height"])) {
339-
$height = $replace["height"];
335+
if (isset($replace['height'])) {
336+
$height = $replace['height'];
340337
}
341338
} else {
342339
$imgPath = $replace;
@@ -362,11 +359,11 @@ public function setImageValue($search, $replace, $limit = self::MAXIMUM_REPLACEM
362359
$this->tempDocumentNewImages[$imgPath] = $imgName;
363360

364361
// setup type for image
365-
$xmlImageType = str_replace(array('{IMG}', '{EXT}'), array($imgName, $imgExt), $typeTpl) ;
362+
$xmlImageType = str_replace(array('{IMG}', '{EXT}'), array($imgName, $imgExt), $typeTpl);
366363
$this->tempDocumentContentTypes = str_replace('</Types>', $xmlImageType, $this->tempDocumentContentTypes) . '</Types>';
367364
}
368365

369-
$xmlImage = str_replace(array('{RID}', '{WIDTH}', '{HEIGHT}'), array($rid, $width, $height), $imgTpl) ;
366+
$xmlImage = str_replace(array('{RID}', '{WIDTH}', '{HEIGHT}'), array($rid, $width, $height), $imgTpl);
370367
$xmlImageRelation = str_replace(array('{RID}', '{IMG}'), array($rid, $imgName), $relationTpl);
371368

372369
if (!isset($this->tempDocumentRelations[$partFileName])) {
@@ -381,7 +378,7 @@ public function setImageValue($search, $replace, $limit = self::MAXIMUM_REPLACEM
381378
$this->tempDocumentRelations[$partFileName] = str_replace('</Relationships>', $xmlImageRelation, $this->tempDocumentRelations[$partFileName]) . '</Relationships>';
382379

383380
// collect prepared replaces
384-
$partSearchReplaces["<w:t>".self::ensureMacroCompleted($search)."</w:t>"] = $xmlImage;
381+
$partSearchReplaces['<w:t>' . self::ensureMacroCompleted($search) . '</w:t>'] = $xmlImage;
385382
}
386383

387384
if ($partSearchReplaces) {
@@ -569,8 +566,6 @@ public function save()
569566
/**
570567
* @param string $fileName
571568
* @param string $xml
572-
*
573-
* @return void
574569
*/
575570
protected function savePartWithRels($fileName, $xml)
576571
{
@@ -699,20 +694,21 @@ protected function getFooterName($index)
699694
/**
700695
* Get the name of the relations file for document part.
701696
*
702-
* @param string $docuemntPartName
697+
* @param string $documentPartName
703698
*
704699
* @return string
705700
*/
706701
protected function getRelationsName($documentPartName)
707702
{
708-
return 'word/_rels/'.pathinfo($documentPartName, PATHINFO_BASENAME).'.rels';
703+
return 'word/_rels/' . pathinfo($documentPartName, PATHINFO_BASENAME) . '.rels';
709704
}
710705

711706
protected function getNextRelationsIndex($documentPartName)
712707
{
713708
if (isset($this->tempDocumentRelations[$documentPartName])) {
714709
return substr_count($this->tempDocumentRelations[$documentPartName], '<Relationship');
715710
}
711+
716712
return 1;
717713
}
718714

tests/PhpWord/TemplateProcessorTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ public function testSetImageValue()
211211

212212
$variablesReplace = array(
213213
'headerValue' => $imagePath,
214-
'documentContent' => array("path" => $imagePath, "width" => 500, "height" => 500),
215-
'footerValue' => array("path" => $imagePath, "width" => 50, "height" => 50),
214+
'documentContent' => array('path' => $imagePath, 'width' => 500, 'height' => 500),
215+
'footerValue' => array('path' => $imagePath, 'width' => 50, 'height' => 50),
216216
);
217217
$templateProcessor->setImageValue(array_keys($variablesReplace), $variablesReplace);
218218

0 commit comments

Comments
 (0)