forked from ushahidi/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepositoryFactory.php
More file actions
44 lines (39 loc) · 988 Bytes
/
Copy pathRepositoryFactory.php
File metadata and controls
44 lines (39 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* Ushahidi Platform Factory for Repositories
*
* @author Ushahidi Team <team@ushahidi.com>
* @package Ushahidi\Platform
* @copyright 2014 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/
namespace Ushahidi\Factory;
class RepositoryFactory
{
// Array of repositories, mapped by resource:
//
// $map = [
// 'widgets' => $di->lazyNew('Namespace\To\WidgetRepository'),
// ...
// ]
//
// Resource names correspond with entity types.
protected $map = [];
/**
* @param Array $map
*/
public function __construct(array $map)
{
$this->map = $map;
}
/**
* Gets a repository from the map by resource.
* @param String $resource
* @return Ushahidi\Repository
*/
public function get($resource)
{
$factory = $this->map[$resource];
return $factory();
}
}