Skip to content

Commit

Permalink
added DocumentRepository factories
Browse files Browse the repository at this point in the history
  • Loading branch information
ivannis committed May 9, 2017
1 parent 8571b75 commit 99c2421
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 0 deletions.
55 changes: 55 additions & 0 deletions ODM/MongoDB/DocumentQueryRepositoryFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/**
* This file is part of the Cubiche package.
*
* Copyright (c) Cubiche
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Cubiche\Infrastructure\Repository\Doctrine\ODM\MongoDB;

use Doctrine\ODM\MongoDB\DocumentManager;

/**
* DocumentQueryRepositoryFactory class.
*
* @author Ivannis Suárez Jerez <ivannis.suarez@gmail.com>
*/
class DocumentQueryRepositoryFactory implements DocumentQueryRepositoryFactoryInterface
{
/**
* @var DocumentManager
*/
protected $documentManager;

/**
* @var DocumentDataSourceFactory
*/
protected $documentDatasourceFactory;

/**
* DocumentQueryRepositoryFactory constructor.
*
* @param DocumentManager $documentManager
* @param DocumentDataSourceFactory $documentDatasourceFactory
*/
public function __construct(DocumentManager $documentManager, DocumentDataSourceFactory $documentDatasourceFactory)
{
$this->documentManager = $documentManager;
$this->documentDatasourceFactory = $documentDatasourceFactory;
}

/**
* {@inheritdoc}
*/
public function create($documentName)
{
return new DocumentQueryRepository(
$this->documentManager->getRepository($documentName),
$this->documentDatasourceFactory
);
}
}
27 changes: 27 additions & 0 deletions ODM/MongoDB/DocumentQueryRepositoryFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* This file is part of the Cubiche package.
*
* Copyright (c) Cubiche
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Cubiche\Infrastructure\Repository\Doctrine\ODM\MongoDB;

/**
* DocumentQueryRepositoryFactory interface.
*
* @author Ivannis Suárez Jerez <ivannis.suarez@gmail.com>
*/
interface DocumentQueryRepositoryFactoryInterface
{
/**
* @param string $documentName
*
* @return DocumentQueryRepository
*/
public function create($documentName);
}
55 changes: 55 additions & 0 deletions ODM/MongoDB/DocumentRepositoryFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/**
* This file is part of the Cubiche package.
*
* Copyright (c) Cubiche
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Cubiche\Infrastructure\Repository\Doctrine\ODM\MongoDB;

use Doctrine\ODM\MongoDB\DocumentManager;

/**
* DocumentRepositoryFactory class.
*
* @author Ivannis Suárez Jerez <ivannis.suarez@gmail.com>
*/
class DocumentRepositoryFactory implements DocumentRepositoryFactoryInterface
{
/**
* @var DocumentManager
*/
protected $documentManager;

/**
* @var DocumentDataSourceFactory
*/
protected $documentDatasourceFactory;

/**
* DocumentRepositoryFactory constructor.
*
* @param DocumentManager $documentManager
* @param DocumentDataSourceFactory $documentDatasourceFactory
*/
public function __construct(DocumentManager $documentManager, DocumentDataSourceFactory $documentDatasourceFactory)
{
$this->documentManager = $documentManager;
$this->documentDatasourceFactory = $documentDatasourceFactory;
}

/**
* {@inheritdoc}
*/
public function create($documentName)
{
return new DocumentRepository(
$this->documentManager->getRepository($documentName),
$this->documentDatasourceFactory
);
}
}
27 changes: 27 additions & 0 deletions ODM/MongoDB/DocumentRepositoryFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* This file is part of the Cubiche package.
*
* Copyright (c) Cubiche
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Cubiche\Infrastructure\Repository\Doctrine\ODM\MongoDB;

/**
* DocumentRepositoryFactory interface.
*
* @author Ivannis Suárez Jerez <ivannis.suarez@gmail.com>
*/
interface DocumentRepositoryFactoryInterface
{
/**
* @param string $documentName
*
* @return DocumentRepository
*/
public function create($documentName);
}

0 comments on commit 99c2421

Please sign in to comment.