Project "FreeSWITCH user-contributed scripts, etc" received a push.

branch: master updated

       via: 7f89d85adb464f103abda4c3cee75a10f9515921 (commit)
      from: 68d384edcbabcac7e4058bbf26f409817d2c4505 (commit)


= COMMIT LOG ===========================================================
committer: Mathieu Parent
comments: 
MediaBrotha: Rewrite backend logic a bit
And:
- use type hinting
- MediaBrotha_Backend::_buffer is an Iterator

diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend.php
index f85001b..bb1fe8f 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Backend.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend.php
@@ -28,7 +28,7 @@ require_once('MediaBrotha/Media.php');
 
 class MediaBrotha_Backend extends MediaBrotha_Media implements Iterator {
 	protected $_buffer = Array();
-	public function __construct($args = Array()) {
+	public function __construct(array $args = Array()) {
 		parent::__construct($args);
 		$this->register();
 		$this->setMimeType('application/x-mediabrotha-backend-'.strtolower($this->getName()));
@@ -54,34 +54,36 @@ class MediaBrotha_Backend extends MediaBrotha_Media implements Iterator {
 	}
 
 	// Capability browse
+	protected function _mediaFromBufferItem($item) {
+		return $item;
+	}
+
 	public function fetch($uri) {
 		return false;
 	}
 
 	public function rewind() {
-		reset($this->_buffer);
+		$this->_buffer->rewind();
 	}
 
 	public function current() {
-		return current($this->_buffer);
+		return $this->_mediaFromBufferItem($this->_buffer->current());
 	}
 
 	public function key() {
-		return key($this->_buffer);
+		return $this->_buffer->key();
 	}
 
 	public function next() {
-		return next($this->_buffer);
+		return $this->_mediaFromBufferItem($this->_buffer->next());
 	}
 
 	public function valid() {
-		$key = key($this->_buffer);
-		$var = ($key !== NULL && $key !== FALSE);
-		return $var;
+		return $this->_buffer->valid();
 	}
 
 	// Capability play
-	public function play($media) {
+	public function play(MediaBrotha_Media $media) {
 		return false;
 	}
 	public function pause() {
@@ -91,13 +93,13 @@ class MediaBrotha_Backend extends MediaBrotha_Media implements Iterator {
 		return false;
 	}
 	// Capability playlist
-	public function playlistEnqueue($media) {
+	public function playlistEnqueue(MediaBrotha_Media $media) {
 		return false;
 	}
-	public function playlistNext($media) {
+	public function playlistNext(MediaBrotha_Media $media) {
 		return false;
 	}
-	public function playlistPrevious($media) {
+	public function playlistPrevious(MediaBrotha_Media $media) {
 		return false;
 	}
 }
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php
index 62fcb6f..0dc8972 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend/FileSystem.php
@@ -41,20 +41,13 @@ class MediaBrotha_Backend_FileSystem extends MediaBrotha_Backend {
 		return false;
 	}
 
-	public function fetch($uri) {
-		if ((parse_url($uri, PHP_URL_SCHEME) != 'file') || !$this->isURISafe($uri)) {
-			$uri = 'file://'.$this->getMetadata('base_path');
-		}
-		$this->_buffer = new DirectoryIterator(parse_url($uri, PHP_URL_PATH));
-		return true;
-	}
 	public function capabilities($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
 		return Array(
 			'browse',
 		);
 	}
-	// Iterator
-	public function mediaFromFile($file) {
+	// Capability browse
+	protected function _mediaFromBufferItem($file) {
 		if ($file) {
 			$media = new MediaBrotha_Media(Array(
 				'uri' => 'file://'.realpath($file->getPathname()),
@@ -72,16 +65,12 @@ class MediaBrotha_Backend_FileSystem extends MediaBrotha_Backend {
 		}
 	}
 
-	public function current() {
-		return $this->mediaFromFile($this->_buffer->current());
-	}
-
-	public function next() {
-		return $this->mediaFromFile($this->_buffer->next());
-	}
-
-	public function valid() {
-		return $this->_buffer->valid();
+	public function fetch($uri) {
+		if ((parse_url($uri, PHP_URL_SCHEME) != 'file') || !$this->isURISafe($uri)) {
+			$uri = 'file://'.$this->getMetadata('base_path');
+		}
+		$this->_buffer = new DirectoryIterator(parse_url($uri, PHP_URL_PATH));
+		return true;
 	}
 }
 
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php
index 5e9c5fb..5357cc3 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php
@@ -25,13 +25,6 @@ This file is part of MediaBrotha.
  */
 
 class MediaBrotha_Backend_Root extends MediaBrotha_Backend {
-	public function fetch($uri) {
-		$this->_buffer = Array();
-		foreach(MediaBrotha_Core::getBackends() as $id => $backend) {
-			$this->_buffer[] = $backend;
-		}
-		return true;
-	}
 	public function capabilities($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
 		return Array(
 			'browse',
@@ -40,6 +33,16 @@ class MediaBrotha_Backend_Root extends MediaBrotha_Backend {
 	public function isHidden() {
 		return true;
 	}
+
+	// Capability browse
+	public function fetch($uri) {
+		$this->_buffer = new ArrayIterator();
+		foreach(MediaBrotha_Core::getBackends() as $id => $backend) {
+			$this->_buffer[] = $backend;
+		}
+		return true;
+	}
+
 }
 
 
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php
index 12cbff6..df10f93 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php
@@ -31,28 +31,32 @@ class MediaBrotha_Backend_VLC extends MediaBrotha_Backend {
 		MediaBrotha_Core::registerMimeType($this, 'video/x-msvideo');
 	}
 
-	public function fetch($uri) {
-		$this->_buffer[] = new MediaBrotha_Media();
-		return true;
-	}
 	public function capabilities($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
 		return Array(
 			'play',
 			'playlist',
 		);
 	}
-	private function send_command($command, $args = Array()) {
+	private function send_command($command, array $args = Array()) {
 		$url = $this->getMetadata('http_intf').
 			'/requests/status.xml'.
 			'?command='.$command;
 		foreach ($args as $k => $v) {
 			$url.= '&'.$k.'='.rawurlencode($v);
 		}
-		return fopen($url, 'r');
+		$output = file_get_contents($url);
+		Header('Content-Type: text/xml');
+		print $output.'<!--'.$url."-->\n";
+	}
+
+	// Capability browse
+	public function fetch($uri) {
+		$this->_buffer[] = new MediaBrotha_Media();
+		return true;
 	}
 
 	// Capability play
-	public function play($media) {
+	public function play(MediaBrotha_Media $media) {
 		return $this->send_command('in_play', Array('input' => $media->getURI()));
 	}
 	public function pause() {
@@ -62,13 +66,13 @@ class MediaBrotha_Backend_VLC extends MediaBrotha_Backend {
 		return $this->send_command('pl_stop');
 	}
 	// Capability playlist
-	public function playlistEnqueue($media) {
+	public function playlistEnqueue(MediaBrotha_Media $media) {
 		return $this->send_command('in_enqueue', Array('input' => $media->getURI()));
 	}
-	public function playlistNext($media) {
+	public function playlistNext(MediaBrotha_Media $media) {
 		return $this->send_command('pl_next');
 	}
-	public function playlistPrevious($media) {
+	public function playlistPrevious(MediaBrotha_Media $media) {
 		return $this->send_command('pl_previous');
 	}
 }
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Core.php b/sathieu/cisco-xml/lib/MediaBrotha/Core.php
index e31ee47..b3eaa84 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Core.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Core.php
@@ -60,7 +60,8 @@ class MediaBrotha_Core {
 				break;
 			case 'browse':
 			default:
-				$current_backend->fetch(MediaBrotha_Core::getCurrentURI());
+				$current_uri = MediaBrotha_Core::getCurrentURI();
+				$current_backend->fetch((string) $current_uri);
 				MediaBrotha_Core::$_frontend->begin($current_backend);
 				foreach($current_backend as $item) {
 					if ($item->isHidden()) {
@@ -126,7 +127,7 @@ class MediaBrotha_Core {
 
 	public static function getCurrentURI() {
 		if (!empty($_GET['uri'])) {
-			return $_GET['uri'];
+			return (string) $_GET['uri'];
 		}
 	}
 	public static function getCurrentMedia() {
@@ -136,5 +137,6 @@ class MediaBrotha_Core {
 		}
 		return MediaBrotha_Core::$_media;
 	}
+
 }
 
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Frontend.php b/sathieu/cisco-xml/lib/MediaBrotha/Frontend.php
index 9eab63c..84ce7b7 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Frontend.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Frontend.php
@@ -25,10 +25,8 @@ This file is part of MediaBrotha.
  */
 
 class MediaBrotha_Frontend {
-	protected $_browser = NULL;
 	protected $_infos = NULL;
-	public function __construct($browser, $args = Array()) {
-		$this->_browser = $browser;
+	public function __construct(array $args = Array()) {
 		$this->_infos = $args;
 	}
 }
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Media.php b/sathieu/cisco-xml/lib/MediaBrotha/Media.php
index 0b50a52..cf3d66d 100644
--- a/sathieu/cisco-xml/lib/MediaBrotha/Media.php
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Media.php
@@ -28,7 +28,7 @@ class MediaBrotha_Media {
 	private $_metadata = Array();
 	private $_mimeType = NULL;
 	private $_mimeEncoding = NULL;
-	public function __construct($metadata = Array()) {
+	public function __construct(array $metadata = Array()) {
 		 $this->_metadata = $metadata;
 	}
 	public function setMimeType($mime_type) {
@@ -63,7 +63,7 @@ class MediaBrotha_Media {
 		}
 	}
 	/* Most used metadata */
-	public function getDisplayName() {
+	public function getDisplayName($max_length = 0) {
 		return $this->getMetadata('name');
 	}
 	public function getURI() {
========================================================================

Summary of changes:
 sathieu/cisco-xml/lib/MediaBrotha/Backend.php      |   26 ++++++++++---------
 .../lib/MediaBrotha/Backend/FileSystem.php         |   27 ++++++--------------
 sathieu/cisco-xml/lib/MediaBrotha/Backend/Root.php |   17 +++++++-----
 sathieu/cisco-xml/lib/MediaBrotha/Backend/VLC.php  |   24 ++++++++++-------
 sathieu/cisco-xml/lib/MediaBrotha/Core.php         |    6 +++-
 sathieu/cisco-xml/lib/MediaBrotha/Frontend.php     |    4 +--
 sathieu/cisco-xml/lib/MediaBrotha/Media.php        |    4 +-
 7 files changed, 53 insertions(+), 55 deletions(-)

this email was generated because of /git/your-repo.git/hooks/post-receive by the file /git-core/contrib/hooks/post-receive-email
For more info, see http://blog.chomperstomp.com/?p=630 --
FreeSWITCH user-contributed scripts, etc