@param string      $entity
@param string|null $field

@return string
960801
protected function guessSingularField($entity, $field = null)
    {
        return $field ?: Inflector::singularize(
            lcfirst(basename(str_replace('\\', '/', $entity)))
        );
    }
137459
private function getEntityIdentifierValue($entity)
    {
        $entityMetaData = $this->entityManager->getEntityMetadataRegister()->getEntityMetadata($entity);

        return $entityMetaData ? $entityMetaData->getIdentifierValue() : null;
    }
1254755
public function generateBody(Entity $entity)
    {
        $body       = [];
        $descriptor = $entity->getDescriptor();
        $fields     = $descriptor->getFieldList() ?: [];

        foreach ($fields as $field) {
            if ( ! $field->hasDefaultValue()) {
                continue;
            }

            $name  = $field->getName();
            $value = $this->getDefaultFieldValue($field);

            $body[] = sprintf('$this->%s = %s;', $name, $value);
        }

        $body[] = null;
        $body[] = 'parent::__construct($stream, $configuration);';

        return $body;
    }
640110
public function next($entity, $field = 'datepublish', $where = [])
    {
        if ($field[0] === '-') {
            $operator = '<';
            $field = substr($field, 1);
            $order = '-' . $field;
        } elseif ($field[0] === '+') {
            $operator = '>';
            $field = substr($field, 1);
            $order = $field;
        } else {
            $operator = '>';
            $order = $field;
        }
        $params = [
            $field         => $operator . $entity->get($field),
            'limit'        => 1,
            'order'        => $order,
            'returnsingle' => true,
        ];
        $params = array_merge($params, $where);

        return $this->query->getContent((string) $entity->getContenttype(), $params);
    }
1266819
protected function getField($field)
    {
        foreach ($this->getFields() as $annotatedField) {
            if ($annotatedField->name === $field) {
                return $annotatedField;
            }
        }

        return null;
    }
1000854
public static function dicionario(string $entity = null)
    {
        if(file_exists(PATH_HOME . "entity/cache") && (empty($entity) || file_exists(PATH_HOME . "entity/cache/{$entity}.json"))) {
            if(empty($entity)){

                //read all dicionarios
                $list = [];
                foreach (\Helpers\Helper::listFolder(PATH_HOME . "entity/cache") as $json) {
                    if(preg_match('/^\w+\.json$/i', $json)){
                        $entity = str_replace('.json', '', $json);
                        if($dic = self::dicionario($entity))
                            $list[$entity] = $dic;
                    }
                }

                return $list;

            } else {

                //read dicionario específico
                $setor = empty($_SESSION['userlogin']['setor']) ? 0 : $_SESSION['userlogin']['setor'];
                $entidadesNaoPermitidas = \Config\Config::getEntityNotAllow();
                $entidadesNaoPermitidas = isset($entidadesNaoPermitidas[$setor]) ? $entidadesNaoPermitidas[$setor] : [];

                if(!in_array($entity, $entidadesNaoPermitidas)) {
                    return \Entity\Metadados::getDicionario($entity, true, true);
                }
            }
        }

        return null;
    }
608555
protected function generateFieldMerge(Entity $entity, FieldDescriptorProto $field)
    {
        $lines     = [];
        $fieldName = $field->getName();
        $format    = '$this->%s = ($message->%s !== null) ? $message->%s : $this->%s;';
        $lines[]   = sprintf($format, $fieldName, $fieldName, $fieldName, $fieldName);

        return $lines;
    }
1068997
public function getFieldMapping($entity)
    {
        $fields = $this->getPropertiesByType($entity, self::FIELD_CLASS);

        $mapping = [];
        foreach ($fields as $field) {
            $mapping[$field->getNameWithAlias()] = $field->name;
        }

        $id = $this->getIdentifier($entity);
        $mapping['id'] = $id->name;

        return $mapping;
    }
466297
public function get($entity)
    {
        $key = $this->mapping['fieldname'];
        $valueMethod = 'get' . ucfirst($key);
        $value = $entity->$valueMethod();

        return $value;
    }
188235
protected function generateFieldWriteStatement(Entity $entity, FieldDescriptorProto $field)
    {
        $generator = new WriteFieldStatementGenerator($this->context);
        $statement = $generator->generateFieldWriteStatement($entity, $field);

        return $statement;
    }
745751
private function guessFieldType($field, $entityClass)
    {
        if (!$this->translatableManager->isTranslatable($entityClass)) {
            return null;
        }

        $guess = $this->formRegistry->getTypeGuesser()->guessType($entityClass, $field);

        return $guess->getConfidence() > 0
            ? $guess
            : $this->formRegistry->getTypeGuesser()->guessType($this->translatableManager->getTranslationClass($entityClass), $field);
    }
478646
private Object getEntityFieldValue(EntityMetadata entityMetadata, Object entity, String field)
    {
        Class clazz = entityMetadata.getEntityClazz();
        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                entityMetadata.getPersistenceUnit());
        EntityType entityType = metaModel.entity(clazz);

        if (field.indexOf(".") > 0 && entityMetadata.getEntityClazz().equals(entity.getClass()))
        {
            String fieldName = field.substring(field.indexOf(".") + 1, field.length());
            Attribute attribute = entityType.getAttribute(fieldName);
            return PropertyAccessorHelper.getObject(entity, (Field) attribute.getJavaMember());
        }
        else
        {
            // for hbase v2 client (sends arraylist for specific fields)
            if (entity instanceof ArrayList)
            {
                Object element = ((ArrayList) entity).get(0);
                ((ArrayList) entity).remove(0);
                return element;
            }
            else
            {
                return entity;
            }
        }
    }
906063
public function forTemplate($field = null)
    {
        // debugging info for a specific field
        $class = get_class($this->object);
        if ($field) {
            return "<b>Debugging Information for {$class}->{$field}</b><br/>" . ($this->object->hasMethod($field) ? "Has method '$field'<br/>" : null) . ($this->object->hasField($field) ? "Has field '$field'<br/>" : null);
        }

        // debugging information for the entire class
        $reflector = new ReflectionObject($this->object);
        $debug = "<b>Debugging Information: all methods available in '{$class}'</b><br/><ul>";

        foreach ($this->object->allMethodNames() as $method) {
            // check that the method is public
            if ($method[0] === strtoupper($method[0]) && $method[0] != '_') {
                if ($reflector->hasMethod($method) && $method = $reflector->getMethod($method)) {
                    if ($method->isPublic()) {
                        $debug .= "<li>\${$method->getName()}";

                        if (count($method->getParameters())) {
                            $debug .= ' <small>(' . implode(', ', $method->getParameters()) . ')</small>';
                        }

                        $debug .= '</li>';
                    }
                } else {
                    $debug .= "<li>\$$method</li>";
                }
            }
        }

        $debug .= '</ul>';

        if ($this->object->hasMethod('toMap')) {
            $debug .= "<b>Debugging Information: all fields available in '{$class}'</b><br/><ul>";

            foreach ($this->object->toMap() as $field => $value) {
                $debug .= "<li>\$$field</li>";
            }

            $debug .= "</ul>";
        }

        // check for an extra attached data
        if ($this->object->hasMethod('data') && $this->object->data() != $this->object) {
            $debug .= ViewableData_Debugger::create($this->object->data())->forTemplate();
        }

        return $debug;
    }
1345472
protected function parseToDocument($entity)
    {
        $schemaMapper = $this->getSchemaMapper();
        $parsedDocument = $schemaMapper->map($entity);

        if (is_object($entity)) {
            foreach ($parsedDocument as $field => $value) {
                $entity->$field = $value;
            }
        }

        return $parsedDocument;
    }
284013
protected function generateSetterMethod(Entity $entity, FieldDescriptorProto $field)
    {
        $body       = [];
        $fieldName  = $field->getName();
        $fieldType  = $field->getType();
        $fieldLabel = $field->getLabel();
        $typeHint   = $this->getTypeHint($field);

        if ($fieldType === Type::TYPE_BYTES() && $fieldLabel !== Label::LABEL_REPEATED()) {
            $body[] = 'if ($value !== null && ! $value instanceof \Protobuf\Stream) {';
            $body[] = '    $value = \Protobuf\Stream::wrap($value);';
            $body[] = '}';
            $body[] = null;

            $typeHint = null;
        }

        $body[] = '$this->' . $fieldName . ' = $value;';

        $methodName = $this->getAccessorName('set', $field);
        $method     = MethodGenerator::fromArray([
            'name'       => $methodName,
            'body'       => implode(PHP_EOL, $body),
            'parameters' => [
                [
                    'name'   => 'value',
                    'type'   => $typeHint
                ]
            ],
            'docblock'   => [
                'shortDescription' => "Set '$fieldName' value",
                'tags'             => [
                    [
                        'name'        => 'param',
                        'description' => $this->getDocBlockType($field) . ' $value'
                    ]
                ]
            ]
        ]);

        $method->getDocblock()->setWordWrap(false);

        if ($fieldLabel !== Label::LABEL_REQUIRED()) {
            $method->getParameters()['value']->setDefaultValue(null);
        }

        return $method;
    }
275327
public function geocode(Entity $entity) {
		$addressfields = (array)$this->_config['address'];

		$addressData = [];
		$dirty = false;
		foreach ($addressfields as $field) {
			$fieldData = $entity->get($field);
			if ($fieldData) {
				$addressData[] = $fieldData;
			}
			if ($entity->isDirty($field)) {
				$dirty = true;
			}
		}
		if (!$dirty) {
			if ($this->_config['allowEmpty'] || $entity->lat && $entity->lng) {
				return $entity;
			}
			if ($entity instanceof Entity) {
				$this->invalidate($entity);
			}
			return null;
		}

		$result = $this->_geocode($entity, $addressData);
		if (is_array($result)) {
			throw new RuntimeException('Array type not expected');
		}

		return $result;
	}
948223
protected function generateFieldCondition(Entity $entity, FieldDescriptorProto $field)
    {
        $tag   = $field->getNumber();
        $lines = $this->generateFieldReadStatement($entity, $field);
        $lines = $this->addIndentation($lines, 1);

        $body[] = 'if ($tag === ' . $tag . ') {';
        $body   = array_merge($body, $lines);
        $body[] = '}';
        $body[] = null;

        return $body;
    }