This repository has been archived by the owner on Nov 5, 2020. It is now read-only.
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 #13 from rdohms/v1.1
V1.1
- Loading branch information
Showing
26 changed files
with
911 additions
and
108 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
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
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
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
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
59 changes: 59 additions & 0 deletions
59
src/DMS/Bundles/FilterBundle/Form/EventListener/DelegatingFilterListener.php
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,59 @@ | ||
<?php | ||
namespace DMS\Bundles\FilterBundle\Form\EventListener; | ||
|
||
use Symfony\Component\Form\FormEvents; | ||
use Symfony\Component\Form\Event\FilterDataEvent; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use DMS\Bundles\FilterBundle\Service\Filter; | ||
|
||
/** | ||
* Delegating Filter Listener | ||
* | ||
* This subscriber listens to form events to automatically run filtering | ||
* on the attached entity, like Validation is done. | ||
*/ | ||
class DelegatingFilterListener implements EventSubscriberInterface | ||
{ | ||
/** | ||
* @var \DMS\Bundles\FilterBundle\Service\Filter | ||
*/ | ||
protected $filterService; | ||
|
||
/** | ||
* @param \DMS\Bundles\FilterBundle\Service\Filter $filterService | ||
*/ | ||
public function __construct(Filter $filterService) | ||
{ | ||
$this->filterService = $filterService; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
static public function getSubscribedEvents() | ||
{ | ||
return array( | ||
FormEvents::POST_BIND => array("onPostBind", 1024), | ||
FormEvents::BIND_NORM_DATA => array("onPostBind", 1024), | ||
); | ||
} | ||
|
||
/** | ||
* Listens to the Post Bind event and triggers filtering if adequate. | ||
* | ||
* @param FilterDataEvent $event | ||
*/ | ||
public function onPostBind($event) | ||
{ | ||
$form = $event->getForm(); | ||
|
||
if ( ! $form->isRoot()) return; | ||
|
||
$clientData = $event->getForm()->getClientData(); | ||
|
||
if ( ! is_object($clientData)) return; | ||
|
||
$this->filterService->filterEntity($clientData); | ||
|
||
} | ||
} |
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,48 @@ | ||
<?php | ||
|
||
namespace DMS\Bundles\FilterBundle\Form; | ||
|
||
use Symfony\Component\Form\Extension\Validator\Type; | ||
use Symfony\Component\Form\AbstractExtension; | ||
use DMS\Bundles\FilterBundle\Service\Filter; | ||
use DMS\Bundles\FilterBundle\Form\Type\FormTypeFilterExtension; | ||
|
||
/** | ||
* Filter Extension | ||
* | ||
* Enabled filtering in forms | ||
*/ | ||
class FilterExtension extends AbstractExtension | ||
{ | ||
/** | ||
* @var Filter | ||
*/ | ||
private $filter; | ||
|
||
/** | ||
* @var boolean | ||
*/ | ||
protected $autoFilter; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param \DMS\Bundles\FilterBundle\Service\Filter $filterService | ||
* @param boolean $autoFilter | ||
*/ | ||
public function __construct(Filter $filterService, $autoFilter) | ||
{ | ||
$this->filter = $filterService; | ||
$this->autoFilter = $autoFilter; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function loadTypeExtensions() | ||
{ | ||
return array( | ||
new FormTypeFilterExtension($this->filter, true), | ||
); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/DMS/Bundles/FilterBundle/Form/Type/FormTypeFilterExtension.php
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,55 @@ | ||
<?php | ||
namespace DMS\Bundles\FilterBundle\Form\Type; | ||
|
||
use Symfony\Component\Form\AbstractTypeExtension; | ||
use Symfony\Component\Form\FormBuilder; | ||
use DMS\Bundles\FilterBundle\Service\Filter; | ||
use DMS\Bundles\FilterBundle\Form\EventListener\DelegatingFilterListener; | ||
|
||
/** | ||
* Form Type Filter Extension | ||
* | ||
* Extends the Form Type and adds auto filtering to it. | ||
* It checks the dms_filter.auto_filter_forms parameter to see if it should or | ||
* not enable auto filtering. | ||
*/ | ||
class FormTypeFilterExtension extends AbstractTypeExtension | ||
{ | ||
/** | ||
* @var \DMS\Bundles\FilterBundle\Service\Filter | ||
*/ | ||
protected $filterService; | ||
|
||
/** | ||
* @var boolean | ||
*/ | ||
protected $autoFilter; | ||
|
||
/** | ||
* @param \DMS\Bundles\FilterBundle\Service\Filter $filterService | ||
* @param boolean $autoFilter | ||
*/ | ||
public function __construct(Filter $filterService, $autoFilter) | ||
{ | ||
$this->filterService = $filterService; | ||
$this->autoFilter = $autoFilter; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildForm(FormBuilder $builder, array $options) | ||
{ | ||
if ( ! $this->autoFilter) return; | ||
|
||
$builder->addEventSubscriber(new DelegatingFilterListener($this->filterService)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getExtendedType() | ||
{ | ||
return 'form'; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,11 @@ | ||
services: | ||
dms.filter: | ||
class: DMS\Bundles\FilterBundle\Service\Filter | ||
class: DMS\Bundles\FilterBundle\Service\Filter | ||
|
||
dms.filter.type_extension: | ||
class: DMS\Bundles\FilterBundle\Form\Type\FormTypeFilterExtension | ||
arguments: | ||
filter: @dms.filter | ||
auto_filter: %dms_filter.auto_filter_forms% | ||
tags: | ||
- { name: form.type_extension, alias: form } |
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
30 changes: 30 additions & 0 deletions
30
src/DMS/Bundles/FilterBundle/Tests/Dummy/AnnotatedClass.php
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,30 @@ | ||
<?php | ||
|
||
namespace DMS\Bundles\FilterBundle\Tests\Dummy; | ||
|
||
use DMS\Filter\Rules as Filter; | ||
|
||
class AnnotatedClass | ||
{ | ||
/** | ||
* @Filter\StripTags() | ||
* | ||
* @var string | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* @Filter\StripTags() | ||
* | ||
* @var string | ||
*/ | ||
public $nickname; | ||
|
||
/** | ||
* @Filter\StripTags("<b><i>") | ||
* | ||
* @var string | ||
*/ | ||
public $description; | ||
|
||
} |
Oops, something went wrong.