From 345c6c44fc1bef558e815be8ae6e331472e4a29d Mon Sep 17 00:00:00 2001 From: Jan Gregor Emge-Triebel Date: Sat, 18 Nov 2017 11:05:20 +0200 Subject: [PATCH 01/10] Prepare for symfony 4 --- .gitignore | 1 + .travis.yml | 2 ++ Resources/config/services.yml | 1 + Tests/FactoryTest.php | 2 +- Tests/bootstrap.php | 1 + composer.json | 19 ++++++++++--------- phpunit.xml.dist | 1 + 7 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index b70ddad..f1feda2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ bin vendor Tests/app/cache +composer.lock diff --git a/.travis.yml b/.travis.yml index 243624e..dfd24a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,8 @@ matrix: env: SYMFONY_VERSION="2.8.*@dev symfony/phpunit-bridge:~2.7" - php: 5.6 env: SYMFONY_VERSION="3.0.*@dev" + - php: 7.1 + env: SYMFONY_VERSION="^4.0-BETA" - php: hhvm dist: trusty allow_failures: diff --git a/Resources/config/services.yml b/Resources/config/services.yml index e461300..3bbb65c 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -4,3 +4,4 @@ parameters: services: phpexcel: class: '%phpexcel.class%' + public: true diff --git a/Tests/FactoryTest.php b/Tests/FactoryTest.php index 3a54b01..5d81211 100644 --- a/Tests/FactoryTest.php +++ b/Tests/FactoryTest.php @@ -26,7 +26,7 @@ public function testCreateWriter() public function testCreateStreamedResponse() { - $writer = $this->getMock('\PHPExcel_Writer_IWriter'); + $writer = $this->getMockBuilder('\PHPExcel_Writer_IWriter')->getMock(); $writer->expects($this->once()) ->method('save') ->with('php://output'); diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index 444e2fd..282a421 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -8,3 +8,4 @@ $autoload = require_once $file; require_once __DIR__ . '/app/Controller/FakeController.php'; +require_once __DIR__ . '/app/AppKernel.php'; diff --git a/composer.json b/composer.json index fdfbdd4..6d51a29 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "liuggio/excelbundle", - "description": "This is a Symfony2 Bundle helps you to read and write Excel files (including pdf, xlsx, odt), thanks to the PHPExcel library", + "description": "This is a Symfony Bundle helps you to read and write Excel files (including pdf, xlsx, odt), thanks to the PHPExcel library", "type": "symfony-bundle", "authors": [ { @@ -18,16 +18,17 @@ "license": "MIT", "require": { "php": ">=5.3.2", - "symfony/framework-bundle": "~2.6|~3.0", - "phpoffice/phpexcel": "~1.8.1" + "symfony/framework-bundle": "~2.6|~3.0|^4.0", + "phpoffice/phpexcel": "~1.8.1", + "symfony/symfony": "^4.0-BETA" }, "require-dev": { - "phpunit/phpunit": "~4.6", - "symfony/finder": "~2.6|~3.0", - "symfony/form": "~2.6|~3.0", - "symfony/class-loader": "~2.6|~3.0", - "symfony/validator": "~2.6|~3.0", - "symfony/browser-kit": "~2.6|~3.0", + "phpunit/phpunit": "^5.0", + "symfony/finder": "~2.6|~3.0|^4.0", + "symfony/form": "~2.6|~3.0|^4.0", + "symfony/class-loader": "~2.6|~3.0|^4.0", + "symfony/validator": "~2.6|~3.0|^4.0", + "symfony/browser-kit": "~2.6|~3.0|^4.0", "sensio/framework-extra-bundle": "~2.3|~3.0" }, "autoload": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b651f9a..60fb3b5 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,5 +11,6 @@ + From 0e23f223cbcadfb2ec846e92c9e6d4ee055d9332 Mon Sep 17 00:00:00 2001 From: Jan Gregor Emge-Triebel Date: Sat, 18 Nov 2017 11:21:11 +0200 Subject: [PATCH 02/10] Set symfony 3 as default for all non php 7.1 installations --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index dfd24a9..782f275 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,7 @@ matrix: before_install: - composer self-update + - if [[ "$SYMFONY_VERSION" == "" ]]; then composer require --no-update symfony/symfony:3.0.*@dev; fi - if [[ "$SYMFONY_VERSION" != "" ]]; then composer require --no-update symfony/symfony:${SYMFONY_VERSION}; fi install: From 16937dc37bcbd48356fc8caa1bdbbecb37e24117 Mon Sep 17 00:00:00 2001 From: Jan Gregor Emge-Triebel Date: Sat, 18 Nov 2017 11:32:34 +0200 Subject: [PATCH 03/10] Updated travis build matrix --- .travis.yml | 4 ---- composer.json | 7 +++---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 782f275..3492fab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,14 +24,10 @@ matrix: env: SYMFONY_VERSION="^4.0-BETA" - php: hhvm dist: trusty - allow_failures: - - php: 7.0 - - php: 7.1 fast_finishe: true before_install: - composer self-update - - if [[ "$SYMFONY_VERSION" == "" ]]; then composer require --no-update symfony/symfony:3.0.*@dev; fi - if [[ "$SYMFONY_VERSION" != "" ]]; then composer require --no-update symfony/symfony:${SYMFONY_VERSION}; fi install: diff --git a/composer.json b/composer.json index 6d51a29..a4111bd 100644 --- a/composer.json +++ b/composer.json @@ -17,13 +17,12 @@ "homepage": "http://www.welcometothebundle.com", "license": "MIT", "require": { - "php": ">=5.3.2", + "php": "^5.3.2|^7.0", "symfony/framework-bundle": "~2.6|~3.0|^4.0", - "phpoffice/phpexcel": "~1.8.1", - "symfony/symfony": "^4.0-BETA" + "phpoffice/phpexcel": "~1.8.1" }, "require-dev": { - "phpunit/phpunit": "^5.0", + "phpunit/phpunit": "^4.7|^5.0", "symfony/finder": "~2.6|~3.0|^4.0", "symfony/form": "~2.6|~3.0|^4.0", "symfony/class-loader": "~2.6|~3.0|^4.0", From 2de52544d125a454df866dd47c6c5d96ed19bf16 Mon Sep 17 00:00:00 2001 From: Jan Gregor Emge-Triebel Date: Sat, 18 Nov 2017 11:42:56 +0200 Subject: [PATCH 04/10] Moved PHP5.3 build to precise dist --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3492fab..337901b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ cache: - $HOME/.composer/cache php: - - 5.3 - 5.4 - 5.5 - 5.6 @@ -16,6 +15,8 @@ php: matrix: include: + - php: 5.3 + dist: precise - php: 5.6 env: SYMFONY_VERSION="2.8.*@dev symfony/phpunit-bridge:~2.7" - php: 5.6 From ebd0f04eb0a2dd7b8a0c8c5cb18e45bdb9c3a05a Mon Sep 17 00:00:00 2001 From: Jan Gregor Emge-Triebel Date: Fri, 8 Dec 2017 10:05:30 +0100 Subject: [PATCH 05/10] Moved to FQCN as service name --- Resources/config/services.yml | 9 ++++++++- Tests/app/Controller/FakeController.php | 16 +++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 3bbb65c..d081458 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -2,6 +2,13 @@ parameters: phpexcel.class: Liuggio\ExcelBundle\Factory services: - phpexcel: + Liuggio\ExcelBundle\Factory: class: '%phpexcel.class%' public: true + + # + # This is alias is for legacy support only and will/can be removed soon + # + phpexcel: + alias: Liuggio\ExcelBundle\Factory: + public: true diff --git a/Tests/app/Controller/FakeController.php b/Tests/app/Controller/FakeController.php index b3e48f4..3044378 100644 --- a/Tests/app/Controller/FakeController.php +++ b/Tests/app/Controller/FakeController.php @@ -4,6 +4,8 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Response; +use Liuggio\ExcelBundle\Factory; + class FakeController extends Controller { @@ -12,9 +14,9 @@ public function streamAction() // create an empty object $phpExcelObject = $this->createXSLObject(); // create the writer - $writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5'); + $writer = $this->get(Factory::class)->createWriter($phpExcelObject, 'Excel5'); // create the response - $response = $this->get('phpexcel')->createStreamedResponse($writer); + $response = $this->get(Factory::class)->createStreamedResponse($writer); // adding headers $response->headers->set('Content-Type', 'text/vnd.ms-excel; charset=utf-8'); $response->headers->set('Content-Disposition', 'attachment;filename=stream-file.xls'); @@ -29,7 +31,7 @@ public function storeAction() // create an empty object $phpExcelObject = $this->createXSLObject(); // create the writer - $writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5'); + $writer = $this->get(Factory::class)->createWriter($phpExcelObject, 'Excel5'); $filename = tempnam(sys_get_temp_dir(), 'xls-') . '.xls'; // create filename $writer->save($filename); @@ -42,7 +44,7 @@ public function readerAction() $filename = $this->container->getParameter('xls_fixture_absolute_path'); // load the factory /** @var \Liuggio\ExcelBundle\Factory $reader */ - $factory = $this->get('phpexcel'); + $factory = $this->get(Factory::class); // create a reader /** @var \PHPExcel_Reader_IReader $reader */ $reader = $factory->createReader('Excel5'); @@ -68,7 +70,7 @@ public function readAndSaveAction() // create an object from a filename $phpExcelObject = $this->createXSLObject($filename); // create the writer - $writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5'); + $writer = $this->get(Factory::class)->createWriter($phpExcelObject, 'Excel5'); $filename = tempnam(sys_get_temp_dir(), 'xls-') . '.xls'; // create filename $writer->save($filename); @@ -82,9 +84,9 @@ public function readAndSaveAction() */ private function createXSLObject() { - $phpExcelObject = $this->get('phpexcel')->createPHPExcelObject(); + $phpExcelObject = $this->get(Factory::class)->createPHPExcelObject(); - $htmlHelper = $this->get('phpexcel')->createHelperHTML(); + $htmlHelper = $this->get(Factory::class)->createHelperHTML(); $phpExcelObject->getProperties()->setCreator("liuggio") ->setLastModifiedBy("Giulio De Donato") From 598129aafb4bebb319407a435cec3323d47ffddf Mon Sep 17 00:00:00 2001 From: Jan Gregor Emge-Triebel Date: Fri, 8 Dec 2017 10:12:51 +0100 Subject: [PATCH 06/10] typofix --- Resources/config/services.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/config/services.yml b/Resources/config/services.yml index d081458..b8eeb17 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -10,5 +10,5 @@ services: # This is alias is for legacy support only and will/can be removed soon # phpexcel: - alias: Liuggio\ExcelBundle\Factory: + alias: Liuggio\ExcelBundle\Factory public: true From 55848b57bfb02cfbc31527a5c87f80ffea8f9902 Mon Sep 17 00:00:00 2001 From: Jan Gregor Emge-Triebel Date: Mon, 11 Dec 2017 20:13:59 +0100 Subject: [PATCH 07/10] Fixes for travis tests --- Tests/app/Controller/FakeController.php | 16 +++++++--------- composer.json | 3 ++- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Tests/app/Controller/FakeController.php b/Tests/app/Controller/FakeController.php index 3044378..b3e48f4 100644 --- a/Tests/app/Controller/FakeController.php +++ b/Tests/app/Controller/FakeController.php @@ -4,8 +4,6 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Response; -use Liuggio\ExcelBundle\Factory; - class FakeController extends Controller { @@ -14,9 +12,9 @@ public function streamAction() // create an empty object $phpExcelObject = $this->createXSLObject(); // create the writer - $writer = $this->get(Factory::class)->createWriter($phpExcelObject, 'Excel5'); + $writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5'); // create the response - $response = $this->get(Factory::class)->createStreamedResponse($writer); + $response = $this->get('phpexcel')->createStreamedResponse($writer); // adding headers $response->headers->set('Content-Type', 'text/vnd.ms-excel; charset=utf-8'); $response->headers->set('Content-Disposition', 'attachment;filename=stream-file.xls'); @@ -31,7 +29,7 @@ public function storeAction() // create an empty object $phpExcelObject = $this->createXSLObject(); // create the writer - $writer = $this->get(Factory::class)->createWriter($phpExcelObject, 'Excel5'); + $writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5'); $filename = tempnam(sys_get_temp_dir(), 'xls-') . '.xls'; // create filename $writer->save($filename); @@ -44,7 +42,7 @@ public function readerAction() $filename = $this->container->getParameter('xls_fixture_absolute_path'); // load the factory /** @var \Liuggio\ExcelBundle\Factory $reader */ - $factory = $this->get(Factory::class); + $factory = $this->get('phpexcel'); // create a reader /** @var \PHPExcel_Reader_IReader $reader */ $reader = $factory->createReader('Excel5'); @@ -70,7 +68,7 @@ public function readAndSaveAction() // create an object from a filename $phpExcelObject = $this->createXSLObject($filename); // create the writer - $writer = $this->get(Factory::class)->createWriter($phpExcelObject, 'Excel5'); + $writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5'); $filename = tempnam(sys_get_temp_dir(), 'xls-') . '.xls'; // create filename $writer->save($filename); @@ -84,9 +82,9 @@ public function readAndSaveAction() */ private function createXSLObject() { - $phpExcelObject = $this->get(Factory::class)->createPHPExcelObject(); + $phpExcelObject = $this->get('phpexcel')->createPHPExcelObject(); - $htmlHelper = $this->get(Factory::class)->createHelperHTML(); + $htmlHelper = $this->get('phpexcel')->createHelperHTML(); $phpExcelObject->getProperties()->setCreator("liuggio") ->setLastModifiedBy("Giulio De Donato") diff --git a/composer.json b/composer.json index a4111bd..833bbc1 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "symfony/class-loader": "~2.6|~3.0|^4.0", "symfony/validator": "~2.6|~3.0|^4.0", "symfony/browser-kit": "~2.6|~3.0|^4.0", - "sensio/framework-extra-bundle": "~2.3|~3.0" + "sensio/framework-extra-bundle": "~2.3|~3.0", + "symfony/var-dumper": "^4.0" }, "autoload": { "exclude-from-classmap": ["/Tests/"], From 0f1855e9e7b5987be1ef9c37b3b36d8707a8e51c Mon Sep 17 00:00:00 2001 From: Jan Gregor Emge-Triebel Date: Tue, 12 Dec 2017 08:11:40 +0100 Subject: [PATCH 08/10] Removed var dumper --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 833bbc1..a4111bd 100644 --- a/composer.json +++ b/composer.json @@ -28,8 +28,7 @@ "symfony/class-loader": "~2.6|~3.0|^4.0", "symfony/validator": "~2.6|~3.0|^4.0", "symfony/browser-kit": "~2.6|~3.0|^4.0", - "sensio/framework-extra-bundle": "~2.3|~3.0", - "symfony/var-dumper": "^4.0" + "sensio/framework-extra-bundle": "~2.3|~3.0" }, "autoload": { "exclude-from-classmap": ["/Tests/"], From dd176cc73707e5528d15e9aedb535b61aab803c5 Mon Sep 17 00:00:00 2001 From: Adrian Zmenda Date: Tue, 2 Jan 2018 14:57:59 +0100 Subject: [PATCH 09/10] Tweak travis builds --- .travis.yml | 12 +++++++++--- travis.php.ini | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 travis.php.ini diff --git a/.travis.yml b/.travis.yml index 337901b..70831e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,6 @@ php: - 5.5 - 5.6 - 7.0 - - 7.1 matrix: include: @@ -20,14 +19,21 @@ matrix: - php: 5.6 env: SYMFONY_VERSION="2.8.*@dev symfony/phpunit-bridge:~2.7" - php: 5.6 - env: SYMFONY_VERSION="3.0.*@dev" + env: SYMFONY_VERSION="3.*@dev" - php: 7.1 - env: SYMFONY_VERSION="^4.0-BETA" + env: SYMFONY_VERSION="3.*@dev" + - php: 7.1 + env: SYMFONY_VERSION="4.*@dev" + - php: 7.2 + env: SYMFONY_VERSION="3.*@dev" + - php: 7.2 + env: SYMFONY_VERSION="4.*@dev" - php: hhvm dist: trusty fast_finishe: true before_install: + - phpenv config-add travis.php.ini - composer self-update - if [[ "$SYMFONY_VERSION" != "" ]]; then composer require --no-update symfony/symfony:${SYMFONY_VERSION}; fi diff --git a/travis.php.ini b/travis.php.ini new file mode 100644 index 0000000..5946850 --- /dev/null +++ b/travis.php.ini @@ -0,0 +1 @@ +memory_limit=-1 \ No newline at end of file From ef88ff35d067b401b8a7cffaa4d408d0e402d0a5 Mon Sep 17 00:00:00 2001 From: Adrian Zmenda Date: Tue, 2 Jan 2018 16:00:06 +0100 Subject: [PATCH 10/10] Small tweaks to README file regarding new service name and injecting excel factory --- README.md | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d2a41fb..4a95951 100644 --- a/README.md +++ b/README.md @@ -51,37 +51,37 @@ I encourage you to use the built-in function for csv: http://php.net/manual-look - Create an empty object: ``` php -$phpExcelObject = $this->get('phpexcel')->createPHPExcelObject(); +$phpExcelObject = $this->get('Liuggio\ExcelBundle\Factory')->createPHPExcelObject(); ``` - Create an object from a file: ``` php -$phpExcelObject = $this->get('phpexcel')->createPHPExcelObject('file.xls'); +$phpExcelObject = $this->get('Liuggio\ExcelBundle\Factoryl')->createPHPExcelObject('file.xls'); ``` - Create a Excel5 and write to a file given the object: ```php -$writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5'); +$writer = $this->get('Liuggio\ExcelBundle\Factory')->createWriter($phpExcelObject, 'Excel5'); $writer->save('file.xls'); ``` - Create a Excel5 and create a StreamedResponse: ```php -$writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5'); -$response = $this->get('phpexcel')->createStreamedResponse($writer); +$writer = $this->get('Liuggio\ExcelBundle\Factory')->createWriter($phpExcelObject, 'Excel5'); +$response = $this->get('Liuggio\ExcelBundle\Factory')->createStreamedResponse($writer); ``` - Create a Excel file with an image: ```php -$writer = $this->get('phpexcel')->createPHPExcelObject(); +$writer = $this->get('Liuggio\ExcelBundle\Factory')->createPHPExcelObject(); $writer->setActiveSheetIndex(0); $activesheet = $writer->getActiveSheet(); -$drawingobject = $this->get('phpexcel')->createPHPExcelWorksheetDrawing(); +$drawingobject = $this->get('Liuggio\ExcelBundle\Factory')->createPHPExcelWorksheetDrawing(); $drawingobject->setName('Image name'); $drawingobject->setDescription('Image description'); $drawingobject->setPath('/path/to/image'); @@ -91,6 +91,8 @@ $drawingobject->setCoordinates('A1'); $drawingobject->setWorksheet($activesheet) ``` +_Note: it's recommended to inject factory instead of fetching it from container_ + ## Not Only 'Excel5' The list of the types are: @@ -104,6 +106,7 @@ The list of the types are: 7. 'HTML' 8. 'CSV' + ## Example ### Fake Controller @@ -128,7 +131,8 @@ class DefaultController extends Controller public function indexAction($name) { // ask the service for a Excel5 - $phpExcelObject = $this->get('phpexcel')->createPHPExcelObject(); + $phpExcelObject = $this->get('Liuggio\ExcelBundle\Factory')->createPHPExcelObject(); + // or inject it: $phpExcelObject = $injectedExcelFactory->createPHPExcelObject(); $phpExcelObject->getProperties()->setCreator("liuggio") ->setLastModifiedBy("Giulio De Donato") @@ -145,9 +149,9 @@ class DefaultController extends Controller $phpExcelObject->setActiveSheetIndex(0); // create the writer - $writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel5'); + $writer = $this->get('Liuggio\ExcelBundle\Factory')->createWriter($phpExcelObject, 'Excel5'); // create the response - $response = $this->get('phpexcel')->createStreamedResponse($writer); + $response = $this->get('Liuggio\ExcelBundle\Factory')->createStreamedResponse($writer); // adding headers $dispositionHeader = $response->headers->makeDisposition( ResponseHeaderBag::DISPOSITION_ATTACHMENT, @@ -169,7 +173,7 @@ the [list of contributors](https://github.com/liuggio/ExcelBundle/graphs/contrib ## Contribute -1. fork the project -2. clone the repo -3. get the coding standard fixer: `wget http://cs.sensiolabs.org/get/php-cs-fixer.phar` -4. before the PullRequest you should run the coding standard fixer with `php php-cs-fixer.phar fix -v .` +1. Fork the project +1. Clone the repo +1. Get the coding standard fixer: `wget http://cs.sensiolabs.org/get/php-cs-fixer.phar` +1. Before the PullRequest you should run the coding standard fixer with `php php-cs-fixer.phar fix -v .`