Skip to content

Commit

Permalink
added custom casts - CleanHtml, CleanHtmlInput, CleanHtmlOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
tabacitu committed Oct 9, 2021
1 parent 53f2be3 commit edb1ea3
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Casts/CleanHtml.php
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);
}
}
36 changes: 36 additions & 0 deletions src/Casts/CleanHtmlInput.php
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);
}
}
36 changes: 36 additions & 0 deletions src/Casts/CleanHtmlOutput.php
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;
}
}

0 comments on commit edb1ea3

Please sign in to comment.