Skip to content

Instantly share code, notes, and snippets.

@JeroenDeDauw
Last active August 21, 2018 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeroenDeDauw/b0558444a107d642ee99c40bc2cc9daf to your computer and use it in GitHub Desktop.
Save JeroenDeDauw/b0558444a107d642ee99c40bc2cc9daf to your computer and use it in GitHub Desktop.
<?php
interface EntityRevisionLookup {
public function getLatestRevisionId( EntityId $entityId, RevisionLookupResultHandler $resultHandler ): void;
}
// Interface version
// Great if you have anonymous classes
interface RevisionLookupResultHandler {
public function notFound();
public function redirectFound( int $redirectId, int $entityId );
public function entityFound( int $entityId );
}
// Callback version
class RevisionLookupResultHandler {
// Possibly constructed via fluent interface instead
public function __construct( callable $onNotFound, callable $onRedirectFound, callable $onFound ) {}
public function invokeOnNotFound() {
($this->onNotFound)();
}
public function invokeRedirectFound( int $redirectId, int $entityId ) {
($this->onRedirectFound)( $redirectId, $entityId );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment