-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7854955
Showing
5 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# SimpleCRUD | ||
|
||
*A very simple CRUD interface* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace marcuspi\SimpleCRUD; | ||
|
||
/** | ||
* A collection of documents in a database. | ||
*/ | ||
interface Collection | ||
{ | ||
|
||
/** | ||
* Creates a new document. | ||
* | ||
* @access public | ||
* @param array $data | ||
* @return Document | ||
*/ | ||
public function create($data); | ||
|
||
/** | ||
* Finds a document in the database. | ||
* | ||
* @access public | ||
* @param Id $id The object's unique identifier | ||
* @return Document | ||
*/ | ||
public function read(Id $id); | ||
|
||
/** | ||
* Updates the specified document. | ||
* | ||
* @access public | ||
* @param Id $id The object's unique identifier | ||
* @param array $data The data to update | ||
* @return int The number of modified objects | ||
*/ | ||
public function update(Id $id, $data); | ||
|
||
/** | ||
* Removes the specified document. | ||
* | ||
* @access public | ||
* @param Id $id The object's unique identifier | ||
* @return int The number of modified objects | ||
*/ | ||
public function delete(Id $id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace marcuspi\SimpleCRUD; | ||
|
||
/** | ||
* Interface for interacting with a simple document-based database | ||
*/ | ||
interface Database { | ||
|
||
/** | ||
* Initializes the database. | ||
* | ||
* @access public | ||
* @static | ||
* @param string $path | ||
* @return Database | ||
*/ | ||
public static function connect($path); | ||
|
||
/** | ||
* Returns the collections in the database. | ||
* | ||
* @access public | ||
* @return Collection[] An array of Collection objects | ||
*/ | ||
public function collections(); | ||
|
||
/** | ||
* Returns a specific collection. | ||
* | ||
* @access public | ||
* @param string $title | ||
* @return Collection | ||
*/ | ||
public function collection($title); | ||
|
||
/** | ||
* Adds a collection to the database. | ||
* | ||
* @access public | ||
* @param string $title | ||
* @return boolean True if the operation was successful, false otherwise | ||
*/ | ||
public function addCollection($title); | ||
|
||
/** | ||
* Removes a collection from the database. | ||
* | ||
* @access public | ||
* @param string $title | ||
* @return boolean True if the operation was successful, false otherwise | ||
*/ | ||
public function removeCollection($title); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace marcuspi\SimpleCRUD; | ||
|
||
/** | ||
* A document in the database. Objects are stored in an associative array. | ||
*/ | ||
interface Document { | ||
|
||
|
||
/** | ||
* Finds a document in the collection and returns it. | ||
* | ||
* @access public | ||
* @static | ||
* @param Collection $collection The collection to read from | ||
* @param Id $id The document's unique identifier | ||
* @return Document | ||
*/ | ||
public static function restore(Collection $collection, Id $id); | ||
|
||
/** | ||
* Creates a new document in the collection and returns it. | ||
* | ||
* @access public | ||
* @static | ||
* @param Collection $collection The collection to insert into | ||
* @param mixed $data The document's unique identifier | ||
* @return void | ||
*/ | ||
public static function create(Collection $collection, $data); | ||
|
||
/** | ||
* Pulls the contents of this document from the database. | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function read(); | ||
|
||
/** | ||
* Stores changes made to the document. | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function update(); | ||
|
||
/** | ||
* Removes the document from the collection. | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function delete(); | ||
|
||
/** | ||
* Returns the document as an array. | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function toArray(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace marcuspi\SimpleCRUD; | ||
|
||
interface Id | ||
{ | ||
public static function make(); | ||
|
||
public static function restore($id); | ||
} |