src/OpenGraphGenerator.php
public function generate($obj)
    {
        if (!is_object($obj)) {
            throw new \InvalidArgumentException('OpenGraphGenerator::generate only accept object argument.');
        }

        $openGraph = new OpenGraph();

        $classType = get_class($obj);

        $metadata = $this->factory->getMetadataForClass($classType);

        if (is_array($metadata->namespaces)) {
            foreach ($metadata->namespaces as $namespace) {
                $openGraph->addNamespace($namespace->prefix, $namespace->uri);
            }
        }

        if (is_array($metadata->nodes)) {
            foreach ($metadata->nodes as $graphNode) {
                if (!empty($graphNode['node']->namespaceUri)) {
                    $openGraph->addNamespace($graphNode['node']->namespace, $graphNode['node']->namespaceUri);
                }

                $openGraph->add($graphNode['node']->namespace, $graphNode['node']->tag, $graphNode['object']->getValue($obj));
            }
        }

        return $openGraph;
    }
public function generate($obj)
    {
        if (!is_object($obj)) {
            throw new \InvalidArgumentException('OpenGraphGenerator::generate only accept object argument.');
        }

        $openGraph = new OpenGraph();

        $classType = get_class($obj);

        $metadata = $this->factory->getMetadataForClass($classType);

        if (is_array($metadata->namespaces)) {
            foreach ($metadata->namespaces as $namespace) {
                $openGraph->addNamespace($namespace->prefix, $namespace->uri);
            }
        }

        if (is_array($metadata->nodes)) {
            foreach ($metadata->nodes as $graphNode) {
                if (!empty($graphNode['node']->namespaceUri)) {
                    $openGraph->addNamespace($graphNode['node']->namespace, $graphNode['node']->namespaceUri);
                }

                $openGraph->add($graphNode['node']->namespace, $graphNode['node']->tag, $graphNode['object']->getValue($obj));
            }
        }

        return $openGraph;
    }
public function generate ( $ obj ) { if ( ! is_object ( $ obj ) ) { throw new \ InvalidArgumentException ( 'OpenGraphGenerator::generate only accept object argument.' ) ; } $ openGraph = new OpenGraph ( ) ; $ classType = get_class ( $ obj ) ; $ metadata = $ this -> factory -> getMetadataForClass ( $ classType ) ; if ( is_array ( $ metadata -> namespaces ) ) { foreach ( $ metadata -> namespaces as $ namespace ) { $ openGraph -> addNamespace ( $ namespace -> prefix , $ namespace -> uri ) ; } } if ( is_array ( $ metadata -> nodes ) ) { foreach ( $ metadata -> nodes as $ graphNode ) { if ( ! empty ( $ graphNode [ 'node' ] -> namespaceUri ) ) { $ openGraph -> addNamespace ( $ graphNode [ 'node' ] -> namespace , $ graphNode [ 'node' ] -> namespaceUri ) ; } $ openGraph -> add ( $ graphNode [ 'node' ] -> namespace , $ graphNode [ 'node' ] -> tag , $ graphNode [ 'object' ] -> getValue ( $ obj ) ) ; } } return $ openGraph ; }
Generate OpenGraph through metadata

@param object $obj
@return OpenGraphInterface
Generate OpenGraph through metadata