Convert a data element to a resource object.

@param $data

@return Item
170925
protected function convertToResource($data)
    {
        return Item::make($this->client, $this->bib, $this->holding, $data->item_data->pid)
            ->init($data);
    }
1374487
protected function fromArray($data)
    {
        if (empty($data)) {
            return $this;
        }

        $this->data = array_replace_recursive($this->data, $data);

        return $this;
    }
1093700
protected function convert($data)
    {
        if ($data instanceof DateTime) {
            $data = clone $data; // don't change to original value
            return $data->setTimezone($this->timezone)->format('Y-m-d\TG:i:s\Z');
        }

        if (is_object($data) && !method_exists($data, '__toString')) {
            return null; // can't convert object to a string.
        }

        if (is_array($data)) {
            return null; // can't convert a array to a string.
        }

        if (is_bool($data)) {
            return $data ? '1' : '0'; // would otherwise be empty if converted to a string
        }

        return $data !== null ? (string)$data : null;
    }
303013
public function make($data)
    {
        if ($data instanceof Collection) {
            $this->data = collect($data->toArray());
        } elseif (is_array($data)) {
            $this->data = collect($data);
        } else {
            throw new InvalidArgumentException('Invalid data type.');
        }

        $this->config = Config::get('nestable');

        $this->parent = $this->config['parent'];

        $this->primary_key = $this->config['primary_key'];

        return $this;
    }
927969
public function dataToEntity(array $data)
    {
        $cartItem = new \ShopgateExternalCoupon();
        foreach ($data as $key => $value) {
            $method = 'set' . SimpleDataObjectConverter::snakeCaseToUpperCamelCase($key);
            if (method_exists($cartItem, $method)) {
                $cartItem->{$method}($value);
            }
        }

        return $cartItem;
    }
193558
public function createMenuNode($data) {
		$cls = $this->itemClass;
		$node = $cls::create($data, $this);
		$this->items[$node->ID] = $node;
		return $node;
	}
118635
public function create($data)
    {
        $data = $this->retrieveData($data);
        $insertData = [
            'user_id' => $this->getUserId(),
            'role_id' => $data['role_id'],
        ];
        $this->table->insert($insertData);
        return $data;
    }
652650
final public function setData($data) {
        if ((is_object($data) && !is_a($data, 'Object')) || (!is_object($data) && !is_array($data)))
            throw new \Exception('Data must be either an array or an object that extends Object: ' . gettype($data));
        $data = is_array($data) ? $data : $data->toArray();
        foreach ($data as $attr => $value) {
            if ($this->elements[$attr]) {
                $this->elements[$attr]->setData($value);
            } else
                $this->data[$attr] = $value;
        }
        $this->valid = null;
        return $this;
    }
571644
private static function toXml($data)
    {
        assert(is_array($data) || $data instanceof Traversable);

        $node = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><root />");

        return self::addDataToNode($node, $data)->asXML();
    }
98747
public function item($resourceKey, array $data)
    {
        $id = $this->getIdFromData($data);

        $resource = [
            'data' => [
                'type' => $resourceKey,
                'id' => "$id",
                'attributes' => $data,
            ],
        ];

        unset($resource['data']['attributes']['id']);

        if(isset($resource['data']['attributes']['links'])) {
            $custom_links = $data['links'];
            unset($resource['data']['attributes']['links']);
        }

        if (isset($resource['data']['attributes']['meta'])){
            $resource['data']['meta'] = $data['meta'];
            unset($resource['data']['attributes']['meta']);
        }

        if(empty($resource['data']['attributes'])) {
            $resource['data']['attributes'] = (object) [];
        }

        if ($this->shouldIncludeLinks()) {
            $resource['data']['links'] = [
                'self' => "{$this->baseUrl}/$resourceKey/$id",
            ];
            if(isset($custom_links)) {
                $resource['data']['links'] = array_merge($resource['data']['links'], $custom_links);
            }
        }

        return $resource;
    }
733586
protected function getData($data)
    {
        $method = "load" . strtoupper($this->mode);

        libxml_use_internal_errors(true);
        $this->dom->$method($data);
        $this->errors = libxml_get_errors();
        libxml_clear_errors();

        return $data;
    }
390364
public static function arrayToObject($data)
    {
        if (is_array($data)) {
            /*
            * Return array converted to object
            * Using __FUNCTION__ (Magic constant)
            * for recursive call
            */
            $self_name = 'self::' . __FUNCTION__;

            return (object)array_map($self_name, $data);
        } else {
            // Return object
            return $data;
        }
    }
1047715
protected function bindData($data)
    {
        $dataClass = $this->dataClass;
        $object = new $dataClass();

        if ($object instanceof DataInterface) {
            return $object->bind($data);
        }

        foreach ((array) $data as $field => $value) {
            $object->$field = $value;
        }

        return $object;
    }
917928
public static function encode($data)
    {
        switch (gettype($data)) {
            case 'array':
                return self::encodeArray($data);
            case 'object':
                return self::encodeObject($data);
            case 'string':
                return self::encodeString($data);
            case 'integer':
                return self::encodeInteger($data);
            case 'boolean':
                return self::encodeBoolean($data);
            case 'double':
                return self::encodeDouble($data);
            case 'NULL':
                return self::encodeNull($data);
            case 'resource':
                // TODO
                break;
            default:
                throw new UnencodeableException('Contains unencodeable type', 3);
        }
    }
409277
public static function replicate($data)
    {
        $copy = clone $data;

        foreach ($copy as $key => $value) {
            if (is_object($value)) {
                $copy->{$key} = static::replicate($value);
            }
        }

        return $copy;
    }
471541
protected function createObjectFrom($data)
    {
        $class_name = $this->class_name;

        try {
            return new $class_name($data);
        } catch (\InvalidArgumentException $e) {
            throw new ConverterException(
                sprintf("Unable to create a '%s' instance.", $class_name),
                null,
                $e
            );
        }
    }
317124
public function create($data)
    {
        $data = $this->retrieveData($data);
        $insertData = [
            'role_id'=> $this->getRoleId(),
            'resource' => $data['resource'],
            'methods'=> implode(',', $data['methods']),
        ];
        $this->table->insert($insertData);

        return $data;
    }