initial import from pitchfork-0.5.5
[patchfork.git] / inc / Net / MPD.php
CommitLineData
964dd0bc
JW
1<?php
2/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
4/**
5 * Music Player Daemon API
6 *
7 * PHP Version 5
8 *
9 * LICENSE: This source file is subject to version 3.01 of the PHP license
10 * that is available thorugh the world-wide-web at the following URI:
11 * http://www.php.net/license/3_01.txt. If you did not receive a copy of
12 * the PHP License and are unable to obtain it through the web, please
13 * send a note to license@php.net so we can mail you a copy immediately.
14 *
15 * @category Networking
16 * @package Net_MPD
17 * @author Graham Christensen <graham.christensen@itrebal.com>
18 * @copyright 2006 Graham Christensen
19 * @license http://www.php.net/license/3_01.txt
20 * @version CVS: $ID:$
21 */
22
23
24require_once 'PEAR/Exception.php';
25require_once 'MPD/Common.php';
26
27
28/**
29 * Central class for the Music Player Daemon objects
30 *
31 * Used to utilize the functionality of the provided classes
32 *
33 * @category Networking
34 * @package Net_MPD
35 * @author Graham Christensen <graham.christensen@itrebal.com>
36 * @copyright 2006 Graham Christensen
37 * @license http://www.php.net/license/3_01.txt
38 * @version CVS: $ID:$
39 */
40class Net_MPD
41{
42 /**
43 * The Net_MPD_Admin object
44 */
45 public $Admin;
46
47 /**
48 * The Net_MPD_Common object
49 */
50 public $Common;
51
52 /**
53 * The Net_MPD_Database object
54 */
55 public $Database;
56
57 /**
58 * The Net_MPD_Playback object
59 */
60 public $Playback;
61
62 /**
63 * The Net_MPD_Playlist object
64 */
65 public $Playlist;
66
67 /**
68 * Creates new instances of objects
69 * @param $host Host to connect to, optional (default: localhost)
70 * @param $port Port to connect to, optional (default: 6600)
71 * @param $pass Pass to connect to, optional (default: null)
72 * @return object or false on failure
73 */
74 function __construct($host = 'localhost', $port = 6600, $pass = null)
75 {
76 $this->Admin = self::factory('Admin' , $host, $port, $pass);
77 $this->Common = self::factory('Common' , $host, $port, $pass);
78 $this->Database = self::factory('Database', $host, $port, $pass);
79 $this->Playback = self::factory('Playback', $host, $port, $pass);
80 $this->Playlist = self::factory('Playlist', $host, $port, $pass);
81 }
82
83 /**
84 * Creates new instances of objects
85 * @param $class Class to initiate, with out Net_MPD_$class
86 * @param $host Host to connect to, optional (default: localhost)
87 * @param $port Port to connect to, optional (default: 6600)
88 * @param $pass Pass to connect to, optional (default: null)
89 * @return object or false on failure
90 */
91 public static function factory($class, $host = 'localhost', $port = 6600, $pass = null)
92 {
93 $class = ucfirst(strtolower($class));
94
95 if (!self::_loadClass($class)) {
96 return false;
97 }
98
99 $class = 'Net_MPD_' . $class;
100 $obj = new $class($host, $port, $pass);
101
102 return $obj;
103 }
104
105 /**
106 * Loads the class
107 * @param $class Class to include, with out Net_MPD_
108 * @return bool
109 */
110 protected static function _loadClass($class)
111 {
112 if (class_exists('Net_MPD_' . $class)) {
113 return true;
114 }
115 require_once 'Net/MPD/' . $class . '.php';
116 return true;
117 }
118}
119?>
This page took 0.026942 seconds and 4 git commands to generate.