Skip to content

Commit

Permalink
First Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-helldar committed Aug 22, 2024
0 parents commit 7fc0d70
Show file tree
Hide file tree
Showing 31 changed files with 1,853 additions and 0 deletions.
804 changes: 804 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
* text=auto

.github/ export-ignore
tests/ export-ignore

.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore

phpunit.xml export-ignore
50 changes: 50 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Bug Report
description: Report a bug or other issue

body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
⚠️Review existing issues to see whether someone else has already reported your issue.
- type: textarea
id: environment
attributes:
label: Environment
description: |
Tip: Use the `composer info dragon-code/laravel-http-macros` command to get information for Laravel Lang.
Tip: Use the `php artisan --version` command to get information for Laravel Framework.
Tip: Use the `php -v` command to get information for PHP.
value: |
- PHP Version:
- HTTP Macros Version:
- Laravel Version:
validations:
required: true

- type: textarea
id: description
attributes:
label: Issue description
description: |
Be as specific and detailed as possible to help us triaging your issue. Screenshots and/or animations can be very useful in helping to understand the issue you're facing.
Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in.
Tip: You can use https://www.screentogif.com to record animations and videos.
validations:
required: true

- type: textarea
id: steps
attributes:
label: Steps to reproduce
description: Take some time to try and reproduce the issue, then explain how to do so here.
validations:
required: true

- type: markdown
attributes:
value: |
❤️ The Dragon Code? Please consider supporting our collective on [Boosty](https://boosty.to/dragon-code).
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Laravel issue
url: https://github.com/laravel/framework/issues
about: 'If you have a question about your Laravel implementation, ask it in your Laravel project.'
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Feature Proposal
description: Propose a new feature

body:
- type: textarea
id: description
attributes:
label: Feature description
description: |
Think through your proposal and describe it clearly.
Note that features are only added to the most recent version of Laravel Lang.
validations:
required: true

- type: markdown
attributes:
value: |
❤️ The Dragon Code? Please consider supporting our collective on [Boosty](https://boosty.to/dragon-code).
5 changes: 5 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!--
Pull requests without a descriptive title, thorough description, or tests will be closed.
In addition, please describe the benefit to end users; the reasons it does not break any existing features; how it makes building web applications easier, etc.
-->
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:
-
package-ecosystem: github-actions
directory: /
schedule:
interval: daily
labels:
- dependabot
26 changes: 26 additions & 0 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Code Style

on: [ push, pull_request ]

permissions: write-all

jobs:
style:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Detect job name
id: detect
run: |
[[ ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} ]] && NAME="Fix" || NAME="Check"
echo "name=${NAME}" >> $GITHUB_OUTPUT
- name: ${{ steps.detect.outputs.name }} the code style
uses: TheDragonCode/codestyler@v4
with:
github_token: ${{ secrets.COMPOSER_TOKEN }}
fix: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
32 changes: 32 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Tests

on: [ push, pull_request ]

jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
php: [ "8.2", "8.3" ]
laravel: [ "10.0", "11.0" ]

name: PHP ${{ matrix.php }}, Laravel ${{ matrix.laravel }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, mbstring, zip, pcntl, pdo, pdo_sqlite, iconv
coverage: xdebug

- name: Install dependencies
run: composer require --dev laravel/framework:^${{ matrix.laravel }}

- name: Execute tests
run: composer test
11 changes: 11 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Release Drafter

on:
push:
branches:
- main
workflow_dispatch:

jobs:
Update:
uses: TheDragonCode/.github/.github/workflows/release-drafter.yml@main
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.idea/
_site/
build/
node_modules/
tmp/
vendor/

.cache
.DS_Store
.env
.php_cs.cache
.phpintel
.temp

*.bak
*.cache
*.clover
*.orig

composer.lock
package-lock.json
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Andrey Helldar

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.
145 changes: 145 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# HTTP Macros for Laravel

![the dragon code laravel http macros](https://preview.dragon-code.pro/the-dragon-code/http-macros.svg?brand=laravel&mode=dark)

[![Stable Version][badge_stable]][link_packagist]
[![Total Downloads][badge_downloads]][link_packagist]
[![Github Workflow Status][badge_build]][link_build]
[![License][badge_license]][link_license]

## Installation

```Bash
composer require dragon-code/laravel-http-macros
```

## Usage

### As Class

The class instance will be returned.

```php
use Illuminate\Support\Facades\Http;

// Returns a SomeData object
return Http::get()->toData(SomeData::class);

// Will return a SomeData object generated from the JSON path
return Http::get()->toData(SomeData::class, 'data.item');

// Returns the result of the callback execution
return Http::get()->toData(
fn (array $data) => new SomeData(
$data['data']['item']['id'],
$data['data']['item']['title']
)
);

// Returns the result of the callback execution from a custom JSON path
return Http::get()->toData(
fn (array $data) => new SomeData($data['id'], $data['title']),
'data.item'
);
```

> Note
>
> If a `from` method exists in a class, then it will be called to construct the object.
>
> Compatible with [Spatie Laravel Data](https://spatie.be/docs/laravel-data).
```php
class SomeData
{
public function __construct(
public int $id,
public string $title
) {}

public static function from(array $data): static
{
return new static(...$data);
}
}

return Http::get()->toData(SomeData::class);
```

### As Collection

The `Illuminate\Support\Collection` object or an object inherited from it will be returned.

```php
use Illuminate\Support\Facades\Http;

// Returns a collection of SomeData objects
return Http::get()->toDataCollection(SomeData::class);

// Returns a collection of SomeData objects formed from the JSON path
return Http::get()->toDataCollection(SomeData::class, 'data.item');

// Returns the result of the callback execution
return Http::get()->toDataCollection(
fn (array $data) => collect([
new SomeData(
$data['data']['item']['id'],
$data['data']['item']['title']
),
])
);

// Returns the result of the callback execution from a custom JSON path
return Http::get()->toDataCollection(
fn (array $data) => collect([
new SomeData(...$data),
]),
'data.item'
);
```

> Note
>
> If a `collect` method exists in a class, then it will be called to construct the collection.
>
> Compatible with [Spatie Laravel Data](https://spatie.be/docs/laravel-data).
```php
use Illuminate\Support\Collection;

class SomeData
{
public function __construct(
public int $id,
public string $title
) {}

public static function collect(array $items): Collection
{
return collect($items)->map(
fn (array $item) => new static(...$item)
);
}
}

return Http::get()->toDataCollection(SomeData::class);
```

## License

This package is licensed under the [MIT License](LICENSE).


[badge_build]: https://img.shields.io/github/actions/workflow/status/TheDragonCode/laravel-http-macros/phpunit.yml?style=flat-square

[badge_downloads]: https://img.shields.io/packagist/dt/dragon-code/laravel-http-macros.svg?style=flat-square

[badge_license]: https://img.shields.io/packagist/l/dragon-code/laravel-http-macros.svg?style=flat-square

[badge_stable]: https://img.shields.io/github/v/release/TheDragonCode/laravel-http-macros?label=packagist&style=flat-square

[link_build]: https://github.com/TheDragonCode/laravel-http-macros/actions

[link_license]: LICENSE

[link_packagist]: https://packagist.org/packages/dragon-code/laravel-http-macros
Loading

0 comments on commit 7fc0d70

Please sign in to comment.