-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Edie Lemoine <[email protected]>
- Loading branch information
1 parent
e5dfa23
commit 646e6b9
Showing
40 changed files
with
1,025 additions
and
21 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 |
---|---|---|
|
@@ -71,4 +71,4 @@ | |
"pestphp/pest-plugin": true | ||
} | ||
} | ||
} | ||
} |
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,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\Pdk\App\Audit\Concern; | ||
|
||
use DateTime; | ||
use InvalidArgumentException; | ||
use MyParcelNL\Pdk\Audit\Collection\AuditCollection; | ||
use MyParcelNL\Pdk\Audit\Model\Audit; | ||
use MyParcelNL\Pdk\Facade\Audits; | ||
|
||
/** | ||
* @property AuditCollection $audits | ||
*/ | ||
trait HasAudits | ||
{ | ||
/** | ||
* @param string $action | ||
* @param null|string $type | ||
* @param null|array $arguments | ||
* | ||
* @return void | ||
* @throws \MyParcelNL\Pdk\Base\Exception\InvalidCastException | ||
*/ | ||
public function addAudit(string $action, ?string $type = null, ?array $arguments = []): void | ||
{ | ||
$id = uniqid('', true); | ||
$audit = new Audit([ | ||
'id' => $id, | ||
'arguments' => $arguments, | ||
'action' => $action, | ||
'model' => static::class, | ||
'modelIdentifier' => $this->getAttribute($this->auditIdentifier), | ||
'created' => new DateTime(), | ||
'type' => $type, | ||
]); | ||
|
||
Audits::add($audit); | ||
} | ||
|
||
/** | ||
* @return \MyParcelNL\Pdk\Audit\Collection\AuditCollection | ||
* @throws \MyParcelNL\Pdk\Base\Exception\InvalidCastException | ||
*/ | ||
protected function getAuditsAttribute(): AuditCollection | ||
{ | ||
return Audits::allByModel(static::class, $this->getAttribute($this->auditIdentifier)); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function initializeHasAudits(): void | ||
{ | ||
if (null === $this->auditIdentifier) { | ||
throw new InvalidArgumentException('Audit identifier is not set'); | ||
} | ||
|
||
$this->attributes['audits'] = null; | ||
$this->casts['audits'] = AuditCollection::class; | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\Pdk\Audit\Collection; | ||
|
||
use MyParcelNL\Pdk\Audit\Model\Audit; | ||
use MyParcelNL\Pdk\Base\Support\Collection; | ||
|
||
/** | ||
* @property \MyParcelNL\Pdk\Audit\Model\Audit[] $items | ||
*/ | ||
class AuditCollection extends Collection | ||
{ | ||
protected $cast = Audit::class; | ||
|
||
/** | ||
* @return self | ||
*/ | ||
public function automatic(): self | ||
{ | ||
return $this->where('type', Audit::TYPE_AUTOMATIC); | ||
} | ||
|
||
/** | ||
* @param string $action | ||
* | ||
* @return bool | ||
*/ | ||
public function hasAction(string $action): bool | ||
{ | ||
return $this->contains('action', $action); | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\Pdk\Audit\Contract; | ||
|
||
use MyParcelNL\Pdk\Audit\Collection\AuditCollection; | ||
use MyParcelNL\Pdk\Audit\Model\Audit; | ||
use MyParcelNL\Pdk\Base\Contract\RepositoryInterface; | ||
|
||
interface AuditRepositoryInterface extends RepositoryInterface | ||
{ | ||
/** | ||
* Get all audits from the database. | ||
*/ | ||
public function all(): AuditCollection; | ||
|
||
/** | ||
* Store a single audit in the database of the platform. | ||
*/ | ||
public function store(Audit $audit): void; | ||
} |
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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\Pdk\Audit\Contract; | ||
|
||
use MyParcelNL\Pdk\Audit\Collection\AuditCollection; | ||
use MyParcelNL\Pdk\Audit\Model\Audit; | ||
|
||
interface AuditServiceInterface | ||
{ | ||
/** | ||
* @param \MyParcelNL\Pdk\Audit\Model\Audit $audit | ||
* | ||
* @return \MyParcelNL\Pdk\Audit\Model\Audit | ||
*/ | ||
public function add(Audit $audit): Audit; | ||
|
||
/** | ||
* @param string $model | ||
* @param string $identifier | ||
* | ||
* @return \MyParcelNL\Pdk\Audit\Collection\AuditCollection | ||
*/ | ||
public function allByModel(string $model, string $identifier): AuditCollection; | ||
} |
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,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\Pdk\Audit\Model; | ||
|
||
use MyParcelNL\Pdk\Base\Model\Model; | ||
|
||
/** | ||
* @property null|string $id | ||
* @property array $arguments | ||
* @property string $type | ||
* @property null|string $action | ||
* @property null|class-string<Model> $model | ||
* @property null|string $modelIdentifier | ||
* @property null|\DateTime $created | ||
*/ | ||
class Audit extends Model | ||
{ | ||
public const TYPE_AUTOMATIC = 'automatic'; | ||
public const TYPE_MANUAL = 'manual'; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $attributes = [ | ||
'id' => null, | ||
'arguments' => [], | ||
'type' => self::TYPE_MANUAL, | ||
'action' => null, | ||
|
||
/** | ||
* FQCN of the model that was audited. | ||
* | ||
* @see \MyParcelNL\Pdk\App\Audit\Concern\HasAudits | ||
*/ | ||
'model' => null, | ||
|
||
/** | ||
* Identifier of the model that was audited. | ||
*/ | ||
'modelIdentifier' => null, | ||
|
||
'created' => null, | ||
]; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $casts = [ | ||
'id' => 'string', | ||
'type' => 'string', | ||
'action' => 'string', | ||
'model' => 'string', | ||
'modelIdentifier' => 'string', | ||
'arguments' => 'array', | ||
'created' => 'createdtime', | ||
]; | ||
} |
Oops, something went wrong.