Skip to content

Commit

Permalink
ecs
Browse files Browse the repository at this point in the history
  • Loading branch information
solverat committed Oct 1, 2019
1 parent 64c849b commit 63bb6ac
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 25 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Pimcore Schema
Schema.org type builder and ld+json generator for pimcore. This bundle requires the `spatie/schema-org` package.
Schema.org type builder and ld+json generator for pimcore.
This bundle requires the `spatie/schema-org` package.

[![Join the chat at https://gitter.im/pimcore/pimcore](https://img.shields.io/gitter/room/pimcore/pimcore.svg?style=flat-square)](https://gitter.im/pimcore/pimcore)
[![Software License](https://img.shields.io/badge/license-GPLv3-brightgreen.svg?style=flat-square)](LICENSE.md)
Expand Down Expand Up @@ -91,6 +92,11 @@ class KnowledgeGraphGenerator implements GeneratorInterface
}
```

## Output

![image](https://user-images.githubusercontent.com/700119/65961347-a9e22000-e456-11e9-878e-d5df75536846.png)


### Further Information
- [Add ld+json Twig Helper](docs/01_Twig_Extension.md)
- [Using ld+json Twig Helper](docs/01_Twig_Extension.md)
- [Extended Example](docs/02_Extended_Usage.md)
1 change: 0 additions & 1 deletion src/SchemaBundle/EventListener/SchemaListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,5 @@ public function onKernelRequest(RequestEvent $event)
}

$this->schemaRequestProcessor->process($request);

}
}
12 changes: 6 additions & 6 deletions src/SchemaBundle/Generator/GeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ interface GeneratorInterface
public function supportsRequest(Request $request, string $route): bool;

/**
* @param $element
* @param mixed $element
*
* @return mixed
* @return bool
*/
public function supportsElement($element): bool;

Expand All @@ -28,12 +28,12 @@ public function supportsElement($element): bool;
* @param Request $request
* @param array $schemaBlocks
*/
public function generateForRequest(Graph $graph, Request $request, array &$schemaBlocks): void;
public function generateForRequest(Graph $graph, Request $request, array &$schemaBlocks): void;

/**
* @param $element
* @param mixed $element
*
* @return mixed
* @return null|BaseType
*/
public function generateForElement($element): ?BaseType;
public function generateForElement($element): ?BaseType;
}
5 changes: 3 additions & 2 deletions src/SchemaBundle/Processor/SchemaElementProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ public function __construct(
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function process($element): string
{
$data = null;
foreach ($this->generatorRegistry->all() as $generator) {
if ($generator->supportsElement($element) === true) {
$data = $generator->generateForElement($element);

break;
}
}
Expand All @@ -40,4 +41,4 @@ public function process($element): string

return $data->toScript();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
interface SchemaElementProcessorInterface
{
/**
* @param $element
* @param mixed $element
*
* @return string
*/
public function process($element): string;
}
}
5 changes: 2 additions & 3 deletions src/SchemaBundle/Processor/SchemaRequestProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function process(Request $request): void
{
Expand All @@ -42,7 +42,6 @@ public function process(Request $request): void
$schemaBlocks = [];

foreach ($this->generatorRegistry->all() as $generator) {

if ($generator->supportsRequest($request, $request->attributes->get('_route')) === false) {
continue;
}
Expand All @@ -69,4 +68,4 @@ protected function appendHeadMeta(Graph $graph, array $schemaBlocks)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ interface SchemaRequestProcessorInterface
* @param Request $request
*/
public function process(Request $request): void;
}
}
8 changes: 4 additions & 4 deletions src/SchemaBundle/Registry/SchemaGeneratorRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct($interface)
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function register($service, $alias)
{
Expand All @@ -42,15 +42,15 @@ public function register($service, $alias)
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function has($alias)
{
return isset($this->generator[$alias]);
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function all()
{
Expand All @@ -62,7 +62,7 @@ public function all()
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function get($alias)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface SchemaGeneratorRegistryInterface
{
/**
* @param GeneratorInterface $service
* @param $alias
* @param string $alias
*/
public function register($service, $alias);

Expand All @@ -28,6 +28,7 @@ public function all();
* @param string $alias
*
* @return GeneratorInterface
*
* @throws \Exception
*/
public function get($alias);
Expand Down
5 changes: 2 additions & 3 deletions src/SchemaBundle/Twig/Extension/JsonLdExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
namespace SchemaBundle\Twig\Extension;

use SchemaBundle\Processor\SchemaElementProcessorInterface;
use SchemaBundle\Processor\SchemaRequestProcessorInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

class JsonLdExtension extends AbstractExtension
{
/**
* @var SchemaRequestProcessorInterface
* @var SchemaElementProcessorInterface
*/
protected $schemaElementProcessor;

Expand Down Expand Up @@ -41,4 +40,4 @@ public function jsonLdFilter($element)
{
return $this->schemaElementProcessor->process($element);
}
}
}

0 comments on commit 63bb6ac

Please sign in to comment.