diff --git a/Classes/PHPWord/Autoloader.php b/Classes/PHPWord/Autoloader.php
index 9bd88596..0e740822 100755
--- a/Classes/PHPWord/Autoloader.php
+++ b/Classes/PHPWord/Autoloader.php
@@ -31,9 +31,13 @@ if (!defined('PHPWORD_BASE_PATH')) {
/**
* Class PHPWord_Autoloader
+ *
+ * TODO: remove legacy autoloader once everything is moved to namespaces
*/
class PHPWord_Autoloader
{
+ const PREFIX = 'PHPWord';
+
/**
* Register the autoloader
*
@@ -41,7 +45,8 @@ class PHPWord_Autoloader
*/
public static function register()
{
- spl_autoload_register(array('PHPWord_Autoloader', 'load'));
+ spl_autoload_register(array('PHPWord_Autoloader', 'load')); // Legacy
+ spl_autoload_register(array(new self, 'autoload')); // PSR-4
}
/**
@@ -60,4 +65,21 @@ class PHPWord_Autoloader
return null;
}
+
+ /**
+ * Autoloader
+ *
+ * @param string
+ */
+ public static function autoload($class)
+ {
+ $prefixLength = strlen(self::PREFIX);
+ if (0 === strncmp(self::PREFIX, $class, $prefixLength)) {
+ $file = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, $prefixLength));
+ $file = realpath(__DIR__ . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php');
+ if (file_exists($file)) {
+ require_once $file;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Tests/PHPWord/AutoloaderTest.php b/Tests/PHPWord/AutoloaderTest.php
index 33872466..f24c04e8 100644
--- a/Tests/PHPWord/AutoloaderTest.php
+++ b/Tests/PHPWord/AutoloaderTest.php
@@ -3,6 +3,7 @@ namespace PHPWord\Tests;
use PHPUnit_Framework_TestCase;
use PHPWord_Autoloader;
+use PHPWord_Autoloader as Autoloader;
class AutoloaderTest extends PHPUnit_Framework_TestCase
{
@@ -10,11 +11,22 @@ class AutoloaderTest extends PHPUnit_Framework_TestCase
{
PHPWord_Autoloader::register();
$this->assertContains(array('PHPWord_Autoloader', 'load'), spl_autoload_functions());
+ $this->assertContains(array('PHPWord_Autoloader', 'autoload'), spl_autoload_functions());
}
- public function testAutoload()
+ public function testAutoloadLegacy()
{
$this->assertNull(PHPWord_Autoloader::load('Foo'), 'PHPWord_Autoloader::load() is trying to load classes outside of the PHPWord namespace');
$this->assertTrue(PHPWord_Autoloader::load('PHPWord'), 'PHPWord_Autoloader::load() failed to autoload the PHPWord class');
}
+
+ public function testAutoload()
+ {
+ $declared = get_declared_classes();
+ $declaredCount = count($declared);
+ Autoloader::autoload('Foo');
+ $this->assertEquals($declaredCount, count(get_declared_classes()), 'PHPWord\\Autoloader::autoload() is trying to load classes outside of the PHPWord namespace');
+ Autoloader::autoload('PHPWord\\Exceptions\\InvalidStyleException'); // TODO change this class to the main PHPWord class when it is namespaced
+ $this->assertTrue(in_array('PHPWord\\Exceptions\\InvalidStyleException', get_declared_classes()), 'PHPWord\\Autoloader::autoload() failed to autoload the PHPWord\\Exceptions\\InvalidStyleException class');
+ }
}
\ No newline at end of file
diff --git a/changelog.txt b/changelog.txt
index dd952cae..63d8f626 100755
--- a/changelog.txt
+++ b/changelog.txt
@@ -26,9 +26,10 @@ Changes in branch for release 0.7.1 :
- Bugfix: (gabrielbull) - Fixed bug with cell styling
- Bugfix: (gabrielbull) - Fixed bug list items inside of cells
- Feature: (gabrielbull) - Word2007 : Support sections page numbering
+- Feature: (gabrielbull) - Word2007 : Added support for line height
- QA: (Progi1984) - UnitTests
-Fixed in branch for release 0.7.0 :
+Changes in branch for release 0.7.0 :
- Bugfix: (RomanSyroeshko) GH-32 - "Warning: Invalid error type specified in ...\PHPWord.php on line 226" is thrown when the specified template file is not found
- Bugfix: (RomanSyroeshko) GH-34 - PHPWord_Shared_String.IsUTF8 returns FALSE for Cyrillic UTF-8 input
- Bugfix: (RomanSyroeshko) GH-38 - Temporary files naming logic in PHPWord_Template can lead to a collision
@@ -37,7 +38,7 @@ Fixed in branch for release 0.7.0 :
- Feature: (kaystrobach) - Word2007 : Add rowspan and colspan to cells
- Feature: (RLovelett) - Word2007 : Support for tab stops
- Feature: (RLovelett) - Word2007 : Support Multiple headers
-- Feature: (gavroche) - Word2007 : Wrapping Styles to Images
+- Feature: (gabrielbull) - Word2007 : Wrapping Styles to Images
- General: (MarkBaker) - Add superscript/subscript styling in Excel2007 Writer
- General: (deds) - add indentation support to paragraphs
- General: (Progi1984) GH-27 - Support for Composer
@@ -45,4 +46,4 @@ Fixed in branch for release 0.7.0 :
- General: (Progi1984) - Added PHPWord_Exception and exception when could not copy the template
- General: (Progi1984) - IMPROVED : Moved examples out of Classes directory
- General: (Esmeraldo) CP-49 - IMPROVED : Advanced string replace in setValue for Template
-- Feature: (gavroche) - Added support for image wrapping style
+- Feature: (gabrielbull) - Added support for image wrapping style
diff --git a/composer.json b/composer.json
index 281b8297..8a73f471 100644
--- a/composer.json
+++ b/composer.json
@@ -11,7 +11,8 @@
},
{
"name": "Gabriel Bull",
- "email": "gavroche.bull@gmail.com"
+ "email": "me@gabrielbull.com",
+ "homepage": "http://gabrielbull.com/"
},
{
"name": "Franck Lefevre",
diff --git a/Tests/phpunit.xml.dist b/phpunit.xml.dist
similarity index 90%
rename from Tests/phpunit.xml.dist
rename to phpunit.xml.dist
index 49b6b41f..eaaa9dc2 100644
--- a/Tests/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -10,7 +10,7 @@
syntaxCheck="false">
- ./PHPWord/
+ ./Tests/PHPWord/