Skip to content
This repository has been archived by the owner on Jun 4, 2020. It is now read-only.

Commit

Permalink
Configuratie werkte niet naar behoren als twee lossen 2 grote van gem…
Browse files Browse the repository at this point in the history
…aakt

Guzzle batch downloader in gebruik gemomen voor snellere download
  • Loading branch information
cmodijk committed Dec 30, 2013
1 parent 70ae67e commit ae68ce3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
34 changes: 19 additions & 15 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,28 @@ public function getConfigTreeBuilder()
// Verwerken opgegeven config
->beforeNormalization()

// Key is op root niveau ook mogelijk
->ifTrue(function ($v) { return is_array($v) && array_key_exists("key", $v); })
->then(function ($v) {
// Key opslaan
$key = $v["key"];
unset($v["key"]);

// Key op array niveau plaatsen
foreach ($v as $code => $config) {
$v[$code]["key"] = $key;
// Mogelijk maken om waardes op hoogste niveau op te geven als dit wenselijk is
->ifTrue(function ($v) { return is_array($v) && (array_key_exists("locales", $v) || array_key_exists("key", $v)); })
->then(function ($v) {

// Converten naar sub niveau waar nodig
if (array_key_exists("locales", $v)) {
$v = array("default" => $v);
}
return $v;
})

// Mogelijk maken om waardes op hoogste niveau op te geven als dit wenselijk is
->ifTrue(function ($v) { return is_array($v) && array_key_exists("locales", $v); })
->then(function ($v) { return array("default" => $v); })
// Als key op top nivue zit verplaatsen naar sub niveau
if (array_key_exists("key", $v)) {
$key = $v["key"];
unset($v["key"]);

// Key op array niveau plaatsen
foreach ($v as $code => $config) {
$v[$code]["key"] = $key;
}
}

return $v;
})
->end()

// Minimaal een element nodig
Expand Down
13 changes: 12 additions & 1 deletion Loco/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Jcid\Bundle\LocoBundle\Loco;

use Guzzle\Http\Client;
use Guzzle\Batch\BatchBuilder;

class Downloader
{
Expand All @@ -16,6 +17,13 @@ public function __construct($config)

public function download()
{
// Batch downloader
$batch = BatchBuilder::factory()
->transferRequests(10)
->autoFlushAt(10)
->build();

// Doorlopen bestanden
foreach ($this->config as $name => $config) {
foreach ($config["locales"] as $localeKey => $localeValue) {
foreach ($config["domains"] as $domain) {
Expand All @@ -38,9 +46,12 @@ public function download()
$savePath = sprintf("%s/%s.%s.%s", $config["target"], $domain, $localeKey, $config["extension"]);

// Downloaden
$response = $this->client->get($url, array(), array( "save_to" => $savePath))->send();
$batch->add($this->client->get($url, array(), array( "save_to" => $savePath)));
}
}
}

// Alles binnen halen
$batch->flush();
}
}

0 comments on commit ae68ce3

Please sign in to comment.