Skip to content
Browse files

Tighten up the example adapter.

  • Loading branch information...
1 parent 55cd95b commit 918126e1d1c85852dd8d27074bf926de284cf120 @jimsafley jimsafley committed Mar 19, 2012
Showing with 29 additions and 0 deletions.
  1. +29 −0 lib/Scripto/Adapter/Example.php
View
29 lib/Scripto/Adapter/Example.php
@@ -11,6 +11,11 @@
require_once 'Scripto/Adapter/Interface.php';
/**
+ * @see Scripto_Adapter_Exception
+ */
+require_once 'Scripto/Adapter/Exception.php';
+
+/**
* An example adapter for a hypothetical CMS.
*
* @package Scripto
@@ -115,11 +120,17 @@ public function documentExists($documentId)
public function documentPageExists($documentId, $pageId)
{
+ if (!array_key_exists($documentId, $this->_documents)) {
+ return false;
+ }
return array_key_exists($pageId, $this->_documents[$documentId]['document_pages']);
}
public function getDocumentPages($documentId)
{
+ if (!array_key_exists($documentId, $this->_documents)) {
+ throw new Scripto_Adapter_Exception('Document does not exist.');
+ }
$pages = array();
foreach ($this->_documents[$documentId]['document_pages'] as $pageId => $page) {
$pages[$pageId] = $page['page_name'];
@@ -129,22 +140,40 @@ public function getDocumentPages($documentId)
public function getDocumentPageFileUrl($documentId, $pageId)
{
+ if (!array_key_exists($documentId, $this->_documents)) {
+ throw new Scripto_Adapter_Exception('Document does not exist.');
+ }
+ if (!array_key_exists($pageId, $this->_documents[$documentId]['document_pages'])) {
+ throw new Scripto_Adapter_Exception('Document page does not exist.');
+ }
return $this->_documents[$documentId]['document_pages'][$pageId]['page_file_url'];
}
public function getDocumentFirstPageId($documentId)
{
+ if (!array_key_exists($documentId, $this->_documents)) {
+ throw new Scripto_Adapter_Exception('Document does not exist.');
+ }
reset($this->_documents[$documentId]['document_pages']);
return key($this->_documents[$documentId]['document_pages']);
}
public function getDocumentTitle($documentId)
{
+ if (!array_key_exists($documentId, $this->_documents)) {
+ throw new Scripto_Adapter_Exception('Document does not exist.');
+ }
return $this->_documents[$documentId]['document_title'];
}
public function getDocumentPageName($documentId, $pageId)
{
+ if (!array_key_exists($documentId, $this->_documents)) {
+ throw new Scripto_Adapter_Exception('Document does not exist.');
+ }
+ if (!array_key_exists($pageId, $this->_documents[$documentId]['document_pages'])) {
+ throw new Scripto_Adapter_Exception('Document page does not exist.');
+ }
return $this->_documents[$documentId]['document_pages'][$pageId]['page_name'];
}

0 comments on commit 918126e

Please sign in to comment.
Something went wrong with that request. Please try again.