Processes the given attribute value which references methods / fields of the given objects.

@param string $value
@param ViewableData $object
@param ViewableData $parent
@param array $args

@return string
350575
public function processAttribute($value, ViewableData $object, ViewableData $parent = null, $args = [])
    {
        // Does the value refer to a field or method?
        
        if (strpos($value, '$') === 0) {
            
            // Obtain Field Name:
            
            $field = ltrim($value, '$');
            
            // Detect Object Relationship Format:
            
            if (strpos($field, '.') !== false) {
                
                // Expand Relation Path:
                
                $relations = explode('.', $field);
                
                // Obtain First Relation Name:
                
                $name = array_shift($relations);
                
                // Detect Accessor Method:
                
                if ($object->hasMethod("get{$name}")) {
                    $name = "get{$name}";
                }
                
                // Prepend First Relation Name:
                
                array_unshift($relations, $name);
                
                // Answer Relation Path Value:
                
                return $object->relField(implode('.', $relations));
                
            }
            
            // Obtain Field Value:
            
            if ($object->hasMethod("get{$field}")) {
                
                // First, answer the result of a method call on the receiver:
                
                return call_user_func_array(
                    [$object, "get{$field}"],
                    $this->processAttributeArgs($args, $object, $parent)
                );
                
            } elseif ($object->hasField($field)) {
                
                // Next, answer a field value from the given object:
                
                return $object->$field;
                
            } elseif (is_object($parent) && $parent->hasField($field)) {
                
                // Finally, answer a field value from the given parent object:
                
                return $parent->$field;
                
            }
            
        }
        
        // Answer Value:
        
        return $value;
    }
71928
public function populateManyRelation(DataObject $object, $field, $value)
    {
        // Initialise:
        
        $ids = [];
        
        // Process Value as Array:
        
        if ($value = $this->processValueAsArray($value)) {
            
            // Is Value an Associative Array?
            
            $isAssoc = ArrayLib::is_associative($value);
            
            // Output Verbose Message:
            
            $this->verboseMessage(sprintf('%s has an %s array value', $field, ($isAssoc ? 'associative' : 'indexed')));
            
            // Handle Array Values:
            
            if ($isAssoc) {
                
                foreach ($value as $k => $v) {
                    
                    if ($this->isTypedIdentifier($k)) {
                        
                        // Process Typed Identifier:
                        
                        list($class, $identifier) = $this->processTypedIdentifier($k);
                        
                        // Obtain Remote Join Field:
                        
                        if ($join = $this->getSchema()->getRemoteJoinField($object, $field)) {
                            
                            // Define Item Data:
                            
                            $data = (array) $v;
                            
                            if (!isset($data[$join])) {
                                $data[$join] = $object->ID;
                            }
                            
                            // Define Item Filter:
                            
                            $filter = [$join => $data[$join]];
                            
                            // Create Item Object:
                            
                            $this->getFactory()->createObject($class, $identifier, $data, $filter);
                            
                        }
                        
                    }
                    
                }
                
            } else {
                
                // Obtain ID List:
                
                foreach ($value as $k => $v) {
                    $ids[] = $this->processValue($v);
                }
                
                // Populate Relation:
                
                $this->populateManyRelationByIDs($object, $field, $ids);
                
            }
            
        }
        
        // Answer Object:
        
        return $object;
    }
568773
protected function parseValueAssignment($objectPath, $value)
    {
        $processedValue = $this->getProcessedValue($value);
        $this->setValueInObjectTree($this->getParsedObjectPath($objectPath), $processedValue);
    }
615725
protected function recursiveProcess(Parameter $param, &$value)
    {
        if ($value === null) {
            return;
        }

        if (is_array($value)) {
            $type = $param->getType();
            if ($type == 'array') {
                foreach ($value as &$item) {
                    $this->recursiveProcess($param->getItems(), $item);
                }
            } elseif ($type == 'object' && !isset($value[0])) {
                // On the above line, we ensure that the array is associative and not numerically indexed
                $knownProperties = array();
                if ($properties = $param->getProperties()) {
                    foreach ($properties as $property) {
                        $name = $property->getName();
                        $key = $property->getWireName();
                        $knownProperties[$name] = 1;
                        if (isset($value[$key])) {
                            $this->recursiveProcess($property, $value[$key]);
                            if ($key != $name) {
                                $value[$name] = $value[$key];
                                unset($value[$key]);
                            }
                        }
                    }
                }

                // Remove any unknown and potentially unsafe properties
                if ($param->getAdditionalProperties() === false) {
                    $value = array_intersect_key($value, $knownProperties);
                } elseif (($additional = $param->getAdditionalProperties()) !== true) {
                    // Validate and filter additional properties
                    foreach ($value as &$v) {
                        $this->recursiveProcess($additional, $v);
                    }
                }
            }
        }

        $value = $param->filter($value);
    }
615414
function(field, value) {
    var tmp = this.callParent(field, value)

    if (typeof field === 'object') {
      this.relations = this.relations || {}

      Object.keys(this.definition.relations).forEach(function(relationName) {
        if (field[relationName] !== undefined)
          this[relationName] = field[relationName]
      }, this)
    }

    return tmp
  }
560225
private function computeAssociationChanges(object $parentDocument, array $assoc, $value) : void
    {
        $isNewParentDocument   = isset($this->documentInsertions[spl_object_hash($parentDocument)]);
        $class                 = $this->dm->getClassMetadata(get_class($parentDocument));
        $topOrExistingDocument = ( ! $isNewParentDocument || ! $class->isEmbeddedDocument);

        if ($value instanceof GhostObjectInterface && ! $value->isProxyInitialized()) {
            return;
        }

        if ($value instanceof PersistentCollectionInterface && $value->isDirty() && $value->getOwner() !== null && ($assoc['isOwningSide'] || isset($assoc['embedded']))) {
            if ($topOrExistingDocument || CollectionHelper::usesSet($assoc['strategy'])) {
                $this->scheduleCollectionUpdate($value);
            }

            $topmostOwner                                               = $this->getOwningDocument($value->getOwner());
            $this->visitedCollections[spl_object_hash($topmostOwner)][] = $value;
            if (! empty($assoc['orphanRemoval']) || isset($assoc['embedded'])) {
                $value->initialize();
                foreach ($value->getDeletedDocuments() as $orphan) {
                    $this->scheduleOrphanRemoval($orphan);
                }
            }
        }

        // Look through the documents, and in any of their associations,
        // for transient (new) documents, recursively. ("Persistence by reachability")
        // Unwrap. Uninitialized collections will simply be empty.
        $unwrappedValue = $assoc['type'] === ClassMetadata::ONE ? [$value] : $value->unwrap();

        $count = 0;
        foreach ($unwrappedValue as $key => $entry) {
            if (! is_object($entry)) {
                throw new InvalidArgumentException(
                    sprintf('Expected object, found "%s" in %s::%s', $entry, get_class($parentDocument), $assoc['name'])
                );
            }

            $targetClass = $this->dm->getClassMetadata(get_class($entry));

            $state = $this->getDocumentState($entry, self::STATE_NEW);

            // Handle "set" strategy for multi-level hierarchy
            $pathKey = ! isset($assoc['strategy']) || CollectionHelper::isList($assoc['strategy']) ? $count : $key;
            $path    = $assoc['type'] === 'many' ? $assoc['name'] . '.' . $pathKey : $assoc['name'];

            $count++;

            switch ($state) {
                case self::STATE_NEW:
                    if (! $assoc['isCascadePersist']) {
                        throw new InvalidArgumentException('A new document was found through a relationship that was not'
                            . ' configured to cascade persist operations: ' . $this->objToStr($entry) . '.'
                            . ' Explicitly persist the new document or configure cascading persist operations'
                            . ' on the relationship.');
                    }

                    $this->persistNew($targetClass, $entry);
                    $this->setParentAssociation($entry, $assoc, $parentDocument, $path);
                    $this->computeChangeSet($targetClass, $entry);
                    break;

                case self::STATE_MANAGED:
                    if ($targetClass->isEmbeddedDocument) {
                        [, $knownParent ] = $this->getParentAssociation($entry);
                        if ($knownParent && $knownParent !== $parentDocument) {
                            $entry = clone $entry;
                            if ($assoc['type'] === ClassMetadata::ONE) {
                                $class->setFieldValue($parentDocument, $assoc['fieldName'], $entry);
                                $this->setOriginalDocumentProperty(spl_object_hash($parentDocument), $assoc['fieldName'], $entry);
                                $poid = spl_object_hash($parentDocument);
                                if (isset($this->documentChangeSets[$poid][$assoc['fieldName']])) {
                                    $this->documentChangeSets[$poid][$assoc['fieldName']][1] = $entry;
                                }
                            } else {
                                // must use unwrapped value to not trigger orphan removal
                                $unwrappedValue[$key] = $entry;
                            }
                            $this->persistNew($targetClass, $entry);
                        }
                        $this->setParentAssociation($entry, $assoc, $parentDocument, $path);
                        $this->computeChangeSet($targetClass, $entry);
                    }
                    break;

                case self::STATE_REMOVED:
                    // Consume the $value as array (it's either an array or an ArrayAccess)
                    // and remove the element from Collection.
                    if ($assoc['type'] === ClassMetadata::MANY) {
                        unset($value[$key]);
                    }
                    break;

                case self::STATE_DETACHED:
                    // Can actually not happen right now as we assume STATE_NEW,
                    // so the exception will be raised from the DBAL layer (constraint violation).
                    throw new InvalidArgumentException('A detached document was found through a '
                        . 'relationship during cascading a persist operation.');

                default:
                    // MANAGED associated documents are already taken into account
                    // during changeset calculation anyway, since they are in the identity map.
            }
        }
    }
736139
private function parseValue($value, $types, \ReflectionProperty $property, $object)
    {
        foreach ($types as $type) {
            foreach ($this->context->getParsers() as $parser) {
                if ($parser instanceof ValueParserInterface) {
                    if (is_array($value) && strpos($type, '[]') !== false) {

                        //support for nesting children
                        //https://github.com/rafrsr/lib-array2object/issues/1
                        if (count($value) === 1 && is_array(current($value))) {
                            if (array_key_exists(0, current($value))) {
                                $value = current($value);
                            }
                        }

                        $tmpArray = [];
                        foreach ($value as $key => $arrayValue) {
                            $parsedValue = $parser->toObjectValue($arrayValue, str_replace('[]', null, $type), $property, $object);
                            //the annotation [] is used alone to ignore array keys
                            if (in_array('[]', $types, true)) {
                                $tmpArray[] = $parsedValue;
                            } else {
                                $tmpArray[$key] = $parsedValue;
                            }
                        }
                        $value = $tmpArray;
                    } else {
                        $value = $parser->toObjectValue($value, str_replace('[]', null, $type), $property, $object);
                    }
                } else {
                    throw new \InvalidArgumentException(sprintf('%s is not a valid parser.', get_class($parser)));
                }
            }
        }

        return $value;
    }
37641
public function getAttribute($object, $name, array $args = array(), $type = self::ANY_CALL)
    {
        // array
        if ($type == self::ANY_CALL || $type == self::ARRAY_CALL) {

            $key = is_bool($name) || is_float($name) ? (int) $name : $name;

            if ((is_array($object) && array_key_exists($key, $object)) || ($object instanceof \ArrayAccess && isset($object[$key]))) {
                return $object[$key];
            }

            if ($type == self::ARRAY_CALL) {
                return null;
            }
        }

        // object
        if (!is_object($object)) {
            return null;
        }

        // property
        if ($type == self::ANY_CALL && isset($object->$name)) {
            return $object->$name;
        }

        // method
        $call  = false;
        $name  = (string) $name;
        $item  = strtolower($name);
        $class = get_class($object);

        if (!isset(self::$classes[$class])) {
            self::$classes[$class] = array_change_key_case(array_flip(get_class_methods($object)));
        }

        if (!isset(self::$classes[$class][$item])) {
            if (isset(self::$classes[$class]["get$item"])) {
                $name = "get$name";
            } elseif (isset(self::$classes[$class]["is$item"])) {
                $name = "is$name";
            } elseif (isset(self::$classes[$class]["__call"])) {
                $call = true;
            } else {
                return null;
            }
        }

        try {
            return call_user_func_array(array($object, $name), $args);
        } catch (\BadMethodCallException $e) {
            if (!$call) throw $e;
        }
    }
810700
protected function processFile(DataObject $object, $field, $value, $class)
    {
        // Initialise:
        
        $source = null;
        $folder = null;
        
        // Detect Value Type:
        
        if (is_array($value)) {
            
            // Handle Array Value:
            
            $source = isset($value['Source']) ? $value['Source'] : null;
            $folder = isset($value['Folder']) ? $value['Folder'] : null;
            
        } else {
            
            // Handle String Value:
            
            $source = $value;
            
        }
        
        // Obtain Folder (if required):
        
        if (!$folder) {
            $folder = $this->getFolderName($object, $field);
        }
        
        // Obtain Source Path:
        
        $path = Director::getAbsFile($source);
        
        // Does Source Exist?
        
        if (file_exists($path)) {
            
            // Obtain Base Name:
            
            $basename = basename($path);
            
            // Define Asset Filename:
            
            $filename = sprintf('%s/%s', $folder, $basename);
            
            // Obtain or Create File:
            
            if (!($file = File::find($filename))) {
                $file = Injector::inst()->create($class);
            }
            
            // Define File Contents:
            
            $file->setFromLocalFile($path, $filename);
            
            // Write and Publish File:
            
            $file->write();
            $file->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
            
            // Answer File ID:
            
            return $file->ID;
        }
    }
958017
public function processDefaultValue($key, $default, $value, & $neighbouring_values, $set_neightbouring_values = true, $changed_field = [], $options = []) {
		if (strpos($default, 'dependent::') !== false) {
			// nothing
		} else if (strpos($default, 'master_object::') !== false) {
			$field = explode('::', str_replace(['master_object::', 'static::'], '', $default));
			return $this->master_object->{$field[0]}->{$field[1]}->{$field[2]};
		} else if (strpos($default, 'parent::') !== false) {
			$field = str_replace(['parent::', 'static::'], '', $default);
			$value = $this->values[$field] ?? null;
		} else {
			if ($default === 'now()') $default = \Format::now('timestamp');
			$value = $default;
		}
		// handling override_field_value method
		if (!empty($this->wrapper_methods['processDefaultValue']['main'])) {
			// fix changed field
			if (empty($changed_field)) $changed_field = [];
			$changed_field['parent'] = $changed_field['parent'] ?? null;
			$changed_field['detail'] = $changed_field['detail'] ?? null;
			$changed_field['subdetail'] = $changed_field['subdetail'] ?? null;
			// call override method
			$model = $this->wrapper_methods['processDefaultValue']['main'][0];
			$model->{$this->wrapper_methods['processDefaultValue']['main'][1]}($this, $key, $default, $value, $neighbouring_values, $changed_field, $options);
		}
		// if we need to set neightbouring values
		if ($set_neightbouring_values) {
			$neighbouring_values[$key] = $value;
		}
		return $value;
	}
1239917
function parse(string $value, \CharlotteDunois\Livia\Commands\Context $context, ?\CharlotteDunois\Livia\Arguments\Argument $arg = null) {
        return $value;
    }
284861
static function object($value, &$error, $args)
    {
        $class = isset($args[0])? $args[0] : null;
        if (is_object($value) && (empty($class) || $value instanceof $class)){
            return $value;
        }
        $error = new Error(['Должен быть объектом класса "%s"', $class], 'object');
        return null;
    }
230359
protected function processReference($value)
    {
        if ($this->isReference($value)) {
            
            list($class, $identifier) = $this->processTypedIdentifier($value);
            
            if (!$this->getFactory()->hasFixture($class, $identifier)) {
                
                throw new InvalidArgumentException(
                    sprintf(
                        'No fixture definition found for %s.%s',
                        $class,
                        $identifier
                    )
                );
                
            }
            
            return $this->getFactory()->getFixture($class, $identifier);
        }
    }
991862
protected function denormalizeRelation(string $attributeName, PropertyMetadata $propertyMetadata, string $className, $value, ?string $format, array $context)
    {
        if (\is_string($value)) {
            try {
                return $this->iriConverter->getItemFromIri($value, $context + ['fetch_data' => true]);
            } catch (ItemNotFoundException $e) {
                throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
            } catch (InvalidArgumentException $e) {
                // Give a chance to other normalizers (e.g.: DateTimeNormalizer)
            }
        }

        if (
            !$this->resourceClassResolver->isResourceClass($className) ||
            $propertyMetadata->isWritableLink()
        ) {
            $context['resource_class'] = $className;
            $context['api_allow_update'] = true;

            try {
                if (!$this->serializer instanceof DenormalizerInterface) {
                    throw new LogicException(sprintf('The injected serializer must be an instance of "%s".', DenormalizerInterface::class));
                }

                return $this->serializer->denormalize($value, $className, $format, $context);
            } catch (InvalidValueException $e) {
                if (!$this->allowPlainIdentifiers || null === $this->itemDataProvider) {
                    throw $e;
                }
            }
        }

        if (!\is_array($value)) {
            // repeat the code so that IRIs keep working with the json format
            if (true === $this->allowPlainIdentifiers && $this->itemDataProvider) {
                $item = $this->itemDataProvider->getItem($className, $value, null, $context + ['fetch_data' => true]);
                if (null === $item) {
                    throw new ItemNotFoundException(sprintf('Item not found for "%s".', $value));
                }

                return $item;
            }

            throw new UnexpectedValueException(sprintf(
                'Expected IRI or nested document for attribute "%s", "%s" given.', $attributeName, \gettype($value)
            ));
        }

        throw new UnexpectedValueException(sprintf('Nested documents for attribute "%s" are not allowed. Use IRIs instead.', $attributeName));
    }
1212719
protected function bindData(&$parent, $data)
  {
    if ( is_object($data) ){
      $data = get_object_vars($data);
    }
    else {
      $data = (array) $data;
    }
    
    foreach($data as $k => $v){
      if ( (is_array($v) && ArrayHelper::isAssociative($v)) || is_object($v) ){
        $parent->$k = new \stdClass;
        $this->bindData($parent->$k, $v);
      }
      else {
        $parent->$k = $v;
      }
    }
  }
559464
protected function processHandlerFromResource(Attribute $definition, $value)
    {
        $type = $definition->getType();
        $handler = $this->handlers[$type];
        $parameters = $definition->getTypeParameters();

        if (! $definition->isMany()) {
            return $handler->fromResource($value, $type, $parameters);
        }

        if (! $value instanceof \Traversable && ! is_array($value)) {
            throw new NotIterableAttribute($definition, $value);
        }

        $collection = new \ArrayObject();

        foreach ($value as $item) {
            $collection[] = $handler->fromResource($item, $type, $parameters);
        }

        return $collection;
    }
57397
public function add($id, $value, $parent = 'root', array $meta = [ ], array $attributes = [ ])
    {
        $node = new Node($id, $this, $value, $meta, $attributes);

        if (! is_null($parent) and $this->items->has($parent)) {
            $parentNode = $this->items->get($parent);
            $parentNode->addChild($node);
            $node->setMeta('data-parent', $parent);
        }

        $this->items->put($id, $node);

        return $node;
    }