Skip to content

Commit 950776a

Browse files
committed
finish a first storage layer implementation
Move a lot of code around. Thus, more concrete layers need much less functions to realise concrete implementations (most of the code needed is encapsualated in template based classes in higher layers).
1 parent b4337e5 commit 950776a

File tree

8 files changed

+342
-241
lines changed

8 files changed

+342
-241
lines changed

Manager/StatementManager.php

Lines changed: 0 additions & 82 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the xAPI package.
5+
*
6+
* (c) Christian Flothmann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Xabbuh\XApi\Storage\Doctrine\Repository;
13+
14+
use Xabbuh\XApi\Storage\Api\Mapping\MappedStatement;
15+
16+
/**
17+
* {@link MappedStatement} repository interface definition.
18+
*
19+
* @author Christian Flothmann <[email protected]>
20+
*/
21+
interface MappedStatementRepository
22+
{
23+
/**
24+
* @param array $criteria
25+
*
26+
* @return MappedStatement The statement or null if no matching statement
27+
* has been found
28+
*/
29+
public function findMappedStatement(array $criteria);
30+
31+
/**
32+
* @param array $criteria
33+
*
34+
* @return MappedStatement[] The statements matching the given criteria
35+
*/
36+
public function findMappedStatements(array $criteria);
37+
38+
/**
39+
* Saves a {@link MappedStatement} in the underlying storage.
40+
*
41+
* @param MappedStatement $mappedStatement The statement being stored
42+
* @param bool $flush Whether or not to flush the managed
43+
* objects (i.e. write them to the data
44+
* storage immediately)
45+
*/
46+
public function storeMappedStatement(MappedStatement $mappedStatement, $flush = true);
47+
}

Repository/StatementRepository.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the xAPI package.
5+
*
6+
* (c) Christian Flothmann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Xabbuh\XApi\Storage\Doctrine\Repository;
13+
14+
use Xabbuh\XApi\Storage\Api\StatementRepository as BaseStatementRepository;
15+
use Xabbuh\XApi\Storage\Api\Mapping\MappedStatement;
16+
17+
/**
18+
* Doctrine based {@link Statement} repository.
19+
*
20+
* @author Christian Flothmann <[email protected]>
21+
*/
22+
class StatementRepository extends BaseStatementRepository
23+
{
24+
/**
25+
* @var MappedStatementRepository The statement repository
26+
*/
27+
private $repository;
28+
29+
public function __construct(MappedStatementRepository $repository)
30+
{
31+
$this->repository = $repository;
32+
}
33+
34+
/**
35+
* {@inheritDoc}
36+
*/
37+
protected function findMappedStatement(array $criteria)
38+
{
39+
return $this->repository->findMappedStatement($criteria);
40+
}
41+
42+
/**
43+
* {@inheritDoc}
44+
*/
45+
protected function findMappedStatements(array $criteria)
46+
{
47+
return $this->repository->findMappedStatements($criteria);
48+
}
49+
50+
/**
51+
* {@inheritDoc}
52+
*/
53+
protected function storeMappedStatement(MappedStatement $mappedStatement, $flush)
54+
{
55+
$this->repository->storeMappedStatement($mappedStatement, $flush);
56+
}
57+
}

Repository/StatementRepositoryInterface.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

Tests/Functional/StatementManagerTest.php renamed to Tests/Functional/StatementRepositoryTest.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212
namespace Xabbuh\XApi\Storage\Doctrine\Tests\Functional;
1313

1414
use Doctrine\Common\Persistence\ObjectManager;
15-
use Xabbuh\XApi\Storage\Api\Test\Functional\StatementManagerTest as BaseStatementManagerTest;
16-
use Xabbuh\XApi\Storage\Doctrine\Manager\StatementManager;
17-
use Xabbuh\XApi\Storage\Doctrine\Repository\StatementRepositoryInterface;
15+
use Xabbuh\XApi\Storage\Api\Test\Functional\StatementRepositoryTest as BaseStatementRepositoryTest;
16+
use Xabbuh\XApi\Storage\Doctrine\Repository\MappedStatementRepository;
17+
use Xabbuh\XApi\Storage\Doctrine\Repository\StatementRepository;
1818

1919
/**
2020
* @author Christian Flothmann <[email protected]>
2121
*/
22-
abstract class StatementManagerTest extends BaseStatementManagerTest
22+
abstract class StatementRepositoryTest extends BaseStatementRepositoryTest
2323
{
2424
/**
2525
* @var ObjectManager
2626
*/
2727
protected $objectManager;
2828

2929
/**
30-
* @var StatementRepositoryInterface
30+
* @var MappedStatementRepository
3131
*/
3232
protected $repository;
3333

@@ -39,14 +39,18 @@ protected function setUp()
3939
parent::setUp();
4040
}
4141

42-
protected function createStatementManager()
42+
protected function createStatementRepository()
4343
{
44-
return new StatementManager($this->repository);
44+
return new StatementRepository($this->repository);
4545
}
4646

47-
protected function createRepository()
47+
protected function cleanDatabase()
4848
{
49-
return $this->objectManager->getRepository($this->getStatementClassName());
49+
foreach ($this->repository->findMappedStatements(array()) as $statement) {
50+
$this->objectManager->remove($statement);
51+
}
52+
53+
$this->objectManager->flush();
5054
}
5155

5256
/**
@@ -58,4 +62,9 @@ abstract protected function createObjectManager();
5862
* @return string
5963
*/
6064
abstract protected function getStatementClassName();
65+
66+
private function createRepository()
67+
{
68+
return $this->objectManager->getRepository($this->getStatementClassName());
69+
}
6170
}

0 commit comments

Comments
 (0)