Retentio/Boomgo — pull request #17 by dguyon (2012-03-30 15:25:52+00:00)
Title: Change MapBuilder methods visibility

In order to adjust buildMap algorithm for Repository requirements, 2 methods need to have **protected** visibility rather than **private**.

That way, we'll be able to manipulate Map instance directly (Bundle context sample) :

public function build(array $files, $injectDefaultConnectionParameter)
{
$processed = array();

foreach ($files as $file) {
if ($this->parser->supports($file)) {

// Standard
$metadata = $this->parser->parse($file);

// Settings defaults for Repository
$defaults = array(
'type' => 'document',
'connection' => $injectDefaultConnectionParameter
);
$metadata = array_merge($defaults, $metadata);

$map = $this->buildMap($metadata);

$processed[$map->getClass()] = $map;
}
}

return $processed;
}

protect function buildMap(array $metadata, $defaultConnection)
{
// Definitions processing
$map = parent::buildMap($metadata);

// Configuration processing
$map->setType($metadata['type']);
$map->setConnection($metadata['connection']);

if (isset($metadata['collection'])) {
$map->setCollection($metadata['collection']);
} else {
$collectionName = strtolower($map->getClassName());
$map->setCollection($collectionName);
}

return $map;
}

Your comment on this proposal @ludofleury ?

Another solution would only write the build map logic only with adjusting the public method :

public function build(array $files, $injectDefaultConnectionParameter)
{
$processed = array();

foreach ($files as $file) {
if ($this->parser->supports($file)) {

// Standard processing
$metadata = $this->parser->parse($file);

$map = $this->buildMap($metadata);

// Settings defaults for Repository and processing configurations
$defaults = array(
'type' => 'document',
'connection' => $injectDefaultConnectionParameter
);
$metadata = array_merge($defaults, $metadata);

$map->setType($metadata['type']);
$map->setConnection($metadata['connection']);

if (isset($metadata['collection'])) {
$map->setCollection($metadata['collection']);
} else {
$collectionName = strtolower($map->getClassName());
$map->setCollection($collectionName);
}

$processed[$map->getClass()] = $map;
}
}

return $processed;
}

Up to you guys.