public function inject($target, array $values)
    {
        if (!$target instanceof \core_kernel_classes_Resource) {
            $msg = "The given target is not an instance of core_kernel_classes_Resource.";
            throw new MetadataInjectionException($msg);
        }

        /** @var \core_kernel_classes_Class $targetClass */
        $types = $target->getTypes();
        $targetClass = reset($types);
        $classProperties = $targetClass->getProperties(true);

        $properties = [];
        foreach ($classProperties as $property) {
            $properties[] = $property->getUri();
        }
        $properties = array_diff($properties, GenericLomOntologyClassificationExtractor::$excludedProperties);

        foreach ($values as $metadataValues) {
            /** @var MetadataValue $metadataValue */
            foreach ($metadataValues as $metadataValue) {
                $lang = $metadataValue->getLanguage() ?: DEFAULT_LANG;
                $path = $metadataValue->getPath();
                $valuePath = end($path);
                if (in_array($valuePath, $properties)) {
                    $prop = $this->getProperty($valuePath);
                    if ($target->getPropertyValuesByLg($prop, $lang)->count() > 0) {
                        $target->editPropertyValueByLg($prop, $metadataValue->getValue(), $lang);
                    } else {
                        $target->setPropertyValueByLg($prop, $metadataValue->getValue(), $lang);
                    }
                }
            }
        }
    }
public function inject($target, array $values)
    {
        if (!$target instanceof \core_kernel_classes_Resource) {
            $msg = "The given target is not an instance of core_kernel_classes_Resource.";
            throw new MetadataInjectionException($msg);
        }

        /** @var \core_kernel_classes_Class $targetClass */
        $types = $target->getTypes();
        $targetClass = reset($types);
        $classProperties = $targetClass->getProperties(true);

        $properties = [];
        foreach ($classProperties as $property) {
            $properties[] = $property->getUri();
        }
        $properties = array_diff($properties, GenericLomOntologyClassificationExtractor::$excludedProperties);

        foreach ($values as $metadataValues) {
            /** @var MetadataValue $metadataValue */
            foreach ($metadataValues as $metadataValue) {
                $lang = $metadataValue->getLanguage() ?: DEFAULT_LANG;
                $path = $metadataValue->getPath();
                $valuePath = end($path);
                if (in_array($valuePath, $properties)) {
                    $prop = $this->getProperty($valuePath);
                    if ($target->getPropertyValuesByLg($prop, $lang)->count() > 0) {
                        $target->editPropertyValueByLg($prop, $metadataValue->getValue(), $lang);
                    } else {
                        $target->setPropertyValueByLg($prop, $metadataValue->getValue(), $lang);
                    }
                }
            }
        }
    }
public function inject ( $ target , array $ values ) { if ( ! $ target instanceof \ core_kernel_classes_Resource ) { $ msg = "The given target is not an instance of core_kernel_classes_Resource." ; throw new MetadataInjectionException ( $ msg ) ; } /** @var \core_kernel_classes_Class $targetClass */ $ types = $ target -> getTypes ( ) ; $ targetClass = reset ( $ types ) ; $ classProperties = $ targetClass -> getProperties ( true ) ; $ properties = [ ] ; foreach ( $ classProperties as $ property ) { $ properties [ ] = $ property -> getUri ( ) ; } $ properties = array_diff ( $ properties , GenericLomOntologyClassificationExtractor :: $ excludedProperties ) ; foreach ( $ values as $ metadataValues ) { /** @var MetadataValue $metadataValue */ foreach ( $ metadataValues as $ metadataValue ) { $ lang = $ metadataValue -> getLanguage ( ) ? : DEFAULT_LANG ; $ path = $ metadataValue -> getPath ( ) ; $ valuePath = end ( $ path ) ; if ( in_array ( $ valuePath , $ properties ) ) { $ prop = $ this -> getProperty ( $ valuePath ) ; if ( $ target -> getPropertyValuesByLg ( $ prop , $ lang ) -> count ( ) > 0 ) { $ target -> editPropertyValueByLg ( $ prop , $ metadataValue -> getValue ( ) , $ lang ) ; } else { $ target -> setPropertyValueByLg ( $ prop , $ metadataValue -> getValue ( ) , $ lang ) ; } } } } }
Inject dynamically a metadata to an item property

@param mixed $target
@param array $values
@throws MetadataInjectionException
Inject dynamically a metadata to an item property