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..70831e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,27 +7,33 @@ cache: - $HOME/.composer/cache php: - - 5.3 - 5.4 - 5.5 - 5.6 - 7.0 - - 7.1 matrix: include: + - php: 5.3 + dist: precise - 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="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 - allow_failures: - - php: 7.0 - - php: 7.1 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/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 .` diff --git a/Resources/config/services.yml b/Resources/config/services.yml index e461300..b8eeb17 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -2,5 +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/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..a4111bd 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": [ { @@ -17,17 +17,17 @@ "homepage": "http://www.welcometothebundle.com", "license": "MIT", "require": { - "php": ">=5.3.2", - "symfony/framework-bundle": "~2.6|~3.0", + "php": "^5.3.2|^7.0", + "symfony/framework-bundle": "~2.6|~3.0|^4.0", "phpoffice/phpexcel": "~1.8.1" }, "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": "^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", + "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 @@ + 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