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

Commit

Permalink
feat: Added functionality for get first registered of the client and …
Browse files Browse the repository at this point in the history
…sever
  • Loading branch information
joserick committed Apr 15, 2019
1 parent b1e3b62 commit 4985414
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/Joserick/Plex/Plex.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Joserick\Plex\Exception\Plex_Exception_Machine;
use Joserick\Plex\Exception\Plex_Exception_Server;
use Joserick\Plex\Exception\Plex_Exception_Client;

/**
* Plex Bootstrap
Expand Down Expand Up @@ -148,7 +149,8 @@ private function registerClients(array $clients)
}

/**
* Returns the requested server by the unique name under which it was registered.
* Returns the requested of the firt server or by the unique name under
* which it was registered.
*
* @param string $serverName The unique name of the requested server.
*
Expand All @@ -158,8 +160,12 @@ private function registerClients(array $clients)
*
* @throws Plex_Exception_Server
*/
public function getServer($serverName)
public function getServer($serverName = NULL)
{
if (is_null($serverName)) {
return reset(self::$servers);
}

if (!isset(self::$servers[$serverName])) {
throw new Plex_Exception_Server(
'RESOURCE_NOT_FOUND',
Expand All @@ -171,16 +177,28 @@ public function getServer($serverName)
}

/**
* Returns the requested client by the unique name under which it was registered.
* Returns the requested firt client or by the unique name under which it
* was registered.
*
* @param string $clientName The unique name of the requested client.
*
* @uses Plex::$clients
*
* @return Plex_Client The requested Plex client machine.
*/
public function getClient($clientName)
public function getClient($clientName = NULL)
{
if (is_null($clientName)) {
return reset(self::$clients);
}

if (!isset(self::$clients[$clientName])) {
throw new Plex_Exception_Client(
'RESOURCE_NOT_FOUND',
array($clientName)
);
}

return self::$clients[$clientName];
}

Expand Down

0 comments on commit 4985414

Please sign in to comment.