checkData

Check if the given data is the right entity.

@access protected
@param  mixed        $data
@throws  ConverterException
@return PgEntity     $this
516496
protected function checkData($data)
    {
        if (!$data instanceof $this->flexible_entity_class) {
            throw new ConverterException(
                sprintf(
                    "This converter only knows how to convert entities of type '%s' ('%s' given).",
                    $this->flexible_entity_class,
                    get_class($data)
                )
            );
        }

        return $this;
    }
1167560
public function onData($data)
    {
        if (!$this->handshaked) {
            return $this->handshake($data);
        }
        return $this->handle($data);
    }
1111440
public function setData($Data)
    {
        if (! is_object($Data) || ! $Data instanceof Data) {
            throw new \InvalidArgumentException(
                'The Data Interface must be a valid Data Object'
            );
        }
        $this->Data = $Data;

        return true;
    }
320220
protected function checkReceivedDataMagic($data)
    {
        if (! Str::startsWith($data, self::MAGIC_HEADER)) {
            throw new TransportException('Receive data with error bytes.', TransportException::REMOTE);
        }
    }
1036918
public function convert($data)
    {
        foreach ($this->chain as $converter) {
            $result = $converter->convert($data);
            if ($result !== false) {
                return $result;
            }
        }
        
        return false;
    }
358871
public function setData($data)
    {
        foreach ($data as $name => $value) {
            if ($this->has($name)) {
                $this->get($name)->setValue($value);
            }
        }
        return $this;
    }
1182029
protected function convertValue($data)
    {
        if ($this->isTraversable($data)) {
            return $this->recursiveConvertArray($data);
        }

        if (is_object($data)) {
            return $this->convertObject($data) ?: null;
        }

        return $data;
    }
900922
public function reference($data)
	{
		// Process the given data.
		$processPayload = $this->process(__FUNCTION__, $data);

		if( ! $processPayload->isStatus(Payload::STATUS_VALID))
		{
			return $processPayload;
		}

		$entityPayload = $this->getOneByUuid($data['uuid']);

		if($entityPayload->getStatus() != 'found')
		{
			return $entityPayload;
		}
		
		// Either get an existing entity with uuid given or create a new one with data given.
		if(array_key_exists('uuid', $processPayload->getData()['reference']))
		{
			// @todo: Make this more consistent - returns a collection.
			$referencePayload = $this->getOneByUuid($processPayload->getData()['reference']['uuid']);

			if($referencePayload->getStatus() != 'found')
			{
				return $referencePayload;
			}

			// @todo: Make this more consistent - extra instanciating.
			$referencePayload = new Payload($referencePayload->getData(), 'found');
		}
		elseif(array_key_exists('reference_type', $processPayload->getData()['reference']))
		{
			$referencePayload = $this->create(['entity_type' => $processPayload->getData()['reference']['reference_type']] + $processPayload->getData()['reference']);

			if($referencePayload->getStatus() != 'created')
			{
				return $referencePayload;
			}
		}
		else
		{
			dd("@todo: Implement proper validation to avoid getting to this point");
		}

		// Finally, create the reference.
		$referenceData = [];
		$referenceData['entity_uuid']    = $entityPayload->getData()->first()->getUuid();
		$referenceData['entity_type']    = $entityPayload->getData()->first()->getType();
		$referenceData['entity_id']      = $entityPayload->getData()->first()->getKey();
		$referenceData['reference_uuid'] = $referencePayload->getData()->first()->getUuid();
		$referenceData['reference_type'] = $referencePayload->getData()->first()->getType();
		$referenceData['reference_id']   = $referencePayload->getData()->first()->getKey();

		$newReferencePayload = $this->createReference($referenceData);

		if($newReferencePayload->getStatus() != 'created')
		{
			return $newReferencePayload;
		}

		// @todo: What do we actually want to return here?
		return new Payload($entityPayload->getData()->first(), 'created');
	}
1320661
public function setData($data)
    {
        parent::setData($data);

        //Set the user data
        $this->getSession()->set('user', KObjectConfig::unbox($data));

        return $this;
    }
675048
public function updateIf($data)
    {
        $updated = false;
        foreach ($data as $key => $val) {
            if ($val) {
                $this->{$key} = $val;
                $updated = true;
            }
        }

        if ($updated) {
            $this->save();
        }

        return $this;
    }
1243192
public function data($data)
    {
        if (!$data) {
            return $this;
        }

        // Validate without key
        if (!$this->lastKey) {
            $data = ['' => $data];
        }

        $this->options['data'] = $data;

        return $this;
    }
591518
public function check($data)
	{
		$results = array();

		$data = $this->prepareData($data);

		foreach ($data as $datum)
		{
			$results[] = array(
				'data'  => $datum,
				'tests' => $this->process($datum)
			);
		}

		if ($this->log)
		{
			$this->log($results);
		}

		return $results;
	}
343864
public function setData(array $data): self
    {
        list($this->foreignKeys, $this->belongsToMany, $this->relationshipTypes,
            $this->reversedRelationships,$this->tableNames, $this->primaryKeys,
            $this->attributeTypes, $this->attributeLengths, $this->attributes, $this->rawAttributes,
            $this->reversedClasses) = $data;

        return $this;
    }
1081276
protected function onData($data)
    {
        if (is_null($this->totalRecordCount)) {
            $this->totalRecordCount = $data->total_record_count;
        }

        if (!isset($data->{$this->responseKey})) {
            return;
        }

        foreach ($data->{$this->responseKey} as $result) {
            $this->resources[] = $this->convertToResource($result);
        }
    }
216875
public function validate($data) {
    if ($data === NULL) throw $this->emptyException();
    if (!is_array($data)) throw $this->invalidArgument(1, $data, 'Array', __FUNCTION__);
    
    foreach ($this->languages as $lang) {
      if (!array_key_exists($lang, $data)) {
        throw $this->emptyException();
      }
      
      try {
        $data[$lang] = $this->wrappedRule->validate($data[$lang]);
      } catch (EmptyDataException $e) {
        throw $this->emptyException($e);
      }
    }
    
    return $data;
  }
203905
protected function seeSuccessData($data = null)
    {
        collect($data)->each(function ($value, $key) {
            if (is_array($value)) {
                $this->seeSuccessData($value);
            } else {
                $this->seeJson([$key => $value]);
            }
        });

        return $this;
    }
111809
public function setData($data)
    {
        foreach ($data as $field => $value) {
            $this->set($field, $value);
        }
        return $this;
    }