Skip to content

Instantly share code, notes, and snippets.

@JeroenDeDauw
Last active August 21, 2018 11:26
Embed
What would you like to do?
<?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