Skip to content

Commit

Permalink
Add: Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminPaap committed Jan 3, 2018
0 parents commit 5dde418
Show file tree
Hide file tree
Showing 15 changed files with 1,009 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Annotation/AbstractAnnotation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Bpa\ApiSandboxBundle\Annotation;

/**
* Class AbstractAnnotation
*/
abstract class AbstractAnnotation
{
/**
* Response constructor.
*
* @param array $attributes
*/
public function __construct(array $attributes)
{
foreach ($attributes as $name => $attribute) {
$setter = 'set'.ucfirst($name);

if (method_exists($this, $setter)) {
$this->$setter($attribute);
}
}
}
}
81 changes: 81 additions & 0 deletions Annotation/SandboxRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Bpa\ApiSandboxBundle\Annotation;

use Bpa\ApiSandboxBundle\Annotation\SandboxRequest\Parameter;
use Doctrine\Common\Annotations\Annotation;

/**
* @Annotation
* @Annotation\Target({"METHOD"})
* @Annotation\Attributes({
* @Annotation\Attribute("parameters", type="array<Bpa\ApiSandboxBundle\Annotation\SandboxRequest\Parameter>"),
* @Annotation\Attribute("responses", type="array<Bpa\ApiSandboxBundle\Annotation\SandboxResponse>")
* })
*/
class SandboxRequest extends AbstractAnnotation
{
/**
* @var array
*/
private $parameters = [];

/**
* @var array
*/
private $responses = [];

/**
* @param Parameter $parameter
*
* @return $this
*/
public function addParameter(Parameter $parameter)
{
if (!in_array($parameter, $this->parameters)) {
$this->parameters[] = $parameter;
}

return $this;
}

/**
* @return array|Parameter[]
*/
public function getParameters()
{
return $this->parameters;
}

/**
* @param array $parameters
*
* @return $this
*/
public function setParameters(array $parameters)
{
$this->parameters = $parameters;

return $this;
}

/**
* @return array|SandboxResponse[]
*/
public function getResponses()
{
return $this->responses;
}

/**
* @param array $responses
*
* @return $this
*/
public function setResponses(array $responses)
{
$this->responses = $responses;

return $this;
}
}
174 changes: 174 additions & 0 deletions Annotation/SandboxRequest/Parameter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<?php

namespace Bpa\ApiSandboxBundle\Annotation\SandboxRequest;

use Bpa\ApiSandboxBundle\Annotation\AbstractAnnotation;
use Doctrine\Common\Annotations\Annotation;

/**
* @Annotation
* @Annotation\Attributes({
* @Annotation\Attribute("name", type="string"),
* @Annotation\Attribute("type", type=@Annotation\Enum({Parameter::TYPE_STRING, Parameter::TYPE_INTEGER, Parameter::TYPE_ARRAY})),
* @Annotation\Attribute("required", type="boolean"),
* @Annotation\Attribute("children", type="array<Parameter>"),
* @Annotation\Attribute("value", type="mixed"),
* @Annotation\Attribute("format", type="string"),
* })
*/
class Parameter extends AbstractAnnotation
{
const TYPE_STRING = 'string';
const TYPE_INTEGER = 'integer';
const TYPE_ARRAY = 'array';

/**
* @var string
*/
private $name;

/**
* @var string
*/
private $type;

/**
* @var boolean
*/
private $required;

/**
* @var string
*/
private $format;

/**
* @var string
*/
private $value;

/**
* @var array
*/
private $children;

/**
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* @param string $name
*
* @return $this
*/
public function setName($name)
{
$this->name = $name;

return $this;
}

/**
* @return string
*/
public function getType()
{
return $this->type;
}

/**
* @param string $type
*
* @return $this
*/
public function setType($type)
{
$this->type = $type;

return $this;
}

/**
* @return bool
*/
public function isRequired()
{
return $this->required;
}

/**
* @param bool $required
*
* @return $this
*/
public function setRequired($required)
{
$this->required = $required;

return $this;
}

/**
* @return string
*/
public function getFormat()
{
return $this->format;
}

/**
* @param string $format
*
* @return $this
*/
public function setFormat($format)
{
$this->format = $format;

return $this;
}

/**
* @return mixed
*/
public function getValue()
{
return $this->value;
}

/**
* @param mixed $value
*
* @return $this
*/
public function setValue($value)
{
$this->value = $value;

return $this;
}

/**
* @return array
*/
public function getChildren()
{
return $this->children;
}

/**
* @param array $children
*
* @return $this
*/
public function setChildren(array $children)
{
$this->children = $children;

return $this;
}
}
Loading

0 comments on commit 5dde418

Please sign in to comment.