Skip to content

Commit

Permalink
Fleshed out the abstract classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelgbanks committed Oct 9, 2013
1 parent bd8f7b1 commit 3c39a79
Show file tree
Hide file tree
Showing 5 changed files with 441 additions and 228 deletions.
89 changes: 89 additions & 0 deletions AbstractDatastream.php
Expand Up @@ -2,4 +2,93 @@

/**
* @file
* Defines the AbstractObject interface.
*/

namespace {
/**
* This class can be overriden by anything implementing a datastream.
*/
interface AbstractDatastream {

/**
* This will set the state of the datastream to deleted.
*/
public function delete();

/**
* Set the contents of the datastream from a file.
*
* @param string $file
* The full path of the file to set to the contents of the datastream.
*/
public function setContentFromFile($file);

/**
* Set the contents of the datastream from a URL.
*
* The contents of this URL will be fetched, and the datastream will be
* updated to contain the contents of the URL.
*
* @param string $url
* The full URL to fetch.
*/
public function setContentFromUrl($url);

/**
* Set the contents of the datastream from a string.
*
* @param string $string
* The string whose contents will become the contents of the datastream.
*/
public function setContentFromString($string);

/**
* Get the contents of a datastream and output it to the file provided.
*
* @param string $file
* The path of the file to output the contents of the datastream to.
*
* @return bool
* TRUE on success or FALSE on failure.
*/
public function getContent($file);
}
}

namespace Tuque {

/**
* This class acts as a wrapper for the actual Object implementation.
*/
class Datastream extends Decorator implements \AbstractDatastream {

/**
* Constructor for the Repository object.
*
* @param AbstractObject $object
* The object this object wraps.
*/
public function __construct(\AbstractObject $object) {
parent::__construct($object);
}
// @todo Have wrappers for Datastream objects.
}

/**
* This class acts as a wrapper for the actual NewObject implementation.
*/
class NewDatastream extends Decorator implements \AbstractDatastream {

/**
* Constructor for the Repository object.
*
* @param AbstractDatastream $datastream
* The object this object wraps.
*/
public function __construct(\AbstractDatastream $datastream) {
parent::__construct($datastream);
}
// @todo Have wrappers for Datastream objects.
}
}
120 changes: 120 additions & 0 deletions AbstractObject.php
Expand Up @@ -4,3 +4,123 @@
* @file
* Defines the AbstractObject interface.
*/

namespace {

/**
* An abstract class defining a Object in the repository. This is the class
* that needs to be implemented in order to create new repository backends
* that can be accessed using Tuque.
*
* These classes implement the php object array interfaces so that the object
* can be accessed as an array. This provides access to datastreams. The
* object is also traversable with foreach, so that each datastream can be
* accessed.
*
* @code
* $object = new AbstractObject()
*
* // access every object
* foreach ($object as $dsid => $dsObject) {
* // print dsid and set contents to "foo"
* print($dsid);
* $dsObject->content = 'foo';
* }
*
* // test if there is a datastream called 'DC'
* if (isset($object['DC'])) {
* // if there is print its contents
* print($object['DC']->content);
* }
*
* @endcode
*/
interface AbstractObject extends Countable, ArrayAccess, IteratorAggregate {

/**
* Set the state of the object to deleted.
*/
public function delete();

/**
* Get a datastream from the object.
*
* @param string $id
* The id of the datastream to retreve.
*
* @return AbstractDatastream
* Returns FALSE if the datastream could not be found. Otherwise it return
* an instantiated Datastream object.
*/
public function getDatastream($id);

/**
* Purges a datastream.
*
* @param string $id
* The id of the datastream to purge.
*
* @return bool
* TRUE on success. FALSE on failure.
*/
public function purgeDatastream($id);

/**
* Factory to create new datastream objects.
*
* Creates a new datastream object, this object is not ingested into the
* repository until you call ingestDatastream.
*
* @param string $id
* The identifier of the new datastream.
* @param string $control_group
* The control group the new datastream will be created in.
*
* @return AbstractDatastream
* Returns an instantiated Datastream object.
*/
public function constructDatastream($id, $control_group = 'M');

/**
* Ingests a datastream object into the repository.
*/
public function ingestDatastream(&$ds);
}
}

namespace Tuque {

/**
* This class acts as a wrapper for the actual Object implementation.
*/
class Object extends Decorator implements \AbstractObject {

/**
* Constructor for the Repository object.
*
* @param AbstractObject $object
* The object this object wraps.
*/
public function __construct(\AbstractObject $object) {
parent::__construct($object);
}
// @todo Have wrappers for Datastream objects.
}

/**
* This class acts as a wrapper for the actual NewObject implementation.
*/
class NewObject extends Decorator implements \AbstractObject {

/**
* Constructor for the Repository object.
*
* @param AbstractObject $object
* The object this object wraps.
*/
public function __construct(\AbstractObject $object) {
parent::__construct($object);
}
// @todo Have wrappers for Datastream objects.
}
}

0 comments on commit 3c39a79

Please sign in to comment.