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/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'); diff --git a/src/Providers/ArrayedServiceProvider.php b/src/Providers/ArrayedServiceProvider.php new file mode 100644 index 0000000..ec14033 --- /dev/null +++ b/src/Providers/ArrayedServiceProvider.php @@ -0,0 +1,29 @@ +publishes([ + __DIR__ . '/../../config/arrayed.php' => config_path('arrayed.php'), + ], 'arrayed'); + + $this->app->bind(ArrayedInterface::class, Arrayed::class); + } + + public function register() + { + $this->mergeConfigFrom(__DIR__ . '/../../config/arrayed.php', 'arrayed'); + } +}