Пример #1
0
 /**
  * Unserialize the given data
  *
  * @param string $string
  * @throws \Cundd\PersistentObjectStore\Serializer\Exception if the data could not be unserialized
  * @return mixed
  */
 public function unserialize($string)
 {
     $data = parent::unserialize($string);
     if ($data === NULL) {
         return NULL;
     }
     $databaseIdentifier = ObjectUtility::valueForKeyPathOfObject(Constants::DATA_META_KEY . '.' . Constants::DATA_DATABASE_KEY, $data, '');
     if ($databaseIdentifier) {
         GeneralUtility::assertDatabaseIdentifier($databaseIdentifier);
     }
     return new Document($data, $databaseIdentifier);
 }
Пример #2
0
 /**
  * Returns the configuration for the given key path
  *
  * @param string $keyPath
  * @return mixed
  */
 public function getConfigurationForKeyPath($keyPath)
 {
     return ObjectUtility::valueForKeyPathOfObject($keyPath, $this->configuration);
 }
Пример #3
0
 /**
  * Sort the collection of objects by the given key
  *
  * @param Database|\Iterator|array $collection
  * @param string                   $keyPath
  * @param bool                     $descending
  * @return SortResult
  */
 public function sortCollectionByPropertyKeyPath($collection, $keyPath, $descending = FALSE)
 {
     $packedObjectsKey = 'objects';
     $resultArray = array();
     if (is_array($collection)) {
         $dataCollectionRaw = SplFixedArray::fromArray($collection);
     } else {
         if ($collection instanceof SplFixedArray) {
             $dataCollectionRaw = $collection;
         } else {
             if ($collection instanceof Database) {
                 //			$dataCollectionRaw = $collection->getRawData();
                 $dataCollectionRaw = $collection->toFixedArray();
             } else {
                 $dataCollectionRaw = SplFixedArray::fromArray(iterator_to_array($collection));
             }
         }
     }
     $dataCollectionCount = $dataCollectionRaw->getSize();
     // Pack the objects grouped by the property value
     $i = 0;
     while ($i < $dataCollectionCount) {
         $item = $dataCollectionRaw[$i];
         // Fetch to property value
         if ($item instanceof KeyValueCodingInterface) {
             $propertyValue = $item->valueForKeyPath($keyPath);
         } else {
             $propertyValue = ObjectUtility::valueForKeyPathOfObject($keyPath, $item);
         }
         // Prepare the packed result array
         if (is_float($propertyValue)) {
             $propertyValue .= '';
         } else {
             if ($propertyValue !== NULL && !is_scalar($propertyValue)) {
                 throw new SortingException(sprintf('Could not sort by property key path %s, because one value is of type %s', $keyPath, gettype($propertyValue)), 1412021636);
             }
         }
         if (!isset($resultArray[$propertyValue])) {
             $resultArray[$propertyValue] = array($packedObjectsKey => array());
         }
         $resultArray[$propertyValue][$packedObjectsKey][] = $item;
         $i++;
     }
     // Sort the objects
     if (!$descending) {
         $result = ksort($resultArray, $this->sortFlags);
     } else {
         $result = krsort($resultArray, $this->sortFlags);
     }
     if (!$result) {
         throw new SortingException('Could not sort the database', 1412021636);
     }
     // Unpack the objects
     $i = 0;
     $j = 0;
     $resultFixedArray = new SortResult($dataCollectionCount);
     $resultArray = SplFixedArray::fromArray(array_values($resultArray));
     $resultArrayCount = $resultArray->count();
     while ($i < $resultArrayCount) {
         $packedObjects = $resultArray[$i][$packedObjectsKey];
         $item = current($packedObjects);
         do {
             $resultFixedArray[$j] = $item;
             $j++;
         } while ($item = next($packedObjects));
         $i++;
     }
     if ($j != $dataCollectionCount) {
         throw new SortingException(sprintf('Number of result items does not match the number of input items (%d/%d)', $j, $dataCollectionCount), 1412243235);
     }
     return $resultFixedArray;
 }
Пример #4
0
 /**
  * Removes the given entry in the Index
  *
  * @param DocumentInterface|array $document
  * @return $this
  */
 public function deleteEntry($document)
 {
     $key = ObjectUtility::valueForKeyPathOfObject($this->getProperty(), $document);
     if (!isset($this->map[$key])) {
         throw new InvalidEntryException(sprintf('Entry \'%s\' not found to delete', $key), 1415047176);
     }
     unset($this->map[$key]);
     return $this;
 }
Пример #5
0
 /**
  * Returns the value for the given key path from the data
  *
  * @param string $keyPath
  * @return mixed
  */
 public function valueForKeyPath($keyPath)
 {
     if (!strpos($keyPath, '.')) {
         return $this->valueForKey($keyPath);
     }
     return ObjectUtility::valueForKeyPathOfObject($keyPath, $this->getData());
 }
Пример #6
0
 /**
  * Performs the comparison against the given test value
  *
  * @param mixed $testValue
  * @return bool
  */
 public function perform($testValue)
 {
     if ($testValue instanceof KeyValueCodingInterface) {
         //			$testValue = $testValue->getData();
         $propertyValue = $testValue->valueForKeyPath($this->property);
         //			$propertyValue = $testValue->valueForKeyPath($this->getProperty());
     } else {
         $propertyValue = ObjectUtility::valueForKeyPathOfObject($this->property, $testValue);
         //			$propertyValue = ObjectUtility::valueForKeyPathOfObject($this->getProperty(), $testValue);
     }
     $operator = $this->getOperator();
     switch ($operator) {
         case PropertyComparisonInterface::TYPE_EQUAL_TO:
             return $propertyValue === $this->getValue();
         case PropertyComparisonInterface::TYPE_NOT_EQUAL_TO:
             return $propertyValue !== $this->getValue();
         case PropertyComparisonInterface::TYPE_LESS_THAN:
             return $propertyValue < $this->getValue();
         case PropertyComparisonInterface::TYPE_LESS_THAN_OR_EQUAL_TO:
             return $propertyValue <= $this->getValue();
         case PropertyComparisonInterface::TYPE_GREATER_THAN:
             return $propertyValue > $this->getValue();
         case PropertyComparisonInterface::TYPE_GREATER_THAN_OR_EQUAL_TO:
             return $propertyValue >= $this->getValue();
         case PropertyComparisonInterface::TYPE_LIKE:
             return $this->performLike($propertyValue, $this->getValue());
         case PropertyComparisonInterface::TYPE_CONTAINS:
             return $this->performContains($propertyValue, $this->getValue());
         case PropertyComparisonInterface::TYPE_IN:
             return $this->performContains($this->getValue(), $propertyValue);
         case PropertyComparisonInterface::TYPE_AND:
         case PropertyComparisonInterface::TYPE_OR:
             return $this->performLogical($testValue, $this->getOperator());
         case PropertyComparisonInterface::TYPE_IS_NULL:
             return is_null($propertyValue);
         case PropertyComparisonInterface::TYPE_IS_EMPTY:
             return !$propertyValue;
     }
     return FALSE;
 }