Skip to content

Commit

Permalink
simplify default loading and bump data-manager dependency to develop
Browse files Browse the repository at this point in the history
  • Loading branch information
electricjones committed Sep 6, 2015
1 parent 9ca8616 commit 2e568ed
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 39 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],
"require": {
"php": ">=5.4.0",
"michaels/data-manager": "dev-dependency-injection",
"michaels/data-manager": "dev-develop",
"ostico/phporient": "1.2.*",
"brightzone/gremlin-php": "*",
"everyman/neo4jphp": "dev-master",
Expand Down
62 changes: 24 additions & 38 deletions src/Spider.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,51 +111,36 @@ public function __construct(array $config = [], $connection = null, IocManagerIn
*/
public function configure(array $config = [], $connection = null)
{
/* Merge cascading defaults into config */
if (empty($config)) {
$config = $this->getDefaults();
} else {
/* Set Defaults Where Needed */
foreach ($this->getDefaults() as $key => $value) {
if (!isset($config[$key])) {
$config[$key] = $value;
} elseif (is_array($value)) {
$config[$key] = array_merge($this->getDefaults()[$key], $config[$key]);
}
}
}

/* General Configuration */
$general = $config;
unset($general['connections']);
$this->config->reset($general);
/* General Configuration with cascading defaults */
$this->config->initManager($config);
$this->config->loadDefaults($this->getDefaults());

/* Components for the IoC Manager */
$this->di->initDI($config['integrations']);
unset($config['integrations']);

/* Event Dispatcher */
$integrations = $this->config->get('integrations');
$this->di->initDi($integrations);
$this->di->set('_diManifest.original', $integrations);
$this->di->share('events'); // turns dispatcher into a cached singleton
$this->config->remove('integrations');

/* Connection Manager and Current Connection */
if (isset($config['connections'])) {
// Set the connection manifest
$this->connections->reset($config['connections']);
unset($config['connections']);

// Optional configuration (not supported, etc)
$this->connections->setConfigManager($config);

// Set the Event Dispatcher in Manager
$this->connections->setDispatcher($this->di->fetch('events'));

// Set the current connection for the Query Builder
parent::__construct(
$this->connections->fetch($connection)
);
} else {
if (!$this->config->has('connections')) {
throw new ConnectionNotFoundException("Spider cannot be instantiated without a connection");
}

// Set the connection manifest
$this->connections->initManager($this->config->get('connections'));
$this->config->remove('connections');

// Optional configuration (not supported, etc)
$this->connections->setConfigManager($this->config->getAll());

// Set the Event Dispatcher in Manager
$this->connections->setDispatcher($this->di->fetch('events'));

// Set the current connection for the Query Builder
parent::__construct(
$this->connections->fetch($connection)
);
}

/* Instance Public API: Factories */
Expand Down Expand Up @@ -202,6 +187,7 @@ public function getConfig()
$config['connections'] = $this->connections->all();
unset($config['connections']['cache']);

$config['integrations'] = $this->di->get('_diManifest.original');
return $config;
}

Expand Down

0 comments on commit 2e568ed

Please sign in to comment.