Arlima
Arlima copied to clipboard
Refactor the "list factory"
The class Arlima_ListFactory
does a lot of stuff. If we want to adhere to the single responsibility principle we should separate this class into three different classes.
Arlima_ListRepository — CRUD operations for the lists.
Arlima_VersionRepository — CRUD operations for the list versions.
Arlima_ScheduledVersionRepository — CRUD operations for scheduled list versions (extends VersionRepository).
Arlima_ListBuilder — Class that can create a list object, following a set of instructions.
Example on using the list builder:
$list = Arlima_List::builder()
->id(323) # list id
->slug( 'my-list' ) # can be used instead of id()
->import( $url ) # can be used instead of id() or slug()
->loadVersion(1234) # load articles belonging to version 1234
->loadLatestVersion() # load latest published version
->loadScheduledVersion(1234) # load articles from a scheduled version
->loadPreview() # load latest preview version
->includeFuturePosts()
->build();
- The functions
loadVersion()
,loadLatestVersion()
,loadScheduledVersion()
andloadPreview()
can not be combined. - When loading loading a scheduled version a function call to
includeFuturePosts()
won't have any effect. - When calling
import()
none of the other functions (exceptbuild()
) will have any effect.
I have looked through the current list factory and placed its functions in one of the repositories
Arlima_ListRepository extends Arlima_AbstractRepositoryDB {
save()
load( $id_or_slug )
updated()
delete()
getListId( $slug )
loadListSlugs()
}
Arlima_VersionRepository extends Arlima_AbstractRepositoryDB {
save($articles, $list_id, $preview=false)
loadVersions($limit=5) // get array with list versions, each version containing the articles
loadInfo() // Array with info about all saved versions array( array(verisonID, authorID, date), ... )
updateArticlePublishDate( $post )
updateArticle(...)
getLatestArticle($post_id);
loadListVersionsByPostId($post_id)
removeOldVersions($list_id, $num_versions_to_keep=10)
}
Arlima_ScheduledVersionRepository extends Arlima_VersionRepository {
saveScheduledVersion($articles, $list_id, $date)
...
}
Arlima_AbstractRepositoryDB {
get_result()
db_table()
install()
uninstall()
}
Added some documentation to Server-side, in depth