Skip to content

Commit

Permalink
First release
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusirgens committed Jun 8, 2016
0 parents commit 7854955
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SimpleCRUD

*A very simple CRUD interface*

47 changes: 47 additions & 0 deletions simple-crud/Collection.php
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);
}
55 changes: 55 additions & 0 deletions simple-crud/Database.php
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);

}
65 changes: 65 additions & 0 deletions simple-crud/Document.php
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();

}
10 changes: 10 additions & 0 deletions simple-crud/Id.php
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);
}

0 comments on commit 7854955

Please sign in to comment.