Skip to content

Instantly share code, notes, and snippets.

@petersuhm
Last active March 21, 2017 13:28
Show Gist options
  • Save petersuhm/0ee8510a0252f6878788ef96b8a2df3b to your computer and use it in GitHub Desktop.
Save petersuhm/0ee8510a0252f6878788ef96b8a2df3b to your computer and use it in GitHub Desktop.
WP Pusher Dropbox Exampl
<?php
// We need a new repository
class DropboxRepository extends Repository
{
public $code = 'db';
public function getZipUrl()
{
// Somehow fetch URL to zipball from Dropbox ...
// ... and return it
}
}
// Bind the repository to the container
// NOTE: This is actually not neccessary, since WP Pusher can automatically
// compose dependecies by using PHP's reflection API. This would only be neccessary
// if you wanted to bind DropboxRepository to an interface implementation.
add_action('wppusher_register_dependency', function(Pusher $pusher) {
$pusher->bind('DropboxRepository', 'DropboxRepository');
});
// Then we need to overwrite the RepositoryFactory (this is just
// an example and should probably not be done unless it's a private
// plugin, since it could cause conflicts with other similar implementations)
// so WP Pusher knows how to create a Dropbox repository:
class MyOwnRepositoryFactory
{
public function build($type, $handle)
{
if ($type === 'db') {
return new DropboxRepository($handle);
}
return parent::build($type, $handle);
}
}
// We can then overwrite the RepositoryFactory in the container,
// so that an instance of MyOwnRepositoryFactory is returned
// whenever someone needs a repository factory:
add_action('wppusher_register_dependency', function(Pusher $pusher) {
$pusher->bind('RepositoryFactory', 'MyOwnRepositoryFactory');
});
// Now, you'd only need a few adjustments to the UI, to allow users to
// select Dropbox as a repository!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment