| Total Complexity | 7 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 10 | class PlaylistFactory |
||
| 11 | { |
||
| 12 | |||
| 13 | private function __construct() |
||
| 14 | { |
||
| 15 | |||
| 16 | } |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Factory method for creating playlist objects |
||
| 20 | * @param string $fileName |
||
| 21 | * @param string $format the desired playlist format. Defaults to null, |
||
| 22 | * meaning the configured default format will be used |
||
| 23 | * @return Playlist the playlist object |
||
| 24 | * @throws InvalidRequestException if the playlist format is not supported |
||
| 25 | */ |
||
| 26 | public static function create($fileName, $format = null) |
||
| 27 | { |
||
| 28 | if ($format === null) |
||
| 29 | $format = Setting::getString('playlistFormat'); |
||
| 30 | |||
| 31 | switch ($format) |
||
| 32 | { |
||
| 33 | case Playlist::TYPE_M3U: |
||
| 34 | return new M3UPlaylist($fileName); |
||
| 35 | case Playlist::TYPE_XSPF: |
||
| 36 | return new XSPFPlaylist($fileName); |
||
| 37 | case Playlist::TYPE_PLS: |
||
| 38 | return new PLSPlaylist($fileName); |
||
| 39 | default: |
||
| 40 | throw new InvalidRequestException(); |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @return array the valid playlist formats |
||
| 46 | */ |
||
| 47 | public static function getTypes() |
||
| 53 | ); |
||
| 54 | } |
||
| 55 | |||
| 57 |