Skip to content

v0.1.1 - Method Chaining Support

Choose a tag to compare

@deemonic deemonic released this 17 Oct 12:26
· 28 commits to main since this release

πŸ”— Method Chaining Support

This release adds support for method chaining on Struct objects while maintaining full backward compatibility.

✨ New Features

  • Method chaining: Struct::define()->toJson() now works!
  • toArray() method: Explicitly convert to array with internal caching
  • toJson() method: Direct JSON conversion without extra steps
  • ArrayAccess interface: Use schemas like arrays: $schema['type']
  • JsonSerializable: Works seamlessly with json_encode()

πŸ”„ Changes

The Struct::define() method now returns a Struct object instead of a raw array. This enables method chaining while maintaining backward compatibility through the ArrayAccess interface.

Before (still works):

$schema = Struct::define('User', function (Builder $builder) {
    $builder->string('name')->required();
});
$type = $schema['type']; // Array access still works!

New (method chaining):

$json = Struct::define('User', function (Builder $builder) {
    $builder->string('name')->required();
})->toJson(); // Direct method chaining!

πŸ“š Documentation

  • README updated with comprehensive examples of the new API
  • Added "Flexible API: Array Access + Object Methods" section
  • Updated structure class examples with new return types
  • Updated make:struct command stub to generate classes with correct return types

πŸ§ͺ Technical Details

  • βœ… 119 tests passing with 399 assertions
  • βœ… Full backward compatibility maintained
  • βœ… PHPStan Level 9 compliance
  • βœ… PHP 8.2, 8.3, 8.4 support
  • βœ… Laravel 11 & 12 support

πŸ“¦ Installation

composer require blaspsoft/forerunner:^0.1

Full Changelog: v0.1.0...v0.1.1