From 92e4d66339b094276115790969ea78e8fb3bfebf Mon Sep 17 00:00:00 2001 From: Benjamin Ayles Date: Wed, 16 Oct 2019 19:27:48 +1030 Subject: [PATCH 1/5] use default config in facade --- src/Facades/Xero.php | 18 ++++++++++++++++++ src/Providers/XeroLaravelServiceProvider.php | 17 +++++++++++++++++ src/Xero.php | 11 ++++++----- 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 src/Facades/Xero.php diff --git a/src/Facades/Xero.php b/src/Facades/Xero.php new file mode 100644 index 0000000..7381252 --- /dev/null +++ b/src/Facades/Xero.php @@ -0,0 +1,18 @@ +mergeConfigFrom( Constants::CONFIG_PATH, Constants::CONFIG_KEY ); + + $this->app->singleton('Xero', function () { + return (new \LangleyFoxall\XeroLaravel\Xero())->app(); + }); } /** @@ -29,4 +34,16 @@ public function boot() Constants::CONFIG_PATH => config_path(Constants::CONFIG_KEY.'.php'), ]); } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return [ + Xero::class, + ]; + } } diff --git a/src/Xero.php b/src/Xero.php index 86286f5..6d1c1bc 100644 --- a/src/Xero.php +++ b/src/Xero.php @@ -1,6 +1,7 @@ Date: Wed, 16 Oct 2019 19:28:58 +1030 Subject: [PATCH 2/5] remove import --- src/Xero.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Xero.php b/src/Xero.php index 6d1c1bc..86286f5 100644 --- a/src/Xero.php +++ b/src/Xero.php @@ -1,7 +1,6 @@ Date: Wed, 16 Oct 2019 19:33:26 +1030 Subject: [PATCH 3/5] Fix PSR-2 compliance --- src/Facades/Xero.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Facades/Xero.php b/src/Facades/Xero.php index 7381252..1b03e7b 100644 --- a/src/Facades/Xero.php +++ b/src/Facades/Xero.php @@ -15,4 +15,4 @@ protected static function getFacadeAccessor() { return 'Xero'; } -} \ No newline at end of file +} From 94191b16affc08ac02c81498e4a71e89a62803d1 Mon Sep 17 00:00:00 2001 From: Benjamin Ayles Date: Wed, 16 Oct 2019 19:46:35 +1030 Subject: [PATCH 4/5] add extends --- src/Facades/Xero.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Facades/Xero.php b/src/Facades/Xero.php index 1b03e7b..751924d 100644 --- a/src/Facades/Xero.php +++ b/src/Facades/Xero.php @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Facade; -class Xero +class Xero extends Facade { /** * Get the registered name of the component. From c33523045833d0381af795e12232ccce891b73bc Mon Sep 17 00:00:00 2001 From: Benjamin Ayles Date: Thu, 17 Oct 2019 16:43:16 +1030 Subject: [PATCH 5/5] update readme with example usage --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0648988..feaba75 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,18 @@ $xero = (new Xero())->app(); # To use the 'default' app in the config $xero = (new Xero())->app('foobar'); # To use a custom app called 'foobar' in the config file ``` +Alternately you can use the Xero facade +*Note this is only for the default config* +```php +use LangleyFoxall\XeroLaravel\Facades\Xero; + +# Retrieve all contacts via facade +$contacts = Xero::contacts()->get(); + +# Retrieve an individual contact by its GUID +$contact = Xero::contacts()->find('34xxxx6e-7xx5-2xx4-bxx5-6123xxxxea49'); +``` + You can then immediately access Xero data using Eloquent-like syntax. The following code snippet shows the available syntax. When multiple results are returned from the API they will be returned as Laravel Collection. @@ -88,7 +100,7 @@ $contact = $xero->contacts()->find('34xxxx6e-7xx5-2xx4-bxx5-6123xxxxea49'); $contacts = $xero->contacts()->find([ '34xxxx6e-7xx5-2xx4-bxx5-6123xxxxea49', '364xxxx7f-2xx3-7xx3-gxx7-6726xxxxhe76', - ]); +]); ``` ### Available relationships