1: <?php
2:
3: namespace Charcoal\Source;
4:
5: // Local namespace dependencies
6: use \Charcoal\Source\SourceInterface;
7:
8: /**
9: * Storable items can be stored and loaded from a Source.
10: */
11: interface StorableInterface
12: {
13: /**
14: * Set the object's ID. The actual property set depends on `key()`
15: *
16: * @param mixed $id The object's ID.
17: * @return StorableInterface Chainable
18: */
19: public function setId($id);
20:
21: /**
22: * Get the object's (unique) ID. The actualy property get depends on `key()`
23: *
24: * @return mixed
25: */
26: public function id();
27:
28: /**
29: * Set the key property.
30: *
31: * @param string $key The object's key.
32: * @return StorableInterface Chainable
33: */
34: public function setKey($key);
35:
36: /**
37: * Get the key property.
38: *
39: * @return string
40: */
41: public function key();
42:
43: /**
44: * Get the object's source.
45: *
46: * @return SourceInterface
47: */
48: public function source();
49:
50: /**
51: * Load an object from the database from its ID.
52: *
53: * @param mixed $id The ID of the object to load.
54: * @return boolean Success / Failure
55: */
56: public function load($id);
57:
58: /**
59: * Load an object from the database from its key $key.
60: *
61: * @param string $key Key pointing a column's name.
62: * @param mixed $value Value of said column.
63: * @return StorableInterface Chainable.
64: */
65: public function loadFrom($key = null, $value = null);
66:
67: /**
68: * Load an object from the database from a custom SQL query.
69: *
70: * @param string $query The SQL query.
71: * @param array $binds Optional. The SQL query parameters.
72: * @return StorableInterface Chainable.
73: */
74: public function loadFromQuery($query, array $binds = []);
75:
76: /**
77: * Save an object current state to storage
78: *
79: * @return boolean
80: */
81: public function save();
82:
83: /**
84: * Update the object in storage to the current object state.
85: *
86: * @param string[] $keys If set, only update the properties specified in this array.
87: * @return boolean
88: */
89: public function update(array $keys = null);
90:
91: /**
92: * Delete an object from storage.
93: *
94: * @return boolean
95: */
96: public function delete();
97: }
98: