Skip to content

Commit

Permalink
Merge pull request #38 from matthewsuan/master
Browse files Browse the repository at this point in the history
Add src getter method
  • Loading branch information
dereuromark authored Jul 8, 2019
2 parents d945735 + 153d5ac commit c7a8d46
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ composer.lock
composer.phar
phpunit.phar
.idea/
.phpunit.result.cache
25 changes: 25 additions & 0 deletions src/Object/MediaObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,31 @@ public function getEmbedCode() {
return $this->_buildObject();
}

/**
* Add src getter method
*
* @return string The src attribute
*/
public function getEmbedSrc() {
$source = $this->_stub['iframe-player'];
$count = count($this->_match);

for ($i = 1; $i <= $count; $i++) {
$source = str_ireplace('$' . $i, $this->_match[$i - 1], $source);
}

//add custom params
if ($this->_iframeParams) {
$c = '?';
if (strpos($source, '?') !== false) {
$c = '&amp;';
}
$source .= $c . http_build_query($this->_iframeParams, '', '&amp;');
}

return $source;
}

/**
* Getter/setter of what this Object currently prefers as output type
*
Expand Down
9 changes: 9 additions & 0 deletions src/Object/ObjectInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,13 @@ public function name();
*/
public function getEmbedCode();

/**
* Returns the embed src. Useful for iframes where you only need the src attribute
*
* @api
*
* @return string
*/
public function getEmbedSrc();

}
3 changes: 3 additions & 0 deletions tests/MediaEmbedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ public function testYoutube() {

$code = $Object->getEmbedCode();
$this->assertContains('<iframe', $code);

$src = $Object->getEmbedSrc();
$this->assertContains('//www.youtube.com/embed/h9Pu4bZqWyg', $src);
}

public function testYoutubeWithoutIframe() {
Expand Down

0 comments on commit c7a8d46

Please sign in to comment.