Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here's the base sanitizer:
- ```php
- <?php
- namespace FooProject\Internal\Sanitizers;
- abstract class BaseSanitizer
- {
- /**
- * An array of sanitizer methods to be
- * executed.
- *
- * @var array
- */
- protected $sanitizers = [];
- /**
- * Trigger the sanitization process by
- * iterating the sanitizers array and
- * mutating our data array.
- *
- * @param array $data
- * @return array
- */
- public function sanitize($data)
- {
- // Iterate all of the sanitizer methods.
- foreach ($this->sanitizers as $sanitizer) {
- $method = 'sanitize'.$sanitizer;
- // If the sanitization method exists, call it
- // to mutate our data set.
- if (method_exists($this, $method)) {
- $data = call_user_func([$this, $method], $data);
- }
- }
- return $data;
- }
- }
- ```
- and here's an example:
- ```php
- <?php
- namespace FooProject\Internal\Sanitizers;
- class UsersSanitizer extends BaseSanitizer
- {
- /**
- * An array of sanitizer methods to be
- * executed.
- *
- * @var array
- */
- protected $sanitizers = ['Email'];
- /**
- * Sanitize an email address.
- *
- * @param array $data
- * @return FooProject\Internal\Sanitizer\UserSanitizer
- */
- public function sanitizeEmail($data)
- {
- if (isset($data['email'])) {
- $data['email'] = strtolower($data['email']);
- }
- return $this;
- }
- }
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement