mirror of
https://github.com/archtechx/airwire.git
synced 2025-12-12 10:44:03 +00:00
wip
This commit is contained in:
parent
cdc9f32611
commit
04427ab112
22 changed files with 308 additions and 30 deletions
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Airwire;
|
||||
|
||||
use Airwire\Attributes\Encode;
|
||||
|
|
@ -177,7 +179,7 @@ class Airwire
|
|||
{
|
||||
if (isset(static::$components[$component])) {
|
||||
return new RequestBuilder($component);
|
||||
} else if (in_array($component, static::$components)) {
|
||||
} elseif (in_array($component, static::$components)) {
|
||||
return new RequestBuilder(array_search($component, static::$components));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Airwire;
|
||||
|
||||
use Airwire\Commands\ComponentCommand;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Airwire\Attributes;
|
||||
|
||||
use Attribute;
|
||||
|
|
@ -11,7 +13,8 @@ class Encode
|
|||
public string|null $property = null,
|
||||
public string|null $method = null,
|
||||
public string|null $function = null,
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
public function encode(mixed $value): mixed
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,15 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Airwire\Attributes;
|
||||
|
||||
use Attribute;
|
||||
|
||||
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD)]
|
||||
#[Attribute(Attribute::TARGET_PROPERTY|Attribute::TARGET_METHOD)]
|
||||
class Wired
|
||||
{
|
||||
public function __construct(
|
||||
public mixed $default = null,
|
||||
public bool $readonly = false,
|
||||
public string|null $type = null,
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Airwire\Commands;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ComponentCommand extends Command
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Airwire\Commands;
|
||||
|
||||
use Airwire\Airwire;
|
||||
|
|
@ -36,7 +38,7 @@ class GenerateDefinitions extends Command
|
|||
$namedTypes .= "type {$alias} = {$type};\n\n";
|
||||
}
|
||||
|
||||
$typemap .= "}";
|
||||
$typemap .= '}';
|
||||
|
||||
$defaults = json_encode($defaults);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Airwire;
|
||||
|
||||
use Airwire\Testing\RequestBuilder;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Airwire\Concerns;
|
||||
|
||||
use Airwire\Airwire;
|
||||
use ReflectionMethod;
|
||||
use ReflectionObject;
|
||||
use Illuminate\Foundation\Exceptions\Handler;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use ReflectionMethod;
|
||||
use ReflectionObject;
|
||||
use Throwable;
|
||||
|
||||
trait ManagesActions
|
||||
|
|
@ -28,7 +30,8 @@ trait ManagesActions
|
|||
if ($changes) {
|
||||
try {
|
||||
$this->changed($changes);
|
||||
} catch (ValidationException) {}
|
||||
} catch (ValidationException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +80,8 @@ trait ManagesActions
|
|||
$result = array_merge($readonly, $result);
|
||||
|
||||
$this->readonly = array_unique(array_merge(
|
||||
$this->readonly, array_keys($readonly)
|
||||
$this->readonly,
|
||||
array_keys($readonly)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Airwire\Concerns;
|
||||
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
|
@ -31,7 +33,8 @@ trait ManagesLifecycle
|
|||
if (method_exists($this, 'dehydrate')) {
|
||||
app()->call([$this, 'dehydrate'], $this->requestState);
|
||||
}
|
||||
} catch (ValidationException) {}
|
||||
} catch (ValidationException) {
|
||||
}
|
||||
|
||||
if (isset($this->errors) && ! $this->hasBeenReset) {
|
||||
$this->metadata['errors'] = $this->errors->toArray();
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Airwire\Concerns;
|
||||
|
||||
use Airwire\Airwire;
|
||||
use Airwire\Attributes\Wired;
|
||||
use ReflectionMethod;
|
||||
use ReflectionObject;
|
||||
use ReflectionProperty;
|
||||
use Airwire\Attributes\Wired;
|
||||
|
||||
trait ManagesState
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Airwire\Concerns;
|
||||
|
||||
use Illuminate\Contracts\Validation\Validator as AbstractValidator;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
trait ManagesValidation
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Airwire\Http;
|
||||
|
||||
use Airwire\Airwire;
|
||||
use Airwire\Component;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class AirwireController
|
||||
|
|
@ -47,23 +48,35 @@ class AirwireController
|
|||
}
|
||||
}],
|
||||
'state' => ['nullable', function ($attribute, $value, $fail) {
|
||||
if (! is_array($value)) $fail('State must be an array.');
|
||||
if (! is_array($value)) {
|
||||
$fail('State must be an array.');
|
||||
}
|
||||
foreach ($value as $k => $v) {
|
||||
if (! is_string($k)) $fail("[State] Property name must be a string, {$k} given.");
|
||||
if (! is_string($k)) {
|
||||
$fail("[State] Property name must be a string, {$k} given.");
|
||||
}
|
||||
}
|
||||
}],
|
||||
'changes' => ['nullable', function ($attribute, $value, $fail) {
|
||||
if (! is_array($value)) $fail('Changes must be an array.');
|
||||
if (! is_array($value)) {
|
||||
$fail('Changes must be an array.');
|
||||
}
|
||||
|
||||
foreach ($value as $k => $v) {
|
||||
if (! is_string($k)) $fail("[Changes] Property name must be a string, {$k} given.");
|
||||
if (! is_string($k)) {
|
||||
$fail("[Changes] Property name must be a string, {$k} given.");
|
||||
}
|
||||
}
|
||||
}],
|
||||
'calls' => ['nullable', function ($attribute, $value, $fail) {
|
||||
if (! is_array($value)) $fail('Calls must be an array.');
|
||||
if (! is_array($value)) {
|
||||
$fail('Calls must be an array.');
|
||||
}
|
||||
|
||||
foreach ($value as $k => $v) {
|
||||
if (! is_string($k)) $fail("[Calls] Method name must be a string, {$k} given.");
|
||||
if (! is_string($k)) {
|
||||
$fail("[Calls] Method name must be a string, {$k} given.");
|
||||
}
|
||||
}
|
||||
}],
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Airwire\Testing;
|
||||
|
||||
class AirwireResponse
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Airwire\Testing;
|
||||
|
||||
use Airwire\Airwire;
|
||||
use Airwire\Component;
|
||||
use Airwire\Http\AirwireController;
|
||||
|
||||
|
|
@ -10,7 +11,8 @@ class RequestBuilder
|
|||
{
|
||||
public function __construct(
|
||||
public string $alias,
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
public string $target = 'test';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Airwire\Testing;
|
||||
|
||||
class ResponseMetadata
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Airwire;
|
||||
|
||||
use Airwire\Attributes\Wired;
|
||||
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Support\Collection;
|
||||
|
|
@ -206,7 +207,7 @@ class TypehintConverter
|
|||
}
|
||||
}
|
||||
|
||||
return join(' | ', $results);
|
||||
return implode(' | ', $results);
|
||||
}
|
||||
|
||||
public function convertMethod(object $object, string $method): string
|
||||
|
|
@ -228,7 +229,7 @@ class TypehintConverter
|
|||
$types[] = 'null';
|
||||
}
|
||||
|
||||
$parameters[$parameter->getName()] = join(' | ', array_map(fn (ReflectionNamedType $type) => $this->convertType($type->getName(), 'parameter'), $types));
|
||||
$parameters[$parameter->getName()] = implode(' | ', array_map(fn (ReflectionNamedType $type) => $this->convertType($type->getName(), 'parameter'), $types));
|
||||
}
|
||||
|
||||
$parameters = collect($parameters)->map(fn (string $type, string $name) => "{$name}: {$type}")->join(', ');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue