Skip to content

Commit

Permalink
Encapsulate reader and writer options.
Browse files Browse the repository at this point in the history
  • Loading branch information
comfortablynumb committed Dec 27, 2015
1 parent aee4743 commit 38735bf
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,17 @@ public function load(array $options = [])
{
$options = array_merge(
[
'strategy' => $this->getOption('defaultLoadStrategy')
'file' => null,
'strategy' => $this->getOption('defaultLoadStrategy'),
'readerOptions' => []
],
$options
);

$data = $this->getReader()->read($options);
// Simple shortcut
$options['readerOptions']['file'] = $options['file'];

$data = $this->getReader()->read($options['readerOptions']);

switch ($options['strategy']) {
case self::LOAD_STRATEGY_CLEAR:
Expand Down Expand Up @@ -209,6 +214,17 @@ public function load(array $options = [])
*/
public function save(array $options = [])
{
$options = array_merge(
[
'file' => null,
'writerOptions' => []
],
$options
);

// Simple shortcut
$options['writerOptions']['file'] = $options['file'];

/** @var Callable $callable */
$callable = $this->getOption('onBeforeSave');

Expand All @@ -218,7 +234,7 @@ public function save(array $options = [])

$callable($this, $options);

$this->getWriter()->write($this->getData(), $options);
$this->getWriter()->write($this->getData(), $options['writerOptions']);

return $this;
}
Expand Down

0 comments on commit 38735bf

Please sign in to comment.