Skip to content

Commit

Permalink
Merge pull request #154 from tabacitu/custom-casts
Browse files Browse the repository at this point in the history
added custom casts - CleanHtml, CleanHtmlInput, CleanHtmlOutput
  • Loading branch information
mewebstudio authored Oct 14, 2021
2 parents 9d28db4 + edb1ea3 commit 7ab0f74
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 7ab0f74

Please sign in to comment.