You are here

class MediaInternetTestHandler in D7 Media 7.4

Same name and namespace in other branches
  1. 7.2 modules/media_internet/tests/includes/MediaInternetTestHandler.inc \MediaInternetTestHandler
  2. 7.3 modules/media_internet/tests/includes/MediaInternetTestHandler.inc \MediaInternetTestHandler

Implementation of MediaInternetBaseHandler.

Hierarchy

Expanded class hierarchy of MediaInternetTestHandler

See also

hook_media_internet_providers().

File

modules/media_internet/tests/includes/MediaInternetTestHandler.inc, line 13
Extends the MediaInternetBaseHandler class to handle videos from an imaginary example.com.

View source
class MediaInternetTestHandler extends MediaInternetBaseHandler {
  public function parse($embedCode) {

    // http://example.com/video/*
    $patterns = array(
      '@example\\.com/video/(\\d+)@i',
    );
    foreach ($patterns as $pattern) {
      preg_match($pattern, $embedCode, $matches);
      if (isset($matches[1])) {
        return file_stream_wrapper_uri_normalize('mediainternettest://video/' . $matches[1]);
      }
    }
  }
  public function claim($embedCode) {
    if ($this
      ->parse($embedCode)) {
      return TRUE;
    }
  }
  public function getFileObject() {
    $uri = $this
      ->parse($this->embedCode);
    $file = file_uri_to_object($uri, TRUE);

    // Override the default filename for testing purposes.
    if (empty($file->fid)) {
      $file->filename = 'Drupal';
    }
    return $file;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MediaInternetBaseHandler::postSave public function After the file has been saved, implementors may do additional operations. 1
MediaInternetBaseHandler::preSave public function Before the file has been saved, implementors may do additional operations. 1
MediaInternetBaseHandler::save public function Saves a file to the file_managed table (with file_save).
MediaInternetBaseHandler::validate public function If required, implementors can validate the embedCode.
MediaInternetBaseHandler::__construct public function The constructor for the MediaInternetBaseHandler class. This method is also called from the classes that extend this class and override this method.
MediaInternetTestHandler::claim public function Determines if this handler should claim the item. Overrides MediaInternetBaseHandler::claim
MediaInternetTestHandler::getFileObject public function Returns a file object which can be used for validation. Overrides MediaInternetBaseHandler::getFileObject
MediaInternetTestHandler::parse public function