-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from greg0ire/mime_typed_writer
When applicable, provide mime type
- Loading branch information
Showing
12 changed files
with
210 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,10 @@ | |
|
||
use Exporter\Exception\InvalidDataFormatException; | ||
|
||
class CsvWriter implements WriterInterface | ||
/** | ||
* @author Thomas Rabaix <[email protected]> | ||
*/ | ||
class CsvWriter implements TypedWriterInterface | ||
{ | ||
/** | ||
* @var string | ||
|
@@ -78,6 +81,22 @@ public function __construct($filename, $delimiter = ',', $enclosure = '"', $esca | |
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
final public function getDefaultMimeType() | ||
{ | ||
return 'text/csv'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
final public function getFormat() | ||
{ | ||
return 'csv'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,10 @@ | |
|
||
namespace Exporter\Writer; | ||
|
||
class JsonWriter implements WriterInterface | ||
/** | ||
* @author Thomas Rabaix <[email protected]> | ||
*/ | ||
class JsonWriter implements TypedWriterInterface | ||
{ | ||
/** | ||
* @var string | ||
|
@@ -41,6 +44,22 @@ public function __construct($filename) | |
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
final public function getDefaultMimeType() | ||
{ | ||
return 'application/json'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
final public function getFormat() | ||
{ | ||
return 'json'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Exporter\Writer; | ||
|
||
/** | ||
* @author Grégoire Paris <[email protected]> | ||
*/ | ||
interface TypedWriterInterface extends WriterInterface | ||
{ | ||
/** | ||
* There can be several mime types for a given format, this method should | ||
* return the most appopriate / popular one. | ||
* | ||
* @return string the mime type of the output | ||
*/ | ||
public function getDefaultMimeType(); | ||
|
||
/** | ||
* Returns a string best describing the format of the output (the file | ||
* extension is fine, for example). | ||
* | ||
* @return string a string without spaces, usable in a translation string | ||
*/ | ||
public function getFormat(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,10 @@ | |
|
||
namespace Exporter\Writer; | ||
|
||
class XlsWriter implements WriterInterface | ||
/** | ||
* @author Thomas Rabaix <[email protected]> | ||
*/ | ||
class XlsWriter implements TypedWriterInterface | ||
{ | ||
/** | ||
* @var string | ||
|
@@ -50,6 +53,22 @@ public function __construct($filename, $showHeaders = true) | |
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
final public function getDefaultMimeType() | ||
{ | ||
return 'application/vnd.ms-excel'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
final public function getFormat() | ||
{ | ||
return 'xls'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,10 @@ | |
|
||
use Exporter\Exception\InvalidDataFormatException; | ||
|
||
class XmlWriter implements WriterInterface | ||
/** | ||
* @author Thomas Rabaix <[email protected]> | ||
*/ | ||
class XmlWriter implements TypedWriterInterface | ||
{ | ||
/** | ||
* @var string | ||
|
@@ -57,6 +60,22 @@ public function __construct($filename, $mainElement = 'datas', $childElement = ' | |
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
final public function getDefaultMimeType() | ||
{ | ||
return 'text/xml'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
final public function getFormat() | ||
{ | ||
return 'xml'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Exporter\Test\Writer; | ||
|
||
use Exporter\Writer\WriterInterface; | ||
|
||
/** | ||
* @author Grégoire Paris <[email protected]> | ||
*/ | ||
abstract class AbstractTypedWriterTestCase extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var WriterInterface | ||
*/ | ||
private $writer; | ||
|
||
protected function setUp() | ||
{ | ||
$this->writer = $this->getWriter(); | ||
} | ||
|
||
public function testFormatIsString() | ||
{ | ||
$this->assertInternalType('string', $this->writer->getFormat()); | ||
} | ||
|
||
public function testDefaultMimeTypeIsString() | ||
{ | ||
$this->assertInternalType('string', $this->writer->getDefaultMimeType()); | ||
} | ||
|
||
/** | ||
* Should return a very simple instance of the writer (no need for complex | ||
* configuration). | ||
* | ||
* @return WriterInterface | ||
*/ | ||
abstract protected function getWriter(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters