55use Respect \Relational \Mapper ;
66use Respect \Data \Styles ;
77use \InvalidArgumentException as Argument ;
8+ use Respect \Data \Collections \Collection ;
89
910/**
1011 * Providers the Respect\Relational\Mapper ORM behavior
1516 */
1617class 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