FormatProductAttributes.

Format the product attributes data as an array for saving in a
key value field.

@param array $attributes
Array of product attributes.

@return array
Array of formatted product attributes.
430674
private function formatProductAttributes(array $attributes) {

    $formatted = [];

    foreach ($attributes as $name => $value) {
      if (is_string($value)) {
        $valueAsString = $value;
      }
      else {
        // Does the key=>value store module expect serialize?
        // (I would prefer JSON)
        // >> Yes. (But are we using the key=>value store for this?)
        // Can we pass it the object and get 'auto serialize/unserialize'?
        // >> Maybe.
        if (is_array($value) || is_object($value)) {
          $valueAsString = serialize($value);
        }
        else {
          // 'Trust' PHP's type-casting for now.
          $valueAsString = (string) $value;
        }
      }

      $formatted[] = [
        'key' => $name,
        'value' => $valueAsString,
      ];
    }

    return $formatted;
  }
689020
protected function _cleanAttributes($attributes)
    {
        foreach ($attributes as $key => $value) {
            if (is_int($key) || in_array($key, $this->_config['ignored'])) {
                unset($attributes[$key]);
            } else if ($key != 'memberof' && is_array($value) && count($value) == 1) {
                $attributes[$key] = $value[0];
            }
        }

        return $attributes;
    }
878133
public function setAttributes(array $attributes)
    {
        $flattened = array_dot($attributes);

        $fields = $this->getFields();
        if (empty($fields))
            $fields = array_keys($attributes);

        foreach ($fields as $field) : 

            // make sure we have an aliased fields list
            $fillableKeys   = array_keys($this->fillable);
            $aliasedFields  = !empty($fillableKeys) && !is_integer($fillableKeys[0]);

            // read full path to attribute (get dot notation if available).
            $attribFullPath = isset($this->fillable[$field]) ? $this->fillable[$field] : $field;

            $hasByPath  = array_has($flattened, $attribFullPath);
            $hasByAlias = array_has($attributes, $field);

            if (! $hasByPath && ! $hasByAlias) {
                // try deep find and continue

                // browse attributes array in depth.
                $attrib = $attributes;
                foreach (explode(".", $attribFullPath) as $key) {
                    if (! isset($attrib[$key]))
                        $attrib[$key] = null;

                    $attrib = $attrib[$key];
                }

                $this->setAttribute($field, $attrib);
                continue;
            }

            // use attribute path or alias
            $attribValue = $hasByPath ? array_get($flattened, $attribFullPath)
                                      : array_get($attributes, $field);

            $this->setAttribute($field, $attribValue);
        endforeach ;

        return $this;
    }
1318864
public function save($attributes = [])
    {
        $attributes = (empty($attributes) || is_null($attributes)) ? $this->getAttributes() : $attributes;

        return $this->_save($attributes);
    }
606872
public function store($attributes = [])
    {
        // Set the attributes
        $attributes = (!empty($attributes))? $attributes : $this->app->request->input();

        // Create the record
        $result = $this->model->create($attributes);

        // Return results
        return [
            'success' => true,
            'id' => $result['id'],
            'data' => $result
        ];
    }
327126
protected function expandAttributes(array $attributes)
    {
        foreach ($attributes as &$attribute) {
            if (is_callable($attribute) && ! is_string($attribute) && ! is_array($attribute)) {
                $attribute = $attribute($attributes);
            }

            if ($attribute instanceof static) {
                $attribute = $attribute->create()->getKey();
            }

            if ($attribute instanceof Model) {
                $attribute = $attribute->getKey();
            }
        }

        return $attributes;
    }
218569
private function prepareAttributes($attributes = array())
    {
        if (!is_array($attributes)) {
            throw new InvalidArgumentException("[ImBundle] format attributes must be an array, recieved: " . var_export($attributes, true));
        }
        $result = "";
        foreach ($attributes as $key => $value) {
            if ($key === null || $key === "") {
                $result .= " " . $value;
            } else {
                $result .= " -" . $key;
                if ($value != "") {
                    $result .= " \"" . $value . "\"";
                }
            }
        }

        return $result;
    }
428833
protected function attributes($attributes)
    {
        if (!is_array($attributes)) {
            return $attributes;
        }

        $attr = '';
        foreach ($attributes as $attribute => $value) {
            if (is_int($attribute)) {
                $attribute = $value;
            }
            $attr .= ' ' . $attribute . '="' . $value . '"';
        }

        return $attr;
    }
804934
protected function flatten($attributes)
    {
        foreach ($attributes as $name => $value) {
            
            if (is_array($value)) {
                $attributes[$name] = implode(' ', array_filter($value));
            }
            
        }
        
        return $attributes;
    }
65842
protected function prepareAttributes()
    {

        // prepare the date format for the created at/updated at dates
        $createdAt = $this->getValue(ColumnKeys::CREATED_AT, date('Y-m-d H:i:s'), array($this, 'formatDate'));
        $updatedAt = $this->getValue(ColumnKeys::UPDATED_AT, date('Y-m-d H:i:s'), array($this, 'formatDate'));

        // load the product's attribute set ID
        $attributeSet = $this->getAttributeSetByAttributeSetName($this->getValue(ColumnKeys::ATTRIBUTE_SET_CODE));
        $attributeSetId = $attributeSet[MemberNames::ATTRIBUTE_SET_ID];
        $this->setAttributeSet($attributeSet);

        // initialize parent ID (the parent array entry)
        $parentId = $this->categoryIds[sizeof($this->categoryIds) - 1];

        // initialize the level
        $level = sizeof($this->categoryIds);

        // load the position, if available
        $position = $this->getValue(ColumnKeys::POSITION, 0);

        // return the prepared product
        return $this->initializeEntity(
            array(
                MemberNames::CREATED_AT       => $createdAt,
                MemberNames::UPDATED_AT       => $updatedAt,
                MemberNames::ATTRIBUTE_SET_ID => $attributeSetId,
                MemberNames::PATH             => '',
                MemberNames::PARENT_ID        => $parentId,
                MemberNames::POSITION         => $position,
                MemberNames::LEVEL            => $level,
                MemberNames::CHILDREN_COUNT   => 0
            )
        );
    }
1066523
private function prepareAttributes(array $attributes)
    {
        $attributes = array_merge(
            ['class' => 'g-recaptcha', 'data-sitekey' => $this->siteKey],
            array_filter($attributes)
        );

        self::checkDataAttribute($attributes, 'data-type', ['image', 'audio'], 'image');
        self::checkDataAttribute($attributes, 'data-theme', ['light', 'dark'], 'light');
        self::checkDataAttribute($attributes, 'data-size', ['normal', 'compact', 'invisible'], 'normal');
        self::checkDataAttribute($attributes, 'data-badge', ['bottomright', 'bottomleft', 'inline'], 'bottomright');

        return $attributes;
    }
620581
protected function attributes($attributes)
    {
        $elementStr = '';

        foreach ($attributes as $key => $value) {
            $elementStr .= ($key !== 0) ? "{$key}='{$value}' " : $value;
        }

        return $elementStr;
    }
61218
public function raw(array $attributes = [])
    {
        if ($this->amount === null) {
            return $this->getRawAttributes($attributes);
        }

        if ($this->amount < 1) {
            return [];
        }

        return array_map(function () use ($attributes) {
            return $this->getRawAttributes($attributes);
        }, range(1, $this->amount));
    }
1146964
private function mapAttributeValues(array $attributes, Attribute $attribute)
    {
        $key = $attribute->getName();
        $value = $attribute->getAllAttributeValues();

        if (!array_key_exists($key, $attributes) && 1 === count($value)) {
            $value = array_shift($value);
        }

        if (array_key_exists($key, $attributes)) {
            $currentValue = (is_array($attributes[$key]) ? $attributes[$key] : [$attributes[$key]]);

            $value = array_merge($currentValue, $value);
        }

        $attributes[$key] = $value;

        return $attributes;
    }
247458
protected function prepareAttributes(array $attributes)
    {
        $attributes['data-sitekey'] = $this->sitekey;
        if (!isset($attributes['class'])) {
            $attributes['class'] = '';
        }
        $attributes['class'] = trim('g-recaptcha ' . $attributes['class']);

        return $attributes;
    }
203766
protected function _arrayToAttributesString(array $attributes) {
		$attributes_string = '';
		foreach ($attributes as $key => $value) {
			$attributes_string .= ' ' . $key . '="' . $this->_escape($value) . '"';
		}
		return $attributes_string;
	}
417360
protected function addDateAttributesToArray(array $attributes)
    {
        foreach ($this->getDates() as $key) {
            if (! isset($attributes[$key])) {
                continue;
            }

            $attributes[$key] = $this->serializeDate(
                $this->asDateTime($attributes[$key])
            );
        }

        return $attributes;
    }