-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide valid formats from the format manager given a data type to fo…
…rmat.
- Loading branch information
1 parent
3c952e5
commit f43aeb9
Showing
8 changed files
with
214 additions
and
58 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
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
namespace Consolidation\OutputFormatters\StructuredData; | ||
|
||
use Consolidation\OutputFormatters\RestructureInterface; | ||
use Consolidation\OutputFormatters\FormatterOptions; | ||
use Consolidation\OutputFormatters\StructuredData\ListDataInterface; | ||
use Consolidation\OutputFormatters\Transformations\ReorderFields; | ||
use Consolidation\OutputFormatters\Transformations\TableTransformation; | ||
|
||
/** | ||
* Holds an array where each element of the array is one row, | ||
* and each row contains an associative array where the keys | ||
* are the field names, and the values are the field data. | ||
* | ||
* It is presumed that every row contains the same keys. | ||
*/ | ||
abstract class AbstractStructuredList extends \ArrayObject implements RestructureInterface, ListDataInterface | ||
{ | ||
protected $data; | ||
|
||
public function __construct($data) | ||
{ | ||
parent::__construct($data); | ||
} | ||
|
||
public abstract function restructure(FormatterOptions $options); | ||
|
||
public abstract function getListData(); | ||
|
||
protected function createTableTransformation($data, $options) | ||
{ | ||
$defaults = $this->defaultOptions(); | ||
|
||
$reorderer = new ReorderFields(); | ||
$fieldLabels = $reorderer->reorder($options->get('fields', $defaults), $options->get('field-labels', $defaults), $data); | ||
|
||
$tableTransformer = new TableTransformation($data, $fieldLabels, $options->get('row-labels', $defaults)); | ||
if ($options->get('list-orientation', $defaults)) { | ||
$tableTransformer->setLayout(TableTransformation::LIST_LAYOUT); | ||
} | ||
|
||
return $tableTransformer; | ||
} | ||
|
||
protected function defaultOptions() | ||
{ | ||
return [ | ||
'list-orientation' => false, | ||
'fields' => [], | ||
'field-labels' => [], | ||
'row-labels' => [], | ||
'default-fields' => [], | ||
]; | ||
} | ||
} |
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