Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kmadejski committed Mar 28, 2017
0 parents commit 05d22e6
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 0 deletions.
23 changes: 23 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace EzSystems\RESTAPIExtensionExampleBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* Class Configuration
* @package EzSystems\RESTAPIExtensionExampleBundle\DependencyInjection
*/
class Configuration implements ConfigurationInterface
{
/**
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('ez_systems_restapi_extension_example');
return $treeBuilder;
}
}
28 changes: 28 additions & 0 deletions DependencyInjection/EzSystemsRESTAPIExtensionExampleExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace EzSystems\RESTAPIExtensionExampleBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
* Class EzSystemsRESTAPIExtensionExampleExtension
* @package EzSystems\RESTAPIExtensionExampleBundle\DependencyInjection
*/
class EzSystemsRESTAPIExtensionExampleExtension extends Extension
{
/**
* @param array $configs
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
13 changes: 13 additions & 0 deletions EzSystemsRESTAPIExtensionExampleBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace EzSystems\RESTAPIExtensionExampleBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* Class EzSystemsRESTAPIExtensionExampleBundle
* @package EzSystems\RESTAPIExtensionExampleBundle
*/
class EzSystemsRESTAPIExtensionExampleBundle extends Bundle
{
}
5 changes: 5 additions & 0 deletions Resources/config/routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ez_systems_restapi_extension_example_hello:
path: /rest/example/hello/{name}
defaults:
_controller: ez_systems_restapi_extension_example.controller:hello
methods: [GET]
18 changes: 18 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
parameters:
ez_systems_restapi_extension_example.controller.class: EzSystems\RESTAPIExtensionExampleBundle\Rest\Controller\RESTExampleController
ez_systems_restapi_extension_example.value_object_visitor.class: EzSystems\RESTAPIExtensionExampleBundle\Rest\ValueObjectVisitor\Hello
ez_systems_restapi_extension_example.input_parser.class: EzSystems\RESTAPIExtensionExampleBundle\Rest\InputParser\Hello
services:
ez_systems_restapi_extension_example.controller:
class: %ez_systems_restapi_extension_example.controller.class%
ez_systems_restapi_extension_example.value_object_visitor:
parent: ezpublish_rest.output.value_object_visitor.base
class: %ez_systems_restapi_extension_example.value_object_visitor.class%
tags:
- { name: ezpublish_rest.output.value_object_visitor, type: EzSystems\RESTAPIExtensionExampleBundle\Rest\Values\Hello }
ez_systems_restapi_extension_example.input_parser:
parent: ezpublish_rest.input.parser
class: %ez_systems_restapi_extension_example.input_parser.class%
tags:
- { name: ezpublish_rest.input.parser, mediaType: application/vnd.ez.api.Hello }

1 change: 1 addition & 0 deletions Resources/views/Default/index.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
22 changes: 22 additions & 0 deletions Rest/Controller/RESTExampleController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace EzSystems\RESTAPIExtensionExampleBundle\Rest\Controller;

use EzSystems\RESTAPIExtensionExampleBundle\Rest\Values\Hello;
use eZ\Publish\Core\REST\Server\Controller;

/**
* Class RESTExampleController
* @package EzSystems\RESTAPIExtensionExampleBundle\Rest\Controller
*/
class RESTExampleController extends Controller
{
/**
* @param $name
* @return \EzSystems\RESTAPIExtensionExampleBundle\Rest\Values\Hello
*/
public function hello($name)
{
return new Hello($name);
}
}
28 changes: 28 additions & 0 deletions Rest/InputParser/Hello.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace EzSystems\RESTAPIExtensionExampleBundle\Rest\InputParser;

use eZ\Publish\Core\REST\Common\Input\BaseParser;
use eZ\Publish\Core\REST\Common\Input\ParsingDispatcher;
use eZ\Publish\Core\REST\Common\Exceptions;
use EzSystems\RESTAPIExtensionExampleBundle\Rest\Values\Hello as HelloValue;

/**
* Class Hello
* @package EzSystems\RESTAPIExtensionExampleBundle\Rest\InputParser
*/
class Hello extends BaseParser
{
/**
* @param array $data
* @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
* @return \EzSystems\RESTAPIExtensionExampleBundle\Rest\Values\Hello
*/
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
{
if (!isset($data['name'])) {
throw new Exceptions\Parser("Missing or ivalid 'name' element for Hello.");
}
return new HelloValue($data['name']);
}
}
27 changes: 27 additions & 0 deletions Rest/ValueObjectVisitor/Hello.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace EzSystems\RESTAPIExtensionExampleBundle\Rest\ValueObjectVisitor;

use eZ\Publish\Core\REST\Common\Output\Generator;
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
use eZ\Publish\Core\REST\Common\Output\Visitor;

/**
* Class Hello
* @package EzSystems\RESTAPIExtensionExampleBundle\Rest\ValueObjectVisitor
*/
class Hello extends ValueObjectVisitor
{
/**
* @param \eZ\Publish\Core\REST\Common\Output\Visitor $visitor
* @param \eZ\Publish\Core\REST\Common\Output\Generator $generator
* @param mixed $data
*/
public function visit(Visitor $visitor, Generator $generator, $data)
{
$generator->startHashElement("Hello");
$generator->startAttribute("name", $data->name);
$generator->endAttribute("name");
$generator->endHashElement("Hello");
}
}
27 changes: 27 additions & 0 deletions Rest/Values/Hello.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace EzSystems\RESTAPIExtensionExampleBundle\Rest\Values;

use eZ\Publish\API\Repository\Values\ValueObject;

/**
* Class Hello
* @package EzSystems\RESTAPIExtensionExampleBundle\Rest\Values
*/
class Hello extends ValueObject
{
/**
* @var string
*/
public $name;

/**
* Hello constructor.
* @param string $name
*/
public function __construct(string $name)
{
parent::__construct();
$this->name = $name;
}
}

0 comments on commit 05d22e6

Please sign in to comment.