Skip to content

Commit

Permalink
Merge pull request #3 from mrvnklm/master
Browse files Browse the repository at this point in the history
added configpath parameter and delete method
  • Loading branch information
DivineOmega authored Jan 7, 2019
2 parents 2fe6266 + ccffbfa commit af19c57
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ $amazonConfig->setMWSAuthToken('ABC');
$amazonConfig->setAmazonServiceURL('https://mws.amazonservices.com/');
$amazonConfig->setLogPath('/tmp/amazon-log.txt');
$amazonConfig->setMuteLog(false);
$amazonConfig->setConfigPath('/tmp/config/config-file.php');

// Save out Amazon config to a file
$configPath = $amazonConfig->save();
Expand All @@ -25,9 +26,11 @@ $configPath = $amazonConfig->save();
$amz=new AmazonFeed(null, false, null, $configPath);

// Use as normal...
$amz->setFeedType("_POST_INVENTORY_AVAILABILITY_DATA_");
$amz->setFeedType("_POST_INVENTORY_AVAILABILITY_DATA_");
$amz->setFeedContent($feed);
$amz->submitFeed();
return $amz->getResponse();

```
// Delete previously generated amazon config (for temporary use)
$amazonConfig->delete();
```
31 changes: 27 additions & 4 deletions src/ConfigGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ class ConfigGenerator
'logpath' => '\'.__DIR__.\'/log.txt',
'logfunction' => '',
'muteLog' => 'false',
'configpath' => __DIR__.'/../configs/',
];

private $filename;


public function __construct()
{
$this->generateFilename();
}

public function setStoreName($storeName)
{
$this->config['storeName'] = $storeName;
Expand Down Expand Up @@ -67,21 +76,35 @@ public function setMuteLog($muteLog)
$this->config['muteLog'] = $muteLog ? 'true' : 'false';
}

public function setConfigPath($configPath) {
$this->config['configpath'] = $configPath;
}

public function setFilename($filename) {
$this->filename = $filename;
}

public function save()
{
$fileContents = $this->populateTemplate($this->getTemplate());

$filePath = __DIR__.'/../configs/'.$this->generateFilename();
$filePath = $this->config['configpath'] . $this->filename;

$result = file_put_contents($filePath, $fileContents);

if (!$result) {
throw new Exception('Error saving to file: '.$filePath);
throw new \Exception('Error saving to file: '. $filePath);
}

return realpath($filePath);
}

public function delete()
{
$file = $this->config['configpath'] . $this->filename;
return unlink($file);
}

private function getTemplate()
{
return file_get_contents(__DIR__.'/../resources/amazon-config.template.php');
Expand All @@ -98,6 +121,6 @@ private function populateTemplate($template)

private function generateFilename()
{
return 'amazon-config.'.sha1(serialize($this->config)).'.php';
$this->filename = 'amazon-config.'.sha1(serialize($this->config)).'.php';
}
}
}

0 comments on commit af19c57

Please sign in to comment.