From 18c225ada9f9907a3fca19fa002d3a60bd94fa65 Mon Sep 17 00:00:00 2001 From: Oluwatobi Samue Omisakin Date: Wed, 13 May 2020 14:35:01 +0300 Subject: [PATCH 1/5] Add service provider with publishable config file --- composer.json | 9 ++++++++ src/Providers/ArrayedServiceProvider.php | 29 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/Providers/ArrayedServiceProvider.php diff --git a/composer.json b/composer.json index 52ec921..d2e24da 100644 --- a/composer.json +++ b/composer.json @@ -42,5 +42,14 @@ "psr-4": { "Transprime\\Arrayed\\Tests\\": "tests/" } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "extra": { + "laravel": { + "providers": [ + "Transprime\\Arrayed\\Providers\\ArrayedServiceProvider" + ] + } } } diff --git a/src/Providers/ArrayedServiceProvider.php b/src/Providers/ArrayedServiceProvider.php new file mode 100644 index 0000000..97ecc65 --- /dev/null +++ b/src/Providers/ArrayedServiceProvider.php @@ -0,0 +1,29 @@ +publishes([ + __DIR__.'/../../config/migrations-snapshot.php' => config_path('arrayed'), + ], 'arrayed'); + + $this->app->bind(ArrayedInterface::class, Arrayed::class); + } + + public function register() + { + $this->mergeConfigFrom(__DIR__.'/../../config/arrayed.php', 'arrayed'); + } +} From 327f36909ebf04227a6b2c0adfda746a00c2db10 Mon Sep 17 00:00:00 2001 From: Oluwatobi Samue Omisakin Date: Wed, 13 May 2020 18:37:29 +0300 Subject: [PATCH 2/5] Fix with phpfixer --- src/Providers/ArrayedServiceProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Providers/ArrayedServiceProvider.php b/src/Providers/ArrayedServiceProvider.php index 97ecc65..321c5ba 100644 --- a/src/Providers/ArrayedServiceProvider.php +++ b/src/Providers/ArrayedServiceProvider.php @@ -16,7 +16,7 @@ class ArrayedServiceProvider extends ServiceProvider public function boot() { $this->publishes([ - __DIR__.'/../../config/migrations-snapshot.php' => config_path('arrayed'), + __DIR__ . '/../../config/migrations-snapshot.php' => config_path('arrayed'), ], 'arrayed'); $this->app->bind(ArrayedInterface::class, Arrayed::class); @@ -24,6 +24,6 @@ public function boot() public function register() { - $this->mergeConfigFrom(__DIR__.'/../../config/arrayed.php', 'arrayed'); + $this->mergeConfigFrom(__DIR__ . '/../../config/arrayed.php', 'arrayed'); } } From adeedb9ff7ce0fa55edecf4fc8d4090c010a6b54 Mon Sep 17 00:00:00 2001 From: Oluwatobi Samue Omisakin Date: Wed, 13 May 2020 18:46:06 +0300 Subject: [PATCH 3/5] Fix config path --- src/Providers/ArrayedServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Providers/ArrayedServiceProvider.php b/src/Providers/ArrayedServiceProvider.php index 321c5ba..fed315e 100644 --- a/src/Providers/ArrayedServiceProvider.php +++ b/src/Providers/ArrayedServiceProvider.php @@ -16,7 +16,7 @@ class ArrayedServiceProvider extends ServiceProvider public function boot() { $this->publishes([ - __DIR__ . '/../../config/migrations-snapshot.php' => config_path('arrayed'), + __DIR__ . '/../../config/arrayed.php' => config_path('arrayed'), ], 'arrayed'); $this->app->bind(ArrayedInterface::class, Arrayed::class); From 00fbe6a26401ca3eee71f62fa43597ee73820071 Mon Sep 17 00:00:00 2001 From: Oluwatobi Samue Omisakin Date: Wed, 13 May 2020 18:55:20 +0300 Subject: [PATCH 4/5] Fix config path and file type --- src/Providers/ArrayedServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Providers/ArrayedServiceProvider.php b/src/Providers/ArrayedServiceProvider.php index fed315e..ec14033 100644 --- a/src/Providers/ArrayedServiceProvider.php +++ b/src/Providers/ArrayedServiceProvider.php @@ -16,7 +16,7 @@ class ArrayedServiceProvider extends ServiceProvider public function boot() { $this->publishes([ - __DIR__ . '/../../config/arrayed.php' => config_path('arrayed'), + __DIR__ . '/../../config/arrayed.php' => config_path('arrayed.php'), ], 'arrayed'); $this->app->bind(ArrayedInterface::class, Arrayed::class); From 4e057790199a096dd62cf8bccabdec936efe53c9 Mon Sep 17 00:00:00 2001 From: Oluwatobi Samue Omisakin Date: Wed, 13 May 2020 19:07:44 +0300 Subject: [PATCH 5/5] Get array as array inside collect --- src/Arrayed.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Arrayed.php b/src/Arrayed.php index 06d7d09..f2f26eb 100644 --- a/src/Arrayed.php +++ b/src/Arrayed.php @@ -18,14 +18,19 @@ class Arrayed implements ArrayedInterface private $result; public function __construct(...$values) + { + $this->raw = $this->argumentsToArray(...$values); + + $this->setResult(new Undefined()); + } + + private function argumentsToArray(...$values) { if (func_num_args() === 1 && is_array($values[0])) { - $this->raw = $values[0]; - } else { - $this->raw = $values; + return $values[0]; } - $this->setResult(new Undefined()); + return $values; } public static function on(...$values): ArrayedInterface @@ -237,7 +242,7 @@ public function collect(...$with) $collectionClass = $this->getConfig('collection_class'); if ($collectionClass && class_exists($collectionClass)) { - return new $collectionClass($this->copy()->merge($with)->result()); + return new $collectionClass($this->copy()->merge($this->argumentsToArray(...$with))->result()); } throw new ArrayedException('Collection class is not set or does not exist');