Neos\Flow\Reflection\ReflectionService::getPropertyNamesByTag PHP Method

getPropertyNamesByTag() public method

If no properties were found, an empty array is returned.
public getPropertyNamesByTag ( string $className, string $tag ) : array
$className string Name of the class containing the properties
$tag string Tag to search for
return array An array of property names tagged by the tag
    public function getPropertyNamesByTag($className, $tag)
    {
        $className = $this->prepareClassReflectionForUsage($className);
        if (!isset($this->classReflectionData[$className][self::DATA_CLASS_PROPERTIES])) {
            return [];
        }
        $propertyNames = [];
        foreach ($this->classReflectionData[$className][self::DATA_CLASS_PROPERTIES] as $propertyName => $propertyData) {
            if (isset($propertyData[self::DATA_PROPERTY_TAGS_VALUES][$tag])) {
                $propertyNames[$propertyName] = true;
            }
        }
        return array_keys($propertyNames);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Check if the referenced column name is set (and valid) and if not make sure
  * it is initialized properly.
  *
  * @param array $joinColumns
  * @param array $mapping
  * @param \ReflectionProperty $property
  * @param integer $direction regular or inverse mapping (use is to be coded)
  * @return array
  */
 protected function buildJoinColumnsIfNeeded(array $joinColumns, array $mapping, \ReflectionProperty $property, $direction = self::MAPPING_REGULAR)
 {
     if ($joinColumns === []) {
         $joinColumns[] = ['name' => strtolower($property->getName()), 'referencedColumnName' => null];
     }
     foreach ($joinColumns as &$joinColumn) {
         if ($joinColumn['referencedColumnName'] === null || $joinColumn['referencedColumnName'] === 'id') {
             if ($direction === self::MAPPING_REGULAR) {
                 $idProperties = $this->reflectionService->getPropertyNamesByTag($mapping['targetEntity'], 'id');
                 $joinColumnName = $this->buildJoinTableColumnName($mapping['targetEntity']);
             } else {
                 $className = $this->getUnproxiedClassName($property->getDeclaringClass()->getName());
                 $idProperties = $this->reflectionService->getPropertyNamesByTag($className, 'id');
                 $joinColumnName = $this->buildJoinTableColumnName($className);
             }
             if (count($idProperties) === 0) {
                 $joinColumn['name'] = $joinColumn['name'] === null ? $joinColumnName : $joinColumn['name'];
                 $joinColumn['referencedColumnName'] = strtolower('Persistence_Object_Identifier');
             } elseif (count($idProperties) === 1) {
                 $joinColumn['name'] = $joinColumn['name'] === null ? $joinColumnName : $joinColumn['name'];
                 $joinColumn['referencedColumnName'] = strtolower(current($idProperties));
             }
         }
     }
     return $joinColumns;
 }
All Usage Examples Of Neos\Flow\Reflection\ReflectionService::getPropertyNamesByTag
ReflectionService