Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
akbarali1 committed May 2, 2024
1 parent c88bdb7 commit d21778d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name":"akbarali/action-data",
"version":"1.2.5",
"version":"1.2.6",
"description":"Action Data Validate PHP Laravel",
"license":"MIT",
"minimum-stability":"stable",
Expand Down
24 changes: 13 additions & 11 deletions src/ActionDataBaseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
trait ActionDataBaseTrait
{
private \Illuminate\Contracts\Validation\Validator $validator;
protected array $rules = [];
protected mixed $user = null;
protected bool $updated;

protected function prepare(): void {}
private array $rules = [];
private bool $updated;

/**
* @param array $parameters
Expand All @@ -29,7 +26,13 @@ public static function createFromArray(array $parameters = []): static
try {
/** @var array<string, \ReflectionProperty> $fields */
$fields = DOCache::resolve(static::class, static function () {
$class = new \ReflectionClass(static::class);
$class = new \ReflectionClass(static::class);
$interfacesCheck = $class->implementsInterface(ActionDataTraitContract::class);

if (!$interfacesCheck) {
throw new ActionDataException("Class ".static::class." must implement ".ActionDataTraitContract::class, ActionDataException::ERROR_INTERFACE_NOT_IMPLEMENTED);
}

$fields = [];
foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $reflectionProperty) {
if ($reflectionProperty->isStatic()) {
Expand All @@ -56,10 +59,9 @@ public static function createFromArray(array $parameters = []): static
}
}

$instance->prepare();

if (method_exists($instance, 'setUser')) {
$instance->setUser();
//prepare method check
if (method_exists($instance, 'prepare')) {
$instance->prepare();
}

return $instance;
Expand Down Expand Up @@ -370,7 +372,7 @@ public function has(string $property): bool
throw new ActionDataException("Property {$property} not exists in ".static::class);
}

return isset($this->{$property});
return isset($this->{$proprty});
}

}
6 changes: 4 additions & 2 deletions src/ActionDataException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public function __construct(string $message = "", int $code = 0, Throwable $prev
parent::__construct($message, $code, $previous);
}

public const ERROR_INPUT_VALIDATION = -423;
public const ERROR_NOT_NULLABLE = -623;
public const ERROR_INPUT_VALIDATION = -423;
public const ERROR_NOT_NULLABLE = -623;
public const ERROR_INTERFACE_NOT_IMPLEMENTED = -823;

}
8 changes: 8 additions & 0 deletions src/ActionDataTraitContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Akbarali\ActionData;

interface ActionDataTraitContract
{

}

0 comments on commit d21778d

Please sign in to comment.