Skip to content

Commit 4f3bb4c

Browse files
bdgreggctgraham
authored andcommitted
Enable interface to code tables
1 parent 536c67f commit 4f3bb4c

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

src/Client.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Scriptotek\Alma\Conf\Jobs;
2525
use Scriptotek\Alma\Conf\Libraries;
2626
use Scriptotek\Alma\Conf\Library;
27+
use Scriptotek\Alma\Conf\CodeTables;
2728
use Scriptotek\Alma\Exception\ClientException as AlmaClientException;
2829
use Scriptotek\Alma\Exception\InvalidApiKey;
2930
use Scriptotek\Alma\Exception\MaxNumberOfAttemptsExhausted;
@@ -103,6 +104,11 @@ class Client
103104
*/
104105
public $jobs;
105106

107+
/**
108+
* @var CodeTables
109+
*/
110+
public $codetables;
111+
106112
/**
107113
* @var TaskLists
108114
*/
@@ -152,6 +158,7 @@ public function __construct(
152158
$this->conf = new Conf($this);
153159
$this->libraries = $this->conf->libraries; // shortcut
154160
$this->jobs = $this->conf->jobs; // shortcut
161+
$this->codetables = $this->conf->codetables; // shortcut
155162

156163
$this->taskLists = new TaskLists($this);
157164

src/Conf/CodeTable.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Scriptotek\Alma\Conf;
4+
5+
use Scriptotek\Alma\Client;
6+
use Scriptotek\Alma\Model\LazyResource;
7+
8+
/**
9+
* A single CodeTable resource.
10+
*/
11+
class CodeTable extends LazyResource
12+
{
13+
/** @var string */
14+
public $code;
15+
16+
/**
17+
* CodeTable constructor.
18+
*
19+
* @param Client $client
20+
* @param string $code
21+
*/
22+
public function __construct(Client $client, $code)
23+
{
24+
parent::__construct($client);
25+
$this->code = $code;
26+
}
27+
28+
/**
29+
* Check if we have the full representation of our data object.
30+
*
31+
* @param \stdClass $data
32+
*
33+
* @return bool
34+
*/
35+
protected function isInitialized($data)
36+
{
37+
return isset($data->name);
38+
}
39+
40+
/**
41+
* Generate the base URL for this resource.
42+
*
43+
* @return string
44+
*/
45+
protected function urlBase()
46+
{
47+
return "/conf/code-tables/{$this->code}";
48+
}
49+
}

src/Conf/CodeTables.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Scriptotek\Alma\Conf;
4+
5+
use Scriptotek\Alma\Client;
6+
use Scriptotek\Alma\Model\ReadOnlyArrayAccess;
7+
8+
/**
9+
* A non-iterable collection of CodeTable resources
10+
*/
11+
class CodeTables implements \ArrayAccess
12+
{
13+
use ReadOnlyArrayAccess;
14+
15+
protected $client;
16+
17+
/**
18+
* CodeTables constructor.
19+
*
20+
* @param Client $client
21+
*/
22+
public function __construct(Client $client)
23+
{
24+
$this->client = $client;
25+
}
26+
27+
/**
28+
* Get a CodeTable by identifier
29+
*
30+
* @param $code The identifier of a CodeTable
31+
*
32+
* @return CodeTable
33+
*/
34+
public function get($code)
35+
{
36+
return CodeTable::make($this->client, $code);
37+
}
38+
}

src/Conf/Conf.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ public function __construct(Client $client)
1212
$this->client = $client;
1313
$this->libraries = new Libraries($client);
1414
$this->jobs = new Jobs($client);
15+
$this->codetables = new CodeTables($client);
1516
}
1617
}

0 commit comments

Comments
 (0)