Skip to content

Commit 97f4b9c

Browse files
committed
Simplify operation calls
1 parent 06bea81 commit 97f4b9c

File tree

2 files changed

+6
-108
lines changed

2 files changed

+6
-108
lines changed

README.md

-14
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,6 @@ The following services are supported
4747
| Site | [Tripleseat documentation](https://support.tripleseat.com/hc/en-us/articles/212912147-Sites-API) | [Schema](http://api.tripleseat.com/v1/site_schema.json) |
4848
| User | [Tripleseat documentation](https://support.tripleseat.com/hc/en-us/articles/212567567-Users-API) | [Schema](http://api.tripleseat.com/v1/user_schema.json) |
4949

50-
### Calling operations
51-
52-
```php
53-
// Option 1: $tripleseat->[service]->[operation]()
54-
55-
$tripleseat->booking->all();
56-
$tripleseat->user->get(1);
57-
58-
// Option 2: $tripleseat->[operation][Service]()
59-
60-
$tripleseat->allBooking();
61-
$tripleseat->getUser(1);
62-
```
63-
6450
### Sites
6551
> A site represents a group of venues. Sites can have multiple locations.
6652

src/Tripleseat.php

+6-94
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php namespace Tripleseat;
22

3-
use Generator;
43
use Psr\Http\Client\ClientInterface;
54
use Tripleseat\Exceptions\InvalidArgumentException;
65
use Tripleseat\Exceptions\InvalidAuthConfiguration;
@@ -18,48 +17,6 @@
1817
* @property Services\Location location
1918
* @property Services\Site site
2019
* @property Services\User user
21-
*
22-
* @method Generator allAccount(int $fromPage = 1, int $untilPage = PHP_INT_MAX)
23-
* @method Generator searchAccount(array $parameters, int $fromPage = 1, int $untilPage = PHP_INT_MAX)
24-
* @method getAccount(int $id)
25-
* @method createAccount(array $account)
26-
* @method updateAccount(int $id, array $account)
27-
* @method deleteAccount(int $id)
28-
*
29-
* @method Generator allBooking(int $fromPage = 1, int $untilPage = PHP_INT_MAX)
30-
* @method Generator searchBooking(array $parameters, int $fromPage = 1, int $untilPage = PHP_INT_MAX)
31-
* @method getBooking(int $id)
32-
* @method createBooking(array $booking)
33-
* @method updateBooking(int $id, array $booking)
34-
* @method deleteBooking(int $id)
35-
*
36-
* @method Generator allContact(int $fromPage = 1, int $untilPage = PHP_INT_MAX)
37-
* @method Generator searchContact(array $parameters, int $fromPage = 1, int $untilPage = PHP_INT_MAX)
38-
* @method getContact(int $id)
39-
* @method createContact(array $contact)
40-
* @method updateContact(int $id, array $contact)
41-
* @method deleteContact(int $id)
42-
*
43-
* @method Generator allEvent(int $fromPage = 1, int $untilPage = PHP_INT_MAX)
44-
* @method Generator searchEvent(array $parameters, int $fromPage = 1, int $untilPage = PHP_INT_MAX)
45-
* @method getEvent(int $id)
46-
* @method createEvent(array $event)
47-
* @method updateEvent(int $id, array $event)
48-
* @method deleteEvent(int $id)
49-
*
50-
* @method Generator allLead(int $fromPage = 1, int $untilPage = PHP_INT_MAX)
51-
* @method Generator searchLead(array $parameters, int $fromPage = 1, int $untilPage = PHP_INT_MAX)
52-
* @method getLead(int $id)
53-
* @method createLead(array $lead, array $additionalData = [])
54-
* @method Generator formsLead()
55-
*
56-
* @method Generator allLocation()
57-
*
58-
* @method Generator allSite()
59-
*
60-
* @method Generator allUser(int $fromPage = 1, int $untilPage = PHP_INT_MAX)
61-
* @method Generator searchUser(array $parameters, int $fromPage = 1, int $untilPage = PHP_INT_MAX)
62-
* @method getUser(int $id)
6320
*/
6421
class Tripleseat implements \ArrayAccess
6522
{
@@ -141,48 +98,12 @@ public function __get(string $name)
14198
}
14299

143100
/**
144-
* @param $name
145-
* @param $arguments
146-
* @return mixed
147-
* @throws InvalidService
148-
*/
149-
public function __call($name, $arguments)
150-
{
151-
if ([$service, $method] = $this->extractServiceAndMethod($name)) {
152-
$service = $this->__get($service);
153-
154-
if (!empty($method)) {
155-
return call_user_func_array([$service, $method], $arguments);
156-
}
157-
}
158-
159-
throw new InvalidService($name);
160-
}
161-
162-
/**
163-
* Parses a string to check if the last part matches any of the defined
164-
* services and returns an array with the service and the string in front
165-
* of the service as the method name.
166-
*
167-
* @param string $haystack
168-
* @return array|null
101+
* @param int $offset
102+
* @return bool
169103
*/
170-
private function extractServiceAndMethod(string $haystack)
171-
{
172-
$haystack = strtolower($haystack);
173-
$needles = array_keys($this->availableServices);
174-
175-
foreach ($needles as $needle) {
176-
if ($needle !== '' && substr_compare($haystack, (string)$needle, -strlen($needle), null, true) === 0) {
177-
return [strtolower($needle), strstr($haystack, (string)$needle, true)];
178-
}
179-
}
180-
181-
return null;
182-
}
183-
184-
private function sites()
104+
public function offsetExists($offset)
185105
{
106+
// Load and cache the sites
186107
if (is_null($this->sites)) {
187108
$this->sites = [];
188109

@@ -191,20 +112,11 @@ private function sites()
191112
}
192113
}
193114

194-
return $this->sites;
195-
}
196-
197-
/**
198-
* @param mixed $offset
199-
* @return bool
200-
*/
201-
public function offsetExists($offset)
202-
{
203-
return array_key_exists($offset, $this->sites());
115+
return array_key_exists($offset, $this->sites);
204116
}
205117

206118
/**
207-
* @param mixed $offset
119+
* @param int $offset
208120
* @return Tripleseat
209121
* @throws InvalidSite
210122
*/

0 commit comments

Comments
 (0)