Skip to content

Commit

Permalink
#148 Adding more convenient methods to UriInterface (#149)
Browse files Browse the repository at this point in the history
#148 Adding convenient methods to UriInterface
  • Loading branch information
nyamsprod authored Dec 24, 2024
1 parent 6a2fb0a commit 67d54f3
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@

All Notable changes to `League\Uri\Interfaces` will be documented in this file

## [Next](https://github.com/thephpleague/uri-interfaces/compare/7.5.0...master) - TBD

### Added

- `Contidionable` interface
- `UriInterface::resolve`
- `UriInterface::relativize`
- `UriInterface::isAbsolute`
- `UriInterface::isNetworkPath`
- `UriInterface::isAbsolutePath`
- `UriInterface::isRelativePath`
- `UriInterface::isSameDocument`
- `UriInterface::equals`
- `UriInterface::toNormalizedString`
- `UriInterface::getOrigin`
- `UriInterface::isSameOrigin`
- `UriInterface::isCrossOrigin`

### Fixed

- None

### Deprecated

- None

### Removed

- None

## [7.5.0](https://github.com/thephpleague/uri-interfaces/compare/7.3.1...7.5.0) - 2024-12-08

### Added
Expand Down
26 changes: 26 additions & 0 deletions Contracts/Conditionable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* League.Uri (https://uri.thephpleague.com)
*
* (c) Ignace Nyamagana Butera <nyamsprod@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace League\Uri\Contracts;

interface Conditionable
{
/**
* Apply the callback if the given "condition" is (or resolves to) true.
*
* @param (callable(static): bool)|bool $condition
* @param callable(static): (static|null) $onSuccess
* @param ?callable(static): (static|null) $onFail
*/
public function when(callable|bool $condition, callable $onSuccess, ?callable $onFail = null): static;
}
16 changes: 15 additions & 1 deletion Contracts/UriInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,22 @@
*
* @method string|null getUsername() returns the user component of the URI.
* @method string|null getPassword() returns the scheme-specific information about how to gain authorization to access the resource.
* @method string toNormalizedString() returns the normalized string representation of the URI
* @method array toComponents() returns an associative array containing all the URI components.
* @method self when(callable|bool $condition, callable $onSuccess, ?callable $onFail = null) conditionally return a new instance
* @method self normalize() returns a new URI instance with normalized components
* @method self resolve(UriInterface $uri) resolves a URI against a base URI using RFC3986 rules
* @method self relativize(UriInterface $uri) relativize a URI against a base URI using RFC3986 rules
* @method self|null getOrigin() returns the URI origin as described in the WHATWG URL Living standard specification
* @method bool isOpaque() tells whether the given URI object represents an opaque URI.
* @method bool isAbsolute() tells whether the URI represents an absolute URI.
* @method bool isNetworkPath() tells whether the URI represents a network path URI.
* @method bool isAbsolutePath() tells whether the URI represents an absolute URI path.
* @method bool isRelativePath() tells whether the given URI object represents a relative path.
* @method bool isCrossOrigin(UriInterface $uri) tells whether the URI comes from a different origin than the current instance.
* @method bool isSameOrigin(UriInterface $uri) tells whether the URI comes from the same origin as the current instance.
* @method bool isSameDocument(UriInterface $uri) tells whether the given URI object represents the same document.
* @method bool isLocalFile() tells whether the `file` scheme base URI represents a local file.
* @method bool equals(UriInterface $uri, bool $excludeFragment) tells whether the given URI object represents the same document. It can take the fragment in account if it is explicitly specified
*/
interface UriInterface extends JsonSerializable, Stringable
{
Expand Down
4 changes: 2 additions & 2 deletions IPv4/BCMathCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public function pow(mixed $value, int $exponent): string
return bcpow((string) $value, (string) $exponent, self::SCALE);
}

public function compare(mixed $value1, $value2): int
public function compare(mixed $value1, mixed $value2): int
{
return bccomp((string) $value1, (string) $value2, self::SCALE);
}

public function multiply(mixed $value1, $value2): string
public function multiply(mixed $value1, mixed $value2): string
{
return bcmul((string) $value1, (string) $value2, self::SCALE);
}
Expand Down

0 comments on commit 67d54f3

Please sign in to comment.