public static function fromEntity($entity, array $overrides = []): self
    {
        if (!is_object($entity)) {
            throw new \InvalidArgumentException('Given entity must be an object.');
        }

        $annotations = annotationsOf($entity);
        if (!$annotations->contain('RssFeedItem')) {
            throw new XmlException(
                    'Class ' . get_class($entity) . ' is not annotated with @RssFeedItem.'
            );
        }

        $rssFeedItemAnnotation = $annotations->firstNamed('RssFeedItem');
        $self = new self(
                $overrides['title'] ??
                self::getRequiredAttribute(
                        $entity,
                        'title',
                        $rssFeedItemAnnotation->getTitleMethod('getTitle')
                ),
                $overrides['link'] ??
                self::getRequiredAttribute(
                        $entity,
                        'link',
                        $rssFeedItemAnnotation->getLinkMethod('getLink')
                ),
                $overrides['description'] ??
                self::getRequiredAttribute(
                        $entity,
                        'description',
                        $rssFeedItemAnnotation->getDescriptionMethod('getDescription')
                )
        );

        foreach (self::METHODS as $itemMethod => $defaultMethod) {
            if (isset($overrides[$itemMethod])) {
                $self->$itemMethod($overrides[$itemMethod]);
                continue;
            }

            if (substr($defaultMethod, 0, 3) === 'get') {
                $annotationMethod = $defaultMethod . 'Method';
            } else {
                $annotationMethod = 'get' . $defaultMethod . 'Method';
            }

            $entityMethod = $rssFeedItemAnnotation->$annotationMethod($defaultMethod);
            if (method_exists($entity, $entityMethod)) {
                $self->$itemMethod($entity->$entityMethod());
            }
        }

        return $self;
    }
public static function fromEntity($entity, array $overrides = []): self
    {
        if (!is_object($entity)) {
            throw new \InvalidArgumentException('Given entity must be an object.');
        }

        $annotations = annotationsOf($entity);
        if (!$annotations->contain('RssFeedItem')) {
            throw new XmlException(
                    'Class ' . get_class($entity) . ' is not annotated with @RssFeedItem.'
            );
        }

        $rssFeedItemAnnotation = $annotations->firstNamed('RssFeedItem');
        $self = new self(
                $overrides['title'] ??
                self::getRequiredAttribute(
                        $entity,
                        'title',
                        $rssFeedItemAnnotation->getTitleMethod('getTitle')
                ),
                $overrides['link'] ??
                self::getRequiredAttribute(
                        $entity,
                        'link',
                        $rssFeedItemAnnotation->getLinkMethod('getLink')
                ),
                $overrides['description'] ??
                self::getRequiredAttribute(
                        $entity,
                        'description',
                        $rssFeedItemAnnotation->getDescriptionMethod('getDescription')
                )
        );

        foreach (self::METHODS as $itemMethod => $defaultMethod) {
            if (isset($overrides[$itemMethod])) {
                $self->$itemMethod($overrides[$itemMethod]);
                continue;
            }

            if (substr($defaultMethod, 0, 3) === 'get') {
                $annotationMethod = $defaultMethod . 'Method';
            } else {
                $annotationMethod = 'get' . $defaultMethod . 'Method';
            }

            $entityMethod = $rssFeedItemAnnotation->$annotationMethod($defaultMethod);
            if (method_exists($entity, $entityMethod)) {
                $self->$itemMethod($entity->$entityMethod());
            }
        }

        return $self;
    }
public static function fromEntity ( $ entity , array $ overrides = [ ] ) : self { if ( ! is_object ( $ entity ) ) { throw new \ InvalidArgumentException ( 'Given entity must be an object.' ) ; } $ annotations = annotationsOf ( $ entity ) ; if ( ! $ annotations -> contain ( 'RssFeedItem' ) ) { throw new XmlException ( 'Class ' . get_class ( $ entity ) . ' is not annotated with @RssFeedItem.' ) ; } $ rssFeedItemAnnotation = $ annotations -> firstNamed ( 'RssFeedItem' ) ; $ self = new self ( $ overrides [ 'title' ] ?? self :: getRequiredAttribute ( $ entity , 'title' , $ rssFeedItemAnnotation -> getTitleMethod ( 'getTitle' ) ) , $ overrides [ 'link' ] ?? self :: getRequiredAttribute ( $ entity , 'link' , $ rssFeedItemAnnotation -> getLinkMethod ( 'getLink' ) ) , $ overrides [ 'description' ] ?? self :: getRequiredAttribute ( $ entity , 'description' , $ rssFeedItemAnnotation -> getDescriptionMethod ( 'getDescription' ) ) ) ; foreach ( self :: METHODS as $ itemMethod => $ defaultMethod ) { if ( isset ( $ overrides [ $ itemMethod ] ) ) { $ self -> $ itemMethod ( $ overrides [ $ itemMethod ] ) ; continue ; } if ( substr ( $ defaultMethod , 0 , 3 ) === 'get' ) { $ annotationMethod = $ defaultMethod . 'Method' ; } else { $ annotationMethod = 'get' . $ defaultMethod . 'Method' ; } $ entityMethod = $ rssFeedItemAnnotation -> $ annotationMethod ( $ defaultMethod ) ; if ( method_exists ( $ entity , $ entityMethod ) ) { $ self -> $ itemMethod ( $ entity -> $ entityMethod ( ) ) ; } } return $ self ; }
creates a new stubRssFeedItem from given entity

@param   object  $entity
@param   array   $overrides
@return  \stubbles\xml\rss\RssFeedItem
@throws  \InvalidArgumentException
@throws  \stubbles\xml\XmlException
creates a new stubRssFeedItem from given entity