Skip to content

Commit

Permalink
Core contracts (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaEstes authored Oct 31, 2023
1 parent 056c0de commit 0ced97b
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Packages
/.github @JoshuaEstes
/tools @JoshuaEstes
/docs @JoshuaEstes
/src/SonsOfPHP/Bard @JoshuaEstes
/src/SonsOfPHP/Bridge/Doctrine/EventSourcing @JoshuaEstes
/src/SonsOfPHP/Bridge/Doctrine/FeatureToggle @JoshuaEstes
Expand Down Expand Up @@ -30,3 +32,4 @@
/src/SonsOfPHP/Component/PhoneNumber @JoshuaEstes
/src/SonsOfPHP/Component/Queue @JoshuaEstes
/src/SonsOfPHP/Component/Version @JoshuaEstes
/src/SonsOfPHP/Contract/Core @JoshuaEstes
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,9 @@ Version:
- docs/components/version/*
- src/SonsOfPHP/**/Version/*

Contracts:
- docs/contracts/**
- src/SonsOfPHP/Contract/**

documentation:
- docs/**
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Examples:
* [PR #51](https://github.com/SonsOfPHP/sonsofphp/pull/51) Added new Filesystem component
* [PR #59](https://github.com/SonsOfPHP/sonsofphp/pull/59) Added new HttpMessage component
* [PR #59](https://github.com/SonsOfPHP/sonsofphp/pull/59) Added new HttpFactory component
* [PR #70](https://github.com/SonsOfPHP/sonsofphp/pull/70) Added new Core contract

## [0.3.8]

Expand Down
4 changes: 4 additions & 0 deletions bard.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
{
"path": "src/SonsOfPHP/Component/Version",
"repository": "[email protected]:SonsOfPHP/version.git"
},
{
"path": "src/SonsOfPHP/Contract/Core",
"repository": "[email protected]:SonsOfPHP/core-contract.git"
}
]
}
19 changes: 19 additions & 0 deletions docs/contracts/core/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: Core Contracts - Overview
---

# Core Contracts

Core Contracts are generic contracts that are not specific to any one package or
project.

## Installation

```shell
composer require sonsofphp/core-contract
```

## Includes Interfaces

* ComparableInterface
* EquatableInterface
25 changes: 25 additions & 0 deletions docs/contracts/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: Contracts
---

# Contracts

Contracts are interfaces that can be reusable across multiple different
libraries and projects. The actual implementation of the interfaces is left up
to you.

The interfaces also enhance existing PSRs.

Whenever possible, the components and projects created by Sons of PHP will
implement these interfaces.

## Implementation

If you want to provide a concrete library for others to use, add this to your
`composer.json` file.

```json
"provide": {
"sonsofphp/core-contract-implementation": "^1.0"
},
```
7 changes: 5 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ nav:
- Getting Help: getting-help.md
- Code of Conduct: code-of-conduct.md
- Security Policy: security.md
- Bard:
- bard/index.md
- Components:
- components/index.md
- Clock: components/clock/index.md
Expand Down Expand Up @@ -95,5 +97,6 @@ nav:
- Operators: components/money/operators.md
- Queries: components/money/queries.md
- Version: components/version/index.md
- Bard:
- bard/index.md
- Contracts:
- contracts/index.md
- Core: contracts/core/index.md
2 changes: 2 additions & 0 deletions src/SonsOfPHP/Contract/Core/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.gitattributes export-ignore
/.gitignore export-ignore
2 changes: 2 additions & 0 deletions src/SonsOfPHP/Contract/Core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
composer.lock
vendor/
22 changes: 22 additions & 0 deletions src/SonsOfPHP/Contract/Core/ComparableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace SonsOfPHP\Contract\Core;

/**
* @author Joshua Estes <[email protected]>
*/
interface ComparableInterface
{
/**
* Returns -1 if $this < $other
* Returns 0 if $this === $other
* Returns 1 if $this > $other
*
* @param mixed $other
*
* @throws \RuntimeException When the two objects cannot be compared
*/
public function compare($other): int;
}
30 changes: 30 additions & 0 deletions src/SonsOfPHP/Contract/Core/EquatableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace SonsOfPHP\Contract\Core;

/**
* Equatable Interface is used for objects that can be checked to see if they
* are equal to each other.
*
* @author Joshua Estes <[email protected]>
*/
interface EquatableInterface
{
/**
* Checks object to see if it is equal to another object.
*
* @param mixed $other
* @param bool $strict
* When true, this MUST compare objects using === and when false objects
* MUST be compared using ==
*
* @throws \InvalidArgumentException
* If $other is unexpected type
*
* @throws \RuntimeException
* When it cannot be determined if the objects are equal to each other
*/
public function equals($other, bool $strict = true): bool;
}
19 changes: 19 additions & 0 deletions src/SonsOfPHP/Contract/Core/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright 2022 to Present Joshua Estes

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 20 additions & 0 deletions src/SonsOfPHP/Contract/Core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Sons of PHP - Core Contract
===========================

Core Contracts include very generic interfaces that can be used across many
different libraries. These would be the missing PHP interfaces that would be
helpful.

## Learn More

* [Documentation][docs]
* [Contributing][contributing]
* [Report Issues][issues] and [Submit Pull Requests][pull-requests] in the [Mother Repository][mother-repo]
* Get Help & Support using [Discussions][discussions]

[discussions]: https://github.com/orgs/SonsOfPHP/discussions
[mother-repo]: https://github.com/SonsOfPHP/sonsofphp
[contributing]: https://docs.sonsofphp.com/contributing/
[docs]: https://docs.sonsofphp.com/components/http-message/
[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3ACore
[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3ACore
48 changes: 48 additions & 0 deletions src/SonsOfPHP/Contract/Core/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "sonsofphp/core-contract",
"type": "library",
"description": "Core Contracts that are not specific to any one library",
"keywords": ["abstractions", "contracts", "decoupling", "interfaces", "interoperability", "standards"],
"homepage": "https://github.com/SonsOfPHP/core-contract",
"license": "MIT",
"authors": [
{
"name": "Joshua Estes",
"email": "[email protected]"
}
],
"support": {
"issues": "https://github.com/SonsOfPHP/sonsofphp/issues",
"forum": "https://github.com/orgs/SonsOfPHP/discussions",
"docs": "https://docs.sonsofphp.com"
},
"autoload": {
"psr-4": {
"SonsOfPHP\\Contract\\Core\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.1"
},
"extra": {
"sort-packages": true,
"branch-alias": {
"dev-main": "0.3.x-dev"
}
},
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/JoshuaEstes"
},
{
"type": "tidelift",
"url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp"
}
]
}

0 comments on commit 0ced97b

Please sign in to comment.