Skip to content

Commit

Permalink
Update: Code conventions for PHP 8.x & Update: .gitignore to include …
Browse files Browse the repository at this point in the history
…composer.lock (in support of PR PHPOffice#2722 : Autoload)
  • Loading branch information
Sambit003 committed Jan 17, 2025
1 parent 514c210 commit 71b625a
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ _build
/build
phpunit.xml
composer.phar
composer.lock
vendor
/report
/build
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/IOFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class IOFactory
*/
public static function createWriter(PhpWord $phpWord, $name = 'Word2007')
{
if ($name !== 'WriterInterface' && !in_array($name, ['ODText', 'RTF', 'Word2007', 'HTML', 'PDF', 'EPUB'], true)) {
if ($name !== 'WriterInterface' && !in_array($name, ['ODText', 'RTF', 'Word2007', 'HTML', 'PDF', 'EPub3'], true)) {
throw new Exception("\"{$name}\" is not a valid writer.");
}

Expand Down
13 changes: 6 additions & 7 deletions src/PhpWord/Writer/ePub3.php → src/PhpWord/Writer/EPub3.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
Expand All @@ -19,17 +20,15 @@

use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Writer\ePub3\Part\AbstractPart;
use PhpOffice\PhpWord\Writer\EPub3\Part\AbstractPart;

/**
* ePub3 writer.
* EPub3 writer.
*/
class ePub3 extends AbstractWriter implements WriterInterface
class EPub3 extends AbstractWriter implements WriterInterface
{
/**
* Create new ePub3 writer.
*
* @param \PhpOffice\PhpWord\PhpWord
* Create new EPub3 writer.
*/
public function __construct(?PhpWord $phpWord = null)
{
Expand All @@ -47,7 +46,7 @@ public function __construct(?PhpWord $phpWord = null)
foreach (array_keys($this->parts) as $partName) {
$partClass = static::class . '\\Part\\' . $partName;
if (class_exists($partClass)) {
/** @var \PhpOffice\PhpWord\Writer\ePub3\Part\AbstractPart $partObject Type hint */
/** @var AbstractPart $partObject Type hint */
$partObject = new $partClass();
$partObject->setParentWriter($this);
$this->writerParts[strtolower($partName)] = $partObject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
Expand All @@ -15,19 +16,19 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWord\Writer\ePub3\Part;
namespace PhpOffice\PhpWord\Writer\EPub3\Part;

use PhpOffice\PhpWord\Writer\AbstractWriter;

/**
* Abstract class for ePub3 parts.
* Abstract class for EPub3 parts.
*/
abstract class AbstractPart
{
/**
* Parent writer.
*
* @var \PhpOffice\PhpWord\Writer\AbstractWriter
* @var AbstractWriter
*/
protected $parentWriter;

Expand All @@ -46,7 +47,7 @@ public function setParentWriter(AbstractWriter $writer)
/**
* Get parent writer.
*
* @return \PhpOffice\PhpWord\Writer\AbstractWriter
* @return AbstractWriter
*/
public function getParentWriter()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
Expand All @@ -15,10 +16,10 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWord\Writer\ePub3\Part;
namespace PhpOffice\PhpWord\Writer\EPub3\Part;

/**
* Class for ePub3 content part.
* Class for EPub3 content part.
*/
class Content extends AbstractPart
{
Expand All @@ -32,7 +33,7 @@ public function write()
$content = '<?xml version="1.0" encoding="UTF-8"?>';
$content .= '<package xmlns="http://www.idpf.org/2007/opf" version="3.0">';
$content .= '<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">';
$content .= '<dc:title>Sample ePub3 Document</dc:title>';
$content .= '<dc:title>Sample EPub3 Document</dc:title>';
$content .= '<dc:language>en</dc:language>';
$content .= '</metadata>';
$content .= '<manifest>';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
Expand All @@ -15,10 +16,10 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWord\Writer\ePub3\Part;
namespace PhpOffice\PhpWord\Writer\EPub3\Part;

/**
* Class for ePub3 manifest part.
* Class for EPub3 manifest part.
*/
class Manifest extends AbstractPart
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
Expand All @@ -15,10 +16,10 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWord\Writer\ePub3\Part;
namespace PhpOffice\PhpWord\Writer\EPub3\Part;

/**
* Class for ePub3 metadata part.
* Class for EPub3 metadata part.
*/
class Meta extends AbstractPart
{
Expand All @@ -31,7 +32,7 @@ public function write()
{
$content = '<?xml version="1.0" encoding="UTF-8"?>';
$content .= '<metadata xmlns="http://www.idpf.org/2007/opf">';
$content .= '<dc:title>Sample ePub3 Document</dc:title>';
$content .= '<dc:title>Sample EPub3 Document</dc:title>';
$content .= '<dc:language>en</dc:language>';
$content .= '<dc:identifier id="bookid">urn:uuid:12345</dc:identifier>';
$content .= '<meta property="dcterms:modified">2023-01-01T00:00:00Z</meta>';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
Expand All @@ -15,10 +16,10 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWord\Writer\ePub3\Part;
namespace PhpOffice\PhpWord\Writer\EPub3\Part;

/**
* Class for ePub3 mimetype part.
* Class for EPub3 mimetype part.
*/
class Mimetype extends AbstractPart
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
Expand All @@ -15,19 +16,19 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWord\Writer\ePub3\Style;
namespace PhpOffice\PhpWord\Writer\EPub3\Style;

use PhpOffice\PhpWord\Writer\AbstractWriter;

/**
* Abstract class for ePub3 styles.
* Abstract class for EPub3 styles.
*/
abstract class AbstractStyle
{
/**
* Parent writer.
*
* @var \PhpOffice\PhpWord\Writer\AbstractWriter
* @var AbstractWriter
*/
protected $parentWriter;

Expand All @@ -46,7 +47,7 @@ public function setParentWriter(AbstractWriter $writer)
/**
* Get parent writer.
*
* @return \PhpOffice\PhpWord\Writer\AbstractWriter
* @return AbstractWriter
*/
public function getParentWriter()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
Expand All @@ -15,10 +16,10 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWord\Writer\ePub3\Style;
namespace PhpOffice\PhpWord\Writer\EPub3\Style;

/**
* Class for ePub3 font styles.
* Class for EPub3 font styles.
*/
class Font extends AbstractStyle
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
Expand All @@ -15,10 +16,10 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWord\Writer\ePub3\Style;
namespace PhpOffice\PhpWord\Writer\EPub3\Style;

/**
* Class for ePub3 paragraph styles.
* Class for EPub3 paragraph styles.
*/
class Paragraph extends AbstractStyle
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
Expand All @@ -15,10 +16,10 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWord\Writer\ePub3\Style;
namespace PhpOffice\PhpWord\Writer\EPub3\Style;

/**
* Class for ePub3 table styles.
* Class for EPub3 table styles.
*/
class Table extends AbstractStyle
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
Expand All @@ -19,21 +20,21 @@

use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\Writer\ePub3;
use PhpOffice\PhpWord\Writer\EPub3;

/**
* Test class for PhpOffice\PhpWord\Writer\Epub3.
*
* @runTestsInSeparateProcesses
*/
class ePub3Test extends \PHPUnit\Framework\TestCase
class EPub3Test extends \PHPUnit\Framework\TestCase
{
/**
* Test document construction.
*/
public function testConstruct(): void
{
$object = new ePub3(new PhpWord());
$object = new EPub3(new PhpWord());
self::assertInstanceOf(PhpWord::class, $object->getPhpWord());
self::assertEquals('./', $object->getDiskCachingDirectory());
foreach (['Content', 'Manifest', 'Mimetype'] as $part) {
Expand All @@ -55,7 +56,7 @@ public function testConstructWithNull(): void
{
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
$this->expectExceptionMessage('No PhpWord assigned.');
$object = new ePub3();
$object = new EPub3();
$object->getPhpWord();
}

Expand All @@ -76,7 +77,7 @@ public function testSave(): void
$section->addTitle('Test', 1);
$section->addPageBreak();
$section->addImage($imageSrc);
$writer = new ePub3($phpWord);
$writer = new EPub3($phpWord);
$writer->save($file);
self::assertFileExists($file);
unlink($file);
Expand All @@ -90,7 +91,7 @@ public function testSavePhpOutput(): void
$phpWord = new PhpWord();
$section = $phpWord->addSection();
$section->addText('Test');
$writer = new ePub3($phpWord);
$writer = new EPub3($phpWord);
ob_start();
$writer->save('php://output');
$contents = ob_get_contents();
Expand All @@ -103,7 +104,7 @@ public function testSavePhpOutput(): void
*/
public function testSetGetUseDiskCaching(): void
{
$object = new ePub3();
$object = new EPub3();
$object->setUseDiskCaching(true, PHPWORD_TESTS_BASE_DIR);
self::assertTrue($object->isUseDiskCaching());
self::assertEquals(PHPWORD_TESTS_BASE_DIR, $object->getDiskCachingDirectory());
Expand All @@ -117,7 +118,7 @@ public function testSetUseDiskCachingException(): void
$this->expectException(\PhpOffice\PhpWord\Exception\Exception::class);
$dir = implode(DIRECTORY_SEPARATOR, [PHPWORD_TESTS_BASE_DIR, 'foo']);

$object = new ePub3();
$object = new EPub3();
$object->setUseDiskCaching(true, $dir);
}
}

0 comments on commit 71b625a

Please sign in to comment.