@param      $data
@param null $toEntity

@return object
768558
protected function denormalize($data, $toEntity = null)
    {
        return $this->serializer->denormalize($data, $this->entityClass, $this->factory, $toEntity);
    }
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;
    }
968652
public static function updateOrNull($data = null)
    {
        static $request;
        if (!$request) {
            $request = Di::getDefault()->getShared('request');
        }

        if (!$request->isPost() && !$request->isPut() && !$request->isPatch()) {
            return null;
        }

        $model = new static;

        $pkName = $model->getPrimaryKey();

        $_request = $request->get();

        $instance = static::get(isset($data[$pkName]) ? $data[$pkName] : $request->getId($pkName));

        if ($data === null || !isset($data[0])) {
            foreach ($model->getSafeFields() as $field) {
                if (isset($_request[$field])) {
                    $instance->$field = $_request[$field];
                }
            }
        }

        if ($data) {
            foreach ($data as $k => $v) {
                if (is_int($k)) {
                    $field = $v;
                    if (!isset($_request[$field])) {
                        throw new MissingFieldException($field);
                    }
                    $instance->$field = $_request[$field];
                } else {
                    $instance->$k = $v;
                }
            }
        }

        return $instance->update();
    }
1330201
public function sendData($data)
    {
        $request = new LegacyNotifyRequest($this->httpClient, $this->httpRequest);
        $request->initialize($this->parameters->all());
        $request->setAlipayPublicKey($this->getAlipayPublicKey());
        $request->setVerifyNotifyId($this->verifyNotifyId);
        $request->setKey($this->getKey());
        $response = $request->send();

        $data = $response->getData();

        return $this->response = new LegacyCompletePurchaseResponse($this, $data);
    }
344542
public function setData($data)
    {
        foreach ($data as $key => $dtoData) {
            $this->data[$key] = new RuneDto($dtoData);
        }
    
        return $this;
    }
15316
protected function _instantiateEntity($identifier, $data)
    {
        $identifier = clone $identifier;
        $identifier->package = str_replace('com_', '', $data['option']);
        register_default(array(
            'identifier' => $identifier,
            'default' => array('ComComponentsDomainEntityComponent')
        ));

        return clone AnDomain::getRepository($identifier)->getClone();
    }
974128
public function create($data)
	{
		$this->getResponse()
			->setStatusCode(Response::STATUS_CODE_201);
		
		$request = $this->getRequest();
		$content = $request->getContent();
		$content = !empty($content) ? Json::decode($content, Json::TYPE_ARRAY) : array();
		$post = array_merge_recursive(
			$request->getPost()->toArray(),
			$content
		);
		
		// Inject user data if connected checking if it is not the admin
		// write better this part, peraphs in some service or using doctrine
		$main = $this->getServiceLocator()->get('neobazaar.service.main');
		$userRepository = $main->getUserEntityRepository();
		if($this->zfcUserAuthentication()->hasIdentity()) {
			$identity = $this->zfcUserAuthentication()->getIdentity();
			$userModel = new UserModel($identity, $this->getServiceLocator());
			$classifiedId = 
				isset($post['document']) && isset($post['document']['id']) ? 
				$post['document']['id'] : 
				null;
			
			// Set identity values in any case!!
			$post['user'] = array (
				'email' => $identity->getEmail(),
				'name' => $identity->getName(),
				'id' => $userRepository->getEncryptedId($identity->getUserId())
			);
			
			// admin that want to edit other user classified, 
			// set the correct user to the data.
			if($userModel->isAdmin && null !== $classifiedId) {
				// must check if the classified owner is the admin
				$documentRepository = $main->getDocumentEntityRepository();
				$classified = $documentRepository->findByEncryptedId($classifiedId, 'documentId'); 
				if(null !== $classified) {
					if($classified->getUser()->getUserId() == $identity->getUserId()) {
						$name = $identity->getName();
						$post['user'] = array(
							'email' => $identity->getEmail(),
							'name' => strlen($name) > 2 ? $name : 'xx',
							'id' => $userRepository->getEncryptedId($identity->getUserId())
						);
					} else {
						$user = $userRepository->find($classified->getUser()->getUserId());
						$name = $user->getName();
						$post['user'] = array(
							'email' => $user->getEmail(),
							'name' => strlen($name) > 2 ? $name : 'xx',
							'id' => $userRepository->getEncryptedId($user->getUserId())
						);
					}
				}
			}
		}
		
		try {
			$classifiedService = $this->getServiceLocator()->get('document.service.classified');
			$document = $classifiedService->save($post);
			$data = array(
				'status' => 'success',
				'message' => $document->getDocumentId()
			);
		} catch(\Exception $e) {
			$this->getResponse()
				->setStatusCode(Response::STATUS_CODE_500);
			$data = @unserialize($e->getMessage());
			
			if(!is_array($data)) {
				$data = array(
					'status' => 'danger',
					'message' => $e->getMessage()
				);
			}
		}
		
		return new JsonModel($data);
	}
695943
protected function createToken($data)
    {
        if (empty($data) || !is_array($data)) {
            return null;
        }

        if (!isset($data['auth']) || !is_array($data['auth'])) {
            return null;
        }

        if (!isset($data['auth']['passwordCredentials']) || !is_array($data['auth']['passwordCredentials'])) {
            return null;
        }

        $credentials = $data['auth']['passwordCredentials'];

        if (!isset($credentials['username']) || !isset($credentials['password'])) {
            return null;
        }

        // validate using Username and password
        $username = $credentials['username'];
        $password = $credentials['password'];

        return new UsernamePasswordToken($username, $password, $this->providerKey);
    }
139731
public function getById($id, $data = null)
    {
        $data = $this->includeEverything($data);
        return parent::getById($id, $data);
    }
266824
private function resetVisitorUuid($data = null)
    {
        $this->visitorInfo['uuid'] = null;

        $data = $data ?: $this->visitorInfo;

        unset($data['uuid']);

        $this->putSessionData($data);
        $this->checkVisitorUuid();

        return $data;
    }
1069846
public function load( $data = null )
    {

        if( !$this->isLoaded() ) {

            // Get repository. Sadly lateloading introduces a dependancy on repository.
            // I can't see any way round this.
            $repository = $this->r();

            if( $data = $repository->data( $this->lateLoadKey ) ) {
                $this->__construct( $data );
                $this->lateLoadKey = null;
            } else {
                throw new LateLoadException("Object late loaded with a invalid key `{$this->lateLoadKey}`");
            }

        }
        return $this;

    }
1197225
protected function updateEntity($data)
    {
        if (!$data instanceof DataInterface) {
            return;
        }
        $family = $data->getFamily();

        if (!array_key_exists($data->getFamilyCode(), $this->familyMap)) {
            return;
        }
        $resource = $data->get($this->familyMap[$data->getFamilyCode()]);
        if (!$resource instanceof Document) {
            // Maybe we should reset the values to null
            return;
        }
        $data->setFileSize($resource->getFileSize());
        $this->valuesToPersist[] = $data->getValue($family->getAttribute('fileSize'));

        $data->setMimeType($resource->getMimeType());
        $this->valuesToPersist[] = $data->getValue($family->getAttribute('mimeType'));

        $data->setFileName($resource->getOriginalFileName());
        $this->valuesToPersist[] = $data->getValue($family->getAttribute('fileName'));
    }
870221
public static function data($data, $type = null)
    {
        $type === null && $type = MongoBinData::BYTE_ARRAY;

        return new MongoBinData($data, $type);
    }
883002
public function makeData(Data $data): ?DataObjectFormat
    {
        if (!$data->isInstanceOf(Data::class)) {
            return null;
        }

        return DataObjectFormat::make($data);
    }
148639
public function initByData( array $data = null )
    {

        if( !$data ) {
            return null;
        }

        // table inheritance - ghetto?
        /*
        if( isset( $data['tableoid'] ) ) {
            if( $data['tableoid'] != static::OID ) {
                $repo = Repository::init( $data['tableoid'] );
                return $repo->initByData( $data );
            }
            unset( $data['tableoid'] );
        }
        */

        $key = call_user_func(
            array( $this->entityClass, 'keyGet' ),
            $data
        );

        // is this already in the cache? Are we initalising something we've already loaded?
        if( isset( $this->instancesPersisted[$key] ) ) {

            // Late loading? Don't need this anymore.
            $obj = $this->instancesPersisted[$key];
            $obj->__construct( $data );
            return $obj;

        }

        $obj = parent::initByData($data);
        $this->instancesPersisted[$key] = $obj;

        return $obj;

    }
451369
public function getObject($data)
    {
        $obj = (object)json_decode($data);

        if ($obj->success === false) {
            $this->handleErrors($obj);

            return null;
        }

        return $obj->data;
    }
971871
private function createAndReturnNewSecondEntity($data, $secondEntityName)
    {
        /** @var EntityInterface $entity */
        $entity = $this->getSecondEntityByName($secondEntityName);
        if (is_array($data)) {
            return $this->mapAttributesFromFirstEntityToSecondEntityAndReturnEntity($data, $entity);
        }

        return null;
    }