Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,14 @@
"psr-4": {
"Transprime\\Arrayed\\Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"laravel": {
"providers": [
"Transprime\\Arrayed\\Providers\\ArrayedServiceProvider"
]
}
}
}
15 changes: 10 additions & 5 deletions src/Arrayed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
Expand Down
29 changes: 29 additions & 0 deletions src/Providers/ArrayedServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Transprime\Arrayed\Providers;

use Illuminate\Support\ServiceProvider;
use Transprime\Arrayed\Arrayed;
use Transprime\Arrayed\Interfaces\ArrayedInterface;

class ArrayedServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
$this->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');
}
}