store.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Template for creating a Keyring Token Store. All storage engines
  4. * MUST extend this. These engines are used for storing and managing
  5. * authentication tokens for remote Services. Use $meta to handle any
  6. * custom requirements (access v request tokens, scope, etc)
  7. *
  8. * @package Keyring
  9. */
  10. abstract class Keyring_Store {
  11. /**
  12. * Any set up required to initiate this storage engine.
  13. */
  14. static function &init() {}
  15. /**
  16. * Insert a new token into this storage engine.
  17. */
  18. abstract function insert( $token );
  19. /**
  20. * Update an existing token with a new token value and/or metadata.
  21. */
  22. abstract function update( $token );
  23. /**
  24. * Delete a token, or tokens.
  25. */
  26. abstract function delete( $args = array() );
  27. /**
  28. * Get an array of tokens for $service. If an $id is provided, then only get that single
  29. * specific token (for the specified service).
  30. */
  31. abstract function get_tokens( $args = array() );
  32. /**
  33. * Singular version of ::get_tokens(). Functions exactly the same, but
  34. * only ever returns one token.
  35. */
  36. abstract function get_token( $args = array() );
  37. /**
  38. * Get the number of tokens for a service
  39. */
  40. abstract function count( $args = array() );
  41. }
  42. // Load all packaged token store engines in the ./includes/stores/ directory by including all PHP files
  43. // Remove a Token Store (prevent it from loading at all) by filtering on 'keyring_token_stores'
  44. $keyring_stores = glob( dirname( __FILE__ ) . "/includes/stores/*.php" );
  45. $keyring_stores = apply_filters( 'keyring_token_stores', $keyring_stores );
  46. foreach ( $keyring_stores as $keyring_store )
  47. require $keyring_store;
  48. unset( $keyring_stores, $keyring_store );