Parse attribute key recursively

@param ArrayObject  $parsedFields Reference to array of parsed fields
@param StringObject $key Current key to parse
352845
private function buildFields(&$parsedFields, StringObject $key)
    {
        if ($key->contains('.')) {
            $parts = $key->explode('.', 2)->val();
            if (!isset($parsedFields[$parts[0]])) {
                $parsedFields[$parts[0]] = [];
            } elseif (!is_array($parsedFields[$parts[0]])) {
                $parsedFields[$parts[0]] = [];
            }

            $this->buildFields($parsedFields[$parts[0]], $this->str($parts[1]));
        } else {
            $parsedFields[$key->val()] = '';
        }
    }
182385
private function parseKey($key)
    {
        if (is_object($key) and $key instanceof AccessKey) {
            return $key;
        }

        $key = AccessKey::create($key);

        return $key;
    }
114224
public function hasAttribute($key, $subKey = null)
    {
        // Normalize key.
        $key = $this->normalizeAttributeKey($key);
        
        if (is_null($subKey)) {
            return Arr::has($this->attributes, $key);
        }

        return Arr::has($this->attributes, "$key.$subKey");
    }
1104076
function parse($key = '') {
    global $messageStack;

    if (isset($_FILES[$this->file])) {
      if (zen_not_null($key)) {
        $file = array('name' => $_FILES[$this->file]['name'][$key],
        'type' => $_FILES[$this->file]['type'][$key],
        'size' => $_FILES[$this->file]['size'][$key],
        'tmp_name' => $_FILES[$this->file]['tmp_name'][$key]);
      } else {
        $file = array('name' => $_FILES[$this->file]['name'],
        'type' => $_FILES[$this->file]['type'],
        'size' => $_FILES[$this->file]['size'],
        'tmp_name' => $_FILES[$this->file]['tmp_name']);
      }
    } elseif (isset($GLOBALS['HTTP_POST_FILES'][$this->file])) {
      global $HTTP_POST_FILES;

      $file = array('name' => $HTTP_POST_FILES[$this->file]['name'],
      'type' => $HTTP_POST_FILES[$this->file]['type'],
      'size' => $HTTP_POST_FILES[$this->file]['size'],
      'tmp_name' => $HTTP_POST_FILES[$this->file]['tmp_name']);
    } else {
      $file = array('name' => (isset($GLOBALS[$this->file . '_name']) ? $GLOBALS[$this->file . '_name'] : ''),
      'type' => (isset($GLOBALS[$this->file . '_type']) ? $GLOBALS[$this->file . '_type'] : ''),
      'size' => (isset($GLOBALS[$this->file . '_size']) ? $GLOBALS[$this->file . '_size'] : ''),
      'tmp_name' => (isset($GLOBALS[$this->file]) ? $GLOBALS[$this->file] : ''));
    }
    //if (!zen_not_null($file['tmp_name'])) return false;
    //if ($file['tmp_name'] == 'none') return false;
    //if (!is_uploaded_file($file['tmp_name'])) return false;

// not working at this time to test for server limit error
    if (!is_uploaded_file($file['tmp_name'])) {
      if ($this->message_location == 'direct') {
        $messageStack->add_session('header', WARNING_NO_FILE_UPLOADED, 'warning');
      } else {
        $messageStack->add_session('upload', WARNING_NO_FILE_UPLOADED, 'warning');
      }
      return false;
    }

    if ( zen_not_null($file['tmp_name']) && ($file['tmp_name'] != 'none') && is_uploaded_file($file['tmp_name']) ) {
      if (zen_not_null($file['size']) and ($file['size'] > MAX_FILE_UPLOAD_SIZE)) {
        if ($this->message_location == 'direct') {
          $messageStack->add_session('header', ERROR_FILE_TOO_BIG, 'error');
        } else {
          $messageStack->add_session('upload', ERROR_FILE_TOO_BIG, 'error');
        }
        return false;
      }
      if (substr($file['name'], -9) == '.htaccess' || (sizeof($this->extensions) > 0 && !in_array(strtolower(substr($file['name'], strrpos($file['name'], '.')+1)), $this->extensions))) {
          if ($this->message_location == 'direct') {
            $messageStack->add_session('header', ERROR_FILETYPE_NOT_ALLOWED . ' ' . UPLOAD_FILENAME_EXTENSIONS, 'error');
          } else {
            $messageStack->add_session('upload', ERROR_FILETYPE_NOT_ALLOWED . ' - ' . UPLOAD_FILENAME_EXTENSIONS, 'error');
          }
          return false;
      }

      $this->set_file($file);
      $this->set_filename($file['name']);
      $this->set_tmp_filename($file['tmp_name']);

      return $this->check_destination();
    } else {
      if ($this->message_location == 'direct') {
        $messageStack->add_session('header', WARNING_NO_FILE_UPLOADED, 'warning');
      } else {
        $messageStack->add_session('upload', WARNING_NO_FILE_UPLOADED, 'warning');
      }
      return false;
    }
  }
816152
public function copyfrom($key, $fields = null) {
		$f3 = \Base::instance();
		$srcfields = is_array($key) ? $key : $f3->get($key);
		if ($fields)
			if (is_callable($fields))
				$srcfields = $fields($srcfields);
			else {
				if (is_string($fields))
					$fields = $f3->split($fields);
				$srcfields = array_intersect_key($srcfields, array_flip($fields));
			}
		foreach ($srcfields as $key => $val) {
			if (isset($this->fieldConf[$key]) && isset($this->fieldConf[$key]['type'])) {
				if ($this->fieldConf[$key]['type'] == self::DT_JSON && is_string($val))
					$val = json_decode($val);
				elseif ($this->fieldConf[$key]['type'] == self::DT_SERIALIZED && is_string($val))
					$val = unserialize($val);
			}
			$this->set($key, $val);
		}
	}
1324935
private function parseRequestedFields($fieldString)
	{
		$raw = explode(',', $fieldString);
		$results = $this->parseRequestedFieldsArray($raw);
		return $results;
	}
131532
protected function parseMappings()
    {
        $this->mappedAttributes = [];

        foreach ($this->getMaps() as $attribute => $mapping) {
            if (is_array($mapping)) {
                $this->parseImplicitMapping($mapping, $attribute);
            } else {
                $this->mappedAttributes[$attribute] = $mapping;
            }
        }
    }
1172270
public function parseData($data, array $modes, $key = null)
    {
        $return = [];

        uksort($modes, function ($a, $b) {
            return substr_count($b, '.')-substr_count($a, '.');
        });

        if (Utility::isCollection($data)) {
            $parsed = $this->parseCollection($modes, $data, $return);
        } else {
            $parsed = $this->parseResource($modes, $data, $return);
        }

        if ($key !== null) {
            $return[$key] = $parsed;
        } else {
            if (in_array('sideload', $modes)) {
                throw new InvalidArgumentException('$key cannot be null when ' .
                                    'resources are transformed using sideload.');
            }

            $return = $parsed;
        }

        return $return;
    }
1310812
private function parseFieldRepeaters(array $fields, $key)
    {
        $blacklist = ['repeater', 'slug', 'templatefield'];
        $repeater = $fields[$key];

        if (!isset($repeater['fields']) || !is_array($repeater['fields'])) {
            return;
        }

        foreach ($repeater['fields'] as $repeaterKey => $repeaterField) {
            if (!isset($repeaterField['type']) || in_array($repeaterField['type'], $blacklist)) {
                unset($repeater['fields'][$repeaterKey]);
            }
        }

        return $repeater;
    }
88302
public function hmSet($key, $fields)
    {
        $this->log(__FUNCTION__, $key);
        return $this->persistence->hmSet($key, $fields);
    }
1051074
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $parsedData = array();

        //@todo XSD has a login element, but it's not possible to update login

        if (array_key_exists('email', $data)) {
            $parsedData['email'] = $data['email'];
        }

        if (array_key_exists('password', $data)) {
            $parsedData['password'] = $data['password'];
        }

        if (array_key_exists('enabled', $data)) {
            $parsedData['enabled'] = $this->parserTools->parseBooleanValue($data['enabled']);
        }

        if (array_key_exists('mainLanguageCode', $data)) {
            $parsedData['mainLanguageCode'] = $data['mainLanguageCode'];
        }

        if (array_key_exists('Section', $data) && is_array($data['Section'])) {
            if (!array_key_exists('_href', $data['Section'])) {
                throw new Exceptions\Parser("Missing '_href' attribute for Section element in UserUpdate.");
            }

            $parsedData['sectionId'] = $this->requestParser->parseHref($data['Section']['_href'], 'sectionId');
        }

        if (array_key_exists('remoteId', $data)) {
            $parsedData['remoteId'] = $data['remoteId'];
        }

        if (array_key_exists('fields', $data)) {
            $userId = $this->requestParser->parseHref($data['__url'], 'userId');

            if (!is_array($data['fields']) || !array_key_exists('field', $data['fields']) || !is_array($data['fields']['field'])) {
                throw new Exceptions\Parser("Invalid 'fields' element for UserUpdate.");
            }

            $parsedData['fields'] = array();
            foreach ($data['fields']['field'] as $fieldData) {
                if (!array_key_exists('fieldDefinitionIdentifier', $fieldData)) {
                    throw new Exceptions\Parser("Missing 'fieldDefinitionIdentifier' element in field data for UserUpdate.");
                }

                if (!array_key_exists('fieldValue', $fieldData)) {
                    throw new Exceptions\Parser("Missing 'fieldValue' element for '{$fieldData['fieldDefinitionIdentifier']}' identifier in UserUpdate.");
                }

                $fieldValue = $this->fieldTypeParser->parseFieldValue($userId, $fieldData['fieldDefinitionIdentifier'], $fieldData['fieldValue']);

                $languageCode = null;
                if (array_key_exists('languageCode', $fieldData)) {
                    $languageCode = $fieldData['languageCode'];
                }

                $parsedData['fields'][$fieldData['fieldDefinitionIdentifier']] = array(
                    'fieldValue' => $fieldValue,
                    'languageCode' => $languageCode,
                );
            }
        }

        $userUpdateStruct = $this->userService->newUserUpdateStruct();

        if (!empty($parsedData)) {
            if (array_key_exists('email', $parsedData)) {
                $userUpdateStruct->email = $parsedData['email'];
            }

            if (array_key_exists('password', $parsedData)) {
                $userUpdateStruct->password = $parsedData['password'];
            }

            if (array_key_exists('enabled', $parsedData)) {
                $userUpdateStruct->enabled = $parsedData['enabled'];
            }

            if (array_key_exists('mainLanguageCode', $parsedData) || array_key_exists('remoteId', $parsedData)) {
                $userUpdateStruct->contentMetadataUpdateStruct = $this->contentService->newContentMetadataUpdateStruct();

                if (array_key_exists('mainLanguageCode', $parsedData)) {
                    $userUpdateStruct->contentMetadataUpdateStruct->mainLanguageCode = $parsedData['mainLanguageCode'];
                }

                if (array_key_exists('remoteId', $parsedData)) {
                    $userUpdateStruct->contentMetadataUpdateStruct->remoteId = $parsedData['remoteId'];
                }
            }

            if (array_key_exists('fields', $parsedData)) {
                $userUpdateStruct->contentUpdateStruct = $this->contentService->newContentUpdateStruct();

                foreach ($parsedData['fields'] as $fieldDefinitionIdentifier => $fieldValue) {
                    $userUpdateStruct->contentUpdateStruct->setField(
                        $fieldDefinitionIdentifier,
                        $fieldValue['fieldValue'],
                        $fieldValue['languageCode']
                    );
                }
            }
        }

        return new RestUserUpdateStruct(
            $userUpdateStruct,
            array_key_exists('sectionId', $parsedData) ? $parsedData['sectionId'] : null
        );
    }
732229
protected function parseResponseData($key = null)
    {
        $responseData = get_array_data('resource_response.data', $this->data);

        if (!$responseData) {
            return false;
        }

        return $key ?
            get_array_data($key, $responseData) :
            $responseData;
    }
1107401
private function parseFields(array $fields)
    {
        $propertyStub = $this->generateProperty();
        $setterStub   = $this->generateSetter();
        $getterStub   = $this->generateGetter();
        foreach ($fields as $fieldInfo) {
            $this->parseProperty($propertyStub, $fieldInfo);
            $this->parseSetter($setterStub, $fieldInfo);
            $this->parseGetter($getterStub, $fieldInfo);
        }
    }
559363
private function deserializeObjectRecursively($serializedObject)
    {
        Assert::keyExists($serializedObject, 'class', "Key 'class' should be set.");
        Assert::keyExists($serializedObject, 'payload', "Key 'payload' should be set.");

        $reflection = new ReflectionClass($serializedObject['class']);
        $properties = $reflection->getProperties();
        $object = $reflection->newInstanceWithoutConstructor();

        foreach ($serializedObject['payload'] as $name => $value) {
            $matchedProperty = $this->findProperty($properties, $name);
            if (null === $matchedProperty) {
                throw new SerializationException(sprintf(
                    'Property \'%s\' not found for object \'%s\'',
                    $name,
                    $serializedObject['class']
                ));
            }

            $value = $this->deserializeValue($value);

            $matchedProperty->setAccessible(true);
            $matchedProperty->setValue($object, $value);
            $matchedProperty->setAccessible(false);
        }

        return $object;
    }
1298868
private static function parseKeyValue($key, $val, & $pointer) 
    {
        // Flags
        $openQuote = false;
        $openDoubleQuote = false;

        // Buffer
        $buff = '';

        // Parse
        for($i = 0; $i < strlen($key); $i++) {
            // Handle quoting
            if($key[$i] == '"') {
                if(!$openQuote) {
                    if($openDoubleQuote) {
                        $openDoubleQuote = false;
                    } else {
                        $openDoubleQuote = true;
                    }
                    continue;
                }
            }
            if($key[$i] == "'") {
                if(!$openDoubleQuote) {
                    if($openQuote) {
                        $openQuote = false;
                    } else {
                        $openQuote = true;
                    }
                    continue;
                }
            }

            // Handle dotted keys
            if($key[$i] == "." && !$openQuote && !$openDoubleQuote) {
                if(is_array($pointer)) {
                    if(!isset($pointer[$buff])) {
                        $pointer[$buff] = new stdClass();
                    }
                    $pointer = & $pointer[$buff];
                } else {
                    if(!isset($pointer->{$buff})) {
                        $pointer->{$buff} = new stdClass();
                    }
                    $pointer = & $pointer->{$buff};
                }

                // Cleanup buffer
                $buff = '';
                continue;
            }

            $buff .= $key[$i];
        }

        if(is_array($pointer)) {
            $pointer[$buff] = self::parseValue( $val );
        } else {
            $pointer->{$buff} = self::parseValue( $val );
        }

        return $buff;
    }
1193320
public function delete($key1, $key2, $unsets = null)
    {
        if (!is_array($unsets)) {
            $unsets = (array) $unsets;
        }

        switch ($key1) {
            case 'entityDefs':
                //unset related additional fields, e.g. a field with "address" type
                $fieldDefinitionList = $this->get('fields');

                $unsetList = $unsets;
                foreach ($unsetList as $unsetItem) {
                    if (preg_match('/fields\.([^\.]+)/', $unsetItem, $matches) && isset($matches[1])) {
                        $fieldName = $matches[1];
                        $fieldPath = [$key1, $key2, 'fields', $fieldName];

                        $additionalFields = $this->getMetadataHelper()->getAdditionalFieldList($fieldName, $this->get($fieldPath, []), $fieldDefinitionList);
                        if (is_array($additionalFields)) {
                            foreach ($additionalFields as $additionalFieldName => $additionalFieldParams) {
                                $unsets[] = 'fields.' . $additionalFieldName;
                            }
                        }
                    }
                }
                break;
        }

        $normalizedData = array(
            '__APPEND__',
        );
        $metadataUnsetData = array();
        foreach ($unsets as $unsetItem) {
            $normalizedData[] = $unsetItem;
            $metadataUnsetData[] = implode('.', array($key1, $key2, $unsetItem));
        }

        $unsetData = array(
            $key1 => array(
                $key2 => $normalizedData
            )
        );

        $this->deletedData = Util::merge($this->deletedData, $unsetData);
        $this->deletedData = Util::unsetInArrayByValue('__APPEND__', $this->deletedData, true);

        $this->data = Util::unsetInArray($this->getData(), $metadataUnsetData, true);
    }
722031
public function fieldsByKey($key)
	{
		$keys = array();

		if ($this->rows && $this->count())
		{
			foreach ($this->rows as $row)
			{
				$keys[] = $row->$key;
			}
		}

		return $keys;
	}