Paperyard
Public Member Functions | List of all members
Paperyard\Helpers\CensorTwigExtension Class Reference
Inheritance diagram for Paperyard\Helpers\CensorTwigExtension:

Public Member Functions

 getFilters ()
 
 censor ($value, $censors, $explode=true)
 
 getName ()
 

Detailed Description

Definition at line 12 of file CensorTwigExtension.php.

Member Function Documentation

Paperyard\Helpers\CensorTwigExtension::censor (   $value,
  $censors,
  $explode = true 
)

Definition at line 21 of file CensorTwigExtension.php.

22  {
23  // censor array with array
24  if (is_array($value) && is_array($censors)) {
25  return array_diff($value, $censors);
26  }
27 
28  // censor string (explode)
29  if (!is_array($value) && $explode) {
30  $arrayed = explode(',', $value);
31 
32  // make array from single string and filter
33  $censored = array_diff($arrayed, $censors);
34 
35  // check if empty
36  if (empty($censored)) {
37  return '';
38  }
39 
40  // return first (and only?) string
41  return $censored[0];
42  }
43 
44  return ($value != $censors) ? $value : '';
45 
46  }
Paperyard\Helpers\CensorTwigExtension::getFilters ( )

Definition at line 14 of file CensorTwigExtension.php.

15  {
16  return array(
17  'censor' => new \Twig_SimpleFilter('censor', array($this, 'censor'))
18  );
19  }
Paperyard\Helpers\CensorTwigExtension::getName ( )

Definition at line 48 of file CensorTwigExtension.php.

49  {
50  return 'censor_extention';
51  }

The documentation for this class was generated from the following file: