2017 © Pedro Peláez
 

library lib-media

Library for abstraction of media services in the Ride framework

image

ride/lib-media

Library for abstraction of media services in the Ride framework

  • Friday, May 4, 2018
  • by ride-user
  • Repository
  • 8 Watchers
  • 0 Stars
  • 3,240 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 16 Versions
  • 2 % Grown

The README.md

ride/lib-media

This library adds support for custom media items, like Youtube videos, Soundcloud music or plain URL's., (*1)

MediaItem classes live in the item/ directory, and their factories in the factory directory., (*2)

What's In This Library

MediaItemFactory

The MediaItemFactory class is the interface for all media item factories. This factory has two responsibilities:, (*3)

  • check a given URL if it is valid for the assosiated MediaItem class
  • instantiate a new MediaItem class

The AbstractMediaItemFactory has a default implementation for the createFormUrl, createFromId and setClientId methods. Its constructor requires an instance of ride\library\http\client\Client., (*4)

The isValidUrl method should always be implemented in the child class, and should contain logic in order to determine if an URL is parseable for the related media item., (*5)

MediaItem

The MediaItem class is the interface for all media items. There is an abstract implementation called AbstractMediaItem from which all classes can extend. Each MediaItem class should implement at least following methods:, (*6)

abstract protected function parseUrl($url);
abstract protected function loadProperties();

The parseUrl method will take a given URL and parse it for this specific MediaItem implementation. It can be assumed that this URL is parseable because of the check done in the MediaItemFactory., (*7)

Each media item needs a factory for the MediaFactory to be able to use it., (*8)

MediaFactory

The MediaFactory interface glues all the MediaItemFactory instances together into an easy facade. It will use specific media item factories to test if a given URL can be parsed., (*9)

A generic implementation is provided through the SimpleMediaFactory class., (*10)

Code sample

You can check the following code sample to see some of the possibilities of this library:, (*11)

use ride\library\media\factory\UrlMediaItemFactory;
use ride\library\media\factory\VimeoMediaItemFactory;
use ride\library\media\factory\YoutubeMediaItemFactory;
use ride\library\media\MediaFactory;
use ride\library\media\SimpleMediaFactory;
use ride\library\http\client\Client;

function createMediaFactory(Client $httpClient) {
    $youtubeMediaItemFactory = new YoutubeMediaItemFactory($httpClient);
    $youtubeMediaItemFactory->setClientId('client-id');

    $vimeoMediaItemFactory = new VimeoMediaItemFactory($httpClient);

    $urlMediaItemFactory = new UrlMediaItemFactory($httpClient);

    $mediaFactory = new SimpleMediaFactory($httpClient);
    $mediaFactory->setMediaItemFactory($youtubeMediaItemFactory);
    $mediaFactory->setMediaItemFactory($vimeoMediaItemFactory);
    $mediaFactory->setDefaultMediaItemFactory($urlMediaItemFactory);

    return $mediaFactory;
}

function useMediaFactory(MediaFactory $mediaFactory) {
    // create a MediaItem using a URL
    $youtubeMediaItem = $simpleMediaFactory->createMediaItem('https://www.youtube.com/watch?v=njos57IJf-0');

    $type = $youtubeMediaItem->getType();
    // youtube
    $id = $youtubeMediaItem->getId();
    // njos57IJf-0
    $title = $youtubeMediaItem->getTitle();
    $description = $youtubeMediaItem->getDescription();

    // if you know the type and id, you can fetch it like this
    $youtubeMediaItem = $simpleMediaFactory->getMediaItem($type, $id);
}

Installation

You can use Composer to install this library., (*12)

composer require ride/lib-media

The Versions

04/05 2018

dev-master

9999999-dev

Library for abstraction of media services in the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

04/05 2018

1.0.3

1.0.3.0

Library for abstraction of media services in the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

04/05 2018

dev-develop

dev-develop

Library for abstraction of media services in the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

04/05 2017

1.0.2

1.0.2.0

Library for abstraction of media services in the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

19/01 2017

1.0.1

1.0.1.0

Library for abstraction of media services in the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

13/10 2016

1.0.0

1.0.0.0

Library for abstraction of media services in the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

14/09 2016

0.5.2

0.5.2.0

Library for abstraction of media services in the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

06/07 2016

0.5.1

0.5.1.0

Library for abstraction of media services in the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

24/11 2015

0.5.0

0.5.0.0

Library for abstraction of media services in the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

21/11 2015

0.4.0

0.4.0.0

Library for abstraction of media services in the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

03/06 2015

0.3.0

0.3.0.0

Library for abstraction of media services in the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

03/03 2015

0.2.1

0.2.1.0

Library for abstraction of media services in the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

15/12 2014

0.2.0

0.2.0.0

Library for abstraction of media services in the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

22/10 2014

0.1.2

0.1.2.0

Library for abstraction of media services in the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

22/05 2014

0.1.1

0.1.1.0

Library for abstraction of media services in the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd

22/05 2014

0.1.0

0.1.0.0

Library for abstraction of media services in the Ride framework

  Sources   Download

MIT

The Requires

 

by Joris Vandeweerd