From 288cd6b4da1989ecfdb44db14b4d9a327a3003de Mon Sep 17 00:00:00 2001 From: Giulio De Donato Date: Fri, 27 Apr 2012 16:28:46 +0200 Subject: [PATCH] moved logic into yml --- README.md | 2 + Resources/config/services.yml | 24 +++++--- Service/ExcelContainer.php | 107 +--------------------------------- 3 files changed, 22 insertions(+), 111 deletions(-) diff --git a/README.md b/README.md index 28de993..75e84eb 100644 --- a/README.md +++ b/README.md @@ -130,3 +130,5 @@ if you need PDF, or XLS7 see and modify ``liuggio\ExcelBundle\Resources\config\s ## TEST + + diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 738516b..987c373 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -11,21 +11,25 @@ parameters: services: xls.phpexcel: class: %xls.phpexcel.class% - xls.response: - class: %xls.stream_response.class% - xls.stream_writer_output: - class: %xls.stream_writer.class% - argument: "php://output" + #factory for xls5 xls.factory_xls5: class: %xls.factory5.method% factory_class: %xls.factory.class% factory_method: createWriter arguments: [@xls.phpexcel, "Excel5"] +#setter injection + xls.stream_writer_output_xls5: + class: %xls.stream_writer.class% + argument: "php://output" + calls: + - [ setWriter, [ @xls.factory_xls5, %xls.factory.write_method% ] ] + #service to call xls.service_xls5: class: %xls.service.class% - arguments: [@xls.phpexcel, @xls.factory_xls5, %xls.factory.write_method%, @xls.stream_writer_output, %xls.stream_response.class%] + arguments: [@xls.phpexcel, @xls.stream_writer_output_xls5, %xls.stream_response.class%] + # if you need to create another PHP object #factory for another format xls.factory_pdf: @@ -33,7 +37,13 @@ services: factory_class: %xls.factory.class% factory_method: createWriter arguments: [@xls.phpexcel, "PDF"] +#setter injection + xls.stream_writer_output_PDF: + class: %xls.stream_writer.class% + argument: "php://output" + calls: + - [ setWriter, [ @xls.factory_pdf, %xls.factory.write_method% ] ] #service to call xls.service_pdf: class: %xls.service.class% - arguments: [@xls.phpexcel, @xls.factory_pdf, %xls.factory.write_method%, @xls.stream_writer_output, %xls.stream_response.class%] + arguments: [@xls.phpexcel, @xls.stream_writer_output_PDF, %xls.stream_response.class%] diff --git a/Service/ExcelContainer.php b/Service/ExcelContainer.php index 66668ed..5303d91 100644 --- a/Service/ExcelContainer.php +++ b/Service/ExcelContainer.php @@ -12,14 +12,6 @@ class ExcelContainer * @var */ public $excelObj; - /** - * @var - */ - protected $factory_writer; - /** - * @var - */ - protected $factory_write_method; /** * @var */ @@ -30,7 +22,6 @@ class ExcelContainer protected $response_service; - /** * @param $excelObj * @param $factory_writer @@ -38,29 +29,15 @@ class ExcelContainer * @param $stream_writer * @param $response_service */ - public function __construct($excelObj, $factory_writer, $factory_write_method = 'save', $stream_writer, $response_service) + + public function __construct($excelObj, $stream_writer, $response_service) { $this->setExcelObj($excelObj); - $this->setFactoryWriter($factory_writer); - $this->setFactoryWriteMethod($factory_write_method); $this->setStreamWriter($stream_writer); $this->setResponseService($response_service); } - - - /** - * This function populate the StreamWriter - * @return streamwriter - */ - public function createStreamWriter() - { - $writer = $this->getFactoryWriter(); - $this->getStreamWriter()->setWriter($writer, $this->getFactoryWriteMethod()); - return $this->getStreamWriter(); - } - /* * create the response with the file content * @@ -69,17 +46,15 @@ public function createStreamWriter() public function getResponse() { $responsiveClass = $this->getResponseService(); - return new $responsiveClass($this->createStreamWriter()); + return new $responsiveClass($this->getStreamWriter()); } - /* * * Getters and setters * */ - /** * @param $excelObj */ @@ -96,69 +71,7 @@ public function getExcelObj() return $this->excelObj; } - /** - * @param $factory_class - */ - public function setFactoryWriter($factory_writer) - { - $this->factory_writer = $factory_writer; - } - /** - * @return - */ - public function getFactoryWriter() - { - return $this->factory_writer; - } - - /** - * @param $factory_method - */ - public function setFactoryMethod($factory_method) - { - $this->factory_method = $factory_method; - } - - /** - * @return - */ - public function getFactoryMethod() - { - return $this->factory_method; - } - - /** - * @param string $factory_write_method - */ - public function setFactoryWriteMethod($factory_write_method) - { - $this->factory_write_method = $factory_write_method; - } - - /** - * @return string - */ - public function getFactoryWriteMethod() - { - return $this->factory_write_method; - } - - /** - * @param string $file_type - */ - public function setFileType($file_type) - { - $this->file_type = $file_type; - } - - /** - * @return string - */ - public function getFileType() - { - return $this->file_type; - } /** * @param $response_service @@ -192,19 +105,5 @@ public function getStreamWriter() return $this->stream_writer; } - /** - * @param $writer - */ - public function setWriter($writer) - { - $this->writer = $writer; - } - /** - * @return - */ - public function getWriter() - { - return $this->writer; - } }