Example #1
0
 /**
  * @param \GoIntegro\Hateoas\JsonApi\ResourceEntityInterface|string $entityClassName
  * @param ResourceRelationships $relationships
  * @return array
  * @todo Publicar o eliminar el parámetro $entityClassName.
  */
 protected function getFields($entityClassName, ResourceRelationships $relationships)
 {
     $fields = [];
     $class = $this->metadataCache->getReflection($entityClassName);
     foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
         if (in_array($method->getShortName(), self::$reservedGetters)) {
             continue;
         }
         if (Reflection::isMethodGetter($method)) {
             $fields[] = Inflector::hyphenate(substr($method->getShortName(), 3));
         }
     }
     foreach (ResourceRelationships::$kinds as $kind) {
         $fields = array_diff($fields, array_keys($relationships->{$kind}));
     }
     $fields = array_diff($fields, $relationships->dbOnly);
     return new ResourceFields($fields);
 }
 /**
  * @param \GoIntegro\Hateoas\JsonApi\ResourceEntityInterface|string $entityClassName
  * @param string $primaryType
  * @return array
  * @todo Publicar o eliminar el parámetro $entityClassName.
  */
 protected function getRelationships($entityClassName, $primaryType)
 {
     $relationships = new ResourceRelationships();
     $metadata = $this->metadataCache->getMapping($entityClassName);
     $class = $this->metadataCache->getReflection($entityClassName);
     foreach ($metadata->getAssociationMappings() as $name => $mapping) {
         $relationshipName = Inflector::hyphenate($name);
         $mappingClass = $this->metadataCache->getReflection($mapping['targetEntity']);
         if (self::isDbOnlyRelation($class, $mappingClass, $name)) {
             $relationships->dbOnly[] = $relationshipName;
             continue;
         }
         $className = $mappingClass->getName();
         $mappingField = $mapping['mappedBy'] ?: $mapping['inversedBy'];
         $relationshipKind = $this->getRelationshipKind($mapping['type']);
         $relationship = new ResourceRelationship($className, $this->parseType($className), $this->parseSubtype($className), $relationshipKind, $relationshipName, $mappingField);
         if (self::isLinkOnlyRelation($class, $name)) {
             $relationshipKind = 'linkOnly';
         }
         $relationshipsPerKind =& $relationships->{$relationshipKind};
         $relationshipsPerKind[$relationshipName] = $relationship;
     }
     return $relationships;
 }
Example #3
0
 /**
  * @param \ReflectionMethod $method
  * @return string
  * @todo ¿Quizás moverlo al Inflector?
  */
 private static function fieldFromInjector(\ReflectionMethod $method)
 {
     $name = substr($method->getShortName(), strlen('inject'));
     return Inflector::hyphenate($name);
 }