-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
65 changed files
with
2,778 additions
and
2,183 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace Ergnuor\SphinxConfig; | ||
|
||
class Config | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $placeholderValues = []; | ||
|
||
/** | ||
* @var Section\Reader\Adapter | ||
*/ | ||
private $sectionReaderAdapter; | ||
|
||
/** | ||
* @var Section\Writer\Adapter | ||
*/ | ||
private $sectionWriterAdapter; | ||
|
||
/** | ||
* @param Section\Reader\Adapter $sectionReaderAdapter | ||
* @param Section\Writer\Adapter $sectionWriterAdapter | ||
*/ | ||
public function __construct( | ||
Section\Reader\Adapter $sectionReaderAdapter, | ||
Section\Writer\Adapter $sectionWriterAdapter | ||
) | ||
{ | ||
$this->sectionReaderAdapter = $sectionReaderAdapter; | ||
$this->sectionWriterAdapter = $sectionWriterAdapter; | ||
} | ||
|
||
public static function phpArrayToNativeConfigStdout($srcPath) | ||
{ | ||
return new static( | ||
new Section\Reader\Adapter\File\PhpArray($srcPath), | ||
new Section\Writer\Adapter\NativeConfig() | ||
); | ||
} | ||
|
||
public static function phpArrayToNativeConfigFile($srcPath, $dstPath) | ||
{ | ||
return new static( | ||
new Section\Reader\Adapter\File\PhpArray($srcPath), | ||
new Section\Writer\Adapter\NativeConfig($dstPath) | ||
); | ||
} | ||
|
||
/** | ||
* @param string $configName | ||
* @return $this | ||
*/ | ||
public function transform($configName) | ||
{ | ||
$sections = Section\Type::getTypes(); | ||
|
||
$this->sectionWriterAdapter->reset(); | ||
$this->sectionReaderAdapter->reset(); | ||
|
||
foreach ($sections as $sectionName) { | ||
$section = new Section( | ||
$configName, | ||
$sectionName, | ||
$this->sectionReaderAdapter, | ||
$this->sectionWriterAdapter, | ||
$this->getPlaceholderValues() | ||
); | ||
$section->transform(); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getPlaceholderValues() | ||
{ | ||
return $this->placeholderValues; | ||
} | ||
|
||
/** | ||
* @param array $placeholderValues | ||
* @return Config | ||
*/ | ||
public function setPlaceholderValues(array $placeholderValues) | ||
{ | ||
$this->placeholderValues = $placeholderValues; | ||
return $this; | ||
} | ||
} |
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
Oops, something went wrong.