Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 76df592a6b
Fetching contributors…

Cannot retrieve contributors at this time

93 lines (76 sloc) 2.081 kb
<?php
namespace DMS\Filter;
/**
* Filter Object, responsible for retrieving the filtering rules
* for the object and applying them
*
* @package DMS
* @subpackage Filter
*
*/
class Filter implements FilterInterface
{
/**
*
* @var Mapping\ClassMetadataFactory
*/
protected $metadataFactory;
/**
* Constructor
*
* @param Mapping\ClassMetadataFactory $metadataFactory
*/
public function __construct(Mapping\ClassMetadataFactory $metadataFactory)
{
$this->metadataFactory = $metadataFactory;
}
/**
* {@inheritDoc}
*/
public function filter($object)
{
$this->walkObject($object);
}
/**
* {@inheritDoc}
*/
public function filterProperty($object, $property)
{
$this->walkObject($object, $property);
}
/**
* {@inheritDoc}
*/
public function filterValue($value, Rules\Rule $filter)
{
return $filter->applyFilter($value);
}
/**
* {@inheritDoc}
*/
public function getMetadataFactory()
{
return $this->metadataFactory;
}
/**
* Iterates over annotated properties in an object filtering the selected
* values
*
* @param object $object
* @param string $limitProperty
*/
protected function walkObject($object, $limitProperty = null) {
if ( $object === null ) {
return;
}
$metadata = $this->metadataFactory->getClassMetadata(get_class($object));
//Get a Object Handler/Walker
$walker = new ObjectWalker($object);
//Get all filtered properties or limit with selected
$properties = ($limitProperty !== null)? array($limitProperty) : $metadata->getFilteredProperties();
//Iterate over properties with filters
foreach( $properties as $property ) {
$walker->applyFilterRules($property, $metadata->getPropertyRules($property));
}
}
}
Jump to Line
Something went wrong with that request. Please try again.