Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for symfony 4 #SymfonyConHackday2017 #125

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin
vendor
Tests/app/cache
composer.lock
18 changes: 12 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo "Factoryl"

```

- 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');
Expand All @@ -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:
Expand All @@ -104,6 +106,7 @@ The list of the types are:
7. 'HTML'
8. 'CSV'


## Example

### Fake Controller
Expand All @@ -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")
Expand All @@ -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,
Expand All @@ -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 .`
10 changes: 9 additions & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions Tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
$autoload = require_once $file;

require_once __DIR__ . '/app/Controller/FakeController.php';
require_once __DIR__ . '/app/AppKernel.php';
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand All @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@

<php>
<server name="KERNEL_DIR" value="Tests/app" />
<env name="KERNEL_CLASS" value="AppKernel" />
</php>
</phpunit>
1 change: 1 addition & 0 deletions travis.php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
memory_limit=-1