Returns the current request entity (as \stdClass) if possible

@param array $fields if you only need certain fields, you can specify them here

@return null|object
162951
public function getCurrentEntity(array $fields = null)
    {
        $currentRecordId = null;

        // first, let's the one from the payload..
        if (isset($this->currentData->id)) {
            $currentRecordId = $this->currentData->id;
        }

        // if we have a request, it must override it..
        if ($this->requestStack->getCurrentRequest() instanceof Request &&
            $this->requestStack->getCurrentRequest()->attributes->has('id')
        ) {
            $currentRecordId = $this->requestStack->getCurrentRequest()->attributes->get('id');
        }

        if (isset($this->currentSchema->{'x-documentClass'}) &&
            !empty($this->currentSchema->{'x-documentClass'}) &&
            !is_null($currentRecordId)
        ) {
            return $this->getSerializedEntity($this->currentSchema->{'x-documentClass'}, $currentRecordId, $fields);
        }

        return null;
    }
657893
protected function getPrimaryField(array $fields)
    {
        foreach ($fields as $field) {
            if ($this->isField($field) && ($field->isPrimary || $field->isAutoIncrement)) {
                return $field;
            }
        }

        return null;
    }
1316740
private function getRelation($field)
    {
        $relations = $this->getRelations();
        return isset($relations[$field]) ? $relations[$field] : null;
    }
952645
protected function getHeaderField(array $fields)
    {
        foreach ($fields as $field) {
            if ($this->isField($field) && $field->isHeader) {
                return $field;
            }
        }

        return null;
    }
540510
public static function getField($field)
    {
        return isset(self::$fields[$field]) ? self::$fields[$field] : null;
    }
472901
public function offsetGet($field) {
        if (isset($this->values[$field]) || $this->load($field)) {
            return $this->values[$field];
        }

        return NULL;
    }
452677
public function order($fields = null)
    {
        if (!$fields) {
            return $this;
        }
        if ($fields = is_array($fields) ? $fields : func_get_args()) {
            $this->_parts['order'] = array_merge($this->_parts['order'], $this->_order($fields));
        }
        return $this;
    }
162609
protected function getDataMethod(array $fields)
    {
        $stub = $this->getStubContent('controller-getdata-method');

        $this->replaceFileSnippet($stub, $this->getFileSnippet($fields, '$this'))
            ->replaceValidationRules($stub, $this->getValidationRules($fields))
            ->replaceFillables($stub, $this->getFillables($fields))
            ->replaceBooleadSnippet($stub, $this->getBooleanSnippet($fields))
            ->replaceStringToNullSnippet($stub, $this->getStringToNullSnippet($fields))
            ->replaceRequestNameComment($stub, '')
            ->replaceMethodVisibilityLevel($stub, 'public');

        $stub = str_replace(PHP_EOL . PHP_EOL, PHP_EOL, $stub);

        return $stub;
    }
1287623
protected function get($field)
    {
        if (isset($this->raw[$field])) {
            return $this->raw[$field];
        }
        if (preg_match('/^is_/', $field)) {
            return false;
        }

        return null;
    }
152433
public function getData($entity = array())
    {
        if ($this->accessor == null) {
            $this->accessor = new PropertyAccessor;
        }

        foreach ($this->getFields() as $name => $field) {
            if ($mapping = $field->getMappingName()) {
                if (is_array($entity)) {
                    $entity[$mapping] = $field->getMappingValue();
                } else {
                    $this->accessor->setValue($entity, $mapping, $field->getMappingValue());
                }
            }
        }

        return $entity;
    }
1267416
public function getEntityAttributeValue($field)
    {
        if ($field) {
            $functionName = 'get'.ucfirst($field);

            // Avoid error when the widget refer to a property that has been removed
            if (!method_exists($this, $functionName)) {
                return;
            }

            $fieldValue = $this->{$functionName}();
        } else {
            $fieldValue = null;
        }

        return $fieldValue;
    }
1325621
public function get($fields = null)
    {
        if (!$r = $this->first($fields)) {
            throw new Model\NotFoundException('record is not exists');
        }

        return $r;
    }
134137
public function getField($field)
    {
        if (!$this->isFieldSupported($field)) {
            return null;
        }

        if (!$this->hasLoadedField($field)) {
            $loaderData = $this->getLoaderData($field);
            if (isset($this->normalizersMap[$field])) {
                $normalizerName = $this->normalizersMap[$field];
                $normalizerFunction = sprintf('%sNormalizer', $normalizerName);
                $this->fields[$field] = $this->$normalizerFunction($loaderData);
            } else {
                $this->fields[$field] = $loaderData;
            }
        }

        return parent::getField($field);
    }
1201633
public static function firstOrNull($fields = null)
    {
        static $request;
        if (!$request) {
            $request = Di::getDefault()->getShared('request');
        }

        if (!$request->isAjax()) {
            return null;
        }

        $model = new static();
        return static::get($request->getId($model->getPrimaryKey()));
    }
348926
public function getFields()
    {
        $fields = $this->getRequest()->get('fields');

        return (null != $fields) ? explode(',', $fields) : null;
    }
599954
protected function getAccessors(array $fields = null)
    {
        $accessors = [];

        foreach ($fields as $field) {
            if ($field->isMultipleAnswers()) {
                $content = $this->getStubContent('model-accessor-multiple-answers');

                $accessors[] = $this->getAccessor($field, $content);
            }

            if ($field->isDateOrTime()) {
                $content = $this->getStubContent('model-accessor-datetime');
                $this->replaceDateFormat($content, $field->dateFormat);

                $accessors[] = $this->getAccessor($field, $content);
            }
        }

        return implode(PHP_EOL, $accessors);
    }
1063036
public function createEntity($className, array $fields = [])
    {
        $metadata = $this->getEntityMetadata($className);

        if (is_null($metadata)) {
            return null;
        }

        $reflection = $metadata->getReflectionClass();

        try {
            $entity = $reflection->newInstance();
        } catch (\Exception $e) {
            $entity = $reflection->newInstanceWithoutConstructor();
        }

        foreach ($fields as $fieldName => $fieldValue) {
            if (self::IDENTITY === $fieldName) {
                $property = $reflection->getProperty($this->getEntityIdName($className));
            } else {
                $property = $reflection->getProperty($fieldName);
            }

            try {
                $property->setValue($entity, $fieldValue);
            } catch (\Exception $e) {
                $property->setAccessible(true);
                $property->setValue($entity, $fieldValue);
                $property->setAccessible(false);
            }
        }

        return $entity;
    }