-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from gregi99/extended-configuration
extended configuration for merge many tags
- Loading branch information
Showing
8 changed files
with
370 additions
and
40 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,16 @@ | ||
<?php | ||
|
||
namespace nediam\PhraseAppBundle\Events; | ||
|
||
final class PhraseappEvents | ||
{ | ||
/** | ||
* The 'phraseapp.post_download event is thrown each time when all files are downloaded and wait for final save | ||
* | ||
* The event listener receives an | ||
* nediam\PhraseAppBundle\Events\PostDownloadEvent instance. | ||
* | ||
* @var string | ||
*/ | ||
const POST_DOWNLOAD = 'phraseapp.post_download'; | ||
} |
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,128 @@ | ||
<?php | ||
/** | ||
* Author: grzegorz | ||
* Date: 14.01.16 20:39 | ||
*/ | ||
|
||
namespace nediam\PhraseAppBundle\Events; | ||
|
||
use Symfony\Component\EventDispatcher\Event; | ||
|
||
class PostDownloadEvent extends Event | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $tempData = []; | ||
|
||
/** | ||
* @var null|string | ||
*/ | ||
private $finalFilePath = null; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $locale; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $catalogue; | ||
|
||
/** | ||
* PostDownloadEvent constructor. | ||
* | ||
* @param array $tempData | ||
* @param string $locale | ||
* @param string $catalogue | ||
*/ | ||
public function __construct(array $tempData, $locale, $catalogue) | ||
{ | ||
$this->tempData = $tempData; | ||
$this->locale = $locale; | ||
$this->catalogue = $catalogue; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getTempData() | ||
{ | ||
return $this->tempData; | ||
} | ||
|
||
/** | ||
* @param array $tempFiles | ||
* | ||
* @return $this | ||
*/ | ||
public function setTempData(array $tempData) | ||
{ | ||
$this->tempData = $tempData; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return null|string | ||
*/ | ||
public function getFinalFilePath() | ||
{ | ||
return $this->finalFilePath; | ||
} | ||
|
||
/** | ||
* @param null|string $finalFilePath | ||
* | ||
* @return $this | ||
*/ | ||
public function setFinalFilePath($finalFilePath = null) | ||
{ | ||
$this->finalFilePath = $finalFilePath; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getLocale() | ||
{ | ||
return $this->locale; | ||
} | ||
|
||
/** | ||
* @param string $locale | ||
* | ||
* @return $this | ||
*/ | ||
public function setLocale($locale) | ||
{ | ||
$this->locale = $locale; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCatalogue() | ||
{ | ||
return $this->catalogue; | ||
} | ||
|
||
/** | ||
* @param string $catalogue | ||
* | ||
* @return $this | ||
*/ | ||
public function setCatalogue($catalogue) | ||
{ | ||
$this->catalogue = $catalogue; | ||
|
||
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
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,45 @@ | ||
<?php | ||
/** | ||
* Author: grzegorz | ||
* Date: 15.01.16 11:29 | ||
*/ | ||
|
||
namespace nediam\PhraseAppBundle\Service; | ||
|
||
use nediam\PhraseAppBundle\Service\MergeStrategy\MergeInterface; | ||
use nediam\PhraseAppBundle\Service\MergeStrategy\YamlMerger; | ||
|
||
class FileMerger | ||
{ | ||
/** | ||
* @var MergeInterface[] | ||
*/ | ||
private $handlers = []; | ||
|
||
/** | ||
* FileMerger constructor. | ||
* | ||
* @param array $adapters | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->handlers[] = new YamlMerger(); | ||
} | ||
|
||
/** | ||
* @param $content | ||
* @param $format | ||
* | ||
* @return string | ||
*/ | ||
public function merge($content, $format) | ||
{ | ||
foreach ($this->handlers as $handler) { | ||
if ($handler->canMerge($format)) { | ||
return $handler->merge($content); | ||
} | ||
} | ||
|
||
throw new \InvalidArgumentException('No handler for requested format'); | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
namespace nediam\PhraseAppBundle\Service\MergeStrategy; | ||
|
||
interface MergeInterface | ||
{ | ||
/** | ||
* @param $format | ||
* | ||
* @return bool | ||
*/ | ||
public function canMerge($format); | ||
|
||
/** | ||
* Megres array of jsons | ||
* | ||
* @param array $content | ||
* | ||
* @return string | ||
*/ | ||
public function merge($content); | ||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace nediam\PhraseAppBundle\Service\MergeStrategy; | ||
|
||
use Symfony\Component\Yaml\Dumper; | ||
|
||
class YamlMerger | ||
{ | ||
/** | ||
* @param $format | ||
* | ||
* @return bool | ||
*/ | ||
public function canMerge($format) | ||
{ | ||
return 'yml' === $format; | ||
} | ||
|
||
/** | ||
* @param array $files | ||
* | ||
* @return string | ||
*/ | ||
public function merge($content) | ||
{ | ||
$yamlTempArray = []; | ||
|
||
foreach($content as $input) { | ||
$input = json_decode($input, true); | ||
|
||
$yamlTempArray = array_merge($yamlTempArray, $input); | ||
} | ||
|
||
ksort($yamlTempArray); | ||
|
||
$dumper = new Dumper(); | ||
|
||
return $dumper->dump($yamlTempArray, 5); | ||
} | ||
} |
Oops, something went wrong.