Releases: dshafik/bag
Add the Ability to Strip Extra Params
What's Changed
Full Changelog: 2.0.3...2.1.0
Fix an issue with eloquent casting and nested bags
What's Changed
- fix: ensure nested bags are cast correctly with Eloquent by @dshafik in #71 (thanks to @ agentphoenix for the report)
Full Changelog: 2.0.2...2.0.3
Fix an issue with name mapping when running validation
What's Changed
Full Changelog: 2.0.1...2.0.2
Fix a bug where route params overwrites explicitly set bag data
Breaking Changes: Support for Union Types & Fill Nullables
What's Changed
Breaking Changes
This release has one major breaking change, and a minor breaking change:
Casting with Union Types
To support union types fully, the \Bag\Casts\CastsPropertySet::set()
method signature has changed the first argument from:
public function set(string $propertyType, string $propertyName, \Illuminate\Support\Collection $properties): mixed
to:
public function set(\Bag\Collection $propertyTypes, string $propertyName, \Illuminate\Support\Collection $properties): mixed
To update your code and retain the previous behavior, you will want to do the following:
- public function set(string $propertyType, string $propertyName, \Illuminate\Support\Collection $properties): mixed
- {
+ public function set(\Bag\Collection $propertyTypes, string $propertyName, \Illuminate\Support\Collection $properties): mixed
+ {
+ $propertyType = $propertyTypes->first();
Fill Nullables
The behavior when instantiating a Bag has changed such that arguments that are nullable without a default value are filled with nulls. Previously, this would have caused exception to be thrown. This solves for a common scenario when you are filling a Bag from user input.
readonly class MyBag extends Bag {
public function __construct(
public ?string $name
}
}
// Bag 1.4.0 (and older)
MyBag::from([]); // throws MissingPropertiesException
// Bag 2.0.0+
MyBag::from([]); // MyBag { $name = null }
Full Changelog: 1.4.0...2.0.0
Manual Validation, To Collection, PHP 8.4 support, Bug Fixes
Fix handling of extra properties
Fix Eloquent Casting for Non-Bag Values
This is a bug fix release that resolves an issue where non-Bag values were cast incorrectly when using Eloquent casting
Support named and positional arguments when instantiating a Bag
New Features
With this release Bag now supports the ability to create new instances by passing in named or positional arguments. (docs)
To get auto-complete in your editor, you will need to add @method
phpdocs to your bag class. This can be automated using artisan make:bag <Bag> --docs --update
. (docs)
Full Changelog: 1.2.2...1.3.0
Fix null support for Magic Casts
Fixes
- Fix an issue where
MagicCast
would error when casting to Bag objects, and would be less strict when casting to other types (i.e. it would act likestrict_types
was off,null -> int = 0
)
Full Changelog: 1.2.1...1.2.2