/** * @param string $className * @param Field $field * @return string|null */ private function getAccessor($className, Field $field) { $class = new \ReflectionClass($className); $property = $field->getField() ?: $field->getName(); $camelName = String::camelize($property); $getter = 'get' . $camelName; $getsetter = lcfirst($camelName); $isser = 'is' . $camelName; $hasser = 'has' . $camelName; $test = [$getter, $getsetter, $isser, $hasser]; $reflMethods = $class->getMethods(\ReflectionMethod::IS_PUBLIC); $methods = []; foreach ($reflMethods as $reflMethod) { $methods[$reflMethod->getName()] = true; } foreach ($test as $method) { if (isset($methods[$method])) { return $method; } } }
/** * @param ClassMetadataInfo $metadata * @param Field $field * @param SchemaContainer $schemaContainer * @return TypeGuess * @throws MappingException */ private function guessAssociation(ClassMetadataInfo $metadata, Field $field, SchemaContainer $schemaContainer) { $property = $field->getProperty() ?: $field->getName(); $multiple = $metadata->isCollectionValuedAssociation($property); $mapping = $metadata->getAssociationMapping($property); foreach ($schemaContainer->getTypes() as $type) { $containerContext = new ContainerContext($type, $schemaContainer); if (!$this->isFieldContainerSupported($containerContext)) { continue; } if ($type->getModel() === $mapping['targetEntity']) { $typeName = $type->getName(); if ($multiple) { $typeName = sprintf('[%s]', $typeName); } return new TypeGuess($typeName, Guess::HIGH_CONFIDENCE); } } }