Skip to content

Commit fc33092

Browse files
committed
initial
0 parents  commit fc33092

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

README.md

Whitespace-only changes.

composer.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "redaelfillali/laravel-secure-model",
3+
"description": "Eloquent base model with auto-sanitized getters and setters.",
4+
"type": "library",
5+
"license": "MIT",
6+
"autoload": {
7+
"psr-4": {
8+
"Redaelfillali\\laravel-secure-model\\": "src/"
9+
}
10+
},
11+
"require": {
12+
"php": "^8.1",
13+
"illuminate/database": "^9.0|^10.0|^11.0",
14+
"stevebauman/purify": "^4.0"
15+
},
16+
"extra": {
17+
"laravel": {
18+
"providers": [
19+
"Redaelfillali\\laravel-secure-model\\SecureModelServiceProvider"
20+
]
21+
}
22+
},
23+
"minimum-stability": "stable"
24+
}

src/SecureModel.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Reda\SecureModel;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Stevebauman\Purify\Facades\Purify;
7+
8+
class SecureModel extends Model
9+
{
10+
protected array $sanitizeAttributes = [];
11+
12+
public function getAttribute($key)
13+
{
14+
$value = parent::getAttribute($key);
15+
16+
if (in_array($key, $this->sanitizeAttributes) && is_string($value)) {
17+
return Purify::clean($value);
18+
}
19+
20+
return $value;
21+
}
22+
23+
public function setAttribute($key, $value)
24+
{
25+
if (in_array($key, $this->sanitizeAttributes) && is_string($value)) {
26+
$value = Purify::clean($value);
27+
}
28+
29+
return parent::setAttribute($key, $value);
30+
}
31+
}

src/SecureModelServiceProvider.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Reda\SecureModel;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
class SecureModelServiceProvider extends ServiceProvider
8+
{
9+
public function boot(): void
10+
{
11+
// Pas forcément besoin d'y mettre quelque chose ici
12+
}
13+
14+
public function register(): void
15+
{
16+
//
17+
}
18+
}

0 commit comments

Comments
 (0)