Skip to content

Instantly share code, notes, and snippets.

@aryadiahmad4689
Created October 21, 2021 03:16
Show Gist options
  • Save aryadiahmad4689/bae0f7fa18a3811c25a1c7092ad7b8b2 to your computer and use it in GitHub Desktop.
Save aryadiahmad4689/bae0f7fa18a3811c25a1c7092ad7b8b2 to your computer and use it in GitHub Desktop.
<?php
// kita membuat interface autenticate
interface DocManager
{
public function authenticate($user, $pwd);
public function getDocuments($folderid);
public function getDocumentsByType($folderid, $type);
public function getFolders($folderid=null);
public function saveDocument($document);
}
class Writely implements DocManager
{
public function authenticate($user, $pwd)
{
//authenticate using Writely authentication scheme
}
public function getDocuments($folderid)
{
//get documents available in a folder
}
public function getDocumentsByType($folderid, $type)
{
//get documents of specific type from a folder
}
public function getFolders($folderid=null)
{
//get all folders under a specific folder
}
public function saveDocument($document)
{
//save the document
}
}
class GoogleDocsAdapter implements DocManager
{
private $manager;
public function __construct()
{
$this->manager = new GoogleDocs();
}
public function authenticate($user, $pwd)
{
$this->manager->setUser($user);
$this->manager->setPwd($pwd);
$this->manager->authenticateByClientLogin();
}
public function getDocuments($folderid)
{
return $this->manager->getAllDocuments();
}
public function getDocumentsByType($folderid, $type)
{
//get documents using GoogleDocs object and return only
//which match the type
}
public function getFolders($folderid=null)
{
//for example there is no folder in GoogleDocs, so
//return anything.
}
public function saveDocument($document)
{
//save the document using GoogleDocs object
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment