Skip to content

Commit

Permalink
PHPOffice#176 : Implementation for ZIP Adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Mar 4, 2016
1 parent c689721 commit 53499b7
Show file tree
Hide file tree
Showing 28 changed files with 256 additions and 168 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## 0.7.0 -WIP
## 0.7.0 - WIP

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

## 0.6.0 - 2016-01-24

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.0
0.6.0
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"php": ">=5.3.0",
"ext-xml": "*",
"ext-zip": "*",
"phpoffice/common": "0.2.*"
"phpoffice/common": "0.2.*"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
Expand Down
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ PHPPresentation is a library written in pure PHP that provides a set of classes
slides
shapes
styles
writersreaders
writers
readers
recipes
faq
credits
Expand Down
44 changes: 44 additions & 0 deletions docs/readers.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.. _writersreaders:

Readers
=======

ODPresentation
--------------

The name of the reader is ``ODPresentation``.

.. code-block:: php
$oWriter = IOFactory::createReader('ODPresentation');
$oWriter->load(__DIR__ . '/sample.odp');
PowerPoint97
------------

The name of the reader is ``PowerPoint97``.

.. code-block:: php
$oWriter = IOFactory::createReader('PowerPoint97');
$oWriter->load(__DIR__ . '/sample.ppt');
PowerPoint2007
--------------

The name of the reader is ``PowerPoint2007``.

.. code-block:: php
$oWriter = IOFactory::createReader('PowerPoint2007');
$oWriter->load(__DIR__ . '/sample.pptx');
Serialized
----------

The name of the reader is ``Serialized``.

.. code-block:: php
$oWriter = IOFactory::createReader('Serialized');
$oWriter->load(__DIR__ . '/sample.phppt');
58 changes: 58 additions & 0 deletions docs/writers.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.. _writersreaders:

Writers
=======


ODPresentation
--------------

The name of the writer is ``ODPresentation``.

.. code-block:: php
$oWriter = IOFactory::createWriter($oPhpPresentation, 'PowerPoint2007');
$oWriter->save(__DIR__ . '/sample.pptx');
PowerPoint2007
--------------

The name of the writer is ``PowerPoint2007``.

.. code-block:: php
$oWriter = IOFactory::createWriter($oPhpPresentation, 'PowerPoint2007');
$oWriter->save(__DIR__ . '/sample.pptx');
You can change the ZIP Adapter for the writer. By default, the ZIP Adapter is ZipArchiveAdapter.

.. code-block:: php
use PhpOffice\Common\Adapter\Zip\PclZipAdapter;
use PhpOffice\Common\Adapter\Zip\ZipArchiveAdapter;
$oWriter = IOFactory::createWriter($oPhpPresentation, 'PowerPoint2007');
$oWriter->setZipAdapter(PclZipAdapter);
$oWriter->save(__DIR__ . '/sample.pptx');
Serialized
----------

The name of the writer is ``Serialized``.

.. code-block:: php
$oWriter = IOFactory::createWriter($oPhpPresentation, 'Serialized');
$oWriter->save(__DIR__ . '/sample.phppt');
You can change the ZIP Adapter for the writer. By default, the ZIP Adapter is ZipArchiveAdapter.

.. code-block:: php
use PhpOffice\Common\Adapter\Zip\PclZipAdapter;
use PhpOffice\Common\Adapter\Zip\ZipArchiveAdapter;
$oWriter = IOFactory::createWriter($oPhpPresentation, 'Serialized');
$oWriter->setZipAdapter(PclZipAdapter);
$oWriter->save(__DIR__ . '/sample.phppt');
106 changes: 0 additions & 106 deletions docs/writersreaders.rst

This file was deleted.

31 changes: 31 additions & 0 deletions src/PhpPresentation/Writer/AbstractWriter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace PhpOffice\PhpPresentation\Writer;

use PhpOffice\Common\Adapter\Zip\ZipInterface;

abstract class AbstractWriter
{
/**
* @var ZipInterface
*/
protected $oZipAdapter;

/**
* @param ZipInterface $oZipAdapter
* @return $this
*/
public function setZipAdapter(ZipInterface $oZipAdapter)
{
$this->oZipAdapter = $oZipAdapter;
return $this;
}

/**
* @return ZipInterface
*/
public function getZipAdapter()
{
return $this->oZipAdapter;
}
}
21 changes: 8 additions & 13 deletions src/PhpPresentation/Writer/PowerPoint2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace PhpOffice\PhpPresentation\Writer;

use DirectoryIterator;
use PhpOffice\Common\Adapter\Zip\ZipArchiveAdapter;
use PhpOffice\PhpPresentation\HashTable;
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Shape\AbstractDrawing;
Expand All @@ -30,7 +31,7 @@
/**
* \PhpOffice\PhpPresentation\Writer\PowerPoint2007
*/
class PowerPoint2007 implements WriterInterface
class PowerPoint2007 extends AbstractWriter implements WriterInterface
{
/**
* Private PhpPresentation
Expand Down Expand Up @@ -68,7 +69,7 @@ class PowerPoint2007 implements WriterInterface
protected $layoutPack;

/**
* Create a new \PhpOffice\PhpPresentation\Writer\PowerPoint2007
* Create a new PowerPoint2007 file
*
* @param PhpPresentation $pPhpPresentation
*/
Expand All @@ -85,6 +86,8 @@ public function __construct(PhpPresentation $pPhpPresentation = null)

// Set HashTable variables
$this->drawingHashTable = new HashTable();

$this->setZipAdapter(new ZipArchiveAdapter());
}

/**
Expand Down Expand Up @@ -113,14 +116,8 @@ public function save($pFilename)
// Create drawing dictionary
$this->drawingHashTable->addFromSource($this->allDrawings());

$oZip = new \ZipArchive();

// Try opening the ZIP file
if ($oZip->open($pFilename, \ZipArchive::OVERWRITE) !== true) {
if ($oZip->open($pFilename, \ZipArchive::CREATE) !== true) {
throw new \Exception("Could not open " . $pFilename . " for writing.");
}
}
$oZip = $this->getZipAdapter();
$oZip->open($pFilename);

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

// Close file
if ($oZip->close() === false) {
throw new \Exception("Could not close zip file $pFilename.");
}
$oZip->close();

// If a temporary file was used, copy it to the correct file stream
if ($originalFilename != $pFilename) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace PhpOffice\PhpPresentation\Writer\PowerPoint2007;

use PhpOffice\Common\Adapter\Zip\ZipInterface;
use PhpOffice\Common\Drawing as CommonDrawing;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpPresentation\HashTable;
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Style\Border;
use PhpOffice\PhpPresentation\Style\Fill;
use \ZipArchive;

abstract class AbstractDecoratorWriter
{
/**
* @return \ZipArchive
* @return ZipInterface
*/
abstract public function render();

Expand Down Expand Up @@ -71,18 +71,18 @@ public function getDrawingHashTable()
}

/**
* @var ZipArchive
* @var ZipInterface
*/
protected $oZip;

public function setZip(ZipArchive $oZip)
public function setZip(ZipInterface $oZip)
{
$this->oZip = $oZip;
return $this;
}

/**
* @return ZipArchive
* @return ZipInterface
*/
public function getZip()
{
Expand Down
4 changes: 4 additions & 0 deletions src/PhpPresentation/Writer/PowerPoint2007/ContentTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
*/
class ContentTypes extends AbstractDecoratorWriter
{
/**
* @return \PhpOffice\Common\Adapter\Zip\ZipInterface
* @throws \Exception
*/
public function render()
{
$oLayoutPack = new PowerPoint2007\LayoutPack\PackDefault();
Expand Down
Loading

0 comments on commit 53499b7

Please sign in to comment.