Beispiel #1
0
 /**
  * Retrieve filters based on the supported input/output type.
  *
  * @param $inputTypeDescription a type description that has to match the input type
  * @param $outputTypeDescription a type description that has to match the output type
  *  NB: input and output type description can contain wildcards.
  * @param $data mixed the data to be matched by the filter. If no data is given then
  *  all filters will be matched.
  * @param $dataIsInput boolean true if the given data object is to be checked as
  *  input type, false to check against the output type.
  * @return array a list of matched filters.
  */
 function &getObjectsByTypeDescription($inputTypeDescription, $outputTypeDescription, $data = null, $dataIsInput = true)
 {
     static $filterCache = array();
     static $objectFilterCache = array();
     // We do not yet support array data types. Implement when required.
     assert(!is_array($data));
     // Build the adapter cache.
     $filterCacheKey = md5($inputTypeDescription . '=>' . $outputTypeDescription);
     if (!isset($filterCache[$filterCacheKey])) {
         // Get all adapter filters.
         $result =& $this->retrieve('SELECT f.*' . ' FROM filters f' . '  INNER JOIN filter_groups fg ON f.filter_group_id = fg.filter_group_id' . ' WHERE fg.input_type like ?' . '  AND fg.output_type like ?' . '  AND f.parent_filter_id = 0 AND f.is_template = 0', array($inputTypeDescription, $outputTypeDescription));
         // Instantiate all filters.
         $filterFactory = new DAOResultFactory($result, $this, '_fromRow', array('filter_id'));
         $filterCache[$filterCacheKey] =& $filterFactory->toAssociativeArray();
     }
     // Return all filter candidates if no data is given to check against.
     if (is_null($data)) {
         return $filterCache[$filterCacheKey];
     }
     // Build the object-specific adapter cache.
     $objectFilterCacheKey = md5($filterCacheKey . (is_object($data) ? get_class($data) : "'{$data}'") . ($dataIsInput ? 'in' : 'out'));
     if (!isset($objectFilterCache[$objectFilterCacheKey])) {
         $objectFilterCache[$objectFilterCacheKey] = array();
         foreach ($filterCache[$filterCacheKey] as $filterCandidateId => $filterCandidate) {
             /* @var $filterCandidate PersistableFilter */
             // Check whether the given object can be transformed
             // with this filter.
             if ($dataIsInput) {
                 $filterDataType =& $filterCandidate->getInputType();
             } else {
                 $filterDataType =& $filterCandidate->getOutputType();
             }
             if ($filterDataType->checkType($data)) {
                 $objectFilterCache[$objectFilterCacheKey][$filterCandidateId] =& $filterCandidate;
             }
             unset($filterCandidate);
         }
     }
     return $objectFilterCache[$objectFilterCacheKey];
 }