From 97f4b9ca706acd98fc95a3de3bcd157e127a57ba Mon Sep 17 00:00:00 2001 From: Roy de Vos Burchart Date: Mon, 16 Nov 2020 16:27:56 +0100 Subject: [PATCH] Simplify operation calls --- README.md | 14 ------- src/Tripleseat.php | 100 +++------------------------------------------ 2 files changed, 6 insertions(+), 108 deletions(-) diff --git a/README.md b/README.md index f48fd56..6b4a8e7 100644 --- a/README.md +++ b/README.md @@ -47,20 +47,6 @@ The following services are supported | Site | [Tripleseat documentation](https://support.tripleseat.com/hc/en-us/articles/212912147-Sites-API) | [Schema](http://api.tripleseat.com/v1/site_schema.json) | | User | [Tripleseat documentation](https://support.tripleseat.com/hc/en-us/articles/212567567-Users-API) | [Schema](http://api.tripleseat.com/v1/user_schema.json) | -### Calling operations - -```php -// Option 1: $tripleseat->[service]->[operation]() - -$tripleseat->booking->all(); -$tripleseat->user->get(1); - -// Option 2: $tripleseat->[operation][Service]() - -$tripleseat->allBooking(); -$tripleseat->getUser(1); -``` - ### Sites > A site represents a group of venues. Sites can have multiple locations. diff --git a/src/Tripleseat.php b/src/Tripleseat.php index 8ab2cf6..641d6c1 100644 --- a/src/Tripleseat.php +++ b/src/Tripleseat.php @@ -1,6 +1,5 @@ extractServiceAndMethod($name)) { - $service = $this->__get($service); - - if (!empty($method)) { - return call_user_func_array([$service, $method], $arguments); - } - } - - throw new InvalidService($name); - } - - /** - * Parses a string to check if the last part matches any of the defined - * services and returns an array with the service and the string in front - * of the service as the method name. - * - * @param string $haystack - * @return array|null + * @param int $offset + * @return bool */ - private function extractServiceAndMethod(string $haystack) - { - $haystack = strtolower($haystack); - $needles = array_keys($this->availableServices); - - foreach ($needles as $needle) { - if ($needle !== '' && substr_compare($haystack, (string)$needle, -strlen($needle), null, true) === 0) { - return [strtolower($needle), strstr($haystack, (string)$needle, true)]; - } - } - - return null; - } - - private function sites() + public function offsetExists($offset) { + // Load and cache the sites if (is_null($this->sites)) { $this->sites = []; @@ -191,20 +112,11 @@ private function sites() } } - return $this->sites; - } - - /** - * @param mixed $offset - * @return bool - */ - public function offsetExists($offset) - { - return array_key_exists($offset, $this->sites()); + return array_key_exists($offset, $this->sites); } /** - * @param mixed $offset + * @param int $offset * @return Tripleseat * @throws InvalidSite */