Skip to content
Permalink
Browse files

restore & cleanup initial work

  • Loading branch information
chirimoya committed Sep 14, 2012
1 parent 996324e commit ffad7f7c2db34e04e3a7376aa7a7c565a7e6326e
@@ -10,9 +10,9 @@ cscope.out
doc/config/phpdoc.ini
doc/html

tests/fixtures/doctrine
tests/fixtures/mongodb
tests/phpunit.xml

vendor/
composer.phar
composer.lock
composer.lock
@@ -5,6 +5,7 @@
"keywords": ["transport implementation", "mongodb"],
"homepage": "http://jackalope.github.com",
"license": "Apache-2.0",
"minimum-stability": "dev",
"authors": [
{
"name": "Jackalope Community",
@@ -13,17 +14,24 @@
],
"require": {
"php": ">=5.3.2",
"phpcr/phpcr": "dev-master",
"jackalope/jackalope": "dev-master",
"phpcr/phpcr": ">=2.1.0-beta3",
"jackalope/jackalope": "1.0.*",
"doctrine/mongodb": "dev-master"
},
"provide": {
"jackalope/jackalope-transport": "dev-master"
"jackalope/jackalope-transport": "1.0.0-alpha1"
},
"require-dev": {
"phpcr/phpcr-api-tests": "dev-master"
},
"autoload": {
"psr-0": { "Jackalope\\": "src/" }
"psr-0": {
"Jackalope\\": "src/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
}
}
@@ -0,0 +1,89 @@
<?php

namespace Jackalope;

use PHPCR\RepositoryFactoryInterface;

/**
* This factory creates repositories with the MongoDB transport
*
* Use repository factory based on parameters (the parameters below are examples):
*
* $factory = new \Jackalope\RepositoryFactoryMongoDB;
*
* $parameters = array('jackalope.mongodb_database' => $db);
* $repo = $factory->getRepository($parameters);
*
* @api
*/
class RepositoryFactoryMongoDB implements RepositoryFactoryInterface
{
static private $required = array(
'jackalope.mongodb_database' => '\Doctrine\MongoDB\Database (required): mongodb database instance',
);

static private $optional = array(
'jackalope.factory' => 'string or object: Use a custom factory class for Jackalope objects',
'jackalope.disable_transactions' => 'boolean: If set and not empty, transactions are disabled, otherwise transactions are enabled',
'jackalope.disable_stream_wrapper' => 'boolean: If set and not empty, stream wrapper is disabled, otherwise the stream wrapper is enabled',
);

/**
* Attempts to establish a connection to a repository using the given
* parameters.
*
*
*
* @param array|null $parameters string key/value pairs as repository arguments or null if a client wishes
* to connect to a default repository.
* @return \PHPCR\RepositoryInterface a repository instance or null if this implementation does
* not understand the passed parameters
* @throws \PHPCR\RepositoryException if no suitable repository is found or another error occurs.
* @api
*/
static public function getRepository(array $parameters = null)
{
if (null == $parameters) {
return null;
}

// check if we have all required keys
$present = array_intersect_key(self::$required, $parameters);
if (count(array_diff_key(self::$required, $present))) {
return null;
}
$defined = array_intersect_key(array_merge(self::$required, self::$optional), $parameters);
if (count(array_diff_key($defined, $parameters))) {
return null;
}

if (isset($parameters['jackalope.factory'])) {
$factory = is_object($parameters['jackalope.factory']) ?
$parameters['jackalope.factory'] :
new $parameters['jackalope.factory'];
} else {
$factory = new Factory();
}

$db = $parameters['jackalope.mongodb_database'];

$transport = $factory->get('Transport\MongoDB\Client', array($db));

$options['transactions'] = empty($parameters['jackalope.disable_transactions']);
$options['stream_wrapper'] = empty($parameters['jackalope.disable_stream_wrapper']);
return new Repository($factory, $transport, $options);
}

/**
* Get the list of configuration options that can be passed to getRepository
*
* The description string should include whether the key is mandatory or
* optional.
*
* @return array hash map of configuration key => english description
*/
static public function getConfigurationKeys()
{
return array_merge(self::$required, self::$optional);
}
}

2 comments on commit ffad7f7

@lsmith77

This comment has been minimized.

Copy link
Member

lsmith77 replied Sep 14, 2012

awesome!

i just realized that maybe the CachedClient could be moved to Jackalope so that it can be reused in other transports:
https://github.com/jackalope/jackalope-doctrine-dbal/blob/master/src/Jackalope/Transport/DoctrineDBAL/CachedClient.php

cc @jmikola

@chirimoya

This comment has been minimized.

Copy link
Member Author

chirimoya replied Sep 14, 2012

thx for the hint. I will have a look.

Please sign in to comment.
You can’t perform that action at this time.