generated from glhd/laravel-package-template
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor to dedicated Properties collection class * Add custom caster support * Add test to make sure multiple custom dumpers can be registered
- Loading branch information
Showing
25 changed files
with
680 additions
and
147 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,23 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- "[0-9]+.[0-9]+.[0-9]+" | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Create GitHub release | ||
uses: docker://antonyurchenko/git-release:v4 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
PRE_RELEASE: true | ||
DRAFT_RELEASE: true |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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
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,69 @@ | ||
<?php | ||
|
||
namespace Glhd\LaravelDumper\Casters; | ||
|
||
use BadMethodCallException; | ||
use Closure; | ||
use Glhd\LaravelDumper\Support\Properties; | ||
use Illuminate\Contracts\Foundation\Application; | ||
use Symfony\Component\VarDumper\Cloner\Stub; | ||
|
||
class CustomCaster extends Caster | ||
{ | ||
protected array $operations = []; | ||
|
||
public static function register(Application $app): void | ||
{ | ||
throw new BadMethodCallException('Custom casters must be registered via the LaravelDumper facade.'); | ||
} | ||
|
||
public function cast($target, Properties $properties, Stub $stub, bool $is_nested, int $filter = 0): array | ||
{ | ||
return collect($this->operations) | ||
->reduce(fn(Properties $properties, Closure $operation) => $operation($properties, $target), $properties) | ||
->applyCutsToStub($stub, $properties) | ||
->all(); | ||
} | ||
|
||
public function reorder(array $rules): CustomCaster | ||
{ | ||
$this->operations[] = fn(Properties $properties) => $properties->reorder($rules); | ||
|
||
return $this; | ||
} | ||
|
||
public function filter(callable $filter = null): CustomCaster | ||
{ | ||
$this->operations[] = fn(Properties $properties) => $properties->filter($filter); | ||
|
||
return $this; | ||
} | ||
|
||
public function dynamic(string $key, Closure $callback): CustomCaster | ||
{ | ||
$this->operations[] = fn(Properties $properties, $target) => $properties->putDynamic($key, $callback($target, $properties)); | ||
|
||
return $this; | ||
} | ||
|
||
public function virtual(string $key, Closure $callback): CustomCaster | ||
{ | ||
$this->operations[] = fn(Properties $properties, $target) => $properties->putVirtual($key, $callback($target, $properties)); | ||
|
||
return $this; | ||
} | ||
|
||
public function only($keys): CustomCaster | ||
{ | ||
$this->operations[] = fn(Properties $properties) => $properties->only($keys); | ||
|
||
return $this; | ||
} | ||
|
||
public function except($keys): CustomCaster | ||
{ | ||
$this->operations[] = fn(Properties $properties) => $properties->except($keys); | ||
|
||
return $this; | ||
} | ||
} |
Oops, something went wrong.