Skip to content

Commit

Permalink
moved logic into yml
Browse files Browse the repository at this point in the history
  • Loading branch information
liuggio committed Apr 27, 2012
1 parent 025428a commit 288cd6b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 111 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -130,3 +130,5 @@ if you need PDF, or XLS7 see and modify ``liuggio\ExcelBundle\Resources\config\s

## TEST



24 changes: 17 additions & 7 deletions Resources/config/services.yml
Expand Up @@ -11,29 +11,39 @@ 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:
class: %xls.factoryPDF.method%
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%]
107 changes: 3 additions & 104 deletions Service/ExcelContainer.php
Expand Up @@ -12,14 +12,6 @@ class ExcelContainer
* @var
*/
public $excelObj;
/**
* @var
*/
protected $factory_writer;
/**
* @var
*/
protected $factory_write_method;
/**
* @var
*/
Expand All @@ -30,37 +22,22 @@ class ExcelContainer
protected $response_service;



/**
* @param $excelObj
* @param $factory_writer
* @param string $factory_write_method
* @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
*
Expand All @@ -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
*/
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 288cd6b

Please sign in to comment.