-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e11a00
commit 71cb046
Showing
5 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Deploy | ||
|
||
on: | ||
workflow_dispatch: {} | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
deploy-docs: | ||
name: Deploy Docs | ||
|
||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
pages: write | ||
id-token: write | ||
|
||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
|
||
steps: | ||
- name: Checkout the code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
cache: npm | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Build Docs | ||
run: npm run docs:build | ||
|
||
- name: Configure pages | ||
uses: actions/configure-pages@v2 | ||
|
||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v1 | ||
with: | ||
path: docs/.vitepress/dist | ||
|
||
- name: Deploy Docs | ||
id: deployment | ||
uses: actions/deploy-pages@v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,10 @@ composer.phar | |
coverage | ||
phpunit.xml | ||
|
||
# Docs | ||
cache | ||
package-lock.json | ||
|
||
# Others | ||
*.cache | ||
*.env | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { defineConfig } from 'vitepress' | ||
|
||
// https://vitepress.dev/reference/site-config | ||
export default defineConfig({ | ||
title: "PHP Results", | ||
description: "An opinionated result type for PHP", | ||
themeConfig: { | ||
// https://vitepress.dev/reference/default-theme-config | ||
nav: [ | ||
{ text: 'Home', link: '/' }, | ||
{ text: 'Examples', link: '/markdown-examples' } | ||
], | ||
sidebar: [ | ||
{ | ||
text: 'Examples', | ||
items: [ | ||
{ text: 'Markdown Examples', link: '/markdown-examples' }, | ||
{ text: 'Runtime API Examples', link: '/api-examples' } | ||
] | ||
} | ||
], | ||
search: { | ||
provider: 'local' | ||
}, | ||
socialLinks: [ | ||
{ icon: 'github', link: 'https://github.com/hereldar/php-results' } | ||
] | ||
}, | ||
base: '/php-date-times/' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
PHP Results | ||
=========== | ||
|
||
This package includes an opinionated version of the `Result` type of Rust. It is | ||
not intended to replicate the original type one-to-one, but to allow developers | ||
to handle the results in any way they choose. | ||
|
||
Use examples | ||
------------ | ||
|
||
This `Result` type allows ignoring errors without a try-catch | ||
block: | ||
|
||
```php | ||
$value = getValue()->or(false); | ||
``` | ||
|
||
It also allows throwing the error as a regular exception: | ||
|
||
```php | ||
doSomething()->orFail(); | ||
``` | ||
|
||
Or throwing a custom exception: | ||
|
||
```php | ||
doSomething()->orThrow(new MyException()); | ||
``` | ||
|
||
More complex flows can be handled by concatenating operations: | ||
|
||
```php | ||
$record = fetchRecord() | ||
->andThen(updateIt(...)) | ||
->orElse(insertIt(...)) | ||
->orFail(); | ||
``` | ||
|
||
And much more: | ||
|
||
```php | ||
$result = myFunction(); | ||
|
||
if ($result->isError()) { | ||
handleFailure($result->message()); | ||
} else { | ||
handleSuccess($result->value()); | ||
} | ||
|
||
return match (true) { | ||
$result instanceof Ok => $result->value(), | ||
$result instanceof MyError => false, | ||
default => throw new MyException(), | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"devDependencies": { | ||
"vitepress": "^1.0.0-alpha.66" | ||
}, | ||
"scripts": { | ||
"docs:dev": "vitepress dev docs", | ||
"docs:build": "vitepress build docs", | ||
"docs:preview": "vitepress preview docs" | ||
} | ||
} |