-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[12.x] Introduce Arr::from() #55715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[12.x] Introduce Arr::from() #55715
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ee40eda
[12.x] Introduce Arr::from()
9e7c7d7
Arr::from should not wrap scalar values
ddf8a5c
Arr::arrayable helper function
6dd3dd8
Arr::from can be used with raw objects except enums; handle UnitEnum …
8cbff5d
Merge branch 'laravel:12.x' into feature/array-from
daniser 7d8fe6b
Add tests
2405861
Replace implicit `getArrayableItems` usage with `Arr::from`
4fdbb89
Handle enums as regular objects in `Arr::from`; wrap enums in `getArr…
a2e6bf0
Remove useless `Arr::arrayable` checks
61bef4d
Revert to `instanceof Traversable` checks
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Support; | ||
|
||
use ArrayIterator; | ||
use Illuminate\Contracts\Support\Arrayable; | ||
use Illuminate\Contracts\Support\Jsonable; | ||
use IteratorAggregate; | ||
use JsonSerializable; | ||
use Traversable; | ||
|
||
class TestArrayableObject implements Arrayable | ||
{ | ||
public function toArray() | ||
{ | ||
return ['foo' => 'bar']; | ||
} | ||
} | ||
|
||
class TestJsonableObject implements Jsonable | ||
{ | ||
public function toJson($options = 0) | ||
{ | ||
return '{"foo":"bar"}'; | ||
} | ||
} | ||
|
||
class TestJsonSerializeObject implements JsonSerializable | ||
{ | ||
public function jsonSerialize(): array | ||
{ | ||
return ['foo' => 'bar']; | ||
} | ||
} | ||
|
||
class TestJsonSerializeWithScalarValueObject implements JsonSerializable | ||
{ | ||
public function jsonSerialize(): string | ||
{ | ||
return 'foo'; | ||
} | ||
} | ||
|
||
class TestTraversableAndJsonSerializableObject implements IteratorAggregate, JsonSerializable | ||
{ | ||
public $items; | ||
|
||
public function __construct($items = []) | ||
{ | ||
$this->items = $items; | ||
} | ||
|
||
public function getIterator(): Traversable | ||
{ | ||
return new ArrayIterator($this->items); | ||
} | ||
|
||
public function jsonSerialize(): array | ||
{ | ||
return json_decode(json_encode($this->items), true); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.