-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from tabacitu/custom-casts
added custom casts - CleanHtml, CleanHtmlInput, CleanHtmlOutput
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Mews\Purifier\Casts; | ||
|
||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes; | ||
|
||
class CleanHtml implements CastsAttributes | ||
{ | ||
/** | ||
* Clean the HTML when casting the given value. | ||
* | ||
* @param \Illuminate\Database\Eloquent\Model $model | ||
* @param string $key | ||
* @param mixed $value | ||
* @param array $attributes | ||
* @return array | ||
*/ | ||
public function get($model, $key, $value, $attributes) | ||
{ | ||
return clean($value); | ||
} | ||
|
||
/** | ||
* Prepare the given value for storage by cleaning the HTML. | ||
* | ||
* @param \Illuminate\Database\Eloquent\Model $model | ||
* @param string $key | ||
* @param array $value | ||
* @param array $attributes | ||
* @return string | ||
*/ | ||
public function set($model, $key, $value, $attributes) | ||
{ | ||
return clean($value); | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
namespace Mews\Purifier\Casts; | ||
|
||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes; | ||
|
||
class CleanHtmlInput implements CastsAttributes | ||
{ | ||
/** | ||
* Cast the given value. Does not clean the HTML. | ||
* | ||
* @param \Illuminate\Database\Eloquent\Model $model | ||
* @param string $key | ||
* @param mixed $value | ||
* @param array $attributes | ||
* @return array | ||
*/ | ||
public function get($model, $key, $value, $attributes) | ||
{ | ||
return $value; | ||
} | ||
|
||
/** | ||
* Prepare the given value for storage by cleaning the HTML. | ||
* | ||
* @param \Illuminate\Database\Eloquent\Model $model | ||
* @param string $key | ||
* @param array $value | ||
* @param array $attributes | ||
* @return string | ||
*/ | ||
public function set($model, $key, $value, $attributes) | ||
{ | ||
return clean($value); | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
namespace Mews\Purifier\Casts; | ||
|
||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes; | ||
|
||
class CleanHtmlOutput implements CastsAttributes | ||
{ | ||
/** | ||
* Clean the HTML when casting the given value. | ||
* | ||
* @param \Illuminate\Database\Eloquent\Model $model | ||
* @param string $key | ||
* @param mixed $value | ||
* @param array $attributes | ||
* @return array | ||
*/ | ||
public function get($model, $key, $value, $attributes) | ||
{ | ||
return clean($value); | ||
} | ||
|
||
/** | ||
* Prepare the given value for storage. Does not clean the HTML. | ||
* | ||
* @param \Illuminate\Database\Eloquent\Model $model | ||
* @param string $key | ||
* @param array $value | ||
* @param array $attributes | ||
* @return string | ||
*/ | ||
public function set($model, $key, $value, $attributes) | ||
{ | ||
return $value; | ||
} | ||
} |