1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92:
<?php
namespace Net\Bazzline\Component\Locator\Generator;
use Net\Bazzline\Component\Locator\Configuration\Configuration;
use Net\Bazzline\Component\Locator\FileExistsStrategy\FileExistsStrategyInterface;
use Net\Bazzline\Component\Locator\Generator\GeneratorInterface;
use Net\Bazzline\Component\Locator\RuntimeException;
abstract class AbstractGenerator implements GeneratorInterface
{
protected $configuration;
protected $fileExistsStrategy;
public function setConfiguration(Configuration $configuration)
{
$this->configuration = $configuration;
return $this;
}
public function setFileExistsStrategy(FileExistsStrategyInterface $strategy)
{
$this->fileExistsStrategy = $strategy;
return $this;
}
protected function moveOldFileIfExists($filePath, $fileName)
{
$fullQualifiedFilePath = $filePath . DIRECTORY_SEPARATOR . $fileName;
if (file_exists($fullQualifiedFilePath)) {
if ($this->fileExistsStrategy instanceof FileExistsStrategyInterface) {
$this->fileExistsStrategy
->setFileName($fileName)
->setFilePath($filePath)
->execute();
} else {
throw new RuntimeException(
'file "' . $fullQualifiedFilePath . '" already exists'
);
}
}
}
protected function dumpToFile($fullQualifiedFileName, $content)
{
if (file_put_contents($fullQualifiedFileName, $content) === false) {
throw new RuntimeException(
'can not create "' . $fullQualifiedFileName . '" or write content'
);
}
}
protected function getAuthorString()
{
return 'Net\Bazzline\Component\Locator';
}
}