Skip to content

Commit 53499b7

Browse files
committed
#176 : Implementation for ZIP Adapter
1 parent c689721 commit 53499b7

28 files changed

+256
-168
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
## 0.7.0 -WIP
3+
## 0.7.0 - WIP
44

55
### Bugfix
66
- Fixed the image project - @mvargasmoran GH-177
@@ -13,6 +13,7 @@
1313
- PowerPoint2007 Writer : Thumbnail of the presentation - @Progi1984 GH-125
1414
- ODPresentation Writer : Add Font Support For Chart Axis - @jrking4 GH-186
1515
- PowerPoint2007 Writer : Add Font Support For Chart Axis - @jrking4 GH-186
16+
- PowerPoint2007 / Serialized Writer : Support for Zip Adapter - @Progi1984 GH-176
1617

1718
## 0.6.0 - 2016-01-24
1819

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.0
1+
0.6.0

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"php": ">=5.3.0",
2323
"ext-xml": "*",
2424
"ext-zip": "*",
25-
"phpoffice/common": "0.2.*"
25+
"phpoffice/common": "0.2.*"
2626
},
2727
"require-dev": {
2828
"phpunit/phpunit": "3.7.*",

docs/index.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ PHPPresentation is a library written in pure PHP that provides a set of classes
1919
slides
2020
shapes
2121
styles
22-
writersreaders
22+
writers
23+
readers
2324
recipes
2425
faq
2526
credits

docs/readers.rst

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
.. _writersreaders:
2+
3+
Readers
4+
=======
5+
6+
ODPresentation
7+
--------------
8+
9+
The name of the reader is ``ODPresentation``.
10+
11+
.. code-block:: php
12+
13+
$oWriter = IOFactory::createReader('ODPresentation');
14+
$oWriter->load(__DIR__ . '/sample.odp');
15+
16+
PowerPoint97
17+
------------
18+
19+
The name of the reader is ``PowerPoint97``.
20+
21+
.. code-block:: php
22+
23+
$oWriter = IOFactory::createReader('PowerPoint97');
24+
$oWriter->load(__DIR__ . '/sample.ppt');
25+
26+
PowerPoint2007
27+
--------------
28+
29+
The name of the reader is ``PowerPoint2007``.
30+
31+
.. code-block:: php
32+
33+
$oWriter = IOFactory::createReader('PowerPoint2007');
34+
$oWriter->load(__DIR__ . '/sample.pptx');
35+
36+
Serialized
37+
----------
38+
39+
The name of the reader is ``Serialized``.
40+
41+
.. code-block:: php
42+
43+
$oWriter = IOFactory::createReader('Serialized');
44+
$oWriter->load(__DIR__ . '/sample.phppt');

docs/writers.rst

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
.. _writersreaders:
2+
3+
Writers
4+
=======
5+
6+
7+
ODPresentation
8+
--------------
9+
10+
The name of the writer is ``ODPresentation``.
11+
12+
.. code-block:: php
13+
14+
$oWriter = IOFactory::createWriter($oPhpPresentation, 'PowerPoint2007');
15+
$oWriter->save(__DIR__ . '/sample.pptx');
16+
17+
PowerPoint2007
18+
--------------
19+
20+
The name of the writer is ``PowerPoint2007``.
21+
22+
.. code-block:: php
23+
24+
$oWriter = IOFactory::createWriter($oPhpPresentation, 'PowerPoint2007');
25+
$oWriter->save(__DIR__ . '/sample.pptx');
26+
27+
You can change the ZIP Adapter for the writer. By default, the ZIP Adapter is ZipArchiveAdapter.
28+
29+
.. code-block:: php
30+
31+
use PhpOffice\Common\Adapter\Zip\PclZipAdapter;
32+
use PhpOffice\Common\Adapter\Zip\ZipArchiveAdapter;
33+
34+
$oWriter = IOFactory::createWriter($oPhpPresentation, 'PowerPoint2007');
35+
$oWriter->setZipAdapter(PclZipAdapter);
36+
$oWriter->save(__DIR__ . '/sample.pptx');
37+
38+
Serialized
39+
----------
40+
41+
The name of the writer is ``Serialized``.
42+
43+
.. code-block:: php
44+
45+
$oWriter = IOFactory::createWriter($oPhpPresentation, 'Serialized');
46+
$oWriter->save(__DIR__ . '/sample.phppt');
47+
48+
You can change the ZIP Adapter for the writer. By default, the ZIP Adapter is ZipArchiveAdapter.
49+
50+
.. code-block:: php
51+
52+
use PhpOffice\Common\Adapter\Zip\PclZipAdapter;
53+
use PhpOffice\Common\Adapter\Zip\ZipArchiveAdapter;
54+
55+
$oWriter = IOFactory::createWriter($oPhpPresentation, 'Serialized');
56+
$oWriter->setZipAdapter(PclZipAdapter);
57+
$oWriter->save(__DIR__ . '/sample.phppt');
58+

docs/writersreaders.rst

-106
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpPresentation\Writer;
4+
5+
use PhpOffice\Common\Adapter\Zip\ZipInterface;
6+
7+
abstract class AbstractWriter
8+
{
9+
/**
10+
* @var ZipInterface
11+
*/
12+
protected $oZipAdapter;
13+
14+
/**
15+
* @param ZipInterface $oZipAdapter
16+
* @return $this
17+
*/
18+
public function setZipAdapter(ZipInterface $oZipAdapter)
19+
{
20+
$this->oZipAdapter = $oZipAdapter;
21+
return $this;
22+
}
23+
24+
/**
25+
* @return ZipInterface
26+
*/
27+
public function getZipAdapter()
28+
{
29+
return $this->oZipAdapter;
30+
}
31+
}

src/PhpPresentation/Writer/PowerPoint2007.php

+8-13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
namespace PhpOffice\PhpPresentation\Writer;
1919

2020
use DirectoryIterator;
21+
use PhpOffice\Common\Adapter\Zip\ZipArchiveAdapter;
2122
use PhpOffice\PhpPresentation\HashTable;
2223
use PhpOffice\PhpPresentation\PhpPresentation;
2324
use PhpOffice\PhpPresentation\Shape\AbstractDrawing;
@@ -30,7 +31,7 @@
3031
/**
3132
* \PhpOffice\PhpPresentation\Writer\PowerPoint2007
3233
*/
33-
class PowerPoint2007 implements WriterInterface
34+
class PowerPoint2007 extends AbstractWriter implements WriterInterface
3435
{
3536
/**
3637
* Private PhpPresentation
@@ -68,7 +69,7 @@ class PowerPoint2007 implements WriterInterface
6869
protected $layoutPack;
6970

7071
/**
71-
* Create a new \PhpOffice\PhpPresentation\Writer\PowerPoint2007
72+
* Create a new PowerPoint2007 file
7273
*
7374
* @param PhpPresentation $pPhpPresentation
7475
*/
@@ -85,6 +86,8 @@ public function __construct(PhpPresentation $pPhpPresentation = null)
8586

8687
// Set HashTable variables
8788
$this->drawingHashTable = new HashTable();
89+
90+
$this->setZipAdapter(new ZipArchiveAdapter());
8891
}
8992

9093
/**
@@ -113,14 +116,8 @@ public function save($pFilename)
113116
// Create drawing dictionary
114117
$this->drawingHashTable->addFromSource($this->allDrawings());
115118

116-
$oZip = new \ZipArchive();
117-
118-
// Try opening the ZIP file
119-
if ($oZip->open($pFilename, \ZipArchive::OVERWRITE) !== true) {
120-
if ($oZip->open($pFilename, \ZipArchive::CREATE) !== true) {
121-
throw new \Exception("Could not open " . $pFilename . " for writing.");
122-
}
123-
}
119+
$oZip = $this->getZipAdapter();
120+
$oZip->open($pFilename);
124121

125122
$oDir = new DirectoryIterator(dirname(__FILE__).DIRECTORY_SEPARATOR.'PowerPoint2007');
126123
foreach ($oDir as $oFile) {
@@ -142,9 +139,7 @@ public function save($pFilename)
142139
}
143140

144141
// Close file
145-
if ($oZip->close() === false) {
146-
throw new \Exception("Could not close zip file $pFilename.");
147-
}
142+
$oZip->close();
148143

149144
// If a temporary file was used, copy it to the correct file stream
150145
if ($originalFilename != $pFilename) {

src/PhpPresentation/Writer/PowerPoint2007/AbstractDecoratorWriter.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
namespace PhpOffice\PhpPresentation\Writer\PowerPoint2007;
44

5+
use PhpOffice\Common\Adapter\Zip\ZipInterface;
56
use PhpOffice\Common\Drawing as CommonDrawing;
67
use PhpOffice\Common\XMLWriter;
78
use PhpOffice\PhpPresentation\HashTable;
89
use PhpOffice\PhpPresentation\PhpPresentation;
910
use PhpOffice\PhpPresentation\Style\Border;
1011
use PhpOffice\PhpPresentation\Style\Fill;
11-
use \ZipArchive;
1212

1313
abstract class AbstractDecoratorWriter
1414
{
1515
/**
16-
* @return \ZipArchive
16+
* @return ZipInterface
1717
*/
1818
abstract public function render();
1919

@@ -71,18 +71,18 @@ public function getDrawingHashTable()
7171
}
7272

7373
/**
74-
* @var ZipArchive
74+
* @var ZipInterface
7575
*/
7676
protected $oZip;
7777

78-
public function setZip(ZipArchive $oZip)
78+
public function setZip(ZipInterface $oZip)
7979
{
8080
$this->oZip = $oZip;
8181
return $this;
8282
}
8383

8484
/**
85-
* @return ZipArchive
85+
* @return ZipInterface
8686
*/
8787
public function getZip()
8888
{

src/PhpPresentation/Writer/PowerPoint2007/ContentTypes.php

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
*/
3030
class ContentTypes extends AbstractDecoratorWriter
3131
{
32+
/**
33+
* @return \PhpOffice\Common\Adapter\Zip\ZipInterface
34+
* @throws \Exception
35+
*/
3236
public function render()
3337
{
3438
$oLayoutPack = new PowerPoint2007\LayoutPack\PackDefault();

0 commit comments

Comments
 (0)