Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
francoism90 committed Oct 31, 2024
1 parent 5c766cb commit 7150196
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 399 deletions.
92 changes: 92 additions & 0 deletions src/Forms/Concerns/WithAttributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace Foxws\WireUse\Forms\Concerns;

use Illuminate\Support\Collection;
use Illuminate\Support\Fluent;

trait WithAttributes
{
protected function keys(): array
{
return array_keys($this->all());
}

public function fill($values)
{
$values = $this->callHook('beforeFill', $values);

return parent::fill($values);
}

public function get(string $key, mixed $default = null): mixed
{
return $this->getPropertyValue($key) ?: $default;
}

public function has(...$properties): bool
{
return $this->toCollection()
->has($properties);
}

public function contains(string $property, mixed $args): bool
{
$propertyValue = $this->get($property);

if (is_array($propertyValue)) {
return in_array($args, $propertyValue);
}

return $propertyValue === $args;
}

public function is(string $property, mixed $args = null): bool
{
return $this->get($property) == $args;
}

public function isStrict(string $property, mixed $args = null): bool
{
return $this->get($property) === $args;
}

public function filled(...$properties): bool
{
return $this->toCollection($properties)
->filter()
->isNotEmpty();
}

public function blank(...$properties): bool
{
return $this->toCollection($properties)
->filter()
->isEmpty();
}

public function clear(bool $submit = true): void
{
$properties = $this->keys();

$this->reset($properties);

if ($submit && method_exists($this, 'submit')) {
$this->submit();
}
}

protected function toCollection(...$properties): Collection
{
return $properties
? new Collection($this->only(...$properties))
: new Collection($this->all());
}

protected function toFluent(...$properties): Fluent
{
return $properties
? new Fluent($this->only(...$properties))
: new Fluent($this->all());
}
}
87 changes: 2 additions & 85 deletions src/Forms/Support/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

use Foxws\WireUse\Auth\Concerns\WithAuthorization;
use Foxws\WireUse\Exceptions\RateLimitedException;
use Foxws\WireUse\Forms\Concerns\WithAttributes;
use Foxws\WireUse\Forms\Concerns\WithSession;
use Foxws\WireUse\Forms\Concerns\WithThrottle;
use Foxws\WireUse\Forms\Concerns\WithValidation;
use Foxws\WireUse\Support\Concerns\WithHooks;
use Foxws\WireUse\Views\Concerns\WithHash;
use Illuminate\Support\Collection;
use Illuminate\Support\Fluent;
use Livewire\Form as BaseForm;

abstract class Form extends BaseForm
{
use WithAttributes;
use WithAuthorization;
use WithHash;
use WithHooks;
Expand Down Expand Up @@ -49,87 +49,4 @@ protected function handle(): void
{
//
}

protected function keys(): array
{
return array_keys($this->all());
}

public function fill($values)
{
$values = $this->callHook('beforeFill', $values);

return parent::fill($values);
}

public function get(string $key, mixed $default = null): mixed
{
return $this->getPropertyValue($key) ?: $default;
}

public function has(...$properties): bool
{
return $this->toCollection()
->has($properties);
}

public function contains(string $property, mixed $args): bool
{
$propertyValue = $this->get($property);

if (is_array($propertyValue)) {
return in_array($args, $propertyValue);
}

return $propertyValue === $args;
}

public function is(string $property, mixed $args = null): bool
{
return $this->get($property) == $args;
}

public function isStrict(string $property, mixed $args = null): bool
{
return $this->get($property) === $args;
}

public function filled(...$properties): bool
{
return $this->toCollection($properties)
->filter()
->isNotEmpty();
}

public function blank(...$properties): bool
{
return $this->toCollection($properties)
->filter()
->isEmpty();
}

public function clear(bool $submit = true): void
{
$properties = $this->keys();

$this->reset($properties);

if ($submit && method_exists($this, 'submit')) {
$this->submit();
}
}

protected function toCollection(...$properties): Collection
{
return $properties
? new Collection($this->only(...$properties))
: new Collection($this->all());
}

protected function toFluent(...$properties): Fluent
{
return $properties
? new Fluent($this->only(...$properties))
: new Fluent($this->all());
}
}
160 changes: 0 additions & 160 deletions src/Layout/Concerns/WithScroll.php

This file was deleted.

Loading

0 comments on commit 7150196

Please sign in to comment.