1: <?php
2:
3: namespace webfilesframework\core\datastore;
4:
5: use webfilesframework\core\datastore\types\database\MDatabaseDatastore;
6: use webfilesframework\core\datastore\types\directory\MDirectoryDatastore;
7: use webfilesframework\core\datasystem\database\MDatabaseConnection;
8: use webfilesframework\core\datasystem\file\system\MDirectory;
9:
10: /**
11: * @TODO eliminate class because only two types are supported and datastore defintions should happen be too dynamically
12: * to create them in an genral way.
13: *
14: * Creates depending on the given type a datastore, which can
15: * be used to access and store webfiles.
16: *
17: * @author Sebastian Monzel < mail@sebastianmonzel.de >
18: * @since 0.1.7
19: */
20: class MDatastoreFactory
21: {
22:
23: /**
24: * Creates a new datastore. The following input object types are
25: * actually supported:
26: * <ul>
27: * <li>MDirectory</li>
28: * <li>MDatabaseConnection</li>
29: * </ul>
30: *
31: * @param MDirectory|MDatabaseConnection $item
32: *
33: * @return MAbstractDatastore Returns a datastore depending on the
34: * given item.
35: * @throws MDatastoreException
36: * @throws \ReflectionException
37: * @throws \webfilesframework\MWebfilesFrameworkException
38: */
39: public static function createDatastore($item)
40: {
41: if ($item instanceof MDirectory) {
42: return new MDirectoryDatastore($item);
43: } else if ($item instanceof MDatabaseConnection) {
44: return new MDatabaseDatastore($item);
45: } else {
46: throw new Exeption("Unsupported type to create datastore.");
47: }
48: }
49: }