Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MAXakaWIZARD committed Apr 17, 2015
1 parent ad9504f commit e672185
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,32 @@ class Parser
*
* @throws \Exception
*/
public function __construct(
$adapterName,
$xgettextBin
) {
$this->basePath = realpath(__DIR__.'/..');
public function __construct($adapterName, $xgettextBin)
{
$this->basePath = realpath(__DIR__ . '/..');

//init files
$this->logPath = $this->basePath . '/po_parser.log';
$this->resultPath = sys_get_temp_dir() . '/poedit_' . $adapterName . '_' . md5(microtime()) . '.php';

$this->setXgettextBin($xgettextBin);

$this->loadAdapter($adapterName);
}

/**
* @param $xgettextBin
*
* @throws \Exception
*/
protected function setXgettextBin($xgettextBin)
{
if (!is_file($xgettextBin)) {
throw new \Exception('Invalid xgettext binary path supplied');
}

$this->xgettextBin = $xgettextBin;
$this->xgettextDir = dirname($this->xgettextBin);

if (is_string($adapterName) && $adapterName !== '') {
$this->loadAdapter($adapterName);
} else {
throw new \Exception('Invalid adapterName supplied');
}
}

/**
Expand All @@ -92,6 +96,10 @@ public function __construct(
*/
protected function loadAdapter($adapterName)
{
if (!is_string($adapterName) || $adapterName === '') {
throw new \Exception('Invalid adapterName supplied');
}

$targetClassName = '\\GettextParser\\Adapter\\' . $adapterName;

if (class_exists($targetClassName)) {
Expand Down

0 comments on commit e672185

Please sign in to comment.