Skip to content

Add a Contract for URL Generation Services - #387

Merged
techmahedy merged 1 commit into
doppar:4.xfrom
techmahedy:url
Oct 30, 2026
Merged

techmahedy merged 1 commit into
doppar:4.xfrom
techmahedy:url

Conversation

@techmahedy

@techmahedy techmahedy commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Pull Request Checklist

Q A
Branch? 4.x
Bug fix? bug
New feature? no
Deprecations? no
Issues -
License MIT

Description

Introduce a URL generator contract so Doppar services can depend on an abstraction rather than the concrete UrlGenerator implementation.

Changes

  • Added Phaseolies\Support\Contracts\UrlGeneratorInterface.
  • Updated UrlGenerator to implement the contract.
  • Added strict typing to isValid(string $path).
  • Bound the contract through the existing URL generator factory closure.
  • Preserved the existing url container key as an alias.
  • Added tests for contract conformance, singleton identity, and URL generation behavior.

Backward Compatibility

Existing app('url'), URL helpers, route URL generation, fluent URL construction, signed URLs, and security settings continue to work. The contract and legacy url service key resolve to the same singleton instance.

Checklist

  • Tests have been added or updated
  • Documentation has been updated if necessary
  • Code follows the project coding standards
  • All tests pass locally

@abdulmajidcse abdulmajidcse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@techmahedy Thanks for the PR! A couple of things should be fixed before merging:

  1. isValid(string $path) breaks on null (UrlGenerator.php:288). URL::isValid($request->input('website')) with a missing field used to return false; now it throws a TypeError. Consider accepting mixed and returning false for non-strings.
  2. Aliasing 'url' to the interface (FacadeLauncher.php:79). Because bind() follows aliases, any later bind('url', ...) overwrites the UrlGeneratorInterface binding. Several tests already do this (e.g. tests/Model/CastSystemTest.php:196), after which type-hinting the contract fails.

Smaller points:

  • The url() helper resolves UrlGenerator::class, which isn't aliased, so it may not get the shared singleton. Adding alias(UrlGeneratorInterface::class, UrlGenerator::class) would fix it.
  • The full() docblock says "without query parameters", but fullUrl() includes them.
  • The URL facade @method docs still reference the concrete class and old signatures.
  • Existing issue, worth considering before the contract locks it in: the singleton builder keeps query/expiration state between calls (e.g. URL::signed(...) then route('home') leaks ?id=..&signature=..).

@abdulmajidcse abdulmajidcse mentioned this pull request Oct 30, 2026
4 tasks done
@techmahedy techmahedy added bug Something isn't working enhancement New feature or request labels Oct 30, 2026
@techmahedy

Copy link
Copy Markdown
Member Author

@abdulmajidcse thanks for the review, but i am going to merge cause

  • Container behavior: bind() following aliases is intentional. Rebinding a nickname replaces the real service, which is how overriding a service is meant to work. It's how Doppar's container is designed.

@techmahedy
techmahedy merged commit f842fdc into doppar:4.x Oct 30, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants