Skip to content
This repository has been archived by the owner on Jun 19, 2018. It is now read-only.

Commit

Permalink
BREAKING CHANGE to Constructor/::create && example
Browse files Browse the repository at this point in the history
I made a breaking change to the constructor and factory creation
functions to allow for enabling/disabling of almost all features
via the constructor.

A discussion was brought up regarding the chaining on /r/PHP and
it was mentioned that for programmatic usefulness, it would be
better to have an array of flags to set during the construction,
instead of testing for certain variables and then triggering the
function call to the YTAudio object.

As such, I've made it so that instead of having two optional
parameters, the constructor and factory creation function have a
single optional parameter (after the still required one).  This
MUST be an array, but can be either associated, indexed, or a mix.

I've added usage of this new constructor to the example.php file
and modified the original pattern to omit the optional parameters.

Both uses in the example.php file will output the same XHTML.

Additionally, added the ability to turn on/off HTTPS.  (On by def.)
  • Loading branch information
navarr committed May 27, 2012
1 parent 570db09 commit 4625b65
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 20 deletions.
60 changes: 46 additions & 14 deletions YTAudio.php
Expand Up @@ -35,36 +35,53 @@ class YTAudio
/**
* Constructor
*
* @see size
* @see theme
*
* @throws YTAudioException
* @param string $source
* @param enum $size
* @param enum $theme
* @param array $settings
*/
public function __construct($source, $size = self::SIZE_SMALL,$theme = self::THEME_LIGHT)
public function __construct($source, $settings = null)
{
$this->source($source)->size($size)->theme($theme);
$this->source($source);

if($settings === null) $settings = array();

// Feature array, ie: array('https','hd','autoplay')
if(in_array('https',$settings)) $this->https();
if(in_array('hd',$settings)) $this->hd();
if(in_array('autoplay',$settings)) $this->autoplay();
if(in_array('jsapi',$settings)) $this->jsAPI();
if(in_array('progressbar',$settings)) $this->progressBar();
if(in_array('timecode',$settings)) $this->timeCode();
if(in_array('cookies',$settings)) $this->cookies();
if(in_array('loop',$settings)) $this->loop();

// Associative Feature Array, ie: array('https' => true, 'hd' => false)
if(isset($settings['https'])) $this->https($settings['https']);
if(isset($settings['size'])) $this->size($settings['size']);
if(isset($settings['hd'])) $this->hd($settings['hd']);
if(isset($settings['autoplay'])) $this->autoplay($settings['autoplay']);
if(isset($settings['jsapi'])) $this->jsAPI($settings['jsapi']);
if(isset($settings['progressbar'])) $this->progressBar($settings['progressbar']);
if(isset($settings['timecode'])) $this->timeCode($settings['timecode']);
if(isset($settings['cookies'])) $this->cookies($settings['cookies']);
if(isset($settings['theme'])) $this->theme($settings['theme']);
if(isset($settings['loop'])) $this->loop($settings['loop']);
}

/**
* Factory
* Allows easy creation and daisy-chaining of a YTAudio object.
*
* @see size
* @see theme
* @see __construct
*
* @throws YTAudioException
* @param string $source
* @param enum $size
* @param enum $theme
* @param array $settings
* @return YTAudio
*/
public static function create($source, $size = self::SIZE_SMALL,$theme = self::THEME_LIGHT)
public static function create($source, $settings = null)
{
$self = new self($source,$size,$theme);
return $self;
return new self($source,$settings);
}

/**
Expand Down Expand Up @@ -476,13 +493,28 @@ public function cookies($useCookies = true)
public function getCookies() { return $this->_cookies; }
public function willUseCookies() { return $this->getCookies(); }

/**
* Set HTTPS
* Choose whether to use HTTPs or HTTP
*
* @param bool $useHTTPS
* @return YTAudio
*/
public function https($useHTTPS = true)
{
if($useHTTPS) $this->_https = true;
else $this->_https = false;
return $this;
}

/**
* Get HTTPS Setting
*
* @return bool
*/
public function getHTTPS() { return $this->_https; }
public function isHTTPS() { return $this->_https; }
public function isHTTP() { return !$this->_https; }

/**
* Get Height (px)
Expand Down
19 changes: 13 additions & 6 deletions example.php
Expand Up @@ -3,15 +3,22 @@

// http://navarr.me/ytaudio/example.php

YTAudio::create
(
'http://www.youtube.com/watch?v=dvgZkm1xWPE&ob=av2n'
,YTAudio::SIZE_LARGE
,YTAudio::THEME_DARK
)
YTAudio::create('http://www.youtube.com/watch?v=dvgZkm1xWPE&ob=av2n')
->size(YTAudio::SIZE_LARGE)
->theme(YTAudio::THEME_DARK)
->hd() // Force HD
->loop() // Loop
->progressBar() // Show Progress Bar
->timeCode() // Show Time Code
->autoplay() // Autoplay
->render(); // Output XHTML

YTAudio::create('http://www.youtube.com/watch?v=dvgZkm1xWPE&ob=av2n',array(
'size' => YTAudio::SIZE_LARGE,
'theme' => YTAudio::THEME_DARK,
'hd',
'loop',
'autoplay',
'progressbar',
'timecode',
))->render();

0 comments on commit 4625b65

Please sign in to comment.