Skip to content

Commit 07bfa71

Browse files
Merge branch 'fix/storage-acessors-on-repository'
* fix/storage-acessors-on-repository: remove optional modules Fix
2 parents f1205db + 7e0a3b8 commit 07bfa71

13 files changed

+973
-50
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ matrix:
1717
before_script:
1818
- travis_retry composer self-update
1919
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source
20+
- travis_retry composer require doctrine/orm
21+
- travis_retry composer require respect/relational
2022

2123
script:
2224
- phpunit --configuration phpunit.xml.dist --coverage-text --coverage-clover=coverage.clover

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
],
2020
"require": {
2121
"php" : ">=5.4",
22-
"ocramius/generated-hydrator": "1.1.0",
23-
"symfony/console": "~2.7"
22+
"ocramius/generated-hydrator": "1.1.0"
2423
},
2524
"require-dev": {
2625
"phpunit/phpunit" : "4.*",

coverage.clover

Lines changed: 764 additions & 0 deletions
Large diffs are not rendered by default.

src/Repository/CollectionFieldRepository.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,35 @@ class CollectionFieldRepository
88
extends RepositoryAbstract
99
implements RepositoryInterface
1010
{
11+
/**
12+
* @var object StorageORMInterface
13+
*/
14+
protected $storage;
15+
1116
public function __construct(StorageORMInterface $storage)
1217
{
1318
$this->setStorage($storage, 'WilliamEspindola\Field\Entity\CollectionField');
1419
}
20+
21+
/**
22+
* @param StorageORMInterface $storage
23+
* @param string $repository
24+
* @return RepositoryAbstract
25+
*/
26+
public function setStorage(StorageORMInterface $storage, $repository)
27+
{
28+
$storage->setRepository($repository);
29+
30+
$this->storage = $storage->getStorage();
31+
32+
return $this;
33+
}
34+
35+
/**
36+
* @return StorageInterface
37+
*/
38+
public function getStorage()
39+
{
40+
return $this->storage;
41+
}
1542
}

src/Repository/CollectionRepository.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,35 @@ class CollectionRepository
88
extends RepositoryAbstract
99
implements RepositoryInterface
1010
{
11+
/**
12+
* @var object StorageORMInterface
13+
*/
14+
protected $storage;
15+
1116
public function __construct(StorageORMInterface $storage)
1217
{
1318
$this->setStorage($storage, 'WilliamEspindola\Field\Entity\Collection');
1419
}
20+
21+
/**
22+
* @param StorageORMInterface $storage
23+
* @param string $repository
24+
* @return RepositoryAbstract
25+
*/
26+
public function setStorage(StorageORMInterface $storage, $repository)
27+
{
28+
$storage->setRepository($repository);
29+
30+
$this->storage = $storage->getStorage();
31+
32+
return $this;
33+
}
34+
35+
/**
36+
* @return StorageInterface
37+
*/
38+
public function getStorage()
39+
{
40+
return $this->storage;
41+
}
1542
}

src/Repository/FieldRepository.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,35 @@ class FieldRepository
88
extends RepositoryAbstract
99
implements RepositoryInterface
1010
{
11+
/**
12+
* @var object StorageORMInterface
13+
*/
14+
protected $storage;
15+
1116
public function __construct(StorageORMInterface $storage)
1217
{
1318
$this->setStorage($storage, 'WilliamEspindola\Field\Entity\Field');
1419
}
20+
21+
/**
22+
* @param StorageORMInterface $storage
23+
* @param string $repository
24+
* @return RepositoryAbstract
25+
*/
26+
public function setStorage(StorageORMInterface $storage, $repository)
27+
{
28+
$storage->setRepository($repository);
29+
30+
$this->storage = $storage->getStorage();
31+
32+
return $this;
33+
}
34+
35+
/**
36+
* @return StorageInterface
37+
*/
38+
public function getStorage()
39+
{
40+
return $this->storage;
41+
}
1542
}

src/Repository/OptionRepository.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,35 @@ class OptionRepository
88
extends RepositoryAbstract
99
implements RepositoryInterface
1010
{
11+
/**
12+
* @var object StorageORMInterface
13+
*/
14+
protected $storage;
15+
1116
public function __construct(StorageORMInterface $storage)
1217
{
1318
$this->setStorage($storage, 'WilliamEspindola\Field\Entity\Options');
1419
}
20+
21+
/**
22+
* @param StorageORMInterface $storage
23+
* @param string $repository
24+
* @return RepositoryAbstract
25+
*/
26+
public function setStorage(StorageORMInterface $storage, $repository)
27+
{
28+
$storage->setRepository($repository);
29+
30+
$this->storage = $storage->getStorage();
31+
32+
return $this;
33+
}
34+
35+
/**
36+
* @return StorageInterface
37+
*/
38+
public function getStorage()
39+
{
40+
return $this->storage;
41+
}
1542
}

src/Repository/RepositoryAbstract.php

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,9 @@
77

88
abstract class RepositoryAbstract
99
{
10-
/**
11-
* @var object StorageORMInterface
12-
*/
13-
protected $storage;
14-
15-
/**
16-
* @param StorageORMInterface $storage
17-
* @param string $repository
18-
* @return RepositoryAbstract
19-
*/
20-
public function setStorage(StorageORMInterface $storage, $repository)
21-
{
22-
$storage->setRepository($repository);
23-
24-
$this->storage = $storage->getRepository();
10+
abstract public function setStorage(StorageORMInterface $storage, $repository);
2511

26-
return $this;
27-
}
28-
29-
/**
30-
* @return StorageInterface
31-
*/
32-
public function getStorage()
33-
{
34-
return $this->storage;
35-
}
12+
abstract public function getStorage();
3613

3714
/**
3815
* @return \ArrayObject

src/Storage/ORM/Doctrine.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,14 @@ public function getRepository()
5858
return $this->getMapper()->getRepository($this->repository);
5959
}
6060

61+
public function getStorage()
62+
{
63+
return $this;
64+
}
65+
6166
public function setRepository($repository)
6267
{
6368
$this->repository = $repository;
64-
65-
return $this;
6669
}
6770

6871
/**

src/Storage/ORM/RespectRelational.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Respect\Relational\Mapper;
66
use Respect\Data\Styles;
77
use \InvalidArgumentException as Argument;
8+
use Respect\Data\Collections\Collection;
89

910
/**
1011
* Providers the Respect\Relational\Mapper ORM behavior
@@ -15,6 +16,9 @@
1516
*/
1617
class RespectRelational implements StorageORMInterface
1718
{
19+
/**
20+
*
21+
*/
1822
const INVALID_MAPPER_MESSAGE = 'Argument must be Respect\Relational\Mapper';
1923

2024
/**
@@ -27,6 +31,9 @@ class RespectRelational implements StorageORMInterface
2731
*/
2832
protected $repository;
2933

34+
/**
35+
* @param Mapper $mapper
36+
*/
3037
public function __construct(Mapper $mapper)
3138
{
3239
$this->setMapper($mapper);
@@ -51,6 +58,10 @@ public function getMapper()
5158
return $this->mapper;
5259
}
5360

61+
/**
62+
* @param $repository
63+
* @throws \InvalidArgumentException
64+
*/
5465
public function setRepository($repository)
5566
{
5667
if (empty($repository))
@@ -61,22 +72,34 @@ public function setRepository($repository)
6172
$repository = strtolower($reflect->getShortName());
6273
}
6374

64-
$this->repository = $repository;
75+
$this->repository = new Collection($repository);
76+
$this->repository->setMapper($this->mapper);
77+
}
6578

79+
/**
80+
* @return $this
81+
*/
82+
public function getStorage()
83+
{
6684
return $this;
6785
}
6886

87+
/**
88+
* @return string
89+
*/
6990
public function getRepository()
7091
{
71-
return $this->getMapper()->{$this->repository};
92+
return $this->repository;
7293
}
7394

7495
/**
7596
* @return array
7697
*/
7798
public function findAll()
7899
{
79-
return $this->getRepository()->fetchAll();
100+
$repository = $this->getRepository();
101+
102+
return $repository->fetchAll();
80103
}
81104

82105
/**

0 commit comments

Comments
 (0)