Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
Change visitors to return nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
crisu83 committed Mar 4, 2018
1 parent 4b252ca commit 780e83a
Show file tree
Hide file tree
Showing 35 changed files with 528 additions and 222 deletions.
29 changes: 29 additions & 0 deletions src/Config/ConfigTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,35 @@ public function __construct(array $config = [])
$this->afterConfig();
}

/**
* @param string $key
* @param mixed|null $default
* @return mixed|null
*/
public function getConfigValue(string $key, $default = null)
{
return $this->config[$key] ?? $default;
}

/**
* @param string $key
* @param mixed $value
* @return $this
*/
public function setConfigValue(string $key, $value)
{
$this->config[$key] = $value;
return $this;
}

/**
* @return array
*/
public function getConfig(): array
{
return $this->config;
}

/**
* Override this method to perform logic BEFORE configuration is applied.
* This method is useful for setting default values for properties
Expand Down
10 changes: 10 additions & 0 deletions src/Language/AST/Node/AliasTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@ public function getAliasAsArray(): ?array
{
return null !== $this->alias ? $this->alias->toArray() : null;
}

/**
* @param NameNode|null $alias
* @return $this
*/
public function setAlias(?NameNode $alias)
{
$this->alias = $alias;
return $this;
}
}
14 changes: 12 additions & 2 deletions src/Language/AST/Node/ArgumentsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ trait ArgumentsTrait
{

/**
* @var InputValueDefinitionNode[]
* @var array|ArgumentNode[]
*/
protected $arguments;

Expand All @@ -21,7 +21,7 @@ public function hasArguments(): bool
}

/**
* @return InputValueDefinitionNode[]
* @return array|ArgumentNode[]
*/
public function getArguments(): array
{
Expand All @@ -37,4 +37,14 @@ public function getArgumentsAsArray(): array
return $node->toArray();
}, $this->arguments);
}

/**
* @param array|ArgumentNode[] $arguments
* @return $this
*/
public function setArguments(array $arguments)
{
$this->arguments = $arguments;
return $this;
}
}
10 changes: 10 additions & 0 deletions src/Language/AST/Node/DescriptionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@ public function getDescriptionAsArray(): ?array
{
return null !== $this->description ? $this->description->toArray() : null;
}

/**
* @param StringValueNode|null $description
* @return $this
*/
public function setDescription(?StringValueNode $description)
{
$this->description = $description;
return $this;
}
}
12 changes: 11 additions & 1 deletion src/Language/AST/Node/DirectiveDefinitionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DirectiveDefinitionNode extends AbstractNode implements DefinitionNodeInte

use DescriptionTrait;
use NameTrait;
use ArgumentsTrait;
use InputArgumentsTrait;

/**
* @var string
Expand Down Expand Up @@ -40,6 +40,16 @@ public function getLocationsAsArray(): array
}, $this->locations);
}

/**
* @param array|NameNode[] $locations
* @return $this
*/
public function setLocations(array $locations)
{
$this->locations = $locations;
return $this;
}

/**
* @inheritdoc
*/
Expand Down
14 changes: 1 addition & 13 deletions src/Language/AST/Node/DirectiveNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,10 @@ class DirectiveNode extends AbstractNode implements NodeInterface
{

use NameTrait;
use ArgumentsTrait;

/**
* @var string
*/
protected $kind = NodeKindEnum::DIRECTIVE;

/**
* @var DirectiveNode[]
*/
protected $arguments;

/**
* @return DirectiveNode[]
*/
public function getArguments(): array
{
return $this->arguments;
}
}
10 changes: 10 additions & 0 deletions src/Language/AST/Node/DirectivesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@ public function getDirectivesAsArray(): array
// TODO: Implement this method.
return [];
}

/**
* @param array|DirectiveNode[] $directives
* @return $this
*/
public function setDirectives(array $directives)
{
$this->directives = $directives;
return $this;
}
}
10 changes: 10 additions & 0 deletions src/Language/AST/Node/DocumentNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ public function getDefinitionsAsArray(): array
}, $this->definitions);
}

/**
* @param array|DefinitionNodeInterface[] $definitions
* @return DocumentNode
*/
public function setDefinitions($definitions)
{
$this->definitions = $definitions;
return $this;
}

/**
* @inheritdoc
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Language/AST/Node/EnumValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class EnumValueNode extends AbstractNode implements ValueNodeInterface
{

use ValueLiteralTrait;
use ValueTrait;

/**
* @var string
Expand Down
10 changes: 10 additions & 0 deletions src/Language/AST/Node/EnumValuesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,14 @@ public function getValuesAsArray(): array
return $node->toArray();
}, $this->values);
}

/**
* @param array|EnumValueDefinitionNode[] $values
* @return $this
*/
public function setValues(array $values)
{
$this->values = $values;
return $this;
}
}
2 changes: 1 addition & 1 deletion src/Language/AST/Node/FieldDefinitionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class FieldDefinitionNode extends AbstractNode implements DefinitionNodeInterfac

use DescriptionTrait;
use NameTrait;
use ArgumentsTrait;
use InputArgumentsTrait;
use TypeTrait;
use DirectivesTrait;

Expand Down
10 changes: 10 additions & 0 deletions src/Language/AST/Node/FieldsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,14 @@ public function getFieldsAsArray(): array
return $node->toArray();
}, $this->fields);
}

/**
* @param array|FieldDefinitionNode[] $fields
* @return $this
*/
public function setFields(array $fields)
{
$this->fields = $fields;
return $this;
}
}
50 changes: 50 additions & 0 deletions src/Language/AST/Node/InputArgumentsTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Digia\GraphQL\Language\AST\Node;

use Digia\GraphQL\Util\SerializationInterface;

trait InputArgumentsTrait
{

/**
* @var InputValueDefinitionNode[]
*/
protected $arguments;

/**
* @return bool
*/
public function hasArguments(): bool
{
return !empty($this->arguments);
}

/**
* @return InputValueDefinitionNode[]
*/
public function getArguments(): array
{
return $this->arguments ?? [];
}

/**
* @return array
*/
public function getArgumentsAsArray(): array
{
return array_map(function (SerializationInterface $node) {
return $node->toArray();
}, $this->arguments);
}

/**
* @param array|InputValueDefinitionNode[] $arguments
* @return $this
*/
public function setArguments(array $arguments)
{
$this->arguments = $arguments;
return $this;
}
}
10 changes: 10 additions & 0 deletions src/Language/AST/Node/InputFieldsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,14 @@ public function getFieldsAsArray(): array
return $node->toArray();
}, $this->fields);
}

/**
* @param array|InputValueDefinitionNode[] $fields
* @return $this
*/
public function setFields(array $fields)
{
$this->fields = $fields;
return $this;
}
}
10 changes: 10 additions & 0 deletions src/Language/AST/Node/InterfacesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,14 @@ public function getInterfacesAsArray(): array
return $node->toArray();
}, $this->interfaces);
}

/**
* @param array|NamedTypeNode[] $interfaces
* @return $this
*/
public function setInterfaces(array $interfaces)
{
$this->interfaces = $interfaces;
return $this;
}
}
10 changes: 10 additions & 0 deletions src/Language/AST/Node/ListValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ public function getValuesAsArray(): array
}, $this->values);
}

/**
* @param array|ValueNodeInterface[] $values
* @return $this
*/
public function setValues(array $values)
{
$this->values = $values;
return $this;
}

/**
* @inheritdoc
*/
Expand Down
10 changes: 10 additions & 0 deletions src/Language/AST/Node/NameTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@ public function getNameAsArray(): ?array
{
return null !== $this->name ? $this->name->toArray() : null;
}

/**
* @param NameNode|null $name
* @return $this
*/
public function setName(?NameNode $name)
{
$this->name = $name;
return $this;
}
}
21 changes: 21 additions & 0 deletions src/Language/AST/Node/ObjectValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Digia\GraphQL\Language\AST\Node;

use Digia\GraphQL\Language\AST\NodeKindEnum;
use Digia\GraphQL\Util\SerializationInterface;

class ObjectValueNode extends AbstractNode implements ValueNodeInterface
{
Expand All @@ -24,4 +25,24 @@ public function getFields(): array
{
return $this->fields;
}

/**
* @return array
*/
public function getFieldsAsArray(): array
{
return array_map(function (SerializationInterface $node) {
return $node->toArray();
}, $this->fields);
}

/**
* @param array $fields
* @return $this
*/
public function setFields(array $fields)
{
$this->fields = $fields;
return $this;
}
}
Loading

0 comments on commit 780e83a

Please sign in to comment.